GC parameter Introduction

Source: Internet
Author: User
Tags print format jconsole java throws

Author: Ken Wu

Email: ken.wug@gmail.com

Reprint this document please indicate the original link http://kenwublog.com/docs/java6-jvm-options-chinese-edition.htm!

 

This article is based on the latest SUN official documentation Java SE 6 Hotspot VM Options. This section describes the non-steady-state options in JVM and their usage instructions.

In order to let readers understand the meaning of each option, the author builds on the original articleSupplemented with a large amount of information. I hope this document will be helpful to anyone who is studying JVM parameters!

 

In addition, considering that this document is the first draft, please correct me if any description is incorrect.

 

Usage of non-steady state options

-XX: + <option> enable option

-XX:-<option> disable option

-XX: <option >=< number> set a numeric value for the option, which can be followed by the Unit, such as 32 k, 1024 m, 2g
-XX: <option >=< string> set a string value for the option, for example,-XX: HeapDumpPath =./dump. core

 

Behavior options

Option

Default and limit

Description

-XX:-allowusersignalhandlers

Limited to Linux and Solaris, disabled by default

Allows you to install a signal processor for a Java Process.

Java signal processing knowledge, see http://kenwublog.com/java-asynchronous-notify-based-on-signal

-XX:-disableexplicitgc

Disabled by default

Explicitly calling system. GC () during runtime is prohibited ().

 

When this option is enabled, the GC trigger time is under full control of garbage collector.
Note: The code you are familiar with does not call system. GC (). It does not mean that the Framework tool you are dependent on is not in use.

For example, RMI explicitly calls GC to prevent its own OOM without the knowledge of most users.

Please carefully weigh the impact of disabling.

-XX:-relaxaccesscontrolcheck

Disabled by default

In the class validator, relax the access control check.

 

Similar to setaccessible in reflection.

-XX:-useconcmarksweepgc

Disabled by default

Enable the CMS low-Pause garbage collector.

 

For more information, see: http://kenwublog.com/docs/CMS_GC.pdf

-XX:-useparallelgc

-Server Enabled

Otherwise, it is disabled by default.

The policy is for the new generation to use parallel cleanup, and the old generation to use the single-thread mark-sweep-compact garbage collector.

-XX:-useparalleloldgc

Disabled by default

The policy is that both the old and new generations use parallel garbage collectors.

-XX:-useserialgc

-Enabled when client

Otherwise, it is disabled by default.

Use the serial garbage collector.

-XX: + usesplitverifier

Java 5 is disabled by default.

Java 6 is enabled by default.

Use the new class type validator.

What are the features of the new Class type validator?
The new class type validator splits the old verification steps into two steps:
1. type inference.
2. type verification.

The new type validator embeds the type information to bytecode during javac compilation, omitting the type inference step, thus improving the classloader performance.

 

Classload sequence (for reference)
Load->Verify-> Prepare-> resove-> init

Association options:
-XX: + failovertooldverifier

-XX: + failovertooldverifier

Java 6 introduces new options, which are enabled by default.

If the new class validator fails to be checked, the old one will be used.

 

Why does it fail?

Jdk6 is highly backward compatible with jdk1.2, while the class info of jdk1.2 is significantly different from the info of jdk6. Therefore, the new checker may fail to verify.


Association options:
-XX: + usesplitverifier

-XX: + handlepromotionfailure

Previously, Java 5 was disabled by default, and Java 6 was enabled by default.

Disable the new generation collection guarantee.

What is the new generation collection guarantee?
In an idealized minor GC, the active objects in the Eden and first choice vor will be copied to the second choice vor.
However, second replicated vor may not be able to accommodate all the active objects copied from Zone E and zone F.

To ensure that the minor GC can be completed smoothly, GC needs to retain an additional memory space that is sufficient to accommodate all active objects in the old generation.
This reserved operation is called the New Generation collection guarantee (New Generation guarantee ). If the reserved operation cannot be completed, the major GC (full GC) will still be triggered ).

Why should we disable the new generation collection guarantee?
Because the size of the space reserved in the old generation cannot be accurately calculated.

To ensure the occurrence of extreme situations, GC refers to the memory usage of the New Generation in the worst case, that is, Eden + first generation vor.

This strategy is undoubtedly a waste of memory in the old generation. From the time sequence point of view, it will trigger full GC in advance.

To avoid this, JVM allows developers to manually disable the new generation collection guarantee.

 

After this option is enabled, minor GC will not provide the new generation collection guarantee. Instead, it will throw a promotion failed exception when there is either fail or the old generation is insufficient.

-XX: + usespinning

You must manually enable Java 1.5 and. Java 6 is enabled by default.

Enable multi-thread spin lock optimization.

Spin lock Optimization Principle

We all know that Java's multi-threaded security is implemented based on the lock mechanism, and the lock performance is often unsatisfactory.
The reason is that the two bytecode primitives monitorenter and monitorexit control multi-thread synchronization are implemented by JVM dependent on the operating system mutex.
Mutex is a resource-consuming operation that causes the thread to be suspended and must be rescheduled back to the original thread in a short period of time.

Java 6 developers have proposed spin lock optimization to avoid mutual exclusion from the OS.

 

The principle of spin lock optimization is to detect the release of the lock by a certain number of times CAS spin before the thread enters the OS mutex.

If the lock has been released before the number of spin times reaches the preset value, the current thread will immediately hold the lock.

 

For the principle of CAS detection lock, see: http://kenwublog.com/theory-of-lightweight-locking-upon-cas.

Association options:
-XX: preblockspin = 10

-XX: PreBlockSpin = 10

-XX: + UseSpinning must be enabled first. It is enabled by default for Java 6. Here, it is spin 10 times by default.

Controls the number of spin times for multi-thread spin lock optimization. (What is spin lock optimization? See-XX: + UseSpinning)

Association options:
-XX: + UseSpinning

-XX: + ScavengeBeforeFullGC

Enabled by default

A Minor GC is triggered before Full GC.

-XX: + UseGCOverheadLimit

Enabled by default

Restrict the GC running time. If the GC takes too long, the OOM is thrown.

-XX: + UseTLAB

Before 1.4.2 and when the-client option is used, it is disabled by default, and other versions are enabled by default.

Enable the Thread Local cache ).

-XX: + UseThreadPriorities

Enabled by default

Use the priority of the local thread.

-XX: + UseAltSigs

Limited to Solaris, enabled by default

To prevent conflicts with other sending applications, alternate signals can be used to replace SIGUSR1 and SIGUSR2.

-XX: + UseBoundThreads

Limited to Solaris, enabled by default

Bind all user threads to the kernel threads.
Reduces the number of times threads enter the hunger state (no cpu time is available.

-XX: + UseLWPSynchronization

Limited to solaris, enabled by default

Use a Lightweight Process (kernel thread) to replace thread synchronization.

-XX: + MaxFDLimit

Limited to Solaris, enabled by default

Set the available file descriptor of the java Process to the maximum value allowed by the operating system.

-XX: + UseVMInterruptibleIO

Limited to solaris, enabled by default

In solaris, thread interruption is allowed during running.

Performance options

 

Options and default values

Default and limit

Description

-XX: + AggressiveOpts

JDK 5 is introduced after update 6, but must be manually enabled.

JDK 6 is enabled by default.

Enable the latest tuning results of the JVM development team. For example, compilation optimization, biased locking, and parallel collection by the elderly.

-XX: CompileThreshold = 10000

1000

Through the JIT compiler, the method is compiled into the trigger threshold value of the machine code, which can be understood as the number of calls to the method, for example, 1000 calls, and the method is compiled into the machine code.

-XX: LargePageSizeInBytes = 4 m

The default value is 4 MB.

Amd64-bit: 2 m

Set the page size of heap memory.

 

Adjust the Memory Page Method and Performance Improvement Principle, see the http://kenwublog.com/tune-large-page-for-jvm-optimization

-XX: MaxHeapFreeRatio = 70

70

After GC, if the idle heap memory accounts for 70% of the overall estimated upper limit, the estimated upper limit is reduced.

 

What is the estimated upper limit?

When the JVM starts, it will apply for the maximum value (the value specified by-Xmx) address space, but most of the space will not be allocated immediately (virtual ).

They are retained until the JVM finds that the actual usage is close to the allocated upper limit during running, and only part of the memory is allocated from the virtual machine.

The allocated upper limit mentioned here can also be called the upper limit.

The advantage of introducing the estimated upper limit is that the heap size can be effectively controlled. The smaller the heap, the higher the GC efficiency.

Note: The estimated upper limit must be smaller than or equal to the maximum value.

-XX: MaxNewSize = size

1.3.1 iSCSI: 32 m

1.3.1 x86: 2.5 m

The new generation accounts for the maximum amount of heap memory.

-XX: MaxPermSize = 64 m

After 5.0: 64-bit VMs will increase the default value by 30%.

1.4 amd64: 96 m

1.3.1-client: 32 m

 

Other Default 64 m

Perm (commonly known as the method area) accounts for the maximum value of the entire heap memory.

-XX: MinHeapFreeRatio = 40

40

After GC, if the idle heap memory accounts for 40% of the overall estimated upper limit, the upper limit is increased.

(What is the estimated upper limit? See-XX: Description of MaxHeapFreeRatio)

 

Association options:

-XX: MaxHeapFreeRatio = 70

-XX: NewRatio = 2

-Client: 8

X86-server: 8

X86-client: 12

-Client: 4 (1.3)

8 (1.3.1 +)

X86: 12

 

Other Default values: 2

Heap memory usage of the new generation and the old generation.

For example, 2 indicates that the new generation accounts for 1/2 of the old generation and 1/3 of the total heap memory.

-XX: NewSize = 2.125 m

After 5.0: 64-bit Vms will increase the default value by 30%.

X86: 1 m

X86, later than 5.0: 640 k

 

Other Default 2.125 m

Default Value of the upper limit of the New Generation estimation. (What is the estimated upper limit? See-XX: Description of MaxHeapFreeRatio)

-XX: ReservedCodeCacheSize = 32 m

Solaris 64-bit, amd64,-server x86: 48 m

Before 1.5.0 _ 06, Solaris 64-bit amd64: 1024 m

 

Other Default 32 m

Set the maximum value of the Code cache for compilation.

-XX: Required vorratio = 8

Solaris amd64: 6

Iscsi in 1.3.1: 25

Before Solaris platforms 5.0: 32

 

Other Default values: 8

The ratio of Eden to vor. For example, 8 indicates that a vor zone occupies 1/8 of the Eden memory, that is, 1/10 of the New Generation memory. Why is it not 1/9?

Because our new generation has two pair vor, namely S1 and S22. Therefore, VOR occupies 2/10 of the memory of the new generation, while Eden accounts for 8/10 of the new generation.

-XX: target1_vorratio = 50

50

The percentage of used vor space. The default value is 50%, and the maximum value is 90%.

-XX: thread stacksize = 512

Iscsi: 512

Solaris x86: 320 (5.0 before 256)

64 bit: 1024

Linux amd64: 1024 (0 before 5.0)

 

Other Default values: 512.

Thread stack size

-XX: + UseBiasedLocking

JDK 5 is introduced after update 6, but must be manually enabled.

JDK 6 is enabled by default.

Enable the biased lock.

 

For the principle of biased lock, see http://kenwublog.com/theory-of-java-biased-locking.

-XX: + UseFastAccessorMethods

Enabled by default

Optimized the performance of the getter method of the original type.

-XX:-UseISM

Enabled by default

Enable the ISM of solaris.

 

For details, see Intimate Shared Memory.

-XX: + UseLargePages

JDK 5 is introduced after update 5, but must be manually enabled.

JDK 6 is enabled by default.

Enable large memory paging.

 

Adjust the Memory Page Method and Performance Improvement Principle, see the http://kenwublog.com/tune-large-page-for-jvm-optimization

 

Association options

-XX: LargePageSizeInBytes = 4 m

-XX: + UseMPSS

Before 1.4.1: Disabled

Other versions are enabled by default.

The MPSS of solaris cannot be used together with ISM.

-XX: + StringCache

Enabled by default

Enable string caching.

-XX: AllocatePrefetchLines = 1

1

This document does not explain the option related to pre-reading machine code commands. If you are interested, please read the official doc on your own.

-XX: AllocatePrefetchStyle = 1

1

This document does not explain the option related to pre-reading machine code commands. If you are interested, please read the official doc on your own.

Debugging options

 

Options and default values

Default and limit

Description

-XX:-CITime

1.4.

Enabled by default

Print the JIT compiler Compilation Time.

-XX: ErrorFile =./hs_err_pid <pid>. log

Java 6 Introduction.

If JVM crashed is used, the error log is output to the specified file path.

-XX:-ExtendedDTraceProbes

Introduced in Java 6, limited to solaris

Disabled by default

Enable dtrace diagnosis.

-XX: HeapDumpPath =./java_pid <pid>. hprof

The default value is the java Process startup location, that is, user. dir.

Path of the storage file of the heap memory snapshot.

 

What is a heap memory snapshot?

When the java Process is forcibly terminated by OS due to OOM or crash, a Heap memory snapshot file in hprof (Heap PROFling) format is generated. This file is used for offline debugging, diagnosis, and troubleshooting.

The file name is generally

Java _ <pid >_< date >_< time> _ heapDump. hprof

You can use tools such as jhat, eclipse mat, and GDB to parse snapshot files.

-XX:-heapdumponoutofmemoryerror

1.4.2 update12 and 5.0 Update 7 are introduced.

Disabled by default

At Oom, a dump. Core File is output to record the current heap memory snapshot (what is a heap memory snapshot? See-XX: Description of heapdumppath ).

-XX: onerror = "<cmd ARGs>; <cmd ARGs>"

1.4.2 update 9 Introduction

When Java throws an error, it runs the specified command line instruction set. The Instruction Set is related to the OS environment. In Linux, most of them are Bash scripts and DOS batch processing in windows.

-XX: onoutofmemoryerror = "<cmd ARGs>;
<Cmd ARGs>"

1.4.2 introduced during update 12 and java6

When OOM occurs for the first time, run the specified command line instruction set. The Instruction Set is related to the OS environment. In Linux, most of them are Bash scripts and DOS batch processing in windows.

-XX:-printclasshistogram

Disabled by default

In Windows, press Ctrl-break or run kill-3 in Linux to print the class bar chart when the sigquit signal is sent.

 

Jmap-histo PID also implements the same function.

See http://java.sun.com/javase/6/docs/technotes/tools/share/jmap.html

-XX:-printconcurrentlocks

Disabled by default

Print the lock status of Java. util. Concurrent while thread dump.

 

Jstack-l PID also implements the same function.

See http://java.sun.com/javase/6/docs/technotes/tools/share/jstack.html

-XX:-printcommandlineflags

5.0 introduced. disabled by default

When Java is started, it prints the currently enabled non-steady JVM options to stdout.

 

For example:

-XX: + useconcmarksweepgc-XX: + heapdumponoutofmemoryerror-XX: + doescapeanalysis

-XX:-printcompilation

Disabled by default

Print the information of the stdout method during JIT compilation.

 

For example:

1 java. Lang. String: charat (33 bytes)

-XX:-printgc

Disabled by default

Enable GC log printing.

 

The print format is as follows:

[Full GC 131115 K-> 7482 K (1015808 K), 0.1633180 secs]

 

This option can be dynamically enabled through COM. Sun. Management. hotspotdiagnosticmxbean API and jconsole.

See http://java.sun.com/developer/technicalArticles/J2SE/monitoring/#Heap_Dump

-XX:-printgcdetails

Introduced in 1.4.0, disabled by default

Print GC recovery details.

 

The print format is as follows:

[Full GC (system) [tenured: 0 k-> 2394 K (466048 K), 0.0624140 secs] 30822 K-> 2394 K (518464 K), [perm: 10443 K-> 10443 K (16384 K)], 0.0625410 secs] [times: User = 0.05 sys = 0.01, real = 0.06 secs]

 

This option can be dynamically enabled through COM. Sun. Management. hotspotdiagnosticmxbean API and jconsole.

See http://java.sun.com/developer/technicalArticles/J2SE/monitoring/#Heap_Dump

-XX:-printgctimestamps

Disabled by default

Print GC pause time.

 

The print format is as follows:

2.744: [Full GC (System) 2.744: [Tenured: 0 K-> 2441 K (466048 K), 0.0598400 secs] 31754 K-> 2441 K (518464 K), [Perm: 10717 K-> 10717 K (16384 K)], 0.0599570 secs] [Times: user = 0.06 sys = 0.00, real = 0.06

Secs]

 

This option can be dynamically enabled through com. sun. management. HotSpotDiagnosticMXBean API and Jconsole.

See http://java.sun.com/developer/technicalArticles/J2SE/monitoring/#Heap_Dump

-XX:-PrintTenuringDistribution

Disabled by default

Prints the object lifecycle information.

 

The print format is as follows:

[GC
Desired primary vor size 4653056 bytes, new threshold 32 (max 32)
-Age 1: 2330640 bytes, 2330640 total
-Age 2: 9520 bytes, 2340160 total

204009 K-> 21850 K (515200 K), 0.1563482 secs]

 

Age1 2 indicates the size of objects that survive after GC of 1st and 2.

-XX:-TraceClassLoading

Disabled by default

Print the class load information to stdout. Record the Loaded status.

 

For example:

[Loaded java. lang. Object from/opt/taobao/install/jdk1.6.0 _ 07/jre/lib/rt. jar]

-XX:-TraceClassLoadingPreorder

1.4.2 introduced, disabled by default

Print the class loading information to stdout according to the class reference/dependency sequence. Unlike TraceClassLoading, this option only records the Loading status.

 

For example:

[Loading java. lang. Object from/home/confsrv/jdk1.6.0 _ 14/jre/lib/rt. jar]

-XX:-TraceClassResolution

1.4.2 introduced, disabled by default

Print the reference positions of all static classes and constants. Used for debug.

 

For example:

RESOLVE java. util. HashMap java. util. HashMap $ Entry HashMap. java: 209

 

The 209 rows of the HashMap class reference the static class java. util. HashMap $ Entry.

-XX:-TraceClassUnloading

Disabled by default

Print the uninstall information of the class to stdout. Unloaded status.

-XX:-TraceLoaderConstraints

Introduced in Java 6, disabled by default

Print the information about the class loading policy changes to stdout.

 

For example:

[Adding new constraint for name: java/lang/String, loader [0]: sun/misc/Launcher $ ExtClassLoader, loader [1]: <bootloader>]

[Setting class object in existing constraint for name: [Ljava/lang/Object; and loader sun/misc/Launcher $ ExtClassLoader]

[Updating constraint for name org/xml/sax/InputSource, loader <bootloader>, by setting class object]

[Extending constraint for name java/lang/Object by adding loader [15]: sun/reflect/DelegatingClassLoader]

 

Loading policy changes are key technologies for implementing classloader isolation/namespace consistency.

For more information, see contraint rules in http://kenwublog.com/docs/Dynamic+Class+Loading+in+the+Java+Virtual+Machine.pdf.

-XX: + PerfSaveDataToFile

Enabled by default

When the java Process is forcibly terminated due to OOM or crashed, a heap snapshot file is generated (what is a heap memory snapshot? See-XX: Description of HeapDumpPath ).

 

Honorific to the author

Well-developed unit testing, functional regression testing, and performance benchmarking can reduce the risk of adjusting non-steady JVM options.

 

References

Java 6 Performance Tuning White Paper

Http://java.sun.com/performance/reference/whitepapers/6_performance.html

Java 6 Gc optimization Guide

Http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html

More comprehensive options list

Http://blogs.sun.com/watt/resource/jvm-options-list.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.