JVM internals and performance
You get to know class loading, bytecode, the JIT and the garbage collectors through measurement and use JFR and heap dumps to find and fix slowness and memory leaks.
Level 501 · 16 lessons · 15 practice labs
Lessons
Classes and bytecode
- Class loaders and the module path
- Reading bytecode with javap
- The JIT compiler and tiered compilation
- Correct benchmarking with JMH
- Short task: explain the bytecode difference between two versions
Memory and garbage collection
- Heap layout, object headers and generations
- G1, ZGC and Parallel: which and when
- Reading garbage collection logs
- Finding memory leaks with a heap dump
- Short task: find and fix a leaking cache
Observation and tools
- Recording with Java Flight Recorder
- Inspecting a live JVM with jcmd and jstat
- The JVM in a container: memory limits and settings
- Start-up time: CDS and class data sharing
- Short task: measure and tune a high-latency service
Capstone
- Capstone: root-cause analysis and fix of a service that fails under load
Practice labs
- Comparing the bytecode of two versions with javap: Compare the javap output of two methods doing the same job and complete the script producing a short report explaining the difference.
- Diagnosing the wrong class being loaded: Find from the class loading log that the wrong one of a class present in two JARs is loaded and fix the classpath.
- Fixing a plugin class loader leak: In a plugin system that keeps old classes in memory on every reload, find the static reference and thread keeping the loader alive, release them and show the class count stabilises.
- Writing a first JMH benchmark: Write a JMH benchmark with proper warm-up and measurement settings for two ways of joining strings.
- Fixing code eliminated in a benchmark: Fix a benchmark where the JIT removes unused results and folds constant input by using Blackhole and State.
- Finding an inlining blocker from the JIT log: Find from the compilation log the method that cannot be inlined in a hot loop because of a megamorphic call, simplify the design and measure the gain with JMH.
- Summarising pauses from a GC log: Write a tool that extracts total pause time, the longest pause and the collection count from a prepared garbage collection log.
- Choosing a collector for the workload: Run the same service with G1, Parallel and ZGC, choose from throughput and pause measurements the collector meeting the latency target and document and verify the choice.
- Reducing collections caused by early promotion: Find from the log why short-lived objects spill into the old generation of a service and cut full collections by changing the allocation pattern and generation settings.
- Finding the suspect class from a heap histogram: Take a class histogram with jcmd and report the class whose instance count grows most between two measurements.
- Bounding a leaking cache: Replace a static map that is never emptied with a size-bounded cache with expiry and show the heap stays flat over a long run.
- Finding the root of a leak from a heap dump: Find the dominant objects and the reference chain holding them in the heap dump of a service hitting OutOfMemoryError, fix the listener never removed and measure again.
- Inspecting a live JVM with jcmd and jstat: Write a script that collects a running process's flags, heap use and collection counts with jcmd and jstat into one summary.
- Fixing the memory settings of a JVM in a container: Choose settings accounting for heap percentage, off-heap areas and thread stacks for a service killed in a memory-limited container and measure that it stays under the limit.
- Measuring and tuning latency with JFR: Take a Flight Recorder recording of a high-latency service, remove lock contention and allocation hot spots, shorten start-up with class data sharing and prove it with measurements.
About this course
You get to know class loading, bytecode, the JIT and the garbage collectors through measurement and use JFR and heap dumps to find and fix slowness and memory leaks.
What you will learn
- Classes and bytecode
- Memory and garbage collection
- Observation and tools
- Capstone
Prerequisites
You should be experienced in the topics of the same path up to level 401.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 501; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.