简体   繁体   中英

JVM stack memory

We Java developers sometimes use java -Xss 1M to make sure we provide a 1 MB space to each stack that's particular to a thread. Now, I often get confused where JVM borrow that 1 MB from, from heap or system memory or is there any specific memory Java allocates for threads. Can you please help me understanding this?

Also, do we have a visual(plug-in) runtime tool that shows the contents of heap and stacks in an understandable way?

Thanks in advance.

where JVM borrow that 1 MB from, from heap or system memory ?

The JVM "borrows" the stack memory from the operating system so maybe this is what you are calling "system memory". The JVM actually makes requests from the OS' virtual memory system for blocks of memory that it uses as thread stack space. All of the memory that the JVM uses (code, stack, heap, etc.) is requested from the OS in the same manner. Stack memory is separate from heap memory which is managed by the JVM itself.

For more information about how the memory of the JVM is divided, I'd check out this answer: How is the java memory pool divided?

Also, do we have a visual(plug-in) runtime tool that shows the contents of heap and stacks in an understandable way?

If you are talking about the contents of heap memory, then you should lookup information about memory profilers. Here's a good question about that topic . Here's also a good tutorial on the subject . However, I'm not sure these tools will show you the memory in an "understandable way". They are used to locate memory leaks or general object allocation bandwidth issues.

There is no tools that show stack memory since it is allocated based on the call stacks of the various threads and is not organized in a way that is easy to investigate.

Lastly, for an overview of how much memory is being used by the various parts of the JVM, you could use jconsole as well .

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