什么是给jvm的线程堆栈大小选项(-Xss)?为什么Windows PC中至少有68k的限制? [英] What is thread stack size option(-Xss) given to jvm? Why does it have a limit of atleast 68k in a windows pc?

查看:169
本文介绍了什么是给jvm的线程堆栈大小选项(-Xss)?为什么Windows PC中至少有68k的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过 JVM选项-Xss - 它究竟做了什么?这个链接,但我的问题是这个选项是如何有用的。

I have seen JVM option -Xss - What does it do exactly? this link, but my question is how is this option useful.

因为,如果我们为-Xss值设置了一个非常小的限制,那么线程可能无法正常工作,因为它可能会在大多数情况下抛出stackOverflow错误。

Because, if we set a very minimum limit to the -Xss value, maybe the threads are not going to work properly as it may throw stackOverflow error most of the times.

为什么至少对于这个值有 64k 限制?

我如何得到这个64k限制是当我我试图在IntelliJ iDE上配置运行时vm选项,我试图给出一些像10k这样的东西,它弹出这个错误,说它需要至少64k的线程堆栈大小。

Why is there a 64k limit at least for this value?
How i got this 64k limit is when i was trying to configure the runtime vm options on the IntelliJ iDE, I tried to give some thing like 10k and it popped up this error stating it needs at least 64k for thread stack size.

另一个问题是,如何从java程序中找到我的嵌入式设备中运行的jvm的默认线程堆栈大小?

Another question is that, how to find the default thread stack size of my jvm running in my embedded device from a java program?

谢谢,

Sen

Thanks,
Sen

推荐答案

-Xss 允许根据应用程序需求配置Java线程堆栈大小:

-Xss allows to configure Java thread stack size according to application needs:


  • 较大的堆栈大小适用于使用递归算法或深度方法调用的应用程序;

  • 较小的堆栈大小适用于运行的应用程序成千上万的线程 - 您可能希望节省线程堆栈占用的内存。

  • larger stack size is for an application that uses recursive algorithms or otherwise deep method calls;
  • smaller stack size is for an application that runs thousands of threads - you may want to save memory occupied by thread stacks.

请记住,HotSpot JVM也使用相同的Java线程用于本机方法和JVM运行时调用的堆栈(例如,类加载)。这意味着Java线程堆栈不仅用于Java方法,而且JVM也应为其自己的操作保留一些堆栈页面。

Bear in mind that HotSpot JVM also utilizes the same Java thread stack for the native methods and JVM runtime calls (e.g. class loading). This means Java thread stack is used not only for Java methods, but JVM should reserve some stack pages for its own operation as well.

所需的最小堆栈大小由公式:

The minimum required stack size is calculated by the formula:

(StackYellowPages + StackRedPages + StackShadowPages + 2*BytesPerWord + 1) * 4096

其中


  • StackYellowPages StackRedPages 是检测和处理StackOverflowError所必需的;

  • StackShadowPages 保留用于本机方法;

  • 2 * 4(32位JVM)或2 * 8(64位JVM)用于VM运行时函数;

  • 额外1用于主线程中的JIT编译器递归;

  • 4096是默认页面大小。

  • StackYellowPages and StackRedPages are required to detect and handle StackOverflowError;
  • StackShadowPages are reserved for native methods;
  • 2*4 (32-bit JVM) or 2*8 (64-bit JVM) is for VM runtime functions;
  • extra 1 is for JIT compiler recursion in main thread;
  • 4096 is the default page size.

例如对于32位Windows JVM最小堆栈大小=(3 + 1 + 4 + 2 * 4 + 1)* 4K = 68K

E.g. for 32-bit Windows JVM minimum stack size = (3 + 1 + 4 + 2*4 + 1) * 4K = 68K

BTW,您可以减少所需的最小值使用这些JVM选项的堆栈大小:(不推荐!)

BTW, you may reduce the minumum required stack size using these JVM options: (not recommended!)

-XX:StackYellowPages=1 -XX:StackRedPages=1 -XX:StackShadowPages=1

这篇关于什么是给jvm的线程堆栈大小选项(-Xss)?为什么Windows PC中至少有68k的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆