GC Fundamentals: Mark-Compact, Copying, and Mark-Sweep
A JVM-focused guide to mark-sweep, mark-compact, and copying algorithms, their heap trade-offs, and how real collectors schedule GC work.
A JVM-focused guide to mark-sweep, mark-compact, and copying algorithms, their heap trade-offs, and how real collectors schedule GC work.
GC Fundamentals: Mark-Compact, Copying, and Mark-Sweep
Introduction
This article uses three textbook algorithms—Mark-Sweep, Mark-Compact, and Copying—to explain how a JVM can find live objects and reclaim memory. Production collectors do not all run these phases the same way. Some work pauses application threads at safepoints; some marking or relocation work can run concurrently with the application. The exact schedule depends on the collector and JDK release. For the HotSpot collectors available in Java 21, see Oracle’s GC tuning guide.
Many JVM collectors are generational: objects that survive young-generation collections may be promoted, while short-lived objects are reclaimed earlier. That is a useful model, but it does not mean every JVM uses a pure copying collector for young objects and a pure mark-compact collector for old objects. Collectors combine techniques, and newer designs may organize memory into regions instead of fixed generations.
The diagrams below show simplified algorithm models. Use them to understand fragmentation, object movement, and pause costs; use GC logs and collector documentation to understand what a particular JVM is doing.
When to Use This Knowledge
Use when:
- Debugging GC pause issues or throughput problems
- Choosing or tuning a garbage collector for a specific workload
- Reading GC logs and trying to make sense of the phases
- Understanding why certain objects are collected while others are not
Do not use when:
- Writing application code that does not deal with memory directly
- Using a managed runtime that abstracts GC entirely (some languages do this well)
When NOT to Use
This is a JVM-focused guide, not a survey of all managed runtimes. Python, JavaScript, and Go use different runtime and collector designs, so the JVM examples here do not transfer directly. For many application developers, understanding allocation patterns and reading a GC log is more useful than choosing an algorithm by name.
Some managed cloud platforms limit which JVM options you can set, but the runtime still performs garbage collection. Check the platform’s supported runtime settings before applying JVM tuning flags.
Serverless functions with tight memory limits also rarely benefit from GC knowledge. The platform may kill your function before it accumulates enough garbage to trigger a significant pause. Algorithm trade-offs do not change the constraints you are operating under.
How Garbage Collection Works: The Big Picture
Every GC algorithm has to solve three problems:
- Find live objects - trace from GC roots (stack, static fields, JNI references)
- Reclaim dead objects - free memory that is no longer reachable
- Keep memory usable - avoid fragmentation so future allocations succeed
Different algorithms solve these in different ways, with different trade-offs around speed, memory overhead, and pause times.
A simplified heap view
This diagram shows a stop-the-world mark-and-sweep cycle. The live set is traced from roots, then unreachable objects are reclaimed. In a concurrent collector, parts of marking may run while application threads continue; brief pauses still occur at collector-specific safepoints.
graph LR
subgraph Before["Heap before collection"]
A["A: live"] --- B["B: unreachable"] --- C["C: live"] --- D["D: unreachable"]
end
R["GC roots"] --> A
A -. reference .-> C
subgraph After["After sweep"]
A2["A: live"] --- F1["free"] --- C2["C: live"] --- F2["free"]
end
The diagram is a teaching model, not a trace of one specific HotSpot collector. Read the collector’s log and documentation before treating a phase as stop-the-world or concurrent.
Mark-Sweep Algorithm
Mark-Sweep is the simplest algorithm. It operates in two phases:
graph LR
A["Phase 1: Mark"] --> B["Phase 2: Sweep"]
A --> C["Traverse from GC roots"]
A --> D["Mark all reachable objects"]
B --> E["Sweep unreachable objects"]
B --> F["Add to free list"]
Phase 1: Initial Mark
The collector starts from GC roots (thread stacks, static fields, JNI handles) and traverses the object graph. Every object it reaches gets marked. At the end of this phase, every reachable object has a mark bit set.
In the simple stop-the-world version of Mark-Sweep, application threads pause while the collector traces and marks reachable objects. This describes the textbook algorithm, not every JVM collector: production collectors can perform some marking concurrently and pause only for specific phases. The collector sets a mark bit for each reachable object; no object moves during marking.
GC roots are the starting point. They include: local variables and parameters on thread stacks, static fields loaded by classes, JNI handles from native code, and JVM internal objects like the method area and runtime constant pool. The collector must examine every slot in every stack frame, even if most contain primitive values that are not heap references. Long thread stacks make the mark phase longer because the collector cannot skip parts of a stack that are not at a safepoint.
When the mark phase finishes, you have a complete list of every reachable object. Unmarked objects at this stage are candidates for reclamation in the sweep phase.
Phase 2: Sweep
In the textbook version, the collector scans the heap and reclaims memory for objects without a mark bit. The free memory is added to a free list (or similar structure) for future allocations.
The sweep phase traverses the entire heap in a single pass. Unlike the mark phase which only follows references, sweep looks at every word of every object. When it finds an object whose mark bit is not set, it adds that object’s memory range to the free list and the object becomes reclaimable.
The free list is the critical difference from Copying and Mark-Compact. Instead of contiguous space, you get a fragmented chain of blocks — each with a size field and a pointer to the next block. Allocating from a free list means searching for a block large enough. First-fit or best-fit strategies apply here, and both get slower as small blocks accumulate.
This fragmentation is the core weakness of Mark-Sweep. After many cycles, you could have 500MB free but spread across hundreds of tiny blocks. A 100MB allocation fails because no single block is that large, even though the total free memory exceeds the request.
Key Characteristics of Mark-Sweep
| Aspect | Behavior |
|---|---|
| Memory overhead | Low - just one mark bit per object |
| Pause time | In a stop-the-world version, both phases pause application threads; production collectors may run some work concurrently |
| Fragmentation | High - free memory is scattered |
| Allocation speed | Slower over time - free list lookup can be costly |
| Cache behavior | Poor - objects far apart in memory |
Why Mark-Sweep Alone Is Rarely Used in Production
Mark-Sweep leaves the heap fragmented. After many cycles, free memory exists as scattered islands. Allocating a large object may fail even though total free memory is plenty, just because nothing is big enough to hold it contiguously.
This is a simplified algorithm model. HotSpot collectors can combine marking, sweeping, compaction, and region evacuation rather than implement this sequence as a pure algorithm.
Mark-Compact Algorithm
Mark-Compact extends Mark-Sweep with a compaction phase that eliminates fragmentation.
The sequence below is a textbook model. A stop-the-world implementation pauses application threads during its marking and compaction work; a production JVM collector may mark concurrently and use pauses for selected phases. Do not infer the pause behavior of G1, ZGC, or another collector from this diagram alone.
graph LR
A["Mark"] --> B["Sweep"] --> C["Compact"]
C --> D["Slide live objects to one end"]
C --> E["Update all object references"]
C --> F["Single contiguous free block"]
Phase 1: Mark
The mark phase starts at GC roots and follows every reference transitively, setting a mark bit on each reachable object. Thread stacks, static fields, JNI handles, and internal JVM structures are the starting points. The collector keeps a bitmap where each bit maps to an object — 1 for reachable, 0 for garbage.
Stack scanning can contribute to a safepoint pause because the collector needs a consistent view of references. The mechanics vary by JVM and collector; this simple model treats marking as a paused phase.
When marking finishes in this model, reachable objects are marked and the rest can be reclaimed. Work and pause time depend on the collector and phase; a concurrent marking phase does not stop application threads for its entire duration.
Phase 2: Sweep (Mark-Sweep)
The collector walks the heap linearly, checking every object’s mark bit. Unmarked objects go onto a free list as reclaimable memory ranges. Sweep does not move anything — it only records which address ranges are available.
After multiple cycles, free blocks of varying sizes pile up across the heap. A 100MB allocation might fail because the largest free block is only 50MB, even though you have 200MB total free space spread across dozens of fragments. That is the problem the third phase fixes.
Compaction is what makes Mark-Compact worth using. Sweep leaves a fragmented free list; compaction defragments it. Sweep marks what is free, compaction packs live objects together.
Phase 3: Compact
This is where Mark-Compact differs from Mark-Sweep. The collector slides all live objects toward one end of the heap, eliminating gaps. All references to moved objects are updated. The result is a single contiguous block of free memory at the far end.
Compaction works in three stages. First, the collector calculates a new address for each live object by building a map of old addresses to new addresses. Second, it copies each live object to its new location, sliding it toward the heap’s start. Third, it updates every reference in the system — stack frames, object fields, static fields, and any internal JVM tables — to point to the new addresses.
In a stop-the-world implementation, moving live objects and updating references can dominate the pause. Concurrent collectors use collector-specific barriers and phases to do some relocation work while application threads run, so the simplified timing model does not apply directly to them.
Compact Phase Details
Compacting is expensive because:
- Every live object’s location changes
- Every reference to those objects must be updated (including stack frames, other object fields, and static fields)
- The collector must update the object table that maps old addresses to new addresses
graph TB
subgraph Before["Before Compact"]
O1["Object A"]
O2["Object B"]
F1["Free"]
O3["Object C"]
F2["Free"]
F3["Free"]
end
subgraph After["After Compact"]
O1A["Object A"]
O2A["Object B"]
O3A["Object C"]
F4["Free (contiguous)"]
end
Before --> After
Key Characteristics
| Aspect | Behavior |
|---|---|
| Memory overhead | Low - same as Mark-Sweep |
| Pause time | Can be long in a stop-the-world implementation because live objects move and references are updated |
| Fragmentation | None - heap is defragmented |
| Allocation speed | Fast after compact - big contiguous block |
| Throughput | Lower than Copying due to compaction cost |
Copying Algorithm
Copying (also called evacuation or scavenge) avoids fragmentation entirely by using two equal-sized spaces called from-space and to-space.
graph TB
subgraph Semispace["Semispace Copying"]
direction LR
From["From-Space"] -->|"Live objects copied"| To["To-Space"]
To -->|"Roles swap"| From2["From-Space (next GC)"]
end
How It Works
The collector starts by picking a region called from-space as the source of truth. When from-space fills up (or on every scheduled minor GC), the collector scans reachable objects starting from GC roots and copies each one to to-space — the other half of the heap. Objects are placed contiguously, back-to-back, so to-space ends up densely packed with no gaps between them.
The forwarding pointer is the key data structure that makes this work. When an object gets copied, the original object in from-space is left behind — but its header gets overwritten with a forwarding pointer to the new location in to-space. If another object being copied holds a reference to the moved object, the collector reads that forwarding pointer and updates the reference to point to the new location instead. This two-step indirection prevents the collector from copying the same object twice during a single collection cycle.
After all live objects are copied and all references updated, from-space is discarded entirely. Every object that lived in from-space is either now in to-space (and alive) or was unreachable and died with the space. No sweep, no free list, no fragmentation. The roles of the two spaces then flip — to-space becomes the new from-space for the next collection cycle, and vice versa.
The dense packing in to-space enables bump-pointer allocation. A pointer tracks the next free address; allocating N bytes means checking that N bytes remain, writing the object, and advancing the pointer. This avoids searching a free list. Copying collectors can work well for short-lived objects, though the cost and space overhead depend on the implementation and workload.
- Objects start in from-space
- When from-space is full (or on every minor GC), the collector copies all reachable objects to to-space, one by one
- Objects are copied densely, filling to-space with no gaps
- The roles of from-space and to-space swap for the next collection
Hot Spots in Copying
In the semispace model, allocation advances a free pointer instead of searching a free list. That keeps the allocation path simple, though the real cost still depends on object size, allocation rate, and collector implementation.
// Allocation with semispace copying - simplified
Object allocate(int size) {
if (freePointer + size > toSpaceEnd) {
triggerGC(); // not enough room
}
Object result = freePointer;
freePointer += size;
return result;
}
Key Characteristics of Copying
| Aspect | Behavior |
|---|---|
| Memory overhead | High - needs two equal spaces (only 50% usable) |
| Pause time | Depends on the implementation and number of surviving objects |
| Fragmentation | None |
| Allocation speed | Very fast - bump-the-pointer allocation |
| Throughput | Workload-dependent; fewer survivors mean less copying |
| Old gen suitability | Depends on survivor rate and space available |
The Generational Twist
Some generational collectors use evacuation for young objects because many die before the next collection. Survivors may be promoted, but the old-generation strategy varies by collector; it is not necessarily pure Mark-Compact.
The table compares simplified algorithms, not the behavior or speed of specific JVM collectors. Measure the collector you run under your own workload.
Trade-off Table
| Aspect | Mark-Sweep | Mark-Compact | Copying |
|---|---|---|---|
| Memory overhead | Low | Low | High (50%) |
| Pause time | Depends on implementation | Can be long in a stop-the-world compacting collector | Depends on survivors and implementation |
| Throughput | Workload-dependent | Workload-dependent | Workload-dependent |
| Fragmentation | High | None | None |
| Allocation speed | Moderate | Fast (after compact) | Very fast |
| Old gen suitability | Some | Best | Poor |
| Young gen suitability | Some | Some | Best |
| Complexity | Low | High | Moderate |
Production Failure Scenarios
1. Premature Old Generation Fill
Symptom: Frequent Full GC events even with plenty of young generation space.
Cause: Objects being promoted too quickly (premature promotion) fill the old generation faster than Full GC can reclaim space.
Solution: Increase Survivor spaces with -XX:SurvivorRatio or reduce the tenuring threshold. Monitor promotion rates with jstat -gc.
2. Fragmentation-Induced Allocation Failure
Symptom: OutOfMemoryError: Heap Space with heap dump showing significant free memory.
Cause: Pure Mark-Sweep or poor compaction strategy leaving fragmented free memory.
Solution: Switch to a collector with better compaction (G1, ZGC, Shenandoah). Increase heap if possible.
3. Long GC Pauses
Symptom: Application freezes for seconds during Old Generation collection.
Cause: A stop-the-world marking, evacuation, or compaction phase may take longer with a large live set. Confirm the actual phase in the collector log; heap size alone does not identify the cause.
Solution: Use a low-pause collector (G1, ZGC, Shenandoah) or reduce heap size and optimize object retention.
Implementation Snippets
Reading GC Logs
On HotSpot JDK 9 and later, unified logging can record GC events. Start with a focused GC log and add detail when diagnosing a specific question. The -Xlog syntax and file options are documented in the Java 21 launcher reference.
-Xlog:gc:file=gc.log:time,uptime,level,tags
Here is a simplified G1 young-collection entry. The numbers are illustrative; exact wording and fields vary by JDK release and collector:
[0.123s][info][gc] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 64M->12M(256M) 8.4ms
[0.123s]— time since JVM startup[info][gc]— log level and tagPause Young ... G1 Evacuation Pause— a young collection pause; this line records a pause, not all work in the cycle64M->12M(256M)— heap usage before and after the event, with 256 MB capacity8.4ms— duration reported for this pause
For a deeper phase breakdown, increase logging detail for a diagnostic run and confirm the selected tag set with -Xlog:help. Avoid treating one log line as a complete description of concurrent work.
Forcing a GC with jcmd
jcmd is how you talk to a running JVM. GC.run forces a full collection and prints the result — useful when you want to see exactly how much memory the JVM thinks it reclaimed and how long it took.
First you need the PID. jps -l lists Java processes, or fall back to ps aux | grep java if jps is not cooperating.
# Find the PID of your Java process
jps -l
# or
ps aux | grep java
Then hand that PID to jcmd:
# Force a full GC and print result
jcmd <pid> GC.run
The output looks like this:
Full GC 16384K->8192K(16384K), 0.1234567 secs
That tells you the heap went from 16384K down to 8192K, the total heap size is 16384K, and the collection took about 123ms. If that number is over a second, you have a pause problem worth digging into.
Do not run this command in production under load. It stops every application thread while GC runs, which will spike your latency. Fine for local testing, benchmarking on dedicated hardware, or when you are trying to reproduce a memory issue in dev. In production, let your GC logging handle it.
Checking GC Algorithm in Use
GarbageCollectorMXBean from the Java Management API exposes the name, collection count, and cumulative collection time for each garbage collector running in the JVM. It tells you which collectors are active, but not the phase-level timings you get from GC logs.
Compile and run this class to see your active collectors:
import java.lang.management.*;
import java.util.*;
public class GCInfo {
public static void main(String[] args) {
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gc : gcBeans) {
System.out.println("GC Name: " + gc.getName());
System.out.println(" Collection count: " + gc.getCollectionCount());
System.out.println(" Collection time: " + gc.getCollectionTime() + "ms");
System.out.println(" Memory pools: " + Arrays.toString(gc.getMemoryPoolNames()));
}
}
}
Common collector names you will see include Serial GC (Serial), Parallel GC (Parallel), ConcMarkSweep GC (CMS), G1 Young Generation and G1 Old Generation (G1), ZGC (Z), and Shenandoah GC (Shenandoah). The memory pool names tell you which heap regions each collector manages — typically Eden, Survivor, and Old for generational collectors.
Observability Checklist
- Enable GC logging with
-Xlog:gc*:file=gc.log - Use
jstat -gc <pid>to monitor heap usage per space - Track
jstat -gccolumnsFGCT(Full GC time) andGCT(Total GC time) - Generate heap dump before and after GC:
jmap -dump:file=before.hprof <pid> - Use Java Flight Recorder to capture GC events with
-XX:StartFlightRecording - Monitor promotion rate from Young to Old with generational sizing tools
- Watch for compaction overhead by comparing
GCC(GC count) vsFGCC(Full GC count)
Security Notes
- GC Logging can reveal application behavior patterns - protect gc.log files
- Heap Dumps from production can expose sensitive data - sanitize before sharing
- JMX Access to GC MBeans should be restricted to authorized monitoring systems
- Memory Access via JVMTI can inspect/modify heap - secure agent attachments
Common Pitfalls / Anti-Patterns
| Pitfall | What happens | Fix |
|---|---|---|
| Assuming Full GC names one algorithm | Scope and phases vary by collector and JDK | Check the event cause and phase details in the GC log |
| Ignoring young gen sizing | Frequent minor GC or premature promotion | Tune -Xmn or -XX:NewRatio |
| Choosing a collector by algorithm label | Costs depend on the live set and workload | Compare collectors using representative measurements |
| Setting heap too small | Frequent GC of any type | Profile and size correctly |
| Assuming GC solves memory leaks | Leaked objects accumulate in old gen | Use heap dumps and profiling to find leaks |
Quick Recap Checklist
- Mark-Sweep = Mark + Sweep (fast but fragmented)
- Mark-Compact = Mark + Sweep + Compact in the textbook model (compaction can be costly)
- Copying = Copy between two spaces (fast allocation, 50% memory overhead)
- Copying can suit workloads with many short-lived objects
- Compaction trades object movement for contiguous free space
- Fragmentation causes allocation failures even with free memory available
- GC algorithm choice directly impacts pause times and throughput
- Production JVM collectors often combine these techniques rather than use one textbook algorithm
Interview Questions
Mark, Sweep, and Compact. Mark traces reachable objects from GC roots. Sweep identifies what is not reachable. Compact slides everything together, updating every reference along the way. Compaction is what separates it from Mark-Sweep and eliminates fragmentation - but it is the most expensive phase.
In a generational collector, many objects die young, so evacuating only the survivors can be efficient. That does not mean every JVM uses a pure copying algorithm for young objects and mark-compact for old objects. The collector and JDK determine how generations or regions are organized and which work runs concurrently.
Mark-Sweep leaves free memory as scattered islands. After enough cycles, you could have 500MB free spread across dozens of tiny blocks. A 100MB allocation fails not because memory is exhausted, but because nothing is big enough to hold it contiguously. Compacting collectors solve this by packing live objects together.
Bump-the-pointer. A free pointer tracks the end of used space. Allocating size N means checking if N bytes remain, writing the object there, and advancing the pointer. No searching, no metadata. Free-list allocators must hunt through a list of blocks to find one that fits - which gets slow under contention.
Throughput and pause time often trade off, but the balance depends on the collector, heap, and workload. A semispace copying collector reserves two spaces; a compacting collector moves live objects. G1 and ZGC use collector-specific concurrent work and pauses, so the textbook algorithms are useful for intuition, not a direct performance ranking.
The generational hypothesis says that many objects become unreachable soon after allocation. A generational collector can use that pattern to reclaim young objects without processing the whole heap each time. It is a design assumption that should fit the workload; it does not prescribe one copying collector or guarantee that a generational design is faster.
GC roots are objects that are guaranteed to be reachable without going through any other object. They include: thread stack frames (local variables), static fields from loaded classes, JNI references, and internal JVM structures. The marking phase starts from these roots and traverses the object graph transitively - every object reached is marked live. Everything else is garbage. GC roots are never collected and serve as the starting point for all GC algorithms.
A safepoint is a point where the JVM can bring application threads to a state that lets it perform operations requiring a consistent view of references. Stop-the-world (STW) means application threads pause for a phase. Concurrent collectors such as G1 and ZGC do substantial work while application threads run, but still use pauses for collector-specific operations. The pause schedule depends on the collector and JDK.
Semispace copying uses two equal halves of memory (from-space and to-space). At any time, only one half is active for allocation. When GC runs, live objects copy to the other half, leaving the filled half empty. This means half your heap is always idle. The trade-off is acceptable in young generation because most objects die there - copying is fast and fragmentation-free, which beats the fragmentation and allocation overhead of Mark-Sweep for short-lived objects.
Some collectors may retain objects that became unreachable after a concurrent marking phase observed them as live. They can be reclaimed in a later cycle. The amount and behavior depend on the collector's marking algorithm and barriers; do not assume every concurrent collector handles it the same way.
The card table is a data structure (typically 512 bytes per card) that tracks which memory regions might contain references from old generation to young generation. When old gen references young gen change, the card is marked "dirty." This lets minor GC scan only cards with potential cross-generational references rather than the entire old generation. This optimization dramatically reduces the scanning overhead for minor GC.
Adaptive sizing (-XX:+UseAdaptiveSizePolicy, enabled by default with G1 and Parallel GC) monitors allocation rates and survival rates, then automatically adjusts heap region sizes to match workload patterns. It can resize Eden, Survivor, and old generation spaces dynamically. The risk in production is that resizing events can trigger GC pauses you cannot predict. For deterministic performance, disable adaptive sizing and set explicit ratios.
In generational HotSpot collectors, a young collection handles young-generation regions or spaces. “Full GC” usually refers to a broader collection, but its exact scope, triggers, and pause behavior depend on the collector and JDK. Read the event details in the GC log rather than assuming a fixed duration or algorithm from the label alone.
Premature promotion. If Survivor spaces are too small, objects get promoted to old gen before they should. Even though the total heap usage is low, old gen fills with short-lived objects that should still be in young gen. This triggers Full GC when old gen eventually fills. The fix is usually to increase Survivor spaces via -XX:SurvivorRatio or -XX:MaxTenuringThreshold tuning.
G1 uses remembered sets to track references into regions, which helps it select regions for collection without scanning the whole heap for every pause. The memory and processing overhead depends on the workload and JVM configuration; avoid treating one percentage as universal.
In the textbook model, mark traces live objects, sweep records free space, and compact moves survivors together. Their cost depends on the live set and the collector's implementation. A stop-the-world compaction can take a long pause, but a concurrent collector may perform some relocation work while application threads run.
When most objects die before a young collection, an evacuation collector copies only the survivors and can reclaim the rest of the region. The cost rises when more objects survive. Modern JVMs do not all use a simple two-space copying scheme, and their old-generation strategies differ by collector.
During an STW phase, application threads pause while the collector performs that phase's work. A pause may include root scanning, evacuation, or other collector-specific tasks; concurrent collectors do some marking or relocation while the application runs. Heap size alone does not predict pause length: live data, allocation rate, collector, and workload matter too.
Common causes include allocation pressure, promotion failure, explicit collection requests, or class-metadata pressure, but triggers vary by collector and JDK. A Full GC event may scan or reclaim a broad part of the heap and can pause application threads; the log's cause and phase details matter. Frequent events are a signal to investigate allocation, live data, and configuration, not proof of a memory leak by themselves.
GC roots are references the collector treats as live starting points, including references in thread stacks, static fields, JNI handles, and JVM structures. Tracing begins from roots, but collectors do not necessarily rescan every root during every pause. Root scanning and stack processing vary by collector; concurrent algorithms may use additional barriers or phases to keep the view consistent.
Further Reading
- JVM Heap Memory: Young Gen, Old Gen, Metaspace, and Object Headers — Internal link to related roadmap blog
- CMS and G1 Collectors: Low-Latency Garbage Collection — Internal link to related roadmap blog
- Oracle Java 21 HotSpot GC Tuning Guide — Collector-specific behavior and tuning guidance
- Baeldung: Understanding Java GC Logs — Practical guide to reading and interpreting GC logs
- Advanced Java & JVM Internals Roadmap — Parent roadmap
Conclusion
Mark-Sweep, Mark-Compact, and Copying are useful models for understanding reclamation, fragmentation, and object movement. Real JVM collectors combine these techniques, and their stop-the-world pauses depend on the collector and JDK. Use the model to read logs; use the current collector documentation and measurements to explain a production pause.
Category
Related Posts
CMS and G1 Collectors: Low-Latency Garbage Collection
Understand G1 for current HotSpot deployments and CMS as a historical collector removed in JDK 14, with version-labeled examples and GC logging.
JVM GC Tuning: Heap Sizing and Threshold Optimization
Practical strategies for sizing JVM heap, tuning generation ratios, and optimizing GC thresholds to reduce pause times and improve throughput.
JVM Heap Memory: Layout, Garbage Collection, and Headers
Learn how JVM heap layouts differ by collector and JDK, where Metaspace fits, and how to measure object headers with JOL on your runtime.