简体   繁体   English

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

[英]Which arguments stand for what in JVM memory options?

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 (eg OutOfMemoryError , StackOverflowError ...)? 当我得到什么错误时,我必须增加哪一个(例如OutOfMemoryErrorStackOverflowError ...)?

I cannot find a good cheat sheet for them - let's create one here. 我找不到一个好的备忘单 - 让我们在这里创建一个。

-Xms: this option sets the initial and minimum Java heap size. -Xms:此选项设置初始和最小Java堆大小。

-Xmx: This option sets the maximum Java heap size. -Xmx:此选项设置最大Java堆大小。 The Java heap (the “heap”) is the part of the memory where blocks of memory are allocated to objects and freed during garbage collection. Java堆(“堆”)是内存的一部分,其中内存块分配给对象并在垃圾回收期间释放。

-XX:PermSize: -XX:MaxPermSize: are used to set size for Permanent Generation. -XX:PermSize: -XX:MaxPermSize:用于设置永久生成的大小。 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). 永久空间是存储类,方法,内化字符串和VM使用的类似对象的地方,永远不会被释放(因此名称)。

-Xss: sets the thread stack size. -Xss:设置线程堆栈大小。 Thread stacks are memory areas allocated for each Java thread for their internal use. 线程堆栈是为每个Java线程分配的内存区域,供内部使用。 This is where the thread stores its local execution state. 这是线程存储其本地执行状态的位置。

-Xns: sets the nursery size. -Xns:设置托儿所的大小。 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. 当使用分代垃圾收集模型时,JRockit JVM使用托儿所,也就是说,当动态垃圾收集器确定应该使用分代垃圾收集模型时或者静态分代并发垃圾收集器(-Xgc:gencon)已经使用时选择。 You can also use -Xns to set a static nursery size when running a dynamic garbage collector (-XgcPrio). 您还可以在运行动态垃圾收集器(-XgcPrio)时使用-Xns设置静态托儿所大小。

  • If you are getting java.lang.OutOfMemoryError: Java heap space than change the value of -Xmx and -Xms . 如果你得到java.lang.OutOfMemoryError: Java heap space比改变-Xmx-Xms的值。

  • if you are getting java.lang.OutOfMemoryError: PermGen space than try increasing the - XX:MaxPermSize value. 如果你得到java.lang.OutOfMemoryError: PermGen space不是尝试增加- XX:MaxPermSize值。

  • if you are getting java.lang.StackOverflowError than try increasing the -Xss value. 如果你得到java.lang.StackOverflowError不是尝试增加-Xss值。 It may be helpful by increasing the stack size but you should have a look at your code as well. 通过增加堆栈大小可能会有所帮助,但您也应该查看代码。

There are hundreds of JVM options available. 有数百种JVM选项可供选择。 Basically they are classified into three types: 基本上它们分为三种类型:

  1. Standard Options, 标准选项,
  2. Non-standard X options, 非标准X选项,
  3. Non-standard XX options, 非标准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 . 如果您想增强您对JVM选项的了解,请参阅此博客 The link is just part 1 out of 8. Find out and read other parts as well. 链接只是第8部分中的第1部分。查找并阅读其他部分。

-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. 永久生成是特殊的,因为它包含虚拟机所需的数据,以描述在Java语言级别上没有等价的对象。 For example objects describing classes and methods are stored in the permanent generation. 例如,描述类和方法的对象存储在永久代中。

You usually run out of permgen space if you are somehow leaking references to classes you load dynamically. 如果你以某种方式泄漏对动态加载的类的引用,通常会耗尽permgen空间。 This plagues some web containers in particular. 这特别困扰了一些网络容器。

Read JVM options explained . 阅读JVM选项说明 Here're excerpts from it: 以下是摘录:

  • If you are frequently recieving java.lang.OutOfMemoryError: Java heap space errors you should increase -Xmx value. 如果您经常收到java.lang.OutOfMemoryError: Java heap space错误,您应该增加-Xmx值。
  • Normally -XX:PermSize and -XX:MaxPermSize do not need to be adjusted but if you are seeing java.lang.OutOfMemoryError: PermGen space events often you can increase these values. 通常-XX:PermSize-XX:MaxPermSize不需要调整,但如果您看到java.lang.OutOfMemoryError: PermGen space事件通常可以增加这些值。
  • -XX:MaxJavaStackTraceDepth - This specifies how many entries a stack trace for a thrown error or exception can have before a StackOverflowError is thrown. -XX:MaxJavaStackTraceDepth - 指定在抛出StackOverflowError之前抛出的错误或异常的堆栈跟踪的条目数。 So if you are dealing with huge stack traces you can use this option to increase the allowed entriers before overflow. 因此,如果您正在处理大量堆栈跟踪,则可以使用此选项在溢出之前增加允许的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM