where is the Java stack allocated?

java

Solution

The answer is:

It is implementation dependent.

In the implementation I looked at, the thread stack allocation was handled by the standard C native thread library, and it looked like the library was going to the OS to allocate a memory segment for the stack. So "none of the above".

You can confirm this by delving into the OpenJDK source code relevant to your platform.

UPDATE

From an old question, here is the snippet of code from `pthread_create` that requests the allocation of the thread stack. This method used by the JVM thread implementation to create the native thread.

 mmap(0, attr.__stacksize, 
     PROT_READ|PROT_WRITE|PROT_EXEC, 
     MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)

As you can see, it just uses the `mmap` system call to request a memory segment from the operating system. As I said in a comment, this is NOT the regular Java heap, NOT the Permgen heap, and NOT the C native heap. It is a segment of memory specifically requested from the operating system.

For reference, here's a link to the mmap syscall manual entry.

update: another reference info: For a 64-bit VM, the C-Heap capacity = Physical server total RAM & virtual memory – Java Heap - PermGen

IMO, that is an oversimplification. (And please provide a link to where you found this information ... so that we can read it in its original form.)

Problem

I have noted the following from a website: The JVM HotSpot memory is split between 3 memory spaces: - The Java Heap - The PermGen (permanent generation) space - The Native Heap (C-Heap) Where is the stack allocated in hotSpot JVM? In native heap? update: another reference info: For a 64-bit VM, the C-Heap capacity = Physical server total RAM & virtual memory – Java Heap - PermGen

Original source