[英]JVM option -Xss - What does it do exactly?
Each thread in a Java application has its own stack . Java应用程序中的每个线程都有自己的堆栈 。 The stack is used to hold return addresses, function/method call arguments, etc. So if a thread tends to process large structures via recursive algorithms, it may need a large stack for all those return addresses and such. 堆栈用于保存返回地址,函数/方法调用参数等。因此,如果线程倾向于通过递归算法处理大型结构,则可能需要为所有这些返回地址等大量堆栈。 With the Sun JVM, you can set that size via that parameter. 使用Sun JVM,您可以通过该参数设置该大小。
It indeed sets the stack size on a JVM. 它确实在JVM上设置堆栈大小。
You should touch it in either of these two situations: 您应该在以下两种情况中触摸它:
The latter usually comes when your Xss is set too large - then you need to balance it (testing!) 后者通常是在你的Xss设置得太大时 - 然后你需要平衡它(测试!)
Each thread has a stack which used for local variables and internal values. 每个线程都有一个堆栈,用于局部变量和内部值。 The stack size limits how deep your calls can be. 堆栈大小限制了您的呼叫的深度。 Generally this is not something you need to change. 通常,这不是您需要改变的。
If I am not mistaken, this is what tells the JVM how much successive calls it will accept before issuing a StackOverflowError. 如果我没有弄错的话,这就是告诉JVM在发出StackOverflowError之前会接受多少次连续调用。 Not something you wish to change generally. 不是你想要改变的东西。
Add my two cents here, besides what mentioned, we can write a simple demo to show the effect of setting Xss.在这里加上我的两分钱,除了上面提到的,我们可以写一个简单的demo来展示设置Xss的效果。
Generally speaking, it controls the stack size arranged to each thread.一般来说,它控制安排到每个线程的堆栈大小。
public static void main(String[] args) {
try{
recur();
}catch (StackOverflowError e){
System.out.println(depth);
}
}
static int depth = 1;
public static void recur(){
depth++;
recur();
}
After compiling above code, you will see the depth
(the invoke hierachy) grows together with the passed Xss
settings.编译上述代码后,您将看到depth
(调用层次结构)与传递的Xss
设置一起增长。
The output of java -Xss1m com.eugene.Main
is 21638
and the output of java -Xss2m com.eugene.Main
is 48325
at my local machine. The output of java -Xss1m com.eugene.Main
is 21638
and the output of java -Xss2m com.eugene.Main
is 48325
at my local machine.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.