简体   繁体   English

JVM堆栈内存

[英]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. 我们的Java开发人员有时会使用java -Xss 1M来确保我们为线程特有的每个堆栈提供1 MB的空间。 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. 现在,我常常感到困惑,在哪里JVM从堆或系统内存中借用了1 MB,或者JVM是否为线程分配了特定的内存。 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 ? JVM在哪里从堆或系统内存中借用了1 MB?

The JVM "borrows" the stack memory from the operating system so maybe this is what you are calling "system memory". JVM从操作系统“借用”堆栈内存,因此也许这就是您所说的“系统内存”。 The JVM actually makes requests from the OS' virtual memory system for blocks of memory that it uses as thread stack space. JVM实际上从OS的虚拟内存系统发出请求,要求将其用作线程堆栈空间的内存块。 All of the memory that the JVM uses (code, stack, heap, etc.) is requested from the OS in the same manner. 操作系统以相同的方式请求JVM使用的所有内存(代码,堆栈,堆等)。 Stack memory is separate from heap memory which is managed by the JVM itself. 堆栈内存与由JVM本身管理的堆内存是分开的。

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? 有关如何划分JVM内存的更多信息,请查看以下答案: java内存池如何划分?

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 . 最后,关于JVM各个部分正在使用多少内存的概述,您也可以使用jconsole

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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