Inside the JVM
Class loading, memory areas, the JIT compiler and garbage collection — what the JVM does with your code.
- Module 10 of 11
- Advanced
- 10 chapters
- 1 h 2 min
Knowing what the JVM does with your code explains memory errors, slow start-ups and garbage-collection pauses — and how to diagnose them in production.
What you will be able to do
- Explain class loading and the JVM's memory areas
- Describe how the JIT speeds up hot code
- Explain how garbage collectors decide what to free
- Read GC behaviour and tune it
Chapters
1. The JVM's PartsThe JVM specification defines what a JVM must do; HotSpot (in OpenJDK and Oracle's JDK) is the implementation almost everyone runs, and it's what3 min2. Class LoadingThe stage crew doesn't bring every prop in before the show — only when a scene needs it. Each prop is fetched, inspected for safety, set up, and4 min3. Runtime Memory AreasMetaspace vs PermGen: before Java 8, class metadata lived in a fixed-size heap area called PermGen, famous for OutOfMemoryError: PermGen space.6 min4. Bytecode and the JITBytecode is the instruction set javac produces. It's stack-based: instructions push values onto an operand stack and pop them off.6 min5. What Garbage Is: Reachability and GC RootsAn object is live if it's reachable by following references from a GC root; everything else is garbage and can be freed3 min6. Generations: Most Objects Die YoungThe weak generational hypothesis: most objects die young — temporary strings, iterators, request objects, boxed numbers. A few live a long time — caches,5 min7. How Collectors Work: Mark, Sweep, Compact, CopyThroughput — the percentage of time spent running the application rather than collecting (batch jobs care).4 min8. The CollectorsChoose with a flag at start-up. Find out which one you're running: java -XX:+PrintCommandLineFlags -version printed -XX:+UseG1GC on this Mac, along with the5 min9. Reference Types: Strong, Soft, Weak, PhantomObject big — new byte[10000000];3 min10. Tuning and Diagnosis-Xms<size> initial heap size e.g. -Xms2g7 min
Extras
The Whole StoryThe whole module retold as one story — no new facts, a fast revision of Inside the JVM.RevisionInterview QuestionsReal interview questions on Inside the JVM, answered the way you would say them out loud.Interview prepQuick ReferenceGlossary and cheat sheet for Inside the JVM — the page to reread before an interview.Reference