分配给线程的堆栈内存从哪里来?
我对 java GC 和内存管理有几个问题。
在java中,我们通过xmx和xms参数定义进程内存上限和下限。 JVM 使用这些参数分配 young old 和 perm 空间。那么,如果创建了新线程,那么堆栈内存将从哪些内存分配给线程?是来自烫发空间还是其他空间?
另外类的静态变量分配到哪个空间young、old或perm空间? (我猜是烫发?)
XmX 参数是否限制了 young + old gen 或 young + old + perm gen 或 young + old + perm + 堆栈大小?
谢谢
I have few questions regarding java GC and memory management.
In java we define process memory upper bound and lower bound by xmx and xms parameters. Using these parameters JVM allocates young old and perm space. So if new threads are created then from which memory do stacks memory is allocated to threads? is it from perm space or any other space?
Also static variables of class is allocated to which space young, old or perm space? (I guess perm?)
Does XmX paramenter bounds the young + old gen OR young + old+ perm gen OR young + old + perm + stack size ??
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上,堆栈内存来自堆栈区域,独立于堆区域和perm
区域。
静态变量在堆中分配,字符串和数字常量除外。
-Xmx
参数仅限制堆的年轻+旧部分,因为 Perm 区域不属于其中。堆栈区域大小由
-Xss
标志设置,堆区域大小由-Xmx
标志设置,永久区域大小由-XX:MaxPermSize
设置>。如果你想深入了解 JVM 内部内存管理,我推荐这个 博客条目。
Basicly, stack memory comes from stack area, which is independent from heap area and perm
area.
Static variables are allocated in the heap, except string and numeric constants.
-Xmx
parameter only bounds the young + old parts of the heap, as perm area is not part of it.Stack area size is set by
-Xss
flag, heap area size is set by-Xmx
flag and perm area size is set by-XX:MaxPermSize
.If you want to dive into JVM internal memory management I recommend this blog entry.
线程堆栈空间由另一个选项-Xss控制。 此处是有关此特定主题的参考资料,可能会对您有所帮助。
The thread stack space is controlled by another option -Xss. Here is a reference that might help you which is on this particular topic.
在Solaris 上,您可以使用“ulimit -a”来查看进程的堆栈限制。我认为线程堆栈是从此资源中获取的。我想知道当堆中有足够的空间用于线程但没有足够的空间用于堆栈时,JVM 是否会发出垃圾回收。
on solaris you can use 'ulimit -a' to see the stack limit of processes. I think that the threads stack is taken from this resource. I am wondering if the JVM will issue garbage collection when there is enough space in the heap for the threads, but not enough space for their stack.