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

查看:1002
本文介绍了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线程只是一个用户线程,并以某种方式映射到内核? (用户线程与内核线程)

更新


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线程,而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天全站免登陆