SlideShare a Scribd company logo
1 of 72
Download to read offline
Garbage Collection
2015.02.13
이소은
목차
0.Garbage Collection을 공부한 이유
1.Garbage Collection
2.Hotspot JVM의 Garbage Collection
3.Hotspot JVM의 Garbage Collector의 종류
2
0. Garbage Collection을 공부한 이유
1. Garbage Collection
1.1 Garbage Collection이란?
1.2 Garbage Collection의 대상
1.3 Garbage Collection과 Fragmentation
1. Garbage Collection
1.1 Garbage Collection이란?
1.2 Garbage Collection의 대상
1.3 Garbage Collection과 Fragmentation
1.1 Garbage Collection이란?
• Java에서 할당 받은 메모리를 해제 하는 것은 개발자의 영역이 아님
• System.gc()나 close()와 같은 함수도 있잖아?
 Garbage Collection을 명시적으로 수행하거나 해당 객체의 사용을 중지하겠
다는 의사 표현일 뿐 제거하고자 하는 객체를 메모리에서 삭제하겠다는 것은 아
님.
7
1. Garbage Collection
“Heap storage for objects is reclaimed by an automatic
storage management system(typically a garbage collector);
objects are never explicitly deallocated.”
--Java Virtual Machine Speculation, Section 3.5.3[JVMS2 1999]
8
1.1 Garbage Collection이란
1. Garbage Collection
1. Garbage Collection
1.1 Garbage Collection이란?
1.2 Garbage Collection의 대상
1.3 Garbage Collection과 Fragmentation
Garbage Collection  Garbage를 모으는 작업.
그럼 Garbage를 정의하고 넘어가면,
Heap과 Method Area에서 사용되지 않는 Object를 의미.
사용되지 않는 다는 의미를 어디까지 볼 것이냐는 문제
10
1.1 Garbage Collection의 대상
1. Garbage Collection
PC Registers
Java Virtual
Machine
Stacks
Method
Area
Heap
Native
Method
Stacks
JVM의 Runtime Data Areas
•현재 사용 여부는 Root Set과의 관계로 판단
•Root Set에서 어떤 식으로든 Reference관계가 있다면 Reachable Object.
즉 현재 사용하고 있는 Object로 간주.
•이렇게 판단해서 Reachable Object가 아니면 Garbage Collection의 대상이 됨.
11
1.2 Garbage Collection의 대상
1. Garbage Collection
Unreachable
Reachable
Root Set
•현재 사용 여부는 Root Set과의 관계로 판단
•Root Set에서 어떤 식으로든 Reference관계가 있다면 Reachable Object.
즉 현재 사용하고 있는 Object로 간주.
•이렇게 판단해서 Reachable Object가 아니면 Garbage Collection의 대상이 됨.
12
1.2 Garbage Collection의 대상
1. Garbage Collection
Unreachable
Reachable
Root Set
한 객체는 여러 다른 객체를 참조하고, 참조된 다른 객체들도 마찬가지로 또 다른 객체들을 참조할 수 있
으므로 객체들은 참조 사슬을 이룬다. 이런 상황에서 유효한 참조 여부를 파악하려면 항상 유효한 최초의
참조가 있어야 하는데 이를 객체 참조의 root set이라고 한다.
•현재 사용 여부는 Root Set과의 관계로 판단
•Root Set에서 어떤 식으로든 Reference관계가 있다면 Reachable Object.
즉 현재 사용하고 있는 Object로 간주.
•이렇게 판단해서 Reachable Object가 아니면 Garbage Collection의 대상이 됨.
13
1.2 Garbage Collection의 대상
1. Garbage Collection
Unreachable
Reachable
Root Set
1. Garbage Collection
1.1 Garbage Collection이란?
1.2 Garbage Collection의 대상
1.3 Garbage Collection과 Fragmentation
•새로운 Object의 할당을 위해 한정된 Heap공간을
재활용하려는 목적으로 수행
•재활용을 위해 수행된 메모리의 해지는 할당한 그 자
리에서 이루어지기 때문에
Garbage가 빠져 나간 자리는 듬성듬성
•Heap의 단편화(Fragmentation)발생
•이러한 현상을 방지하기 위해 Compaction과 같은
Algorithm을 사용
15
1.3 Garbage Collection과 Fragmentation
1. Garbage Collection
Live
Garbage
Live
Live
Garbage
Live
Garbage
Live
Live
Free(1K)
Live
Live
Free(3K)
Live
Free(2K)
Live
Garbage
Collection
다시 한번 정리하면 Garbage Collection이란
Heap을 재활용하기 위해 Root Set에서 참조되지 않는 Object를 없애 가용한 공간을 만드는 작업
2. Hotspot JVM의 Garbage Collection
2.1 Hotspot JVM의 Garbage Collection 소개
18
Garbage Collector는 두 가지 가설 하에 만들어짐.
대부분의 객체는 금방 접근 불가능 상태가 된다. – high infant mortality
오래된 객체에서 젊은 객체로의 참조는 아주 적게 존재한다.
이러한 가설을 ‘weak generational Hypothesis’
이러한 가설의 장점을 최대한 살리기 위해 Hotspot JVM에서는 크게 2개로 물리
적 공간을 나눔.
2.1 Hotspot JVM의 Garbage Collection 소개
2. Hotspot JVM의 Garbage Collection
19
• Young 영역(Yong Generation 영역):
새롭게 생성한 객체의 대부분이 여기에 위치.대부분의 객체가 금방 접근 불가능 상태가 되
기 때문에 매우 많은 객체가 Young 영역에 생성되었다가 사라짐.이 영역에서 객체가 사라
질때 Minor GC가 발생한다고 말함.
• Old 영역(Old Generation 영역):
접근 불가능 상태로 되지 않아 Young 영역에서 살아남은 객체가 여기로 복사됨. 대부분
Young 영역보다 크게 할당하며, 크기가 큰 만큼 Young 영역보다 GC는 적게 발생. 이 영
역에서 객체가 사라질 때 Major GC(혹은 Full GC)가 발생한다고 말함.
2.1 Hotspot JVM의 Garbage Collection 소개
2. Hotspot JVM의 Garbage Collection
20
Eden Tenured Permanent
Young Generation Old Generation Method Area
Survivor1
Survivor2
2.1 Hotspot JVM의 Garbage Collection 소개
2. Hotspot JVM의 Garbage Collection
21
Eden Tenured Permanent
Young Generation Old Generation Method Area
Survivor1
Survivor2
2.1 Hotspot JVM의 Garbage Collection 소개
2. Hotspot JVM의 Garbage Collection
22
Eden Tenured Permanent
Young Generation Old Generation Method Area
Survivor1
Survivor2
2.1 Hotspot JVM의 Garbage Collection 소개
2. Hotspot JVM의 Garbage Collection
25
여기서 잠깐 !
Old 영역에 있는 객체가 Young 영역의 객체를 참조하는 경우가 있을 때에는 어떻게 처리될까?
Card Table이라는 장치를 마련
Card Table  Old Generation의 메모리를 대표하는 별도의 메모리 구조를 의미
만약 Young Object를 참조한 Old Object가 있다면 그 Old Object 시작주소에 해당하는 카드를 Dirty로
표시. 만약 이 Reference가 해제되면 Dirty 표시가 사라짐.
Card Table에 Card들을 늘어 놓고 뒤집어 가며 Reference의 존재 여부를 한 눈에 파악할 수 있게해줌.
3. Hotspot JVM의 Garbage Collector의 종류
3.1 Serial Collector
3.2 Parallel Collector
3.3 Parallel Compaction Collector
3.4 CMS Collector
3.5 Garbage First Collector
3. Hotspot JVM의 Garbage Collector의 종류
3.1 Serial Collector
3.2 Parallel Collector
3.3 Parallel Compaction Collector
3.4 CMS Collector
3.5 Garbage First Collector
• Young Generation과 Old Generation의 Garbage Collection 모두를 Serial로 처리하는 방식
• 1개의 Thread를 가지고 GC수행
• Hotspot JVM의 가장 기본적인 collector
28
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
Young Generation – Generational Algorithm
29
Eden
A
Survivor1 - From
B
Survivor2 - To
EmptyC
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
Young Generation – Generational Algorithm
30
Eden
A
Survivor1 - From
B
Survivor2 - To
C
Minor GC 발생 하면
A’ B’ C’
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
Young Generation – Generational Algorithm
31
Empty
Eden
Survivor1 - From
Empty
Survivor2 - To
Minor GC 발생 후 결과
A’ B’ C’
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
Young Generation – Generational Algorithm
32
Eden
A
Survivor1 - To
Empty B
Survivor2 - From
M
Young
Old
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
Young Generation – Generational Algorithm-Minor GC발생 후
33
Empty
Eden
Survivor1 - From Survivor2 - To
Empty
Young
Old M
A’ B’
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
34
Old Generation –Mark-and-Compacting
Old
Old
Old
Old
Mark
Sweep
Sliding
Compaction
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
35
Old Generation –Mark-and-Compacting
Old
Old
Old
Old
Mark
Sweep
Sliding
Compaction
• Serial Collector가 나온 이후 IT환경이 급변하여, heap의 크기를 점점 크게 설정해야 하는 상황이 도래함에 따
라 Serial Collector의 한계가 드러나기 시작.
• 가장 큰 문제는 GC를 수행 하는 중에 나타나는 suspend현상
• heap이 커짐에 따라 suspend현상은 두드러졌고 application은 점점 실시간에 가까운 성능을 요구하고 있음.
그런데
3.1 Serial Collector
3. Hotspot JVM의 Garbage Collector의 종류
36
1.Throughput Collector
모든 리소스를 투입하여 garbage collector를 빨리 끝내자는 전략.
이는 대용량의 heap에 적합하며,
이 전략을 채택한 garbage collector는 병렬 처리를 수행하는 방법으로 채택.
2. Low Pause Collector
Suspend를 분산시켜 체감 pause time을 줄이자는 전략.
실시간을 요구하는 application에 적합. 이 전략을 채택한 Garbage Collector는 GC를 수행하는
동시에 application의 작업도 수행(concurrent)하는 방식을 사용하고 있음.
그래서!
3. Hotspot JVM의 Garbage Collector의 종류
3.1 Serial Collector
3.2 Parallel Collector
3.3 Parallel Compaction Collector
3.4 CMS Collector
3.5 Garbage First Collector
• Throughput Collector중 하나.
• 많은 CPU를 동원하여 Garbage Collection
시간을 단축 시키자는 아이디어가 parallel
collector로 구체화 됨.
• Multi-Thread가 동시에 Garbage
Collection을 수행. 단 young generation
에만 국한
38
3.2 Parallel Collector
3. Hotspot JVM의 Garbage Collector의 종류
39
Eden
A
B A’ B’
Survivor1 - From Survivor1 - To
Stop & Copy
Serial Collector Parallel Collector
3.2 Parallel Collector
3. Hotspot JVM의 Garbage Collector의 종류
Young Generation – Parallel Copy Algorithm
40
여기서 잠깐 !
메모리의 특성상 같은 메모리 공간을 두 Thread혹은 Process가 접근하게 되면 Corruption이 발생!
이러한 Corruption을 회피하기 위해 동기화 작업이 수반되어야 하는데 이 경우 promotion의 성능이 떨어짐
Hotspot은 이를 위해 PLAB(Parallel Local Allocation Buffer)이라는 Promotion Buffer를 마련.
Promotion Buffer란 Garbage Collection Thread가 Promotion시 배타적으로 사용하기 위해 Thread마다
Old Generation의 일정 부분을 할당해 놓는 것을 말함.
T1 T2 T1
T2
Promotion Buffer
41
그런데
메모리의 특성상 같은 메모리 공간을 두 Thread혹은 Process가 접근하게 되면 Corruption이 발생!
이러한 Corruption을 회피하기 위해 동기화 작업이 수반되어야 하는데 이 경우 promotion의 성능이 떨어짐
Hotspot은 이를 위해 PLAB(Parallel Local Allocation Buffer)이라는 Promotion Buffer를 마련.
Promotion Buffer란 Garbage Collection Thread가 Promotion시 배타적으로 사용하기 위해 Thread마다
Old Generation의 일정 부분을 할당해 놓는 것을 말함.
T1 T2 T1
T2
Promotion Buffer
많은 수의 Thread가 자신의 buffer를 할당 받은 채 사용되지 않거나
어쩔 수 없이 발생하는 buffer내의 자투리 공간이 heap단편화의 원인이 될 수도 있음.
이 문제가 발생할 경우 GC Thread를 감소 시키거나 Old Generation의 size를 늘이는 방범으로 문제를 회피할 수 있음
42
Old Generation –Mark-and-Compacting
Old
Old
Old
Old
Mark
Sweep
Sliding
Compaction
3.2 Parallel Collector
3. Hotspot JVM의 Garbage Collector의 종류
3. Hotspot JVM의 Garbage Collector의 종류
3.1 Serial Collector
3.2 Parallel Collector
3.3 Parallel Compaction Collector
3.4 CMS Collector
3.5 Garbage First Collector
44
• Parallel Collector에서 Old Generation에 새로운 algorithm을 추가한 업그레이드 개념
• Oracle에서도 향후 Parallel Collector를 대체 할 수 있다는 전망을 내놓고 있음
• Multi CPU에 유리하고 Old Generation의 Collection시간을 감소시켜 전체적인 효율을
증가시킨다.
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
454545
Eden
A
B A’ B’
Survivor1 - From Survivor1 - To
Stop & Copy
Serial Collector Parallel Collector
Young Generation – Parallel Copy Algorithm
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
46
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
47
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
old generation을 region이라는 논리적인
단위로 균일하게 나눔.
region이 구분되면 Collection Thread들
은 각각 region별로 Live object를
marking하기 시작
Parallel로 작업
v v vv v v
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
48
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
Concurrent단계.Region단위로 작업을 수행
Region통계정보를 바탕으로 각 region의
Reachable Object의 밀도를 평가 후
Dense Prefix설정해 GC수행 범위를 정함.
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
49
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
Concurrent단계.Region단위로 작업을 수행
Region통계정보를 바탕으로 각 region의
Reachable Object의 밀도를 평가 후
Dense Prefix설정.
V V V V V V V
Dense Prefix
Garbage Collection 대상에서 제외 Garbage Collection의 대상이면서 Compaction 수행
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
50
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
Concurrent단계.Region단위로 작업을 수행
Region통계정보를 바탕으로 각 region의
Reachable Object의 밀도를 평가 후
Dense Prefix설정해 GC수행 범위를 정함.
이를 통해 Compaction범위를 줄여주어
GC에 소요되는 시간을 줄임
Dense Prefix설정 후 Compaction의 대상이
되는 Region의 First Live Object주소를 찾아
저장.
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
51
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
Heap을 잠시 Suspend상태로 만들고, 모든
Thread들이 각 Region을 할당 받아
Compaction 수행.
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
52
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
Heap을 잠시 Suspend상태로 만들고, 모든
Thread들이 각 Region을 할당 받아
Compaction 수행.
V V V V V V V
Destination Source
Source와 Destination이라는 의미는 Live Object를
어디에서 어디로 옮길 것인지를 결정하는 것
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
53
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
Heap을 잠시 Suspend상태로 만들고, 모든
Thread들이 각 Region을 할당 받아
Compaction 수행.
V V V V V V V
Destination Source
V V V V V V V
Destination Source
T1
T2
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
54
Old Generation – Parallel Compaction Algorithm
Mark Phase
Summary Phase
Compaction Phase
Heap을 잠시 Suspend상태로 만들고, 모든
Thread들이 각 Region을 할당 받아
Compaction 수행.
V V V V V V V
Destination Source
V V V V V V V
T1
3.3 Parallel Compaction Collector
3. Hotspot JVM의 Garbage Collector의 종류
3. Hotspot JVM의 Garbage Collector의 종류
3.1 Serial Collector
3.2 Parallel Collector
3.3 Parallel Compaction Collector
3.4 CMS Collector
3.5 Garbage First Collector
• Pause Time Goal에 맞는 collector
• CMS Collector는 Garbage Collection시 수반되는 suspend time을 적절하게 분산
하여 응답시간을 개선하는 방식을 사용
• Young Generation에서는 Parallel Collector와 동일한 Parallel Copy Algorithm
Old Generation에서는 Concurrent Mark-Sweep Algorithm을 사용
56
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
5757
Eden
A
B A’ B’
Survivor1 - From Survivor1 - To
Stop & Copy
Serial Collector Parallel Collector
Young Generation – Parallel Copy Algorithm
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
58
Initial Mark Phase
Concurrent Mark Phase
Remark Phase
Concurrent Sweep Phase
Old Generation –Concurrent Mark-Sweep Algorithm
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
59
Initial Mark Phase
Concurrent Mark Phase
Remark Phase
Concurrent Sweep Phase
Old Generation –Concurrent Mark-Sweep Algorithm
Single Thread만이 사용되는 Serial Phase.
Application에서 직접 Reference되는
Live Object만 빠르게 구별해 냄.
Heap은 Suspend상태가 되는데
root set에서 직접 Reference되는 Object만을
대상으로 하기 때문에 Suspend시간은
최소화 됨.
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
60
Initial Mark Phase
Concurrent Mark Phase
Remark Phase
Concurrent Sweep Phase
Old Generation –Concurrent Mark-Sweep Algorithm
Single Thread만이 사용되는 Serial Phase.
Concurrent라는 단어 처럼 GC Thread외의
Working Thread들은 Application을 수행
Initial Mark Phase에서 선별된 Live Object를
대상으로 reference하고 있는 Object를 추적
Live여부를 구별.
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
61
Initial Mark Phase
Concurrent Mark Phase
Remark Phase
Concurrent Sweep Phase
Old Generation –Concurrent Mark-Sweep Algorithm
모든 Thread들이 GC에 동원.Application의
수행은 잠시 중단. Remark라는 말 그대로
Mark 작업을 다시 수행한다는 의미로
Concurrent 작업으로 이해 발생한 변경 사항을
반영하기 위한 작업.
각 Thread들이 이미 Marking된 Object를
다시 추적, live 여부 확정.
이 작업은 Initial Mark보다 작업량이 많기 때
문에 가용한 모든 resource를 투입하여 수행
시간 단축.
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
62
Initial Mark Phase
Concurrent Mark Phase
Remark Phase
Concurrent Sweep Phase
Old Generation –Concurrent Mark-Sweep Algorithm
Remark작업을 통해 최종적으로 Live로
판명된 Object를 제외한 Dead Object를
지우는 것임. Dead Object를 지워 그 공간을
다시 사용 할 수 있도록 하는 작업 수행.
x x x
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
63
단편화 문제 발생, 이를 해결하기 위해
freelist를 사용하여 young generation에서 promotion된
object와 크기가 비슷한 free space를 탐색하는 방법 고안
그러나 Young Generation의 부담만 가중.
내가 가야 할 위치는 어디?
여긴가?
여긴가?
여긴가?
여긴가?
아 힘들엉
Young Generation Old Generation
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
64
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
또 하나의 문제, Floating Garbage문제
Initial
Mark
Concurrent
Mark
Remark
Concurrent
Sweep
V
V
V
65
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
또 하나의 문제, Floating Garbage문제
Initial
Mark
Concurrent
Mark
Remark
Concurrent
Sweep
V
V
V
V
66
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
또 하나의 문제, Floating Garbage문제
Initial
Mark
Concurrent
Mark
Remark
Concurrent
Sweep
V
V
V
V
Promotion 되자 마자 Garbage
67
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
또 하나의 문제, Floating Garbage문제
Initial
Mark
Concurrent
Mark
Remark
Concurrent
Sweep
V
V
V
V
68
3.4 CMS(Concurrent Mark-Sweep) Collector
3. Hotspot JVM의 Garbage Collector의 종류
또 하나의 문제, Floating Garbage문제
Initial
Mark
Concurrent
Mark
Remark
Concurrent
Sweep
V
V
V
V
A B
Floating Garbage가 되버림
3. Hotspot JVM의 Garbage Collector의 종류
3.1 Serial Collector
3.2 Parallel Collector
3.3 Parallel Compaction Collector
3.4 CMS Collector
3.5 Garbage First Collector
70
• CMS GC를 대체하기 위해서 만들어 짐.
• 물리적인 Generation의 구분을 없애고 전체 Heap을
1Mb~32Mb단위의 Region으로 재편
• Garbage First라는 말대로 Garbage로만 꽉 차있는
Region부터 GC시작
• Concurrent + Parallel + Compacting의 조합
3.5 Garbage First Collector
3. Hotspot JVM의 Garbage Collector의 종류
H O U Y O
H O Y Y O
H U Y O Y
H Y Y Y U
O Y O Y O
Y: Young Generation O: Old Generation
H: humongous U: Unused
71
Appendix.
Collector Serial
Parallel
Compact
CMS G1
장점
작은 data set을 가지고 있는
어플리케이션에서 최고의 성
능을 냄.
• 멀티스레드와 멀티프로세스
를 가진 어플리케이션에 적합.
• Throughput 목적에 가장 부
함.
• 큰 data set에 좋은 성능을
낸다.
• 멀티스레드와 멀티프로세스를
가진 어플리케이션에 적합.
• 큰 data set에 좋은 성능을 낸
다
• 실시간 어플리케이션에 적합
• 작은 data set과 큰 data
set 모두 적합
• Throughput과 low
pause time목적에 적합.
단점
규모가 큰 어플리케이션엔 적
합하지 않음.
• 싱글 코어인 경우 효과를 얻
지 못할 수도 있음. 그래서 따
로 incremental mode를 설
정 해야 함.
• 단편화 문제
• Floating Garbage 문제
72
참조 문헌
• http://blog.takipi.com/garbage-collectors-serial-vs-parallel-vs-cms-vs-the-
g1-and-whats-new-in-java-8/
• http://www.omsn.de/blog/brief-comparison-of-java-7-hotspot-garbage-
collectors
• Java Performance Fundamental 김한도 지음 ㈜엑셈
• http://helloworld.naver.com/helloworld/textyle/1329
• http://blog.jelastic.com/2013/01/24/the-truth-about-paas-vertical-scaling-
and-why-you-are-being-oversold/
• https://www.google.co.kr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1
&sqi=2&ved=0CCUQFjAA&url=http%3A%2F%2Fwww.oracle.com%2Fte
chnetwork%2Fjava%2Fjavase%2Ftech%2Findex-jsp-
140228.html&ei=MMXaVL2TJOe5mwWZnoCADw&usg=AFQjCNHhFj3D5
-BfVBPuZ6JL7JF7PCX-UA&sig2=z4gqAR4bu7LA-
7IN2lLwbg&bvm=bv.85761416,d.dGc&cad=rja
• http://www.infoq.com/articles/Java_Garbage_Collection_Distilled
• http://blog.novatec-gmbh.de/g1-action-better-cms/

More Related Content

What's hot

IBM JVM GC_Wh apm
IBM JVM GC_Wh apmIBM JVM GC_Wh apm
IBM JVM GC_Wh apm엑셈
 
게임서버프로그래밍 #7 - 패킷핸들링 및 암호화
게임서버프로그래밍 #7 - 패킷핸들링 및 암호화게임서버프로그래밍 #7 - 패킷핸들링 및 암호화
게임서버프로그래밍 #7 - 패킷핸들링 및 암호화Seungmo Koo
 
게임서버프로그래밍 #1 - IOCP
게임서버프로그래밍 #1 - IOCP게임서버프로그래밍 #1 - IOCP
게임서버프로그래밍 #1 - IOCPSeungmo Koo
 
MMOG Server-Side 충돌 및 이동처리 설계와 구현
MMOG Server-Side 충돌 및 이동처리 설계와 구현MMOG Server-Side 충돌 및 이동처리 설계와 구현
MMOG Server-Side 충돌 및 이동처리 설계와 구현YEONG-CHEON YOU
 
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012devCAT Studio, NEXON
 
Windows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPWindows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPSeungmo Koo
 
GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리
GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리
GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리YEONG-CHEON YOU
 
양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012
양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012
양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012devCAT Studio, NEXON
 
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍게임서버프로그래밍 #4 - 멀티스레드 프로그래밍
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍Seungmo Koo
 
실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략YEONG-CHEON YOU
 
Next-generation MMORPG service architecture
Next-generation MMORPG service architectureNext-generation MMORPG service architecture
Next-generation MMORPG service architectureJongwon Kim
 
NDC 11 자이언트 서버의 비밀
NDC 11 자이언트 서버의 비밀NDC 11 자이언트 서버의 비밀
NDC 11 자이언트 서버의 비밀승명 양
 
NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현noerror
 
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지강 민우
 
Multiplayer Game Sync Techniques through CAP theorem
Multiplayer Game Sync Techniques through CAP theoremMultiplayer Game Sync Techniques through CAP theorem
Multiplayer Game Sync Techniques through CAP theoremSeungmo Koo
 
레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다Lee Dustin
 
[데브루키160409 박민근] UniRx 시작하기
[데브루키160409 박민근] UniRx 시작하기[데브루키160409 박민근] UniRx 시작하기
[데브루키160409 박민근] UniRx 시작하기MinGeun Park
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기Sang Heon Lee
 
NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들
NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들
NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들영욱 오
 

What's hot (20)

IBM JVM GC_Wh apm
IBM JVM GC_Wh apmIBM JVM GC_Wh apm
IBM JVM GC_Wh apm
 
게임서버프로그래밍 #7 - 패킷핸들링 및 암호화
게임서버프로그래밍 #7 - 패킷핸들링 및 암호화게임서버프로그래밍 #7 - 패킷핸들링 및 암호화
게임서버프로그래밍 #7 - 패킷핸들링 및 암호화
 
게임서버프로그래밍 #1 - IOCP
게임서버프로그래밍 #1 - IOCP게임서버프로그래밍 #1 - IOCP
게임서버프로그래밍 #1 - IOCP
 
MMOG Server-Side 충돌 및 이동처리 설계와 구현
MMOG Server-Side 충돌 및 이동처리 설계와 구현MMOG Server-Side 충돌 및 이동처리 설계와 구현
MMOG Server-Side 충돌 및 이동처리 설계와 구현
 
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
 
Windows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPWindows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCP
 
GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리
GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리
GPGPU(CUDA)를 이용한 MMOG 캐릭터 충돌처리
 
양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012
양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012
양승명, 다음 세대 크로스플랫폼 MMORPG 아키텍처, NDC2012
 
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍게임서버프로그래밍 #4 - 멀티스레드 프로그래밍
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍
 
실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략실시간 게임 서버 최적화 전략
실시간 게임 서버 최적화 전략
 
Next-generation MMORPG service architecture
Next-generation MMORPG service architectureNext-generation MMORPG service architecture
Next-generation MMORPG service architecture
 
NDC 11 자이언트 서버의 비밀
NDC 11 자이언트 서버의 비밀NDC 11 자이언트 서버의 비밀
NDC 11 자이언트 서버의 비밀
 
NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현
 
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지
 
Multiplayer Game Sync Techniques through CAP theorem
Multiplayer Game Sync Techniques through CAP theoremMultiplayer Game Sync Techniques through CAP theorem
Multiplayer Game Sync Techniques through CAP theorem
 
레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다
 
[데브루키160409 박민근] UniRx 시작하기
[데브루키160409 박민근] UniRx 시작하기[데브루키160409 박민근] UniRx 시작하기
[데브루키160409 박민근] UniRx 시작하기
 
Iocp advanced
Iocp advancedIocp advanced
Iocp advanced
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기
 
NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들
NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들
NDC2017 언리얼엔진4 디버깅 101 - 게임 기획자, 프로그래머가 버그와 만났을 때 사용할 수 있는 지침들
 

Similar to Garbage collection

Hotspot JVM GC_Wh apm
Hotspot JVM GC_Wh apmHotspot JVM GC_Wh apm
Hotspot JVM GC_Wh apm엑셈
 
GarbageCollection in JVM
GarbageCollection in JVMGarbageCollection in JVM
GarbageCollection in JVMGyooha Kim
 
UE4 Garbage Collection
UE4 Garbage CollectionUE4 Garbage Collection
UE4 Garbage CollectionQooJuice
 
JVM과 톰캣 튜닝
JVM과 톰캣 튜닝JVM과 톰캣 튜닝
JVM과 톰캣 튜닝Mungyu Choi
 
[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리
[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리
[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리MinGeun Park
 
엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기
엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기
엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기흥래 김
 
R2서버정진욱
R2서버정진욱R2서버정진욱
R2서버정진욱jungjinwouk
 
[NEXT] Android Profiler
[NEXT] Android Profiler[NEXT] Android Profiler
[NEXT] Android ProfilerYoungSu Son
 
[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리MinGeun Park
 
[NEXT] Android Profiler 사용법
[NEXT] Android Profiler 사용법 [NEXT] Android Profiler 사용법
[NEXT] Android Profiler 사용법 YoungSu Son
 
Runtime Data Areas_Wh apm
Runtime Data Areas_Wh apmRuntime Data Areas_Wh apm
Runtime Data Areas_Wh apm엑셈
 
Mec++ chapter3,4
Mec++ chapter3,4Mec++ chapter3,4
Mec++ chapter3,4문익 장
 
Memory Corruption Heap
Memory Corruption HeapMemory Corruption Heap
Memory Corruption Heapcodevania
 
컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법
컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법
컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법ssuser91b87c
 

Similar to Garbage collection (16)

Hotspot JVM GC_Wh apm
Hotspot JVM GC_Wh apmHotspot JVM GC_Wh apm
Hotspot JVM GC_Wh apm
 
About garbage collection
About garbage collectionAbout garbage collection
About garbage collection
 
About gc
About gcAbout gc
About gc
 
GarbageCollection in JVM
GarbageCollection in JVMGarbageCollection in JVM
GarbageCollection in JVM
 
UE4 Garbage Collection
UE4 Garbage CollectionUE4 Garbage Collection
UE4 Garbage Collection
 
JVM과 톰캣 튜닝
JVM과 톰캣 튜닝JVM과 톰캣 튜닝
JVM과 톰캣 튜닝
 
[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리
[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리
[데브루키/141206 박민근] 유니티 최적화 테크닉 총정리
 
엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기
엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기
엘라스틱서치 클러스터로 수십억 건의 데이터 운영하기
 
R2서버정진욱
R2서버정진욱R2서버정진욱
R2서버정진욱
 
[NEXT] Android Profiler
[NEXT] Android Profiler[NEXT] Android Profiler
[NEXT] Android Profiler
 
[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리[Unite2015 박민근] 유니티 최적화 테크닉 총정리
[Unite2015 박민근] 유니티 최적화 테크닉 총정리
 
[NEXT] Android Profiler 사용법
[NEXT] Android Profiler 사용법 [NEXT] Android Profiler 사용법
[NEXT] Android Profiler 사용법
 
Runtime Data Areas_Wh apm
Runtime Data Areas_Wh apmRuntime Data Areas_Wh apm
Runtime Data Areas_Wh apm
 
Mec++ chapter3,4
Mec++ chapter3,4Mec++ chapter3,4
Mec++ chapter3,4
 
Memory Corruption Heap
Memory Corruption HeapMemory Corruption Heap
Memory Corruption Heap
 
컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법
컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법
컴퓨터공학 스터디 W2 발표: 프로그래밍 언어의 메모리 관리 기법
 

Garbage collection

  • 2. 목차 0.Garbage Collection을 공부한 이유 1.Garbage Collection 2.Hotspot JVM의 Garbage Collection 3.Hotspot JVM의 Garbage Collector의 종류 2
  • 3. 0. Garbage Collection을 공부한 이유
  • 4.
  • 5. 1. Garbage Collection 1.1 Garbage Collection이란? 1.2 Garbage Collection의 대상 1.3 Garbage Collection과 Fragmentation
  • 6. 1. Garbage Collection 1.1 Garbage Collection이란? 1.2 Garbage Collection의 대상 1.3 Garbage Collection과 Fragmentation
  • 7. 1.1 Garbage Collection이란? • Java에서 할당 받은 메모리를 해제 하는 것은 개발자의 영역이 아님 • System.gc()나 close()와 같은 함수도 있잖아?  Garbage Collection을 명시적으로 수행하거나 해당 객체의 사용을 중지하겠 다는 의사 표현일 뿐 제거하고자 하는 객체를 메모리에서 삭제하겠다는 것은 아 님. 7 1. Garbage Collection
  • 8. “Heap storage for objects is reclaimed by an automatic storage management system(typically a garbage collector); objects are never explicitly deallocated.” --Java Virtual Machine Speculation, Section 3.5.3[JVMS2 1999] 8 1.1 Garbage Collection이란 1. Garbage Collection
  • 9. 1. Garbage Collection 1.1 Garbage Collection이란? 1.2 Garbage Collection의 대상 1.3 Garbage Collection과 Fragmentation
  • 10. Garbage Collection  Garbage를 모으는 작업. 그럼 Garbage를 정의하고 넘어가면, Heap과 Method Area에서 사용되지 않는 Object를 의미. 사용되지 않는 다는 의미를 어디까지 볼 것이냐는 문제 10 1.1 Garbage Collection의 대상 1. Garbage Collection PC Registers Java Virtual Machine Stacks Method Area Heap Native Method Stacks JVM의 Runtime Data Areas
  • 11. •현재 사용 여부는 Root Set과의 관계로 판단 •Root Set에서 어떤 식으로든 Reference관계가 있다면 Reachable Object. 즉 현재 사용하고 있는 Object로 간주. •이렇게 판단해서 Reachable Object가 아니면 Garbage Collection의 대상이 됨. 11 1.2 Garbage Collection의 대상 1. Garbage Collection Unreachable Reachable Root Set
  • 12. •현재 사용 여부는 Root Set과의 관계로 판단 •Root Set에서 어떤 식으로든 Reference관계가 있다면 Reachable Object. 즉 현재 사용하고 있는 Object로 간주. •이렇게 판단해서 Reachable Object가 아니면 Garbage Collection의 대상이 됨. 12 1.2 Garbage Collection의 대상 1. Garbage Collection Unreachable Reachable Root Set 한 객체는 여러 다른 객체를 참조하고, 참조된 다른 객체들도 마찬가지로 또 다른 객체들을 참조할 수 있 으므로 객체들은 참조 사슬을 이룬다. 이런 상황에서 유효한 참조 여부를 파악하려면 항상 유효한 최초의 참조가 있어야 하는데 이를 객체 참조의 root set이라고 한다.
  • 13. •현재 사용 여부는 Root Set과의 관계로 판단 •Root Set에서 어떤 식으로든 Reference관계가 있다면 Reachable Object. 즉 현재 사용하고 있는 Object로 간주. •이렇게 판단해서 Reachable Object가 아니면 Garbage Collection의 대상이 됨. 13 1.2 Garbage Collection의 대상 1. Garbage Collection Unreachable Reachable Root Set
  • 14. 1. Garbage Collection 1.1 Garbage Collection이란? 1.2 Garbage Collection의 대상 1.3 Garbage Collection과 Fragmentation
  • 15. •새로운 Object의 할당을 위해 한정된 Heap공간을 재활용하려는 목적으로 수행 •재활용을 위해 수행된 메모리의 해지는 할당한 그 자 리에서 이루어지기 때문에 Garbage가 빠져 나간 자리는 듬성듬성 •Heap의 단편화(Fragmentation)발생 •이러한 현상을 방지하기 위해 Compaction과 같은 Algorithm을 사용 15 1.3 Garbage Collection과 Fragmentation 1. Garbage Collection Live Garbage Live Live Garbage Live Garbage Live Live Free(1K) Live Live Free(3K) Live Free(2K) Live Garbage Collection
  • 16. 다시 한번 정리하면 Garbage Collection이란 Heap을 재활용하기 위해 Root Set에서 참조되지 않는 Object를 없애 가용한 공간을 만드는 작업
  • 17. 2. Hotspot JVM의 Garbage Collection 2.1 Hotspot JVM의 Garbage Collection 소개
  • 18. 18 Garbage Collector는 두 가지 가설 하에 만들어짐. 대부분의 객체는 금방 접근 불가능 상태가 된다. – high infant mortality 오래된 객체에서 젊은 객체로의 참조는 아주 적게 존재한다. 이러한 가설을 ‘weak generational Hypothesis’ 이러한 가설의 장점을 최대한 살리기 위해 Hotspot JVM에서는 크게 2개로 물리 적 공간을 나눔. 2.1 Hotspot JVM의 Garbage Collection 소개 2. Hotspot JVM의 Garbage Collection
  • 19. 19 • Young 영역(Yong Generation 영역): 새롭게 생성한 객체의 대부분이 여기에 위치.대부분의 객체가 금방 접근 불가능 상태가 되 기 때문에 매우 많은 객체가 Young 영역에 생성되었다가 사라짐.이 영역에서 객체가 사라 질때 Minor GC가 발생한다고 말함. • Old 영역(Old Generation 영역): 접근 불가능 상태로 되지 않아 Young 영역에서 살아남은 객체가 여기로 복사됨. 대부분 Young 영역보다 크게 할당하며, 크기가 큰 만큼 Young 영역보다 GC는 적게 발생. 이 영 역에서 객체가 사라질 때 Major GC(혹은 Full GC)가 발생한다고 말함. 2.1 Hotspot JVM의 Garbage Collection 소개 2. Hotspot JVM의 Garbage Collection
  • 20. 20 Eden Tenured Permanent Young Generation Old Generation Method Area Survivor1 Survivor2 2.1 Hotspot JVM의 Garbage Collection 소개 2. Hotspot JVM의 Garbage Collection
  • 21. 21 Eden Tenured Permanent Young Generation Old Generation Method Area Survivor1 Survivor2 2.1 Hotspot JVM의 Garbage Collection 소개 2. Hotspot JVM의 Garbage Collection
  • 22. 22 Eden Tenured Permanent Young Generation Old Generation Method Area Survivor1 Survivor2 2.1 Hotspot JVM의 Garbage Collection 소개 2. Hotspot JVM의 Garbage Collection
  • 23.
  • 24.
  • 25. 25 여기서 잠깐 ! Old 영역에 있는 객체가 Young 영역의 객체를 참조하는 경우가 있을 때에는 어떻게 처리될까? Card Table이라는 장치를 마련 Card Table  Old Generation의 메모리를 대표하는 별도의 메모리 구조를 의미 만약 Young Object를 참조한 Old Object가 있다면 그 Old Object 시작주소에 해당하는 카드를 Dirty로 표시. 만약 이 Reference가 해제되면 Dirty 표시가 사라짐. Card Table에 Card들을 늘어 놓고 뒤집어 가며 Reference의 존재 여부를 한 눈에 파악할 수 있게해줌.
  • 26. 3. Hotspot JVM의 Garbage Collector의 종류 3.1 Serial Collector 3.2 Parallel Collector 3.3 Parallel Compaction Collector 3.4 CMS Collector 3.5 Garbage First Collector
  • 27. 3. Hotspot JVM의 Garbage Collector의 종류 3.1 Serial Collector 3.2 Parallel Collector 3.3 Parallel Compaction Collector 3.4 CMS Collector 3.5 Garbage First Collector
  • 28. • Young Generation과 Old Generation의 Garbage Collection 모두를 Serial로 처리하는 방식 • 1개의 Thread를 가지고 GC수행 • Hotspot JVM의 가장 기본적인 collector 28 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 29. Young Generation – Generational Algorithm 29 Eden A Survivor1 - From B Survivor2 - To EmptyC 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 30. Young Generation – Generational Algorithm 30 Eden A Survivor1 - From B Survivor2 - To C Minor GC 발생 하면 A’ B’ C’ 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 31. Young Generation – Generational Algorithm 31 Empty Eden Survivor1 - From Empty Survivor2 - To Minor GC 발생 후 결과 A’ B’ C’ 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 32. Young Generation – Generational Algorithm 32 Eden A Survivor1 - To Empty B Survivor2 - From M Young Old 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 33. Young Generation – Generational Algorithm-Minor GC발생 후 33 Empty Eden Survivor1 - From Survivor2 - To Empty Young Old M A’ B’ 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 34. 34 Old Generation –Mark-and-Compacting Old Old Old Old Mark Sweep Sliding Compaction 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 35. 35 Old Generation –Mark-and-Compacting Old Old Old Old Mark Sweep Sliding Compaction • Serial Collector가 나온 이후 IT환경이 급변하여, heap의 크기를 점점 크게 설정해야 하는 상황이 도래함에 따 라 Serial Collector의 한계가 드러나기 시작. • 가장 큰 문제는 GC를 수행 하는 중에 나타나는 suspend현상 • heap이 커짐에 따라 suspend현상은 두드러졌고 application은 점점 실시간에 가까운 성능을 요구하고 있음. 그런데 3.1 Serial Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 36. 36 1.Throughput Collector 모든 리소스를 투입하여 garbage collector를 빨리 끝내자는 전략. 이는 대용량의 heap에 적합하며, 이 전략을 채택한 garbage collector는 병렬 처리를 수행하는 방법으로 채택. 2. Low Pause Collector Suspend를 분산시켜 체감 pause time을 줄이자는 전략. 실시간을 요구하는 application에 적합. 이 전략을 채택한 Garbage Collector는 GC를 수행하는 동시에 application의 작업도 수행(concurrent)하는 방식을 사용하고 있음. 그래서!
  • 37. 3. Hotspot JVM의 Garbage Collector의 종류 3.1 Serial Collector 3.2 Parallel Collector 3.3 Parallel Compaction Collector 3.4 CMS Collector 3.5 Garbage First Collector
  • 38. • Throughput Collector중 하나. • 많은 CPU를 동원하여 Garbage Collection 시간을 단축 시키자는 아이디어가 parallel collector로 구체화 됨. • Multi-Thread가 동시에 Garbage Collection을 수행. 단 young generation 에만 국한 38 3.2 Parallel Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 39. 39 Eden A B A’ B’ Survivor1 - From Survivor1 - To Stop & Copy Serial Collector Parallel Collector 3.2 Parallel Collector 3. Hotspot JVM의 Garbage Collector의 종류 Young Generation – Parallel Copy Algorithm
  • 40. 40 여기서 잠깐 ! 메모리의 특성상 같은 메모리 공간을 두 Thread혹은 Process가 접근하게 되면 Corruption이 발생! 이러한 Corruption을 회피하기 위해 동기화 작업이 수반되어야 하는데 이 경우 promotion의 성능이 떨어짐 Hotspot은 이를 위해 PLAB(Parallel Local Allocation Buffer)이라는 Promotion Buffer를 마련. Promotion Buffer란 Garbage Collection Thread가 Promotion시 배타적으로 사용하기 위해 Thread마다 Old Generation의 일정 부분을 할당해 놓는 것을 말함. T1 T2 T1 T2 Promotion Buffer
  • 41. 41 그런데 메모리의 특성상 같은 메모리 공간을 두 Thread혹은 Process가 접근하게 되면 Corruption이 발생! 이러한 Corruption을 회피하기 위해 동기화 작업이 수반되어야 하는데 이 경우 promotion의 성능이 떨어짐 Hotspot은 이를 위해 PLAB(Parallel Local Allocation Buffer)이라는 Promotion Buffer를 마련. Promotion Buffer란 Garbage Collection Thread가 Promotion시 배타적으로 사용하기 위해 Thread마다 Old Generation의 일정 부분을 할당해 놓는 것을 말함. T1 T2 T1 T2 Promotion Buffer 많은 수의 Thread가 자신의 buffer를 할당 받은 채 사용되지 않거나 어쩔 수 없이 발생하는 buffer내의 자투리 공간이 heap단편화의 원인이 될 수도 있음. 이 문제가 발생할 경우 GC Thread를 감소 시키거나 Old Generation의 size를 늘이는 방범으로 문제를 회피할 수 있음
  • 42. 42 Old Generation –Mark-and-Compacting Old Old Old Old Mark Sweep Sliding Compaction 3.2 Parallel Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 43. 3. Hotspot JVM의 Garbage Collector의 종류 3.1 Serial Collector 3.2 Parallel Collector 3.3 Parallel Compaction Collector 3.4 CMS Collector 3.5 Garbage First Collector
  • 44. 44 • Parallel Collector에서 Old Generation에 새로운 algorithm을 추가한 업그레이드 개념 • Oracle에서도 향후 Parallel Collector를 대체 할 수 있다는 전망을 내놓고 있음 • Multi CPU에 유리하고 Old Generation의 Collection시간을 감소시켜 전체적인 효율을 증가시킨다. 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 45. 454545 Eden A B A’ B’ Survivor1 - From Survivor1 - To Stop & Copy Serial Collector Parallel Collector Young Generation – Parallel Copy Algorithm 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 46. 46 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 47. 47 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase old generation을 region이라는 논리적인 단위로 균일하게 나눔. region이 구분되면 Collection Thread들 은 각각 region별로 Live object를 marking하기 시작 Parallel로 작업 v v vv v v 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 48. 48 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase Concurrent단계.Region단위로 작업을 수행 Region통계정보를 바탕으로 각 region의 Reachable Object의 밀도를 평가 후 Dense Prefix설정해 GC수행 범위를 정함. 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 49. 49 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase Concurrent단계.Region단위로 작업을 수행 Region통계정보를 바탕으로 각 region의 Reachable Object의 밀도를 평가 후 Dense Prefix설정. V V V V V V V Dense Prefix Garbage Collection 대상에서 제외 Garbage Collection의 대상이면서 Compaction 수행 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 50. 50 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase Concurrent단계.Region단위로 작업을 수행 Region통계정보를 바탕으로 각 region의 Reachable Object의 밀도를 평가 후 Dense Prefix설정해 GC수행 범위를 정함. 이를 통해 Compaction범위를 줄여주어 GC에 소요되는 시간을 줄임 Dense Prefix설정 후 Compaction의 대상이 되는 Region의 First Live Object주소를 찾아 저장. 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 51. 51 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase Heap을 잠시 Suspend상태로 만들고, 모든 Thread들이 각 Region을 할당 받아 Compaction 수행. 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 52. 52 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase Heap을 잠시 Suspend상태로 만들고, 모든 Thread들이 각 Region을 할당 받아 Compaction 수행. V V V V V V V Destination Source Source와 Destination이라는 의미는 Live Object를 어디에서 어디로 옮길 것인지를 결정하는 것 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 53. 53 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase Heap을 잠시 Suspend상태로 만들고, 모든 Thread들이 각 Region을 할당 받아 Compaction 수행. V V V V V V V Destination Source V V V V V V V Destination Source T1 T2 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 54. 54 Old Generation – Parallel Compaction Algorithm Mark Phase Summary Phase Compaction Phase Heap을 잠시 Suspend상태로 만들고, 모든 Thread들이 각 Region을 할당 받아 Compaction 수행. V V V V V V V Destination Source V V V V V V V T1 3.3 Parallel Compaction Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 55. 3. Hotspot JVM의 Garbage Collector의 종류 3.1 Serial Collector 3.2 Parallel Collector 3.3 Parallel Compaction Collector 3.4 CMS Collector 3.5 Garbage First Collector
  • 56. • Pause Time Goal에 맞는 collector • CMS Collector는 Garbage Collection시 수반되는 suspend time을 적절하게 분산 하여 응답시간을 개선하는 방식을 사용 • Young Generation에서는 Parallel Collector와 동일한 Parallel Copy Algorithm Old Generation에서는 Concurrent Mark-Sweep Algorithm을 사용 56 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 57. 5757 Eden A B A’ B’ Survivor1 - From Survivor1 - To Stop & Copy Serial Collector Parallel Collector Young Generation – Parallel Copy Algorithm 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 58. 58 Initial Mark Phase Concurrent Mark Phase Remark Phase Concurrent Sweep Phase Old Generation –Concurrent Mark-Sweep Algorithm 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 59. 59 Initial Mark Phase Concurrent Mark Phase Remark Phase Concurrent Sweep Phase Old Generation –Concurrent Mark-Sweep Algorithm Single Thread만이 사용되는 Serial Phase. Application에서 직접 Reference되는 Live Object만 빠르게 구별해 냄. Heap은 Suspend상태가 되는데 root set에서 직접 Reference되는 Object만을 대상으로 하기 때문에 Suspend시간은 최소화 됨. 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 60. 60 Initial Mark Phase Concurrent Mark Phase Remark Phase Concurrent Sweep Phase Old Generation –Concurrent Mark-Sweep Algorithm Single Thread만이 사용되는 Serial Phase. Concurrent라는 단어 처럼 GC Thread외의 Working Thread들은 Application을 수행 Initial Mark Phase에서 선별된 Live Object를 대상으로 reference하고 있는 Object를 추적 Live여부를 구별. 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 61. 61 Initial Mark Phase Concurrent Mark Phase Remark Phase Concurrent Sweep Phase Old Generation –Concurrent Mark-Sweep Algorithm 모든 Thread들이 GC에 동원.Application의 수행은 잠시 중단. Remark라는 말 그대로 Mark 작업을 다시 수행한다는 의미로 Concurrent 작업으로 이해 발생한 변경 사항을 반영하기 위한 작업. 각 Thread들이 이미 Marking된 Object를 다시 추적, live 여부 확정. 이 작업은 Initial Mark보다 작업량이 많기 때 문에 가용한 모든 resource를 투입하여 수행 시간 단축. 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 62. 62 Initial Mark Phase Concurrent Mark Phase Remark Phase Concurrent Sweep Phase Old Generation –Concurrent Mark-Sweep Algorithm Remark작업을 통해 최종적으로 Live로 판명된 Object를 제외한 Dead Object를 지우는 것임. Dead Object를 지워 그 공간을 다시 사용 할 수 있도록 하는 작업 수행. x x x 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 63. 63 단편화 문제 발생, 이를 해결하기 위해 freelist를 사용하여 young generation에서 promotion된 object와 크기가 비슷한 free space를 탐색하는 방법 고안 그러나 Young Generation의 부담만 가중. 내가 가야 할 위치는 어디? 여긴가? 여긴가? 여긴가? 여긴가? 아 힘들엉 Young Generation Old Generation 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류
  • 64. 64 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류 또 하나의 문제, Floating Garbage문제 Initial Mark Concurrent Mark Remark Concurrent Sweep V V V
  • 65. 65 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류 또 하나의 문제, Floating Garbage문제 Initial Mark Concurrent Mark Remark Concurrent Sweep V V V V
  • 66. 66 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류 또 하나의 문제, Floating Garbage문제 Initial Mark Concurrent Mark Remark Concurrent Sweep V V V V Promotion 되자 마자 Garbage
  • 67. 67 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류 또 하나의 문제, Floating Garbage문제 Initial Mark Concurrent Mark Remark Concurrent Sweep V V V V
  • 68. 68 3.4 CMS(Concurrent Mark-Sweep) Collector 3. Hotspot JVM의 Garbage Collector의 종류 또 하나의 문제, Floating Garbage문제 Initial Mark Concurrent Mark Remark Concurrent Sweep V V V V A B Floating Garbage가 되버림
  • 69. 3. Hotspot JVM의 Garbage Collector의 종류 3.1 Serial Collector 3.2 Parallel Collector 3.3 Parallel Compaction Collector 3.4 CMS Collector 3.5 Garbage First Collector
  • 70. 70 • CMS GC를 대체하기 위해서 만들어 짐. • 물리적인 Generation의 구분을 없애고 전체 Heap을 1Mb~32Mb단위의 Region으로 재편 • Garbage First라는 말대로 Garbage로만 꽉 차있는 Region부터 GC시작 • Concurrent + Parallel + Compacting의 조합 3.5 Garbage First Collector 3. Hotspot JVM의 Garbage Collector의 종류 H O U Y O H O Y Y O H U Y O Y H Y Y Y U O Y O Y O Y: Young Generation O: Old Generation H: humongous U: Unused
  • 71. 71 Appendix. Collector Serial Parallel Compact CMS G1 장점 작은 data set을 가지고 있는 어플리케이션에서 최고의 성 능을 냄. • 멀티스레드와 멀티프로세스 를 가진 어플리케이션에 적합. • Throughput 목적에 가장 부 함. • 큰 data set에 좋은 성능을 낸다. • 멀티스레드와 멀티프로세스를 가진 어플리케이션에 적합. • 큰 data set에 좋은 성능을 낸 다 • 실시간 어플리케이션에 적합 • 작은 data set과 큰 data set 모두 적합 • Throughput과 low pause time목적에 적합. 단점 규모가 큰 어플리케이션엔 적 합하지 않음. • 싱글 코어인 경우 효과를 얻 지 못할 수도 있음. 그래서 따 로 incremental mode를 설 정 해야 함. • 단편화 문제 • Floating Garbage 문제
  • 72. 72 참조 문헌 • http://blog.takipi.com/garbage-collectors-serial-vs-parallel-vs-cms-vs-the- g1-and-whats-new-in-java-8/ • http://www.omsn.de/blog/brief-comparison-of-java-7-hotspot-garbage- collectors • Java Performance Fundamental 김한도 지음 ㈜엑셈 • http://helloworld.naver.com/helloworld/textyle/1329 • http://blog.jelastic.com/2013/01/24/the-truth-about-paas-vertical-scaling- and-why-you-are-being-oversold/ • https://www.google.co.kr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1 &sqi=2&ved=0CCUQFjAA&url=http%3A%2F%2Fwww.oracle.com%2Fte chnetwork%2Fjava%2Fjavase%2Ftech%2Findex-jsp- 140228.html&ei=MMXaVL2TJOe5mwWZnoCADw&usg=AFQjCNHhFj3D5 -BfVBPuZ6JL7JF7PCX-UA&sig2=z4gqAR4bu7LA- 7IN2lLwbg&bvm=bv.85761416,d.dGc&cad=rja • http://www.infoq.com/articles/Java_Garbage_Collection_Distilled • http://blog.novatec-gmbh.de/g1-action-better-cms/