java -Xss JVM 选项实际上做了什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38242634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:14:42  来源:igfitidea点击:

What does -Xss JVM option actually do

javajvm

提问by Kevin

From the documentation, -Xss is used to set the stack size of JVM. But I am very confused about this statement.

从文档中,-Xss 用于设置 JVM 的堆栈大小。但我对这个说法感到非常困惑。

In Java, every thread has its own stack. Does the number specified by -Xss:

在 Java 中,每个线程都有自己的堆栈。-Xss 指定的数字是否:

  1. The total memory that can be used as stack by all threads? e.g. If -Xss is set to 256K, all the threads will create their own stack within this 256K of memory.

  2. The size of each stack of a thread. e.g. If -Xss is set to 256K, each thread will have a stack of 256K big. Hence 10 thread will use 2560K altogether.

  1. 可以被所有线程用作堆栈的总内存?例如,如果 -Xss 设置为 256K,则所有线程将在这 256K 内存中创建自己的堆栈。

  2. 线程的每个堆栈的大小。例如,如果 -Xss 设置为 256K,则每个线程将有一个 256K 大的堆栈。因此 10 个线程将总共使用 2560K。

Thank you very much.

非常感谢你。

EDIT:

编辑:

Thanks for your answers. It looks like it is the (2) senario above. -Xss specifies the largest stack size of a particular thread.

感谢您的回答。看起来它是上面的 (2) senario。-Xss 指定特定线程的最大堆栈大小。

Then I have a follow up question: Where will these memory be allocated on?

然后我有一个后续问题:这些内存将分配在哪里?

We can specify the reserved heap memory using -Xmx and -Xms. Will stack be allocated using these reserved memory? Or it is allocated from the native memory directly?

我们可以使用 -Xmx 和 -Xms 指定保留的堆内存。会使用这些保留的内存分配堆栈吗?还是直接从本机内存分配?

回答by M Anouti

It's the size of the stack per thread, quoting this page on the java command:

这是每个线程的堆栈大小,在 java 命令中引用此页面

-Xsssize

Sets the thread stack size (in bytes)...

-Xss大小

设置线程堆栈大小(以字节为单位)...

So it's the second part in your question. However I don't think it is generally accurate to sum up all thread stack sizes. Depending on the JVM implementation, the actual total stack size may not be 2560K. Note this quote from the JVM spec:

所以这是你问题的第二部分。但是,我认为总结所有线程堆栈大小通常是不准确的。根据 JVM 实现,实际的总堆栈大小可能不是 2560K。请注意 JVM 规范中的引用:

This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the Java Virtual Machine stacks are of a fixed size, the size of each Java Virtual Machine stack may be chosen independently when that stack is created.

该规范允许 Java 虚拟机堆栈具有固定大小或根据计算需要动态扩展和收缩。如果 Java 虚拟机堆栈的大小是固定的,那么在创建该堆栈时可以独立选择每个 Java 虚拟机堆栈的大小。

回答by Peter Lawrey

Each thread has its own stack. Most JVMs use native threads and these stacks use native virtual memory. The advantage of using virtual memory is only the pages touched turn into memory used.

每个线程都有自己的堆栈。大多数 JVM 使用本机线程,而这些堆栈使用本机虚拟内存。使用虚拟内存的好处是只有接触过的页面才会变成使用过的内存。

Where will these memory be allocated on?

这些内存将分配到哪里?

Native memory like threads stack in a C program would.

像 C 程序中的线程堆栈这样的本机内存会。

We can specify the reserved heap memory using -Xmx and -Xms. Will stack be allocated using these reserved memory?

我们可以使用 -Xmx 和 -Xms 指定保留的堆内存。会使用这些保留的内存分配堆栈吗?

The stacks don't use the heap so, no.

堆栈不使用堆,所以,不。

Or it is allocated from the native memory directly?

还是直接从本机内存分配?

yes.

是的。