18 Ocak 2021 Pazartesi

Garbage Collector Terminolojisi

Giriş
Burada Garbage Collector (GC) yazılarında çokça kullanılan bazı terminolojiyi açıklamaya çalıştım. Açıklaması şöyle. Aralarındaki en öenmli fark ne kadar CPU kullandıkları ve ne kadar süre tuttukları
GC phases can have different properties:

- a parallel phase can run on multiple GC threads
- a serial phase runs on a single thread
- a stop-the-world phase can't run concurrently with application code
- a concurrent phase can run in the background, while our application does its work
- an incremental phase can terminate before finishing all of its work and continue it later

Note that all of the above techniques have their strengths and weaknesses. For example, let's say we have a phase that can run concurrently with our application. A serial implementation of this phase requires 1% of the overall CPU performance and runs for 1000ms. In contrast, a parallel implementation utilizes 30% of CPU and completes its work in 50ms.

In this example, the parallel solution uses more CPU overall, because it may be more complex and have to synchronize the threads. For CPU heavy applications (for example, batch jobs), it's a problem since we have less computing power to do useful work.
1. Parallel Garbage Collector Nedir?
Açıklaması şöyle. GC işlemi için birden fazla thread kullanır. Ancak concurrent değildir. Yani uygulamayı durdurur.
When a garbage collector is described as parallel, it uses multiple threads to perform garbage collection.
2. Concurrent Garbage Collector Nedir?
Açıklaması şöyle. Mark aşamasında uygulama ile birlikte çalışır, yani uygulama durdurulmaz. Sweep aşamasında uygulama mecburen durdurulur.
The term concurrent means that garbage collection activity is occurring at the same time as the Java application is executing. 
3. Stop the World Nedir?
Açıklaması şöyle Uygulamayı durdurulur. "Stop the World" emrini az veren GC "Low Pause GC" denilir.
The term stop-the-world means that all Java application threads are stopped during a GC event. A stop-the-world garbage collector is one that stops all Java application threads when it performs a garbage collection. A GC phase or event may be described as stop-the-world, which means that during that particular GC phase or event all Java application threads are stopped.
4. Java Heap Bölümleri Nelerdir
3 kısma ayrılır. Açıklaması şöyle
The heap was divided into the following three categories:

Eden: This where the Objects born. Like in the Bible.
Survivor: If an object lives long enough, it will go into the Survivor area.
Tenured: If it getting really old it will be moved into the Tenured area.
- Eden ve Survivor aynı zamanda Young Generation olarak bilinir.  Tenured ise Old Generation olarak ta bilinir.
Eden alanında GC daha sık çalışmalıdır.

5. GC Events Nelerdir?

5.1 Minor GC Nedir?
Eden alanı dolunca gerçekleşir. Sadece Young Generation (Eden + Young) alanlarının temizlenmesidir. Açıklaması şöyle. Bu işlem sonucunda Eden temizlenir. Eden'deki nesneler Survivor alanına taşınır. Survivor alanındaki bazı nesneler Old Generation alanına taşınır.
1. When allocating an object, it is allocated in the Eden space. This means that those regions that have been designated as “Eden” are the first place that new objects will be added.
2. After the Eden space gets full, a “Minor Garbage Collection” (Minor GC) will start. A Minor GC seeks to free up memory by removing objects from Eden and Survivor regions only. This helps to keep these regions empty and available for new objects.
3. After the Minor GC has finished, any objects that remain in the Eden space will be moved into the Survivor space.
4. Objects in the survivor space that pass the age threshold are moved to the “Old Generation” region. Any objects that haven’t met the age threshold will remain in the survivor space.
Minor GC başında şöyledir. Burada kırmızı nesneler temizlenecekler, mavi nesneler ise Survivor 1 alanına taşınacaklar

İkinci Minor GC'de ise Survivor 1'deki nesneler, Survivor 2'ye taşınacaklar.




5.2 Mixed GC Nedir?
Açıklaması şöyle
It is a Minor GC with some of the old regions are also cleared out (This event is more complicated than a Minor event...)
5.3 Major GC Nedir?
Old Generation (Tenured) alanının temizlenmesidir.

5.3 Full GC Nedir?
Young ve Old Generation alanlarının temizlenmesidir. Açıklaması şöyle
Everything is evacuated. This is typically a bad sign.
6. Nesnelerin Taşınması Yöntemleri
Nesnelerin taşınması bazı GC'lerde Young Generation ve Old Generation için ayrı ayrı seçilebiliyor. Bazılarında ise hepsi için aynı yöntem kullanılıyor.
 
6.1 Mark-sweep
Mark-sweep Nedir yazısına taşıdım. Nesne olduğu yerde bırakılır.

6.2 Mark-sweep-compact
Nesne aynı blokta yan yana olacak şekilde taşınır

6.3 Mark-copy 
Nesne başka bloğa taşınır

Hiç yorum yok:

Yorum Gönder