4

Another developer mentioned to me today the idea that a Full GC (that would show up in verbose gc logs with Full GC) can vary in the effort applied. For a normal Full collection it would, for example, only apply 80% effort, leading to a shorter collection time, but possibly some unreachable objects being left uncollected. If this did not reclaim enough, or the time spent in these kind of collections increased too much, it would then apply greater effort, finding more objects but potentially taking longer.

I can't any references for this, possibly because I'm using the wrong terms.

Is this true, particularly for any of the Oracle Java 7 JVM collector alogorithms?

Thanks

matt freake
  • 4,877
  • 4
  • 27
  • 56

3 Answers3

2

Concerning the Hotspot GC algorithms:

The G1 collector features a pause-time goal that is used by the algorithm to determine how much space to reclaim in order to meet this goal - i.e. finishing within a certain time. But, this not only concerns the Full GC, in fact, in the case of the G1 this concerns all the GC phases. The G1 adjusts its collection strategy (or, the "effort") for each phase at runtime depending on how much was collected and how long it took in the previous phase. See How does the Garbage-First Garbage Collector work? for more details.

The CMS is an incremental GC, and similarly to G1 its collection times and effort may vary between each GC phase.

On the other hand, the Parallel Collector is a compacting collector that will compact the whole OldGen in the best effort manner.

Community
  • 1
  • 1
Aleš
  • 8,896
  • 8
  • 62
  • 107
  • Thank you for that - that's perfect. Do you know if the Parallel Old GC collector also employs the best effort manner always? – matt freake Nov 22 '13 at 11:19
  • Yes. At the end of Parallel Old GC phase the OldGen always contains only live objects, there is no floating garbage. All dead objects are collected in one phase. – Aleš Nov 22 '13 at 17:18
  • See @Paul Medcraft's answer below. The OldGen *can* contain dead objects, if they are to the left of the "Dense Prefix" (see http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf for full details). I'm not sure though whether this means the full gc can vary in its effort though. It would depend if the "dense prefix" moves following some kind of allocation failure – matt freake Jun 24 '14 at 08:34
1

Short answer: Yes.

Long Answer: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html

Dodd10x
  • 3,344
  • 1
  • 18
  • 27
  • 3
    Thanks. I had a look at that link before posting the question, but couldn't see anything. Under which section does it say Full Collections will make different efforts? – matt freake Nov 21 '13 at 17:45
1

According to the this and this, the parallel old collector does not always collect all out of scope objects. From the Chaotic Java article:

Note that in the following image the collection occurs over only 60% of the heap (making the collection twice as fast as if it would collect everything), and reclaiming 82% of the garbage. That means that in order to collect the additional 18%, the garbage collector would have to work just as hard as it did for the first 82%! Obviously, these are not precise calculations, but surely the point is made: this is the reason the dense prefix is an important optimization step.

What I am not sure of is how it determines which regions are "worthwhile for collection". Does this depend on how much it needs to promote to tenured?

Paul Medcraft
  • 1,386
  • 11
  • 23