简体   繁体   中英

where is the Java stack allocated?

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

The answer is:

  1. It is implementation dependent.

  2. 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".

  3. 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.)

If you can find access to those things in any which way, the second Sun (or Oracle it is now adays?) will put out a patch quickly.

Being able to access those sorts of things is a HUGE security risk. A lot of systems for big companies used Java. To leave a hole where it is possible to track down allocation space wouldnt be possible.

as above, MMAP will allocate space and return it for the program and space requirements needed. I do a lot of stuff with MMAP almost every day.

Maybe because i think a bit darker in how things can be used (to better protect my systems), pretty sure there would be a hot fix for it to cancel out your work, or you have Team America World Police knocking at your door suspecting you of foul acts, and in the process seize all your equipment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM