Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the parameters of JVM

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the parameters of JVM". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the parameters of JVM".

Garbage collection policy:

Three modes of garbage collection:

Serial GC

Serial collection: suitable for limited memory, slow recovery.

Parallel GC

Parallel collection: high efficiency, when the Heap is larger, the system pause time is longer.

CMS GC

Concurrent collection: the recovery pause time in Old area is short, the whole GC takes a long time, and consumes CPU resources.

Parameters:

Serial GC:

-XX:+UseSerialGC uses serial collection mode, even if Serail + Serail Old is used for recycling. The default option for virtual machines to run in client mode.

Parallel GC:

-XX:+UseParallelGC uses Parallel Scavenge + Serail Old for recycling. The default option for virtual machines to run in server mode.

-XX:+UseParNewGC uses ParNew + Serial Old for recycling. Set the new generation collector as ParNew collector (parallel collector). This setting is off by default, and when the switch is turned on, jvm uses ParNew + Serial Old to gc.

-the number of collection threads in the XX:ParallelGCThreads ParNew collector is the same as the number of CPU by default.

-XX:+UseParallelOldGC uses Parallel Scavenge + ParallelOld for recycling.

CMS GC:

-XX:+UseConcMarkSweepGC uses ParNew + CMS collector (use Serial Old collector after concurrent collection failure (Concurrent Mode Failure))

-XX:+CMSParallelRemarkEnabled enables parallel remark to reduce the time it takes for programs to be paused during remark.

-XX:CMSInitiatingOccupancyFraction=70 when 70% of the space in the old days is occupied, the CMS collector starts gc.

1 > JVM collects run-time data allocated and released by objects, and analyzes the data to determine when a gc should be done (that is, start a CMS garbage collector).

2 > to guide this process, JVM does some clue lookup before starting the CMS collector, which is set by-XX:CMSInitiatingOccupancyFraction, which indicates the usage of the old age.

-XX:+UseCMSInitiatingOccupancyOnly commands JVM not to judge when to start gc based on the data collected at run time, but to determine whether to do CMS collection based on the value of CMSInitiatingOccupancyFraction. Note: this switch is not usually turned on.

When gc, the XX:+UseCMSCompactAtFullCollection CMS collector allows compression of the old age to solve the problem of memory fragmentation caused by the mark-clear algorithm.

-how many times after the XX:CMSFullGCsBeforeCompaction=0 CMS collector gc, the memory is compressed (demarcated). Because the CMS collector uses the mark-clear algorithm, the CMS will produce memory fragments after gc, which reduces the running efficiency.

-XX:+CMSClassUnloadingEnabled enables the CMS collector to gc the permanent generation (gc is not performed on the permanent generation by default).

-XX:CMSInitiatingPermOccupancyFraction sets the gc that triggers the CMS collector when the ratio reached by the permanent generation is used

-XX:+DisableExplicitGC forbids System.gc () to avoid the adverse impact on system performance caused by improper calls by developers to the System.gc () method.

-Xnoclassgc disables class garbage collection, which avoids loading, unloading, and reloading of the same class (when the class is used again), resulting in higher performance.

1 > operations such as IO and memory allocation are included in the process of loading classes by virtual machines, so JVM will have a certain impact on performance when loading classes.

-XX:+UseFastAccessorMethods optimizes the performance of the original type of getter method, which is enabled by default.

-XX:+PrintClassHistogram encounters Ctrl+Break interrupt and prints column information of class instance, which has the same function as jmap-histo.

-XX:SoftRefLRUPolicyMSPerMB=0 sets the lifetime of soft references (SoftReference) per megabyte of free space, with a default value of 1 (seconds).

1 > softly reachable objects will remain alive for some amount of time after the last time they were referenced. The default value is one second of lifetime per free megabyte in the heap.

2 > SoftReference is only recycled at gc, so the actual survival time of SoftReference may be larger than this set value.

3 > in general, it is recommended to set it to 0.

Auxiliary information:

-XX:+PrintGCDetails prints the details of GC

-XX:+PrintGCTimeStamps prints the timestamp of the GC

-XX:+PrintHeapAtGC prints details of the stack before and after GC

-Xloggc: sets the log log of gc. Eg:-Xloggc:$CATALINA_BASE/logs/gc.log

Stack:

[heap]

When the initial heap size of-Xms or-XX:InitialHeapSize is less than 40% of the default free heap memory (the MinHeapFreeRatio parameter can be adjusted), JVM increases the maximum limit of the heap up to-Xmx.

-Xmx or-XX:MaxHeapSize maximum heap size, when the default free heap memory is greater than 70% (the MaxHeapFreeRatio parameter can be adjusted), JVM reduces the minimum limit of the heap up to-Xms.

-Xmn Cenozoic size:

1 > the larger the new generation, the more objects will be recycled during the minor GC. If you set it too large, the old age will become smaller, and Full GC or even OOM may be triggered frequently.

2 > if the setting of the new generation is too small, it will cause minor GC to become more frequent, which in turn will cause more objects to enter the old era directly. When the space already used in the old era reaches a certain proportion, Full GC will be triggered.

-XX:NewSize sets the Cenozoic size

-the ratio of the maximum capacity of the Cenozoic (Eden+2 Survivor) to the maximum capacity of the old era is 2 by default, that is, NewSize: OldSize = 1:2 Note: the value of this parameter = the maximum capacity of the old era / the maximum capacity of the Cenozoic era.

Eg:jstat-gccapacity PID # can be verified by viewing NGCMX and OGCMN.

-XX:SurvivorRatio sets the ratio of Eden to 1 Survivor. The default is 8, that is, Eden: Survivor1: Survivor2 = 8:1:1

1 > the larger the Eden, the lower the frequency of minor GC. If the Eden is set too large and the Survivor is too small, it will cause the object to be recycled to enter the old age directly after minor GC, thus triggering Full GC more frequently.

[stack]

-Xss the stack size of each thread:

1 > under the same physical memory: decreasing this value can generate more threads, but the operating system has a limit on the number of threads in a process and cannot be generated indefinitely (it is said on the Internet that it is about 3k-5k, and it has not been tested).

2 > generally small systems, if the stack is not very deep, 128k is enough, while larger systems should be set to 256k.

After 3 > jdk5, the stack size of each thread defaults to 1m.

[permanent generation]

-XX:PermSize sets the initial value of permanent generation

-XX:MaxPermSize sets the maximum persistent generation

[other]

-XX:+TraceClassLoading tracks the information of class loading and unloading. We usually add this parameter when troubleshooting memory leaks, jar package version conflicts and other problems.

-XX:-OmitStackTraceInFastThrow

Description:

After jdk1.5, in order to improve performance, when JVM is running in Server mode, the compiler (C2) will recompile the method when some exception is thrown many times in a specific place in the code. After recompilation, if the exception occurs again, it will throw an exception with no call stack prepared in advance. The default optimization can be disabled with-XX:-OmitStackTraceInFastThrow.

Official:

The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions.

For performance purposes, when such an exception is thrown a few times, the method may be recompiled.

After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace.

-XX:LargePageSizeInBytes=128 sets the size of memory pages

-maximum age of XX:MaxTenuringThreshold GC

1 > if set to 0, the new generation of objects will enter the old age without going through the Survivor area. For the applications with more objects in the old years, the efficiency can be improved. 2 > if set to a large value, the new generation object will be copied many times in the Survivor area, which can increase the survival time of the object in the new generation and increase the probability that the object will be recycled in the new generation. This parameter is only valid in serial GC.

Domain name resolution:

-Dsun.net.spi.nameservice.provider.1=dns,sun specifies the domain name parser https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

For example: unable to resolve a domain name, reported a java.net.UnknownHostException error

Solution: add the parameter-Dsun.net.spi.nameservice.provider.1=dns,sun at startup

Add:

The relationship between-XX:CMSInitiatingOccupancyFraction and-Xmn:

Reasons for failed memory allocation guarantee (promontion faild):

1) when Minor GC, when copying the surviving objects in eden and survivor from to survivor to, if the survivor to cannot accommodate these objects, then these objects will be promoted to the old age.

2) at this point, if the remaining space in the old era could not accommodate these objects, it would result in a memory allocation guarantee failure (promontion faild), which in turn led to a full gc.

Conclusion: when the new generation and the old era satisfy eden + survivor from

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report