RFR(s): 8077415: Remove duplicate variables holding the CollectedHeap

Kim Barrett kim.barrett at oracle.com
Sun Apr 12 05:21:43 UTC 2015


On Apr 11, 2015, at 3:05 PM, Kim Barrett <kim.barrett at oracle.com> wrote:
> 
> On Apr 10, 2015, at 10:51 AM, Per Liden <per.liden at oracle.com> wrote:
>> 
>> Hi,
>> 
>> Universe::_collectedHeap points to the current CollectedHeap. However, collectors also have their own static instances for no real good reason. This patch removes all but the Universe::_collectedHeap and let users call Universe::heap() where needed.
>> 
>> Bug: https://bugs.openjdk.java.net/browse/JDK-8077415
>> 
>> Webrev: http://cr.openjdk.java.net/~pliden/8077415/webrev.0/
>> 
>> (This patch build on top of http://cr.openjdk.java.net/~pliden/8077413/webrev.0/ which is currently out for review)
>> 
>> cheers,
>> /Per
> 
> ------------------------------------------------------------------------------
> src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
> 3311 G1CollectedHeap* G1CollectedHeap::heap() {
> 3312   G1CollectedHeap* heap = (G1CollectedHeap*)Universe::heap();
> 3313   assert(heap != NULL, "Uninitialized access to G1CollectedHeap::heap()");
> 3314   assert(heap->kind() == CollectedHeap::G1CollectedHeap, "Not a G1CollectedHeap");
> 3315   return heap;
> 3316 }
> 
> Please don't do this.  If the heap isn't of the expected kind, then
> the cast invokes undefined behavior and the heap->kind() check could
> crash.  So the assert actually provides a false sense of safety.
> 
> It was for this kind of thing that I introduced FakeRttiSupport and
> used it for BarrierSet downcasts.  I was intending to use it similarly
> for CollectedHeap downcasts, but have not gotten around to doing so.
> See barrier_set_cast<>().

The idea with FakeRttiSupport was to make the kind() test so cheap that it would be reasonable
to use it in a guarantee rather than an assert.



More information about the hotspot-gc-dev mailing list