JVM 堆栈、堆和线程如何映射到物理内存或操作系统 [英] How JVM stack, heap and threads are mapped to physical memory or operation system

查看:28
本文介绍了JVM 堆栈、堆和线程如何映射到物理内存或操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译器书(The Dragon Book)解释了值类型是在栈上创建的,引用类型是在堆上创建的.

The compiler book(The dragon book) explains that value types are created on the stack, and reference types are created on the heap.

对于 Java,JVM 还包含运行时数据区中的堆和栈.对象和数组在堆上创建,方法帧被推送到堆栈.一个堆由所有线程共享,而每个线程都有自己的堆栈.下图显示了这一点:

For Java, JVM also contains heap and stack in runtime data area. Objects and arrays are created on heap, method frames are pushed to stack. One heap is shared by all threads, while each thread has its own stack. The following diagram shows this:

更多关于 Java 运行时数据区.

我不明白的是,既然 JVM 本质上是一个软件,那么那些 JVM 堆、堆栈和线程是如何映射到物理机上的?

What I don't understand is that since JVM is essentially a software, how are those JVM heap, stack and threads mapped to physical machine?

如果有人可以比较 Java 和 C++ 之间的这些概念,我将不胜感激.因为 Java 在 JVM 上运行,而 C++ 不是.

I would appreciate it if someone can compare those concept between Java and C++. Because Java runs on JVM, but C++ does not.

为了让这个问题更准确,我想知道以下内容:

To make this question more precise, I want to know the following:

  1. 与 Java 相比,C++ 运行时数据区是什么样的?图片会很有帮助,我找不到像上面的 JVM 那样的好图片.
  2. JVM 堆、堆栈、寄存器和线程如何映射到操作系统?或者我应该问它们如何映射到物理机?
  3. 每个 JVM 线程都只是一个用户线程并以某种方式映射到内核,这是真的吗?(用户线程 vs 内核线程)

更新:我为进程的运行时物理内存绘制了一张图片.

Update: I draw a picture for runtime physical memory of a process.

推荐答案

我不明白的是,既然 JVM 本质上是一个软件,那么那些 JVM 堆、栈和线程是如何映射到物理机上的?

What I don't understand is that since JVM is essentially a software, how are those JVM heap, stack and threads mapped to physical machine?

堆是预先分配的连续虚拟内存区域.例如

The heap is a pre-allocated continuous region of virtual memory. e.g.

 void* heap = malloc(Xmx); // get the maximum size.

堆栈是在线程启动时由线程库分配的.同样,它是一个连续的虚拟内存区域,它是最大堆栈大小.同样,您可以将其视为

The stacks are allocated by the threading library when the thread is started. Again it is a continuous region of virtual memory which is the maximum stack size. Again you could think of it as

 void* stack = malloc(Xss); // get the maximum stack size.

本机线程是操作系统特性,不属于 JVM 空间.

Native threads are OS features which are not part of the JVM space as such.

因为 Java 在 JVM 上运行,而 C++ 不在.

Because Java runs on JVM, but C++ does not.

C++ 仍然需要运行时环境和库来启动.尝试删除您的 C++ 运行时或 libc,它们将无法启动.

C++ still needs a runtime environment and libraries to start up. Try deleting your C++ Runtime or libc and these won't start.

与Java相比,C++运行时数据区是什么样的?

Comparing with Java, What does C++ run-time data area look like?

您可以使用一大块虚拟内存.没有图片,因为它不会告诉你太多.想象一个标记为用户空间的长矩形.

There is one large region of virtual memory you can use. There isn't a picture because it wouldn't tell you much. Imagine one long rectangle labelled user space.

JVM 堆、栈、寄存器和线程是如何映射到操作系统的?或者我应该问他们如何映射到物理机?

How the JVM heap, stack, registers and threads are mapped to operating system? or I should ask how they are mapped to physical machine?

同样没有魔法.JVM 堆是一个内存区域,JVM 堆栈与 C+ 使用的本机堆栈相同,JVM 的寄存器与 C+ 使用的本机寄存器相同,JVM 线程实际上是 C+ 使用的本机线程.

Again there is no magic. The JVM heap is a region of memory, a JVM stack is the same a native stack which is what C+ uses, the JVM's registers is the same as native registers which is what C+ uses and JVMs thread are actually native threads which is what C+ uses.

我认为您假设有比实际更多的魔法或默默无闻.相反,您应该假设已经使用了最简单、高效和轻量级的设计,并且离您不远了.

I think you are assuming there is more magic or obscurity going on than there is. Instead you should assume that the simplest, efficient and lightweight design has been used and you won't be far off.

我想问一下它们是如何映射到物理机上的?

I should ask how they are mapped to physical machine?

基本上是一对一.

这篇关于JVM 堆栈、堆和线程如何映射到物理内存或操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆