1. Concept library
  2. Java & Spring Boot
  3. Module 3: JVM internals

Concept

JIT compilation

How the JVM turns hot bytecode into optimised machine code while your program runs.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain the difference between interpreting bytecode and JIT-compiling it
  2. Describe what makes a method "hot" and how tiered compilation reacts
  3. Name two optimisations the JIT applies, such as inlining and escape analysis

In practice

A few lines that show JIT compilation doing its job.

Java
// A benchmark must warm up before measuring
for (int round = 0; round < 5; round++) {
    long start = System.nanoTime();
    for (int i = 0; i < 1_000_000; i++) work(i);
    System.out.println("round " + round + ": " + (System.nanoTime() - start) / 1_000_000 + " ms");
}
// round 0: 180 ms, round 1: 40 ms, round 2: 12 ms ... as the JIT kicks in

The common mistake

Watch for

Timing a method once in a main() and drawing conclusions. The first run is interpreted and includes class loading; use a harness such as JMH that warms up and repeats.

What to know first

Your roadmap puts these before JIT compilation, unless you already know them.

How it stays learned

Once a session shows you understand JIT compilation, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Related

Next in the modulePerformance profiling →