Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Threading Essentials course
Tips January 2007
Get rid of your performance problems and memory leaks!
Get rid of your performance problems and memory leaks!
Back to newsletter 074 contents
The most complete list of -XX options for Java 6 JVM (Page last updated December 2006, Added 2007-01-29, Author Eugene Kuleshov, Publisher Kuleshov). Tips:
- miscellaneous -XX options : ForceTimeHighResolution SelfDestructTimer MaxDirectMemorySize ThreadStackSize VMThreadStackSize CompilerThreadStackSize InitialCodeCacheSize ReservedCodeCacheSize PauseAtStartup PauseAtStartupFile
- tuning -XX options: ParallelRefProcEnabled AlwaysActAsServerClassMachine DisableExplicitGC UseHeavyMonitors AggressiveOpts UseNiagaraInstrs ProfileMaturityPercentage AlwaysCompileLoopMethods MaxBCEAEstimateLevel MaxBCEAEstimateSize MaxInlineSize PerMethodRecompilationCutoff PerBytecodeRecompilationCutoff InterpreterProfilePercentage EagerInitialization UseLargePages
- monitoring GC -XX options: PrintGCApplicationConcurrentTime PrintGCApplicationStoppedTime PrintPLAB PrintAdaptiveSizePolicy PrintTenuringDistribution PrintHeapAtSIGBREAK PrintParallelOldGCPhaseTimes PrintGCDetails PrintGC PrintGCTimeStamps PrintHeapAtGC PrintReferenceGC
- crash support -XX options: ShowMessageBoxOnError OnError OnOutOfMemoryError GCHeapFreeLimit GCTimeLimit UseGCOverheadLimit ErrorFile MaxJavaStackTraceDepth HeapDumpOnOutOfMemoryError HeapDumpPath AbortVMOnException
- profiling support -XX options: PrintVMQWaitTime PrintSharedSpaces ProfilerPrintByteCodeStatistics ProfilerRecordPC ProfileVM ProfileIntervals EagerXrunInit ProfileIntervalsTicks PerfDataSaveToFile PerfDataSamplingInterval PerfDisableSharedMem PerfDataMemorySize PrintClassHistogram PrintConcurrentLocks PrintMalloc MemProfiling PrintBiasedLockingStatistics PrintInlining PrintMethodData ProfilerNumberOfInterpretedMethods ProfilerNumberOfCompiledMethods ProfilerNumberOfStubMethods ProfilerNumberOfRuntimeStubNodes MemProfilingInterval
- fine tuning -XX options: BiasedLockingStartupDelay BiasedLockingBulkRebiasThreshold BiasedLockingBulkRevokeThreshold BiasedLockingDecayTime
- GC algorithms -XX options: UseSerialGC UseParallelGC UseParallelOldGC UseParallelOldGCCompacting UseConcMarkSweepGC UseCMSCompactAtFullCollection UseAutoGCSelectPolicy
- GC tuning -XX options: AlwaysTenure NeverTenure ScavengeBeforeFullGC ExplicitGCInvokesConcurrent HandlePromotionFailure AutoGCSelectPauseMillis UseAdaptiveSizePolicy UsePSAdaptiveSurvivorSizePolicy MaxGCPauseMillis MaxGCMinorPauseMillis GCTimeRatio MinSurvivorRatio InitialSurvivorRatio SurvivorRatio NewRatio PermSize MaxPermSize
- GC fine tuning -XX options: ParallelGCThreads ParallelCMSThreads UseAdaptiveGenerationSizePolicyAtMinorCollection UseAdaptiveGenerationSizePolicyAtMajorCollection UseAdaptiveGCBoundary TraceAdaptiveGCBoundary CMSTriggerRatio and lots of other CMS options
- heap tuning -XX options: DefaultMaxRAM DefaultMaxRAMFraction DefaultInitialRAMFraction MaxHeapSize MaxNewSize PretenureSizeThreshold OldSize MinHeapFreeRatio MaxHeapFreeRatio MinHeapDeltaBytes MinPermHeapExpansion MaxPermHeapExpansion MaxTenuringThreshold InitialTenuringThreshold TargetSurvivorRatio
- compilation tuning -XX options: CompileOnly CompileCommandFile CompileCommand
- Thread priorities -XX options: DefaultThreadPriority CompilerThreadPriority VMThreadPriority
Java 6 Features and Enhancements (Page last updated December 2006, Added 2007-01-29, Author Sun, Publisher Sun). Tips:
- Improved hardware acceleration on Windows
- Configurable Pop-up splash screen at beginning of Java startup
- Improved startup & footprint for plugin/webstart
- Reduced footprint & startup time
- Improved Painting Performance (fix grey boxes)
- JVMPI and JVMDI have been removed.
- Array Reallocation API
- BigDecimal optimizations
- Java compiler API
- Performance Improvements when compiling using network file systems
- Improved diagnosability of OutOfMemoryError
- Support for java.util.concurrent locks in the lock related facility
- Improved Policy performance
- Improved performance of: compiled code, loop optimization, synchronization, startup time, runtime, JNI
- Escape analysis
- Parallelized concurrent marking & compaction
Java SE 6 Monitoring and Management Enhancements (Page last updated December 2006, Added 2007-01-29, Author Sun, Publisher Sun). Tips:
- Added ThreadMXBean.findDeadlockedThreads() supports concurrent locks as well as normal syncronized monitors
- Added ThreadMXBean methods dumpAllThreads() and getThreadInfo(long ids, boolean lockedMonitor, boolean lockedSynchronizers) to get thread info for threads
- A new method, getSystemLoadAverage(), has been added to OperatingSystemMXBean to return the system load average.
- JConsole now has Plugin support, that allows you to build your own plug-ins to run with JConsole, for example, to add a custom tab for accessing your applications' MBeans.
- jconsole has been enhanced with a number of new features
Java SE 6 Monitoring, Management, Diagnosability (Page last updated December 2006, Added 2007-01-29, Author Mandy Chung, Publisher java.net). Tips:
- Dynamic Attach Capability - the ability to load classes and JVMTI agents on demand from a remotely defined agent [WOW!]
- Heaps dumped on error (-XX:+HeapDumpOnOutOfMemoryError) and with jmap (jmap -dump:file=heap.bin) and from loading in the library (-Xrunhprof) and triggering the dump
- A new -XX:OnOutOfMemoryError=<command> option lets you specify a command that the HotSpot VM will invoke when the OutOfMemoryError is thrown.
- dtrace in 1.6 is supported for the whole stack
- Jconsole attaches dynamically to any running 1.6 app (using the dynamic attach capability, no need to specify command line params)
- jhat is fully supported and enhanced in a number of ways
- jinfo adds a new -flag option to get and set an VM option. For example you can use jinfo to set HeapDumpOnOutOfMemoryError at runtime.
- OperatingSystemMXBean.getSystemLoadAverage() added
- HotSpotDiagnosticMXBean added that has dumpHeap(outputFile, live) to dump the heap in hprof format, and setVMOption() to programatically set VMOptions
- java.lang.instrument enhanced to allow native methods to be wrapped - woohoo, finally automated I/O profiling is possible
From Monitoring to Diagnosing Memory Problem in Mustang (Page last updated February 2006, Added 2007-01-29, Author Mandy Chung, Publisher java.net). Tips:
- Use jconsole to monitor the memory usage and garbage collection activities of your application from the memory tab
- Finalizers can cause a memory leak. JConsole shows the number of objects pending for finalization in the summary tab.
- jmap -histo will print the histogram of the heap showing the number of instances and the amount of memory of each class - extended to support Windows java 6. Heap histograms can help determine if a memory leak exists.
- Obtain heap dump snapshots and use jhat for heap analysis
- Use the -XX:+HeapDumpOnOutOfMemoryError to make the JVM generate a heap dump when it runs out of memory (you can turn this on from jconsole if it wasn't set at startup).
Using Mustang's jmap/jhat to profile (Page last updated February 2006, Added 2007-01-29, Author Jean-Francois Arcand, Publisher java.net). Tips:
- Get a hprof heap dump using jmap, e.g. jmap -dump:file=heap.bin ...
- Analyse hprof heap dumps using jhat, e.g. jhat -J-mx512m heap.bin, which starts a web server on port 7000 by default
- The histogram is a good starting point when analysing hprof heaps with jhat, e.g. http://localhost:7000/histo/
- Useful entry points in jhat are the histogram (http://localhost:7000/histo/) the instance list (http://localhost:7000/showInstanceCounts/includePlatform/), and the OSQL page (http://localhost:7000/oql/)
- An example of using the OSQL page in jhat (http://localhost:7000/oql/) is "select s from com.sun.enterprise.web.connector.grizzly.ReadTask s where s.byteBuffer.position > 0"
- If you cancel a SchedueldFuture before its run it doesn't become eligible for GC for a while (a few seconds?) unless it is purged.
Heap dumps are back (Page last updated September 2005, Added 2007-01-29, Author Alan Bateman, Publisher Sun). Tips:
- Hprof heap dumps can be obtained with: jmap on the running process, e.g. jmap -dump:file=...; jconsole; -XX:+HeapDumpOnOutOfMemoryError; jmap on a core file, e.g. jmap -dump:file=app.bin `which java` core.5831
- Hprof heap dumps can be analysed with jhat
- In 1.5 jmap, jinfo, and jstack utilities in JDK5.0 attach to the target VM using a non-cooperative mechanism and thus observe a snapshot of the process. 1.6 has added a cooperative mechanism so that the tools can safepoint the VM and ensure that they print consistent output.
- If you're not getting a reasonable histogram from jmap with JDK5.0 then an alternative solution is the heap viewer demo. This is a tool agent that runs in the VM. You'll find the source and pre-built binaries in the demo/jvmti/heapViewer directory of the JDK. The output is similar to jmap -histo in that it prints a class-wise histogram of the objects in the heap.
Using Mustang's Attach API (Page last updated December 2005, Added 2007-01-29, Author A. Sundararajan, Publisher Sun). Tips:
- 1.6 (Mustang) JDK includes attach-on-demand.
- You can load any suitably coded native or Java agent into running JVM using the attach API.
- [Article shows a hello world example of an agent dynamically loaded using attach-on-demand].
Monitoring and Managing Java SE 6 Platform Applications (Page last updated August 2006, Added 2007-01-29, Author Mandy Chung, Publisher Sun). Tips:
- Diagnosis of Insufficient memory (Symptom OutOfMemoryError): get hprof heap dump with jmap -dump and use jhat
- Diagnosis of Memory leaks (Symptom Growing use of memory, Frequent garbage collection, A class with a high growth rate, A class with an unexpected number of instances, An object is being referenced unintentionally): monitor with jconsole & jstat to see if memory usage is always growing; use jmap -histo:live to determine leaking classes; use jhat with jmap -dump option;
- Diagnosis of Finalizers (Symptom Objects are pending for finalization): monitor with jconsole; use jmap -histo to determine leaking classes; use jhat with jmap -dump option
- Diagnosis of Deadlocks (Symptom Threads block on object monitor or java.util.concurrent locks): monitor with jconsole & jstack
- Diagnosis of Looping threads (Symptom Thread CPU time is continuously increasing): use jconsole or jtop
- An insufficient memory problem could be due either to a problem with the configuration -- the application really needs that much memory -- or to a performance problem in the application that requires you to profile and optimize to reduce the memory use.
- jmap has a live option with -histo, e.g. jmap -histo:live - the live option forces a full GC so that only application-live references are reported. Without the live option, the histogram shows all references including reclaimable but not-yet reclaimed instances
- heap dumps can be obtained by: jmap -dump:live,file=heap.dump.out,format=b <pid>; jconsole->MBeans tab->HotSpotDiagnostic->Operations->dumpHeap; setting -XX:+HeapDumpOnOutOfMemoryError option at startup (dump created on OutOfMemoryError); using jinfo -flag +HeapDumpOnOutMemoryError <pid> to set the value after startup (dump created on OutOfMemoryError); jconsole->MBeans tab->HotSpotDiagnostic->Operations->setVMOption(HeapDumpOnOutMemoryError,true) to set the value after startup (dump created on OutOfMemoryError);
- Jhat supports an Object Query Language (OQL) interface to drill down through a specific problem. For example, if you want to find all java.lang.String objects of string length 100 or more, you can enter the following query in the OQL query page: select s from java.lang.String s where s.count >= 100
- You can use jmap to find the classes of the finalizable objects (in 1.6 only Solaris & Linux): e.g. jmap -finalizerinfo <pid>
- Deadlocks can be diagnosed from a stack dump (with kill -3 or cntrl-\ on unix, cntrl-brk on windows, or using jstack), and from jconsole-Threads tab
- JTop is a JDK demo that shows an application's usage of CPU time per thread, run with e.g. java -jar <JDK>/demo/management/JTop/JTop.jar or jconsole -pluginpath <JDK>/demo/management/JTop/JTop.jar
- The JDK provides per-thread contention statistics such as the number of times a thread has blocked or waited on object monitors, as well as the total accumulated time spent in lock contention. Information about the number of times that a thread has blocked or waited on object monitors is always available in the thread information displayed in the Threads tab of JConsole. the ability to track the total accumulated time spent in contention is disabled by default. You can enable monitoring of the thread contention time by setting the ThreadContentionMonitoringEnabled attribute of the Threading MBean to true.
Mustang Must-Haves: What's Cool in Java SE 6 (Page last updated December 2006, Added 2007-01-29, Author John Ferguson Smart, Publisher devX). Tips:
- You can also compile some scripting languages to speed up processing.
- Java 6 includes the Apache Derby (formerly IBM Cloudscape) database. Apache Derby is a lightweight, fully transactional, 100 percent Java embedded database.
- JConsole is enhanced: you can monitor several applications in the same JConsole instance; the summary screen has been redesigned to display a graphical dashboard of the key statistics; you also can now export any graph data in CSV form for further analysis in a spreadsheet; you no longer need to specify -Dcom.sun.management.jmxremote to monitor a Java 6 JVM; check for deadlocks by clicking on the Detect Deadlock button in the Threads tab.
- The Java 6 VM can now monitor applications for deadlocked threads involving object monitors and java.util.concurrent ownable synchronizers.
- OutOfMemoryError now prints out a full stack trace (previously it didn't).
- File.getTotalSpace(), File.getFreeSpace() and File.getUsableSpace() have been added to determine the amount of space available (in bytes) on a given disk partition (getUsableSpace() is what you should use to find out how much free space there is).
- File.setReadable(boolean), File.setWritable(boolean) and File.setExecutable(boolean) have also been added to set file permissions.
Back to newsletter 074 contents
Last Updated: 2018-06-28
Copyright © 2000-2018 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us