Like a JVM stack, heap and threads are displayed in physical memory or operating system

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

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

enter image description here

Learn more about Java Runtime Areas at time .

What I don’t understand is that since the JVM is essentially software, how do these JVM heaps, stack and threads map to the physical machine?

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

To clarify this question, I want to know the following:

  • Comparison with Java, what is the C ++ runtime data area? The image would be useful, I can not find a good picture, such as the JVM, which was higher.
  • How are heap, stack, registers, and JVM threads mapped to the operating system? or should I ask how they compare to a physical machine?
  • Is it true that each JVM thread is just a user thread and somehow maps to the kernel? (user thread vs kernel thread)

Update : I am drawing an image for the physical memory of the process. enter image description here

+42
java c ++ memory jvm runtime
Apr 28 '13 at 14:53 on
source share
2 answers

What I don’t understand is that since the JVM is essentially software, how do these JVM heaps, stack, and threads map to the physical machine?

A heap is a pre-allocated contiguous region of virtual memory. eg.

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

Stacks are allocated by the thread library when the thread starts. Again, this is a contiguous region of virtual memory that is the maximum stack size. Again you might think of it as

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

Native threads are OS features that are not part of the JVM space per se.

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

C ++ still requires a runtime and libraries to run. Try removing C ++ Runtime or libc and they will not start.

Comparison with Java, What does the C ++ runtime data area look like?

There is one large area of ​​virtual memory that you can use. There is no picture because it will not tell you much. Imagine one long rectangular labeled user space.

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

Again there is no magic. The JVM heap is a memory region, the JVM stack is the same native stack that C + uses, the JVM registers are the same as the native registers that C + uses, and the JVMs stream are actually natural threads, which and uses C +.

I think you think there is more magic or obscurity than there is. Instead, you should assume that the simplest, most effective, and lightest design was used and you won't be far away.

I have to ask, how do they appear on a physical machine?

one to one basically.

+31
Apr 28 '13 at 16:58
source share

The JVM (Java Virtual Machine) acts as a run-time mechanism for running Java applications. A JVM is one that actually invokes the main method present in Java code. The JVM is part of the JRE (Java Launcher).

Java applications are called WORA (Write Once Run Everywhere). This means that a programmer can develop Java code on one system and can expect him to work on any other Java system without any adjustment. This is all possible due to the JVM. When we compile the .java file, the .class file (containing bytecode) with the same file name is generated by the Java compiler. This .class file performs various actions when it is run. These steps together describe the entire JVM.

Jvm memory

+1
Dec 07 '17 at 12:35 on
source share



All Articles