Professional Documents
Culture Documents
Presentation
Presentation
The JVM copies the reachable objects to “To Space”, S0, and increments the reachable
object's age by 1.
Minor GC
No Space
For me
E
D
Max Tenuring E
Threshold : 15 N
to specify the
object age 1 1 1 1 1 1 1 1
threshold to
promote the
S S
object to
0 1 1 1 2 2 2
tenured space
TENURED SPACE
What is Major GC ?
If minor GC triggers several times, eventually the “Tenured Space” will be filled up and will
require more garbage collection. During this time the JVM triggers a “major GC” event. Some
times we call this full GC. But, as part of full GC, the JVM reclaims the memory from “Meta
Space”. If there are no objects in the heap, then the loaded classes will be removed from the
meta space.
Now let us see what possibilities make the JVM trigger major GC.
If the developer calls System.gc(), or Runtime.getRunTime().gc() suggests the JVM to
initiate GC.
If the JVM decides there is not enough tenured space.
During minor GC, if the JVM is not able to reclaim enough memory from the eden or
survivor spaces, then a major GC may be triggered.
If we set a “MaxMetaspaceSize” option for the JVM and there is not enough space to load
new classes, then the JVM triggers a major GC.
I am a
Premature Promotion bigger size
object
E
D
E
Promoted N
to
Tenured Space
2 2 4 2 No space
S S for me in
0 1 young
generation
3 3 2 3 space
I need
space in
tenured
generation
TENURED SPACE
Major GC vs Full GC
One should notice that there is no formal definitions present for those terms. Neither in
JVM specification nor in the Garbage Collection research papers.
Major GC is cleaning the Tenured space.
Full GC is cleaning the entire Heap – both Young and Tenured spaces.
Instead of worrying whether the GC is called Major or Full GC, you should focus to
finding out whether the GC at hand stopped all the application threads or was it able to
progress concurrently with the application threads.
Table of contents:
What is Garbage Collector (GC) ?
How does Garbage Collector work inside JVM ?
What is Mark and Sweep Algorithm ?
What is Mark-Sweep-Compact Algorithm ?
What are the differences between Minor, Major and Full GC ?
What are different types of Garbage Collector ?
1. What is Serial GC ?
2. What is Parallel GC ?
3. What is Parallel Old GC ?
4. What is Concurrent Mark Sweep Collector ?
5. What is G1 GC ?
Why Garbage Collector plays very important role inside JVM ?
What is compaction in GC ?
What are different types of Garbage Collector ?
1. Serial Garbage Collector
2. Parallel Garbage Collector
3. Parallel Old Garbage Collector
4. Concurrent Mark Sweep Garbage Collector
5. G1 Garbage Collector
What is Serial Garbage Collector ?
The serial collector is the simplest one, and the one you probably won’t be using, as it’s
mainly designed for single-threaded environments (e.g. 32 bit or Windows) and for small
heaps.
This is the simplest GC implementation, as it basically works with a single thread. As a
result, this GC implementation freezes all application threads when it runs. Hence, it is
not a good idea to use it in multi-threaded applications like server environments.
To enable Serial Garbage Collector, we can use the following argument:
G1 performs a concurrent global marking phase to determine the liveness of objects throughout the
heap.
After the marking phase completes, G1 knows which regions are mostly empty. It collects these regions
first, which often yields a large amount of free space.
G1 uses a pause prediction model to meet a user-defined pause time target and selects the number of
regions to collect based on the specified pause time target.
G1 copies objects from one or more regions of the heap to a single region on the heap, and in the process
both compacts and frees up memory.
This evacuation is performed in parallel on multiprocessors to decrease pause times and increase
throughput.
G1 continuously works to reduce fragmentation. This is beyond the capability of both of the previous
methods. CMS (Concurrent Mark Sweep) garbage collection does not do compaction. Parallel compaction
performs only whole-heap compaction, which results in considerable pause times.
The first focus of G1 is to provide a solution for users running applications that require large heaps with
limited GC latency. This means heap sizes of around 6 GB or larger, and a stable and predictable pause time
below 0.5 seconds
G1 is planned as the long-term replacement for the Concurrent Mark-Sweep Collector (CMS).
One difference is that G1 is a compacting collector. Also, G1 offers more predictable garbage collection
pauses than the CMS collector, and allows users to specify desired pause targets.
Which Application needs G1 Garbage Collector ?
The G1 collector is designed for applications that:
Can operate concurrently with applications threads like the CMS collector.
Compact free space without lengthy GC induced pause times.
Need more predictable GC pause durations.
Do not want to sacrifice a lot of throughput performance.
Do not require a much larger Java heap.
The Garbage-First (G1) collector is a server-style garbage collector, targeted for multi-
processor machines with large memories
Table of contents:
What is Garbage Collector (GC) ?
How does Garbage Collector work inside JVM ?
What is Mark and Sweep Algorithm ?
What is Mark-Sweep-Compact Algorithm ?
What are the differences between Minor, Major and Full GC ?
What are different types of Garbage Collector ?
1. What is Serial GC ?
2. What is Parallel GC ?
3. What is Parallel Old GC ?
4. What is Concurrent Mark Sweep Collector ?
5. What is G1 GC ?
Why Garbage Collector plays very important role inside JVM ?
What is compaction in GC ?
Why Garbage Collector plays very important role inside JVM ?
What is compaction in GC ?
https://dzone.com/articles/understanding-
the-java-memory-model-and-the-garbag
The objects which are not fit into the survivor space will be moved to the tenured
space. This process is called “premature promotion”