Appendix A. Summary of Tuning Flags

Table A-1. Flags to Tune the Just-in-Time Compiler
Flag What it doesWhen to use itSee also

-server

Chooses the server compiler

For long-running applications that need fast performance

Hotspot Compilation

-client

Chooses the client compiler

For applications where start-up is the most important factor

Hotspot Compilation

-XX:+TieredCompilation

Utilize tiered compilation (both client and server)

For applications where you want the best possible performance and have enough available native memory for the extra compiled code

Hotspot Compilation

-XX:ReservedCodeCacheSize=<MB>

Reserves space for code compiled by the JIT compiler

When you see a warning that you are out of code cache, and generally with when using tiered compilation.

Tuning the Code Cache

-XX:InitialCodeCacheSize=<MB>

Allocates the initial space for code compiled by the JIT compiler

If you need to pre-allocate the memory for the code cache, which is very uncommon.

Tuning the Code Cache

-XX:CompileThreshold=<N>

The number of times a method or loop is executed before compiling it.

When using the server compiler, can cause more methods to be compiled, and methods to be compiled sooner. The first case is sometimes an advantage if you aren’t using tiered compilation.

Compilation Thresholds

-XX:+PrintCompilation

Provide a log of operations by the JIT compiler.

When you suspect an important method isn’t being compiled, or are generally curious as to what the compiler is doing.

Inspecting the Compilation Process

-XX:+CICompilerCount=<N>

Number of threads used by the JIT compiler.

When using tiered compilation and too many compiler threads are being started (particularly on large machines running multiple JVMs).

Compilation Threads

Table A-2. Flags to Choose the GC Algorithm
Flag What it doesWhen to use itSee also

-XX:+UseSerialGC

Use a simple, single-threaded GC algorithm.

For small (100MB) heaps

The Serial Garbage Collector

-XX:+UseParallelOldGC

Uses multiple threads to collect the old generation while application threads are stopped.

When your application can tolerate occasional long pauses and you want to maximize throughput while minimizing CPU usage.

The Throughput Collector

-XX:+UseParallelGC

Uses multiple threads to collect the young generation while application threads are stopped.

Use in conjunction with UseParallelGC.

The Throughput Collector

-XX:+UseConcMarkSweepGC

Uses background thread(s) to remove garbage from the old generation with minimal pauses.

When you have available CPU for the background thread, you do not want long GC pauses, and you have a relatively small heap.

The CMS Collector

-XX:+UseParNewGC

Uses multiple threads to collect the young generation while application threads are stopped.

Use in conjunction with UseConcMarkSweepGC.

The CMS Collector

-XX:+UseG1GC

Uses multiple threads to collect the young generation while application threads are stopped, and background thread(s) to remove garbage from the old generation with minimal pauses.

When you have available CPU for the background thread, you do not want long GC pauses, and you do not have a small heap.

The G1 Collector

Table A-3. Flags common to all GC Algorithms
Flag What it doesWhen to use itSee also

-Xms

Sets the initial size of the heap.

When the default initial size is too small for your application.

Sizing the Heap

-Xmx

Sets the maximum size of the heap.

When the default maximum size is too small (or possibly too large) for your application.

Sizing the Heap

-XX:NewRatio

Sets the ratio of the young generation to the old generation.

Increase this to reduce the proportion of the heap given to the young generation; lower it to increase the proportion of the heap given to the young generation. This is only an initial setting; the proportional will change unless adaptive sizing is turned off (except for CMS, when the young generation size is constant). As the young generation size is reduced, you will see more frequent young GCs and less frequent Full GCs (and vice versa).

Sizing the Generations

-XX:NewSize

Sets the initial size of the young generation.

When you have finely-tuned your application requirements.

Sizing the Generations

-XX:MaxNewSize

Sets the maximum size of the young generation.

When you have finely-tuned your application requirements.

Sizing the Generations

-Xmn

Sets the initial and maximum size of the young generation.

When you have finely-tuned your application requirements.

Sizing the Generations

-XX:PermSize=N (JDK 7 only)

Sets the initial size of the permgen.

For applications that use a lot of classes, increase this from the default.

Sizing PermGen and Metaspace

-XX:MaxPermSize=N (JDK 7 only)

Sets the maximum size of the permgen.

For applications that use a lot of classes, increase this from the default.

Sizing PermGen and Metaspace

-XX:MetaspaceSize=N (JDK 8 only)

Sets the initial size of the metaspace.

For applications that use a lot of classes, increase this from the default.

Sizing PermGen and Metaspace

-XX:MaxMetaspaceSize=N (JDK 8 only)

Sets the maximum size of the metaspace.

Lower this number to limit the amount of native space used by class metadata.

Sizing PermGen and Metaspace

-XX:ParallelGCThreads=N

Sets the number of threads used by the garbage collectors

Lower this value on systems running many JVMs. Consider increasing it for JVMs with very large heaps on very large systems.

Controlling Parallelism

-verbose:gc

Enables basic GC logging.

GC logging should always be enabled, but other more detailed logs are generally better.

GC Tools

-Xloggc:<path>

Directs the GC log to a special file rather than standard output.

Always, the better to preserve the information in the log.

GC Tools

-XX:+PrintGC

Enables basic GC logging.

GC logging should always be enabled, but other more detailed logs are generally better.

GC Tools

-XX:+PrintGCDetails

Enables detailed GC logging.

Always, even in production (the logging overhead is minimal).

GC Tools

-XX:+PrintGCTimeStamps

Prints a relative time stamp for each entry in the GC log.

Always, unless date stamps are enabled.

GC Tools

-XX:+PrintGCDateStamps

Prints a time of day stamp for each entry in the GC log.

Has slightly more overhead than time stamps, but may be easier to process.

GC Tools

-XX:+PrintReferenceGC

Prints information about soft and weak reference processing during GC.

If the program uses a lot of those references, add this flag to determine their effect on the GC overhead.

Weak, Soft, and Other References

-XX:+UseGCLogFileRotation

Enables rotations of the GC log to conserve file space.

In production systems that run for weeks at a time when the GC logs can be expected to consume a lot of space.

GC Tools

-XX:NumberOfGCLogFiles=N

When log file rotation is enabled, the number of log files to retain.

In production systems that run for weeks at a time when the GC logs can be expected to consume a lot of space.

GC Tools

-XX:GCLogFileSize=N

When log file rotation is enabled, the size of each log file before rotating it.

In production systems that run for weeks at a time when the GC logs can be expected to consume a lot of space.

GC Tools

-XX:+UseAdaptiveSizePolicy

When set, the JVM will resize various heap sizes to attempt to meet GC goals.

Turn this off if the heap sizes have been finely tuned

Adaptive Sizing

-XX:+PrintAdaptiveSizePolicy

Adds information about how generations are resized to the GC log.

Use this flag to gain an understanding of how the JVM is operating. When using G1, check this output to see if full GCs are triggered by humongous object allocation.

Adaptive Sizing

-XX:+PrintTenuringDistribution

Add tenuring information to the GC logs.

Use the tenuring information to determine if and how the tenuring options should be adjusted.

Tenuring and Survivor Spaces

-XX:InitialSurvivorRatio=N

The amount of the young generation set aside for survivor spaces.

Increase this if short-lived objects are being promoted into the old generation too frequently.

Tenuring and Survivor Spaces

-XX:MinSurvivorRatio=N

The adaptive amount of the young generation set aside for survivor spaces.

Decreasing this values reduces maximum size of the survivor spaces (and vice versa).

Tenuring and Survivor Spaces

-XX:TargetSurvivorRatio=N

The amount of free space the JVM attempts to keep in the survivor spaces.

Increasing this value reduces the size of the survivor spaces (and vice versa).

Tenuring and Survivor Spaces

-XX:InitialTenuringThreshold=N

The initial number of GC cycles the JVM attempts to keep an object in the survivor spaces.

Increase this number to keep objects in the survivor spaces longer, though be aware that the JVM will tune it.

Tenuring and Survivor Spaces

-XX:MaxTenuringThreshold=N

The maximum number of GC cycles the JVM attempts to keep an object in the survivor spaces.

Increase this number to keep objects in the survivor spaces longer; the JVM will tune the actual threshold between this value and the initial threshold.

Tenuring and Survivor Spaces

Table A-4. Tunings Flags for the Throughput Collector
Flag What it doesWhen to use itSee also

-XX:MaxGCPauseMillis=N

Hints to the throughput collector how long pauses should be; the heap is dynamically sized to attempt to meet that goal.

As a first step in tuning the throughput collector if the default sizing it calculates doesn’t meet application goals.

Adaptive and Static Heap Size Tuning

-XX:GCTimeRatio=N

Hints to the throughput collector how much time you are willing to spend in GC; the heap is dynamically sized to attempt to meet that goal.

As a first step in tuning the throughput collector if the default sizing it calculates doesn’t meet application goals.

Adaptive and Static Heap Size Tuning

-XX:-AggressiveHeap

Enables a set of tuning flags that are “optimized” for machines with a large amount of memory running a single JVM with a large heap.

It is better not to use this flag, and instead use specific flags as necessary.

AggressiveHeap

Table A-5. Tunings Flags for the CMS Collector
Flag What it doesWhen to use itSee also

-XX:CMSInitiatingOccupancyFraction=N

The point at which CMS should begin background scanning of the old generation.

When CMS experiences concurrent mode failures, reduces this value.

Understanding the CMS Collector

-XX:+UseCMSInitiatingOccupancyOnly

Use only the CMSInitiatingOccupancyFraction to determine when to start CMS background scanning.

Whenever CMSInitiatingOccupancyFraction is specified.

Understanding the CMS Collector

-XX:ConcGCThreads=N

Sets the number of threads to use for CMS background scanning.

When lots of CPU is available and CMS is experiencing concurrent mode failures.

Understanding the CMS Collector

-XX:+CMSPermGenSweepingEnabled

Directs CMS to sweep the permgen.

When using CMS with an application server that performs lots of class unloading.

Understanding the CMS Collector

-XX:CMSInitiatingPermOccupancyFraction=N

Point at which CMS should scan permgen

When CMSPermGenSweepingEnabled is set and full GCs occur because CMS didn’t clean up permgen fast enough.

Understanding the CMS Collector

-XX:+CMSClassUnloadingEnabled

Direct CMS to unload classes after the permgen is scanned.

Whenever CMSPermGenSweepingEnabled is set.

Understanding the CMS Collector

-XX:+CMSIncrementalMode

Run CMS in incremental mode.

If CPU is limited and you still must run CMS.

Incremental CMS

-XX:CMSIncrementalModeSafetyFactor=N

Affects how often incremental CMS background threads run.

When using incremental CMS and experiencing concurrent mode failures, increase this value.

Incremental CMS

-XX:CMSIncrementalDutyCycleMin=N

Affects how often incremental CMS background threads run.

When using incremental CMS and experiencing concurrent mode failures, increase this value, though setting CMSIncrementalModeSafetyFactor is preferred.

Incremental CMS

-XX:CMSIncrementalDutyCycleMax=N

Affects how often incremental CMS background threads run.

When using incremental CMS and experiencing concurrent mode failures, increase this value, though setting CMSIncrementalModeSafetyFactor is preferred.

Incremental CMS

-XX:+CMSIncrementalDutyCycle

Affects how often incremental CMS background threads run.

When using CMSIncrementalDutyCycleMin, set this flag.

Incremental CMS

Table A-6. Tunings Flags for the G1 Collector
Flag What it doesWhen to use itSee also

-XX:MaxGCPauseMillis=N

Hints to the G1 collector how long pauses should be; the G1 algorithm is adjusted to attempt to meet that goal.

As a first step in tuning the G1 collector; increase this value to attempt to prevent full GCs.

Understanding the G1 Collector

-XX:ConcGCThreads=N

Sets the number of threads to use for G1 background scanning.

When lots of CPU is available and G1 is experiencing concurrent mode failures.

Understanding the G1 Collector

-XX:InitiatingHeapOccupancyPercent=N

The point at which G1 background scanning begins.

Lower this value if G1 is experiencing concurrent mode failures.

Understanding the G1 Collector

-XX:G1MixedGCCountTarget=N

The number of mixed GCs over which G1 attempts to free the garbage old generation regions.

Lower this value if G1 is experiencing concurrent mode failures; increase it if mixed GC cycles take too long.

Understanding the G1 Collector

-XX:G1HeapRegionSize=N

The size of a G1 region.

Increase this value for very large heaps, or when the application allocated very, very large objects.

G1 Region Sizes

Table A-7. Tunings Flags for Memory Management
Flag What it doesWhen to use itSee also

-XX:+HeapDumpOnOutOfMemoryError

Generate a heap dump when the JVM throws an out of memory error

Enable this flag if the application throws out of memory errors due to the heap space or permgen so the heap can be analyzed for memory leaks.

Out of Memory Errors

-XX:+HeapDumpPath

Specify the filename where automatic heap dumps should be written.

To specify a path other than java_pid<pid>.hprof for heap dumps generated on out of memory errors or GC events (when those options have been enabled).

Out of Memory Errors

-XX:SoftRefLRUPolicyMSPerMB=N

Controls how long soft references survive after being used.

Decrease this value to clean up soft references more quickly, particularly in low-memory conditions.

Weak, Soft, and Other References

-XX:MaxDirectMemorySize=N

Controls how much native memory can be allocated via the allocateDirect() method of the ByteBuffer class.

Consider setting this if you want to limit the amount of direct memory a program can allocate. Note that it is not longer necessary to set this flag to allocate more than 64MB of direct memory.

Footprint

-XX:+UseLargePages

Directs the JVM to allocate pages from the operating system’s large page system, if applicable.

If supported by the OS, this option will generally improve performance.

Large Pages

-XX:+LargePageSizeInBytes=N

Directs the JVM to allocate large pages of the given size (Solaris only).

On large Solaris systems, increase this value (to, say, 256M) for best performance.

Large Pages

-XX:+StringTableSize=N

Sets the size of the hashtable the JVM uses to hold interned strings.

Increase this value if the application performs a significant amount of string interning.

String Interning

-XX:+UseCompressedOops

Emulate 35-bit pointers for object references.

This is the default for heaps that are less than 32GB in size; there is never an advantage to disabling it.

Compressed oops

-XX:+PrintTLAB

Print summary information about TLABs in the GC log.

When using a JVM without support for JFR, use this to ensure that TLAB allocation is working efficiently.

Thread Local Allocation Buffers

-XX:TLABSize=N

Sets the size of the TLABs.

When the application is performing a lot of allocation outside of TLABs, use this value to increase the TLAB size.

Thread Local Allocation Buffers

-XX:-ResizeTLAB

Disable resizing of TLABs.

Whenever TLABSize is specified, make sure to disable this flag.

Thread Local Allocation Buffers

Table A-8. Tunings Flags for Thread Handling
Flag What it doesWhen to use itSee also

-Xss<N>

Sets ths size of the native stack for threads.

Particularly on 32-bit JVMs, decrease this size to make more memory available for other parts of the JVM.

Tuning Thread Stack Sizes

-XX:-BiasedLocking

Disables the biased locking algorithm of the JVM.

Often helps performance of thread-pool based applications.

Biased Locking

Table A-9. Tunings Flags for Miscellaneous JVM flags
Flag What it doesWhen to use itSee also

-XX:+AlwaysLockClassLoader

Revert the Java 7 parallel classloading scheme to the Java 6 non-parallel scheme.

On large systems loading classes in only a single thread, startup performance may slightly benefit by using this flag.

Class Loading

-XX:-StackTraceInThrowable

Prevents the stack trace from being gathered whenever an exception is thrown.

On systems with very deep stacks where exceptions are frequently thrown (and where fixing the code to throw fewer exceptions is not a possibility).

Exceptions

-XX:-RestrictContended

Allows non-JDK code to use the @Contended annotation.

Set this if application code uses the @Contended annotation to pad variables to prevent false sharing.

The

-XX:-EnableContended

Disables JDK code from using the @Contended annotation.

This should likely be left enabled. Disabling may save a small amount of space in certain JDK classes.

The

-XX:+AggressiveOpts

Enables certain optimizations for the JVM. These optimizations are likely to become defaults in future releases.

You can test with this flag to determine if it helps, but be aware that it may not work the same when JVM versions change.

AggressiveOpts

Table A-10. Tunings Flags for Java Flight Recorder
Flag What it doesWhen to use itSee also

-XX:+FlightRecorder

Enable Java Flight Recorder.

Enabling Flight Recorder is always recommended, as it has very little overhead unless an actual recording is happening (in which case, the overhead will vary depending on the features used, but still be relatively small).

Java Flight Recorder

-XX:+FlightRecorderOptions

Options to set up a default recording via the command line.

Control how a default recording can be made for the JVM.

Java Flight Recorder

-XX:+UnlockCommercialFeatures

Allows the JVM to use commercial (non open-source) features.

If you have the appropriate license, setting this flag is required to enable Java Flight Recorder.

Java Flight Recorder

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.192.59