Skip to content
Ameen Abozaid
MID-001

JVM architecture

  • 6 Lessons
  • 3 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Class loading
  • bytecode
  • runtime data areas
  • JIT compilation

Learn first

3 h of practice (estimate)

Learning outcomes

  1. Describe class loading (loading, linking, initialization) and the class-loader hierarchy.
  2. Read bytecode for a small method with javap -c and relate it to the source.
  3. Name the runtime data areas (heap, stacks, metaspace, code cache) and what lives in each.
  4. Explain interpretation, JIT compilation (C1/C2, tiered), and why performance changes during warm-up.

Lessons

  1. 01From .class file to running code
  2. 02Class loading and class loaders
  3. 03Reading bytecode with javap
  4. 04Runtime data areas
  5. 05The JIT compiler and warm-up
  6. 06Demo: watching the JIT with -XX:+PrintCompilation

Lab and exercises

Lab

MID-001-LAB1 · Warm-up effect

Outcomes: 1–4 · Time: ~3 h Start Shop and send 5,000 checkout requests with a simple load tool, recording each latency. Plot the first 1,000 requests against steady state. Repeat with -XX:+PrintCompilation and mark compilation events on the timeline. Explain the curve. Acceptance: chart plus explanation referencing JIT tiers.

Exercises (assessment: bytecode-reading quiz, a class-loading scenario, and the lab)

IDOutcomeTask
MID-001-EX011Print the class loader of String, a Shop class, and java.sql.Connection; explain each result.
MID-001-EX022Run javap -c -p on a class with total(int,int) and annotate each instruction.
MID-001-EX032Compile if (qty > 0) return price * qty; else return 0; and identify the branch instruction.
MID-001-EX043Draw the runtime data areas and place: an Order object, a local int, a class's method table, JIT output.
MID-001-EX054Run a timing loop with and without warm-up; explain the difference.
MID-001-EX061Scenario: NoClassDefFoundError after deploy though the build passed. Give two likely causes.
Show solutions
  • EX01 String gives null (bootstrap); the Shop class gives the application loader; java.sql.Connection gives the platform loader.
  • EX02 iload_0/iload_1 push arguments, imul multiplies, ireturn returns the top value.
  • EX03 A conditional jump such as ifle skips to the return 0 path.
  • EX04 Object on heap; local int in the thread's stack frame; method table in metaspace; JIT output in the code cache.
  • EX05 The cold loop includes interpretation and compilation; after warm-up the same code is much faster.
  • EX06 A dependency JAR missing from the runtime classpath (compile vs runtime scope mismatch), or a static initializer that threw earlier. ClassNotFoundException would instead be a failed by-name lookup.
  • Outcome 4 is also covered by the lab and Q09-Q10.

Quiz

Outcomes: O1 class loading · O2 bytecode · O3 data areas · O4 JIT and warm-up.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1The three class-loading phases are:O1
  2. 2Which loader loads java.lang.String?O1
  3. 3A class compiled fine but is absent at runtime. You typically get:O1
  4. 4Class.forName("x.Missing") with no such class throws:O1
  5. 5The JVM executes bytecode using an:O2
  6. 6iload_0; iload_1; iadd; ireturn returns:O2
  7. 7Class metadata lives in:O3
  8. 8JIT-compiled machine code lives in:O3
  9. 9In tiered compilation, which compiler applies the heaviest optimization?O4
  10. 10First requests after startup are slow mainly because:O4

Practical part

Six exercises MID-001-EX01 to EX06 plus the lab with its chart. Pass: at least five exercises correct and a lab explanation that names the JIT tiers.

Common mistakes

Benchmarking cold code; assuming the JVM runs bytecode as written.

Assessment

Bytecode-reading quiz and a class-loading scenario (NoClassDefFoundError vs ClassNotFoundException).

Career relevance

Basis for memory tuning (MID-002) and profiling (MID-008).

Type to search levels, phases, modules and lessons.