JVM architecture
On this page 8 topics
Overview
Topics
- Class loading
- bytecode
- runtime data areas
- JIT compilation
Learn first
3 h of practice (estimate)
Learning outcomes
- Describe class loading (loading, linking, initialization) and the class-loader hierarchy.
- Read bytecode for a small method with
javap -cand relate it to the source. - Name the runtime data areas (heap, stacks, metaspace, code cache) and what lives in each.
- Explain interpretation, JIT compilation (C1/C2, tiered), and why performance changes during warm-up.
Lessons
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)
| ID | Outcome | Task |
|---|---|---|
| MID-001-EX01 | 1 | Print the class loader of String, a Shop class, and java.sql.Connection; explain each result. |
| MID-001-EX02 | 2 | Run javap -c -p on a class with total(int,int) and annotate each instruction. |
| MID-001-EX03 | 2 | Compile if (qty > 0) return price * qty; else return 0; and identify the branch instruction. |
| MID-001-EX04 | 3 | Draw the runtime data areas and place: an Order object, a local int, a class's method table, JIT output. |
| MID-001-EX05 | 4 | Run a timing loop with and without warm-up; explain the difference. |
| MID-001-EX06 | 1 | Scenario: NoClassDefFoundError after deploy though the build passed. Give two likely causes. |
Show solutions
- EX01
Stringgivesnull(bootstrap); the Shop class gives the application loader;java.sql.Connectiongives the platform loader. - EX02
iload_0/iload_1push arguments,imulmultiplies,ireturnreturns the top value. - EX03 A conditional jump such as
ifleskips to thereturn 0path. - EX04 Object on heap; local
intin 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.
ClassNotFoundExceptionwould 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.
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).