[concurrency-interest] Garbage First vs a counting collector
davidcholmes at aapt.net.au
Fri Mar 27 20:27:23 EDT 2009
<posted on behalf of Tony Printezis>
Some thoughts on the G1 vs. RC subject. I'm not on the list so thanks to
David Holmes for forwarding your post and posting my reply. If you want,
we can carry on the conversation on hotspot-gc-dev at openjdk.java.net.
It's true that in G1 we have a non-trivial (in the worst case) write
barrier that does make writes more expensive. The write barrier has
three levels of overhead on its path: fast, slow, slower. The fast
happens, I'd guess 90%-95% of the time and it involves no writes (just a
read). The slow path is basically when we do a local write, with no
synchronization needed (queue up a write to a thread-local buffer).
Slower is when we have to make a full buffer globally available for
processing, which does involve synchronization. But It's very, very rare.
Sure, I understand that maintenance of RCs can be done easier with a
CAS. And CASes are relatively cheap these days. However, for heavily
referenced objects, CASes will fail, which will introduce retrying
overhead. I personally would much prefer the approach of buffering
writes and updating RCs in bulk (an extra advantage of this is that some
of the RC updates might cancel each other out). But, this would look
very much like what we have in G1, with the exception (maybe!) of not
being able to filter out as many of the writes as we can.
Still, I wouldn't be in a hurry to implement a GC based on RC for a
couple of reasons.
First, you have to deal with cycles. Yes, there are techniques to do so.
Still, they add code and complexity.
Second, and most importantly, RCed GCs are typically non-moving (i.e.,
you de-allocate in-place), which can create fragmentation. And my 10+
years experience of implementing GCs has taught me that compaction is
really very desirable. Maybe you didn't hit any such issues in your
language. But fragmentation is really a major problem that some of our
customers that use CMS hit every now and then. With G1, it mostly goes
away. And it will allow us and our customers to sleep better at night.
Interestingly, I know the GC policies of at least 6 product-quality JVMs
and none are using RC and I'd guess it's due to some of the issues I
Tony Printezis, HotSpot GC Group
More information about the Concurrency-interest