java -Xlog:all=trace MyApp — OS spawns the JVM process. The -Xlog flag enables verbose GC/JIT/class-load tracing useful for debugging.libjvm.so that initialises the entire JVM runtime from scratch.Delegation model: JVM always tries the parent loader first before attempting to load itself. Prevents duplicate class definitions.
.class file from classpath/module path → Parses bytecode → Derives an internal C++ structure called a Klass → Stores the Klass in Metaspace. Each Klass = the JVM's runtime blueprint of your Java class.int → 0, boolean → false, Object → null. Your code's values are NOT applied yet."java/lang/String" as a string) with actual direct memory pointers. Makes method calls fast.<clinit> method — runs all static { } blocks and assigns the exact user-defined values to static fields. Only runs once per class per JVM.Metaspace lives in native OS memory — completely outside the Java Heap. Capped by -XX:MaxMetaspaceSize. Grows automatically by default (unlike the old PermGen which had a fixed size and frequently caused OutOfMemoryError).
-XX:+UseCompressedClassPointersjava.lang.OutOfMemoryError: PermGen space. Metaspace auto-expands using native memory, vastly reducing this error class.-Xss. Stack overflow → StackOverflowError..class metadata.Index 0:
this reference (instance methods)Index 1..n: method parameters then local variables
Example:
int add(int a, int b)[this][a][b] at indices 0,1,2
Example:
a + b:1.
iload_1 → push a2.
iload_2 → push b3.
iadd → pop both, push resultAll arithmetic flows through here.
Constant Pool ref: pointer to the class's runtime constant pool
Return address: where to jump after the method returns
Exception table: maps bytecode ranges to catch handlers
JVM tracks two counters per method: i (invocation count) and b (backedge/loop count). Hot code is progressively compiled to native machine code.
-XX:ReservedCodeCacheSize.hashCode() is ever called. Zero cost otherwise.G1GC divides the heap into equal-sized regions (1–32 MB each). Allocation path depends on object size:
Each thread pre-owns a private chunk of Eden. Allocation = just bumping a pointer. Zero synchronization needed.
Extremely fast: comparable to stack allocation. TLAB exhausted → thread requests a new one.
Requires 100% physically contiguous regions end-to-end. Any leftover space in the last region is wasted (internal fragmentation).
Avoid large byte[] / int[] allocations in tight loops. Example: a 10 MB byte[] on a 16 MB region size goes Humongous immediately.
Problem: During Young GC, we need to know which Young objects are referenced by Old objects — without scanning ALL of Old Gen (could be 100 GB!). G1GC solves this with a 3-layer tracking system.
Key = External Region Address, Value = Dirty Card Index. Allows GC to scan only a tiny set of cards instead of the full old gen.-XX:G1RSetUpdatingPauseTimePercent controls how much STW time is spent on RSet updates.- Scans RSets of young regions to find incoming Old→Young pointers
- Evacuates (copies) live objects from Eden + From-Survivor → To-Survivor
- GC Age incremented (+1) for every surviving object
| Rule | Condition | Action |
|---|---|---|
| Age Threshold | GC Age reaches 15 (default) | Object promoted to Old Region |
| Survivor Overflow | Survivor space is full (can't fit more) | Excess objects promoted early |
| Humongous Reclaim | Humongous primitive array with 0 incoming refs | Eagerly destroyed during Young GC immediately |
When Old Gen crosses IHOP, G1GC calculates: can marking threads finish before Old Gen completely fills up?
If yes → start concurrent marking. This is an adaptive prediction, not a fixed threshold.
→ Before overwriting a reference, the old value is logged to an SATB queue.
→ Preserves the logical "snapshot" of the heap from marking's start point.
→ Objects modified after snapshot starts = "float garbage" (collected next cycle).
2. Remark STW — Short pause. Drains remaining SATB buffers. Processes weak/soft/phantom references.
3. Cleanup STW — Scrubs/rebuilds RSets. Instantly reclaims regions that are proven 100% garbage (no live objects at all).
4. Mixed GC — Collects ALL Young regions + a carefully chosen subset of Old regions (those with the highest garbage ratio). G1 stops collecting Old regions the moment it would breach
-XX:MaxGCPauseMillis. This is the core of G1's "Garbage First" naming — it always prioritizes the most garbage-dense regions.
-XX:MaxGCPauseMillis=200 is the default. G1 will reduce the Mixed GC collection set to stay within budget. Lower = more frequent, smaller GC pauses.-XX:G1HeapRegionSize=32m. This raises the Humongous threshold from 8 MB → 16 MB.