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: Concurrency, Threading, GC, Advanced Java and more ...
Tips August 2019
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 225 contents
https://www.youtube.com/watch?v=nniYSR4GAH4
Improve Startup Performance and Reduce Footprint with Application Class Data Sharing (Page last updated October 2018, Added 2019-08-29, Author Jiangli Zhou, Ioi Lam, Publisher Oracle). Tips:
- Class data sharing lets classes be memory-mapped for faster startup and for sharing across JVM processes running on the same system. There are multiple spaces in the archive. Only the read-only spaces can be shared (though this is usually the largest component). Read-write pages are shared using copy-on-write.
- G1 created class data shared archives includes some heap objects too (strings, constant pool objects, and some JVM initialized objects), and can be used by G1 (the archive can be used with other GC algorithms, but heap objects will be ignored for GC algorithms other than G1).
- Java 12+ automatically creates archives and has the system archive already present, Java 11 and below need -Xshare:dump to dump and -Xshare:auto to run
- You can do -XX:DumpLoadedClassList=CLASSLIST then -Xshare:dump -XX:SharedArchiveFile=FILEPATH to opimize [or in Java 13+ use -XX:ArchiveClassesAtExit=FILEPATH]
- From Java 11 you don't need -XX:+UseAppCDS to use AppCDS - it's automatically enabled and handled
- Classes loaded by custom classloaders (ie not bootclassloader, appclassloader, platformclassloader) or EE classloader, don't automatically archive as well up to Java 12 at least, so you need to use the DumpLoadedClassList option.
https://vimeo.com/289644820
Class Data Sharing in the HotSpot VM (Page last updated September 2018, Added 2019-08-29, Author Volker Simonis, Publisher JavaZone). Tips:
- Class Data Sharing and AOT compilation uses a shared archive of read-only class metadata to share memory across JVMs and improve startup time
- Use -Xshare:dump to create a class data shared archive (you can specify a location for the archive with other options). -Xshare:on let's you use the shared class archive, and -Xlog:class+load will show you which classes ares shared, with a "shared objects file" message.
- Use -XX:DumpLoadedClassList=FILEPATH -XX:+UseAppCDS to find application classes loaded, and use that to create the shared archive with -XX:+UseAppCDS -XX:SharedClassListFile=FILEPATH -Xshare:dump -XSharedArchiveFile=FILEPATH2 (UseAppCDS is not needed from Java 11) (and -Xshare:on to run with the shared class file dumped with -Xshare:dump)
- You can create a custom classlist for the shared class archive including classes that are not recognized by the shared archive class dumper - see this talk around 23 minutes in for details how to do this as it's complicated. The tool cl4cds will do this conversion
- -XX:SharedArchiveConfigFile=FILEPATH can specify how to include interned strings and symbols into the shared class archive, see JDK-8134448 for details - or see this talk from around 30 minutes in for details.
- If using containers, the archive file needs to be shared from the underlying file system to be shared across containers - the archive needs to be the same inode
- -Xshareclasses is the option in Eclipse OpenJ9 JVM and is more extensive than the HotSpot JVM and produces a lower memory footprint
https://www.youtube.com/watch?v=kF_r3GE3zOo
ZGC: A Scalable Low-Latency Garbage Collector (Page last updated October 2018, Added 2019-08-29, Author Per Liden, Publisher Oracle). Tips:
- ZGC targets maximum 10ms pause times.
- ZGC pause times do not increase with live set size or heap size, but do increase with root set size, roughly number of threads and the depth of the thread stacks, because the only non-concurrent ZGC phase is the thread stack scanning in the marking and relocate-start phases.
- ZGC can't work on 32-bit JVMs nor with compressedoops because it needs a 64-bit size pointer to hold information for the GC management.
- use ZGC with -XX:+UseZGC, set -Xmx with enough headroom to handle the allocation rate over a GC cycle (eg 60 second cycle and 10MB/sec allocation needs 60x10MB=600MB headroom), and -XX:ConcGCThreads=N which tells you how much CPU time to give to ZGC
- Recommended ZGC logging is -Xlog:gc or -Xlog:gc* for detailed logging. With the detailed logging enabled in the line with "Allocated:" see the "Relocate End" column field and that gives you the allocation over tht GC cycle so shows you the headroom needed in your heap to the GC cycle. Also "Memory: Allocation Rate" line gives the running statistics for that
- In the -Xlog:gc* for detailed logging log, the "Phase: Pause" lines give you running pause time statistics
Jack Shirazi
Back to newsletter 225 contents
Last Updated: 2024-08-26
Copyright © 2000-2024 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.
URL: http://www.JavaPerformanceTuning.com/news/newtips225.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us