when will be G1 ( Garbage Collector) starts running and in which memory area it collect first? what is the new GC update on java 8?
2 Answers
when will be G1 ( Garbage Collector) starts running?
When you add -XX:+UseG1GC
to JVM parameters, G1GC is enabled.
when will be G1 ( Garbage Collector) starts running and in which memory area it collect first?
Refer to oracle tutorial on G1GC.
The heap is partitioned into a set of equal-sized heap regions, each a contiguous range of virtual memory. Certain region sets are assigned the same roles (eden, survivor, old)
G1 performs a concurrent global marking phase to determine the liveness of objects throughout the heap. After the mark phase completes, G1 knows which regions are mostly empty. It collects in these regions first, which usually yields a large amount of free space. This is why this method of garbage collection is called Garbage-First. As the name suggests, G1 concentrates its collection and compaction activity on the areas of the heap that are likely to be full of reclaimable objects, that is, garbage. 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.
The regions identified by G1 as ripe for reclamation are garbage collected using evacuation. 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 multi-processors, to decrease pause times and increase throughput. Thus, with each garbage collection, G1 continuously works to reduce fragmentation, working within the user defined pause times. This is beyond the capability of both the previous methods.

- 37,698
- 11
- 250
- 211
When G1 find out that garbage collection is necessary, then it start collecting the regions with least live data. It finds live objects in old generation through a concurrent marking phase and allocate objects to young generation keep promote aged objects into old generation. JVM triggers the marking phase when the total Java heap occupancy exceed the default threshold.
The Initiating Heap Occupancy Percent(IHOP) is the threshold at which an initial mark collection is triggered. G1 by default determine an optimal IHOP by observing how long marking takes and how much memory is typically allocated in old generation.
New in Java 8:
G1 Collector String duplication is the new feature added in Java 8. Since Strings takes much of heap memory, so this new feature enables the G1 collector to identify strings which are duplicated more than once in heap space and correct them to point into the same internal char[] array.
Removal of PermGen space and use of MetaSapce in Java 8 Garbage Collection is new thing. Read this post for more info.

- 2,788
- 4
- 17
- 29