给jvm的线程堆栈大小选项(-Xss)是什么?为什么它在windows电脑中有至少68k的限制?

时间:2021-06-05 03:00:28

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

我已经看到了JVM选项- xss—它到底做了什么?这个链接,但我的问题是这个选项如何有用。

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 * error most of the times.

因为,如果我们对-Xss值设置一个非常小的限制,那么可能线程不能正常工作,因为它可能会在大多数时候抛出*错误。

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.

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

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

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

Thanks,
Sen

谢谢,森

1 个解决方案

#1


11  

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

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

  • 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.
  • 较小的栈大小适用于运行数千个线程的应用程序——您可能想要保存由线程堆栈占用的内存。

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.

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

The minimum required stack size is calculated by the formula:

最小所需的栈大小由公式计算:

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

where

在哪里

  • StackYellowPages and StackRedPages are required to detect and handle *Error;
  • StackYellowPages和StackRedPages需要检测和处理*Error;
  • StackShadowPages are reserved for native methods;
  • StackShadowPages保留为本地方法;
  • 2*4 (32-bit JVM) or 2*8 (64-bit JVM) is for VM runtime functions;
  • 2*4(32位JVM)或2*8(64位JVM)用于VM运行时函数;
  • extra 1 is for JIT compiler recursion in main thread;
  • 在主线程中,额外的1是JIT编译器的递归;
  • 4096 is the default page size.
  • 4096是默认的页面大小。

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

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

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

顺便说一下,您可以使用这些JVM选项减少minumum所需的堆栈大小:(不推荐!)

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

#1


11  

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

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

  • 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.
  • 较小的栈大小适用于运行数千个线程的应用程序——您可能想要保存由线程堆栈占用的内存。

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.

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

The minimum required stack size is calculated by the formula:

最小所需的栈大小由公式计算:

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

where

在哪里

  • StackYellowPages and StackRedPages are required to detect and handle *Error;
  • StackYellowPages和StackRedPages需要检测和处理*Error;
  • StackShadowPages are reserved for native methods;
  • StackShadowPages保留为本地方法;
  • 2*4 (32-bit JVM) or 2*8 (64-bit JVM) is for VM runtime functions;
  • 2*4(32位JVM)或2*8(64位JVM)用于VM运行时函数;
  • extra 1 is for JIT compiler recursion in main thread;
  • 在主线程中,额外的1是JIT编译器的递归;
  • 4096 is the default page size.
  • 4096是默认的页面大小。

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

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

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

顺便说一下,您可以使用这些JVM选项减少minumum所需的堆栈大小:(不推荐!)

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