G1 GC vs Java 23 ZGC

1. Survivor Space
과거 G1 GC에서는 Eden, Survivor0, Survivor1, Old 공간이 존재합니다.
GC가 객체 참조 관계를 추적한 다음, 살아남은 객체들을 이동시켜야 하므로 복사 비용이 발생합니다.
Java 23 ZGC에서는 기본값으로 Generation 모드이며, Young, Old 공간만 존재합니다.
2. Move Alive Object
과거 G1 GC는 대략 Eden → Survivor 0 → Survivor 1 → Old 순으로 살아있는 객체의 위치가 이동됩니다.
Java 23 ZGC에서는 Young → Old 순으로 살아남은 객체의 위치가 이동됩니다.
G1 GC 객체 이동 과정
- objects are allocated in Eden space, while both survival spaces are empty.
- JVM performs a minor GC when Eden space is filled with objects (either dead or alive). Once the dead objects are removed, all the alive objects are now moved from Eden space to S0. Now, Eden and S1 are empty.
- When the Eden space is again filled with objects, another minor GC is performed and removes all the dead objects. This time, the alive objects from Eden space and S0 are moved to S1. Now, Eden and S0 are empty. At any given point of time one of the survivor spaces are empty.
- When the surviving objects reach a certain threshold of moving around the survivor space, they are moved to Old Generation.
3. Stop-The-World 이해하기
Garbage Collection 작업을 위해 JVM이 애플리케이션 실행을 “완전히 멈추는” 현상을 의미합니다.
- GC가 객체 참조 관계를 추적하고 복사할 때, Java 애플리케이션이 동시에 객체를 생성하거나 수정하면, GC 결과가 불일치할 수 있습니다.
- 그래서 잠깐 JVM이 멈추고 GC 작업을 수행합니다.
3-1. Java 23 ZGC : Concurrent
Colored Pointers
- ZGC는 64비트 포인터의 일부 비트를 객체의 상태(이동 중, 새 주소 존재)를 추적 가능하게 합니다.
64비트 포인터: [GC 비트][실제 객체 주소]
↑ ↑
색상 객체 위치

➡️ Colored Pointers는 ZGC가 GC 중에도 Stop-the-World 없이 안전하게 객체를 관리할 수 있게 도와줍니다.
Load Barrier
ZGC가 객체를 참조할 때마다 자동으로 “Load Barrier”라는 코드가 삽입됩니다.
동작 방식:
- 앱이 어떤 객체를 읽으려 한다.
- Load barrier가 가로채서 객체가 GC 도중이면 이동 완료된 새 주소로 redirect
- GC가 객체를 복사 중이더라도 앱은 항상 안전한 위치의 객체를 읽게 된다.
Why?
GC가 객체를 참조 및 복사 중일 때, 앱은 기존 주소에 있는 객체를 그대로 참조한다.
복사가 완료된 후, Load Barrier가 이동된 주소를 감지하여 새 주소로 Redirect 해줍니다.
Qna. GC Root 수집 시 왜 Pause 하는지
ZGC에서 root 참조는 JVM의 레지스터, 스택, 전역 변수 등을 GC가 안전하게 읽기 위해서, 그 순간만큼은 모든 스레드를 멈춰야 합니다.
- Root는 GC가 객체 생존 여부를 판단하기 위해 시작하는 참조의 출발점
Understanding Pause Time in Garbage Collection
Pause time is the period when your application stops running because the system is cleaning up unused memory. If these pauses are too long, your app might feel slow or unresponsive, which can be frustrating for users. Minimizing pause time is important to keep your app running smoothly.
Among Java's garbage collectors, ZGC (Z Garbage Collector) is known for having the least pause time. It’s designed to keep pauses to just a few milliseconds, even with large amounts of memory.
This makes it ideal for applications where minimal interruptions and smooth performance are critical.
Java 23 ZGC 특징
- GC 작업을 앱 실행과 동시에 처리한다. (대부분 Concurrent 처리)
- Colored Pointers + Load Barrier
- Low Pause Times (매우 짧은 일시중지 시간)
- Heap 크기를 수 MB부터 최대 16TB까지 처리 가능
- 객체를 Survivor 공간을 거치며 반복하지 않는다. (복사 최소화)
1. Low Pause Times: One of ZGC's hallmark features is the extremely short and consistent pause times, independent of heap size. Pause times are usually sub-10 ms, even for very large heaps, making it ideal for real-time, latency-sensitive applications.
2. Scalability: ZGC is designed to handle large heap sizes, ranging from megabytes to multi-terabyte scales, without significant degradation in performance.
3. Concurrent Processing: Most of the work in ZGC is done concurrently with the running application, including marking, relocation, and compaction of objects. This allows ZGC to achieve minimal interruptions to the application's processing.
참고자료
2025.04.02 - [JAVA] - Java GC 동작 원리: 가비지 컬렉션이 메모리를 정리하는 법
Java GC 동작 원리: 가비지 컬렉션이 메모리를 정리하는 법
Garbage CollectionJava garbage collection is the process by which java programs perform automatic memory management.➡️ 메모리 자동 관리 When a Java program run on the JVM, objects are created in the heap space, which is a portion of memory ded
kylo8.tistory.com
JDK 23: What to Expect?
JDK 23 introduces pattern matching, modular imports, Class-File API, and ZGC in generational mode, enhancing efficiency and performance in Java apps.
www.unlogged.io
'JAVA' 카테고리의 다른 글
Java GC 동작 원리: 가비지 컬렉션이 메모리를 정리하는 법 (0) | 2025.04.02 |
---|---|
Java 객체 비교: equals()와 hashCode()로 보는 물리적 vs 논리적 동등성 (0) | 2025.03.31 |
Java 버전별 변화 및 주요 기능 - java 8, 11, 17, 21 (0) | 2025.03.14 |
Java Stream map vs flatMap 차이점과 활용법 (kotlin) (0) | 2025.03.04 |
Java 21 가상 스레드란? 기존 OS 스레드와의 차이점 정리 (0) | 2025.02.18 |
G1 GC vs Java 23 ZGC

1. Survivor Space
과거 G1 GC에서는 Eden, Survivor0, Survivor1, Old 공간이 존재합니다.
GC가 객체 참조 관계를 추적한 다음, 살아남은 객체들을 이동시켜야 하므로 복사 비용이 발생합니다.
Java 23 ZGC에서는 기본값으로 Generation 모드이며, Young, Old 공간만 존재합니다.
2. Move Alive Object
과거 G1 GC는 대략 Eden → Survivor 0 → Survivor 1 → Old 순으로 살아있는 객체의 위치가 이동됩니다.
Java 23 ZGC에서는 Young → Old 순으로 살아남은 객체의 위치가 이동됩니다.
G1 GC 객체 이동 과정
- objects are allocated in Eden space, while both survival spaces are empty.
- JVM performs a minor GC when Eden space is filled with objects (either dead or alive). Once the dead objects are removed, all the alive objects are now moved from Eden space to S0. Now, Eden and S1 are empty.
- When the Eden space is again filled with objects, another minor GC is performed and removes all the dead objects. This time, the alive objects from Eden space and S0 are moved to S1. Now, Eden and S0 are empty. At any given point of time one of the survivor spaces are empty.
- When the surviving objects reach a certain threshold of moving around the survivor space, they are moved to Old Generation.
3. Stop-The-World 이해하기
Garbage Collection 작업을 위해 JVM이 애플리케이션 실행을 “완전히 멈추는” 현상을 의미합니다.
- GC가 객체 참조 관계를 추적하고 복사할 때, Java 애플리케이션이 동시에 객체를 생성하거나 수정하면, GC 결과가 불일치할 수 있습니다.
- 그래서 잠깐 JVM이 멈추고 GC 작업을 수행합니다.
3-1. Java 23 ZGC : Concurrent
Colored Pointers
- ZGC는 64비트 포인터의 일부 비트를 객체의 상태(이동 중, 새 주소 존재)를 추적 가능하게 합니다.
64비트 포인터: [GC 비트][실제 객체 주소]
↑ ↑
색상 객체 위치

➡️ Colored Pointers는 ZGC가 GC 중에도 Stop-the-World 없이 안전하게 객체를 관리할 수 있게 도와줍니다.
Load Barrier
ZGC가 객체를 참조할 때마다 자동으로 “Load Barrier”라는 코드가 삽입됩니다.
동작 방식:
- 앱이 어떤 객체를 읽으려 한다.
- Load barrier가 가로채서 객체가 GC 도중이면 이동 완료된 새 주소로 redirect
- GC가 객체를 복사 중이더라도 앱은 항상 안전한 위치의 객체를 읽게 된다.
Why?
GC가 객체를 참조 및 복사 중일 때, 앱은 기존 주소에 있는 객체를 그대로 참조한다.
복사가 완료된 후, Load Barrier가 이동된 주소를 감지하여 새 주소로 Redirect 해줍니다.
Qna. GC Root 수집 시 왜 Pause 하는지
ZGC에서 root 참조는 JVM의 레지스터, 스택, 전역 변수 등을 GC가 안전하게 읽기 위해서, 그 순간만큼은 모든 스레드를 멈춰야 합니다.
- Root는 GC가 객체 생존 여부를 판단하기 위해 시작하는 참조의 출발점
Understanding Pause Time in Garbage Collection
Pause time is the period when your application stops running because the system is cleaning up unused memory. If these pauses are too long, your app might feel slow or unresponsive, which can be frustrating for users. Minimizing pause time is important to keep your app running smoothly.
Among Java's garbage collectors, ZGC (Z Garbage Collector) is known for having the least pause time. It’s designed to keep pauses to just a few milliseconds, even with large amounts of memory.
This makes it ideal for applications where minimal interruptions and smooth performance are critical.
Java 23 ZGC 특징
- GC 작업을 앱 실행과 동시에 처리한다. (대부분 Concurrent 처리)
- Colored Pointers + Load Barrier
- Low Pause Times (매우 짧은 일시중지 시간)
- Heap 크기를 수 MB부터 최대 16TB까지 처리 가능
- 객체를 Survivor 공간을 거치며 반복하지 않는다. (복사 최소화)
1. Low Pause Times: One of ZGC's hallmark features is the extremely short and consistent pause times, independent of heap size. Pause times are usually sub-10 ms, even for very large heaps, making it ideal for real-time, latency-sensitive applications.
2. Scalability: ZGC is designed to handle large heap sizes, ranging from megabytes to multi-terabyte scales, without significant degradation in performance.
3. Concurrent Processing: Most of the work in ZGC is done concurrently with the running application, including marking, relocation, and compaction of objects. This allows ZGC to achieve minimal interruptions to the application's processing.
참고자료
2025.04.02 - [JAVA] - Java GC 동작 원리: 가비지 컬렉션이 메모리를 정리하는 법
Java GC 동작 원리: 가비지 컬렉션이 메모리를 정리하는 법
Garbage CollectionJava garbage collection is the process by which java programs perform automatic memory management.➡️ 메모리 자동 관리 When a Java program run on the JVM, objects are created in the heap space, which is a portion of memory ded
kylo8.tistory.com
JDK 23: What to Expect?
JDK 23 introduces pattern matching, modular imports, Class-File API, and ZGC in generational mode, enhancing efficiency and performance in Java apps.
www.unlogged.io
'JAVA' 카테고리의 다른 글
Java GC 동작 원리: 가비지 컬렉션이 메모리를 정리하는 법 (0) | 2025.04.02 |
---|---|
Java 객체 비교: equals()와 hashCode()로 보는 물리적 vs 논리적 동등성 (0) | 2025.03.31 |
Java 버전별 변화 및 주요 기능 - java 8, 11, 17, 21 (0) | 2025.03.14 |
Java Stream map vs flatMap 차이점과 활용법 (kotlin) (0) | 2025.03.04 |
Java 21 가상 스레드란? 기존 OS 스레드와의 차이점 정리 (0) | 2025.02.18 |