Java 哪些参数代表 JVM 内存选项中的内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19864293/
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-08-12 20:50:12  来源:igfitidea点击:

Which arguments stand for what in JVM memory options?

javajvmjvm-arguments

提问by Francois Bourgeois

There a lot of JVM arguments that affect the JVM's memory usage like -Xms, -Xmx, -Xns, -XX:MaxPermSize...

有很多 JVM 参数会影响 JVM 的内存使用,例如 -Xms, -Xmx, -Xns, -XX:MaxPermSize...

  • What do they do?
  • Are there any more?
  • Which one do I have to increase when I get what error (e.g. OutOfMemoryError, StackOverflowError...)?
  • 他们在做什么?
  • 还有吗?
  • 当我得到什么错误(例如OutOfMemoryErrorStackOverflowError...)时,我必须增加哪一个?

I cannot find a good cheat sheet for them - let's create one here.

我找不到适合他们的备忘单 - 让我们在这里创建一个。

采纳答案by Trying

-Xms:this option sets the initial and minimum Java heap size.

-Xms:此选项设置初始和最小 Java 堆大小。

-Xmx:This option sets the maximum Java heap size. The Java heap (the “heap”) is the part of the memory where blocks of memory are allocated to objects and freed during garbage collection.

-Xmx:此选项设置最大 Java 堆大小。Java 堆(“堆”)是内存的一部分,其中内存块被分配给对象并在垃圾回收期间被释放。

-XX:PermSize:-XX:MaxPermSize:are used to set size for Permanent Generation. The permanent space is where are stored the class, methods, internalized strings, and similar objects used by the VM and never deallocated (hence the name).

-XX:PermSize:-XX:MaxPermSize:用于设置永久代的大小。永久空间是存储类、方法、内部化字符串和 VM 使用的类似对象的地方,并且永远不会被释放(因此得名)。

-Xss:sets the thread stack size. Thread stacks are memory areas allocated for each Java thread for their internal use. This is where the thread stores its local execution state.

-Xss:设置线程堆栈大小。线程栈是分配给每个 Java 线程供其内部使用的内存区域。这是线程存储其本地执行状态的地方。

-Xns:sets the nursery size. the JRockit JVM uses a nursery when the generational garbage collection model is used, that is, when the dynamic garbage collector has determined that the generational garbage collection model should be used or when the static generational concurrent garbage collector ( -Xgc : gencon) has been selected. You can also use -Xns to set a static nursery size when running a dynamic garbage collector (-XgcPrio).

-Xns:设置托儿所的大小。当使用分代垃圾收集模型时,JRockit JVM 使用托儿所,即当动态垃圾收集器确定应该使用分代垃圾收集模型时,或者当静态分代并发垃圾收集器(-Xgc : gencon)已经被使用时被选中。您还可以在运行动态垃圾收集器 (-XgcPrio) 时使用 -Xns 设置静态 Nurseries 大小。

  • If you are getting java.lang.OutOfMemoryError: Java heap spacethan change the value of -Xmxand -Xms.

  • if you are getting java.lang.OutOfMemoryError: PermGen spacethan try increasing the - XX:MaxPermSizevalue.

  • if you are getting java.lang.StackOverflowErrorthan try increasing the -Xssvalue. It may be helpful by increasing the stack size but you should have a look at your code as well.

  • 如果你得到java.lang.OutOfMemoryError: Java heap space比改变-Xmxand的值-Xms

  • 如果你得到java.lang.OutOfMemoryError: PermGen space比尝试增加- XX:MaxPermSize价值。

  • 如果你得到java.lang.StackOverflowError比尝试增加-Xss价值。增加堆栈大小可能会有所帮助,但您也应该查看您的代码。

回答by Markus Koivisto

-Xss: Stack size.

-Xss:堆栈大小。

Used to set the size of your stack. Stack values only exist within the scope of the function they are created in. Once the function returns, they are discarded.

用于设置堆栈的大小。堆栈值仅存在于创建它们的函数范围内。一旦函数返回,它们将被丢弃。

The easiest way to run out of stack space is to recurse too deep.

耗尽堆栈空间的最简单方法是递归太深。

-Xms, -Xmx: Min and max heap size.

-Xms, -Xmx:最小和最大堆大小。

Used to set the size of your heap. The heap is where you allocate objects. Objects persist until they are garbage collected.

用于设置堆的大小。堆是您分配对象的地方。对象一直存在,直到它们被垃圾回收。

The easiest way to run out of heap space is to allocate something massive.

耗尽堆空间的最简单方法是分配大量的东西。

-XX:MaxPermSize: Permanent generation.

-XX:MaxPermSize:永久代。

The permanent generation is special because it holds data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation.

永久代是特殊的,因为它保存虚拟机所需的数据来描述在 Java 语言级别不具有等效性的对象。例如,描述类和方法的对象存储在永久代中。

You usually run out of permgen space if you are somehow leaking references to classes you load dynamically. This plagues some web containers in particular.

如果您以某种方式泄漏对动态加载的类的引用,则通常会耗尽永久代空间。这尤其困扰着一些 Web 容器。

回答by Karthik Bose

There are hundreds of JVM options available. Basically they are classified into three types:

有数百个 JVM 选项可用。基本上可以分为三类:

  1. Standard Options,
  2. Non-standard X options,
  3. Non-standard XX options,
  1. 标准选项,
  2. 非标准 X 选项,
  3. 非标准 XX 选项,

List of few standard options: [To see complete list execute the command "java" without any option]

几个标准选项的列表:[要查看完整列表,请执行不带任何选项的命令“java”]

 -client       to select the "client" VM
 -server       to select the "server" VM
 -cp <class search path of directories and zip/jar files>
 -classpath <class search path of directories and zip/jar files>
               A ; separated list of directories, JAR archives,
               and ZIP archives to search for class files.
 -D<name>=<value>
               set a system property
 -version      print product version and exit
 -showversion  print product version and continue
 -X            print help on non-standard options`

List of few non-standard X options: [To see complete list execute the command "java -X"]

几个非标准 X 选项的列表:[要查看完整列表,请执行命令“java -X”]

-Xincgc           enable incremental garbage collection
-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size
-Xprof            output cpu profiling data
-Xmixed           mixed mode execution (default)
-Xint             interpreted mode execution only

List of few non-standard XX options: [Complete list available here]

一些非标准 XX 选项的列表:[此处提供完整列表]

-XX:InitialHeapSize=<size>        set initial Java heap size. Same as -Xms<size>.
-XX:MaxHeapSize=<size>            set maximum Java heap size. Same as -Xmx<size>.
-XX:+PrintFlagsFinal              prints all JVM options passed.
-XX:+UnlockDiagnosticVMOptions    opens up lot more VM options.

If you want to enhance your knowledge in JVM options, please refer this blog. The link is just part 1 out of 8. Find out and read other parts as well.

如果您想增强您在 JVM 选项方面的知识,请参阅此博客。该链接只是 8 个部分中的第 1 部分。找出并阅读其他部分。

回答by naXa

Read JVM options explained. Here're excerpts from it:

阅读JVM 选项解释。以下是它的摘录:

  • If you are frequently recieving java.lang.OutOfMemoryError: Java heap spaceerrors you should increase -Xmxvalue.
  • Normally -XX:PermSizeand -XX:MaxPermSizedo not need to be adjusted but if you are seeing java.lang.OutOfMemoryError: PermGen spaceevents often you can increase these values.
  • -XX:MaxJavaStackTraceDepth- This specifies how many entries a stack trace for a thrown error or exception can have before a StackOverflowErroris thrown. So if you are dealing with huge stack traces you can use this option to increase the allowed entriers before overflow.
  • 如果您经常收到java.lang.OutOfMemoryError: Java heap space错误,您应该增加-Xmx价值。
  • 通常情况下-XX:PermSize,并-XX:MaxPermSize没有需要调整,但如果你看到java.lang.OutOfMemoryError: PermGen space事件的时候,你可以增加这些值。
  • -XX:MaxJavaStackTraceDepth- 这指定在抛出 a 之前抛出的错误或异常的堆栈跟踪可以包含多少个条目StackOverflowError。因此,如果您正在处理大量堆栈跟踪,您可以使用此选项在溢出之前增加允许的入口。