How JVM stack, heap and threads are mapped to physical memory or operation system

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.

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

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

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

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.

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

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?

one to one basically.

Leave a Comment