Why multiple garbage collectors in Java?

garbage-collection, java

Solution

I am assuming they have overlapping pools.

This assumption is wrong. PS Scavenge will be used on the young (eden, survivor) generation and PS MarkSweep will be used on the old generation. The only "overlap" is that PS Scavenge will move objects into the old generation once they've been around a while and let PS MarkSweep deal with them then.

The benefit of having different garbage collectors for different pools is that an algorithm that works well for objects in the eden pool isn't necessarily going to work well for old generation objects.

This article covers the various options for different garbage collectors working together.

As far as "major" collections which occur when there is no space to move objects into the old generation, this (admittedly old) whitepaper from Sun says the following:

...the young generation collection algorithm is not run. Instead, the old generation collection algorithm is used on the entire heap.

Problem

Every Java process I start on my machine seems to have two garbage collectors by default. I'm checking this via JConsole. Example - for my currently running Eclipse. PS MarkSweep ``` Collection Count - 221 Collection Time - 102118 Memory Pool Names - java.lang.String[4] ``` PS Scavenge ``` Collection Count - 241 Collection Time - 2428 Memory Pool Names - java.lang.String[2] ``` I am assuming they have overlapping pools. How do two garbage collectors work together when using the same pools (Eden, survivor, old gen)? Is there no overlap in movement of objects between pools (like movement from one survivor to another when the second algorithm is called)? Even if it is not, why do we need more than one collector per pool? I have read this article on GC. They refer to using different collectors for different major and minor GC, but there seems to be no reference to using multiple collectors on the same pool.

Original source