Mercurial > hg > truffle
diff src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp @ 21143:e13c65f874e5
Make G1 and Graal be friends in JDK9
author | iveresov |
---|---|
date | Tue, 28 Apr 2015 17:08:47 -0700 |
parents | 7848fc12602b |
children |
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp Tue Apr 28 12:58:40 2015 -0700 +++ b/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp Tue Apr 28 17:08:47 2015 -0700 @@ -255,3 +255,60 @@ } } } + +void G1SATBCardTableModRefBS::write_ref_nmethod_pre(oop* dst, nmethod* nm) { + oop obj = oopDesc::load_heap_oop(dst); + if (obj != NULL) { + G1CollectedHeap* g1h = (G1CollectedHeap*)Universe::heap(); + HeapRegion* hr = g1h->heap_region_containing(obj); + assert(!hr->continuesHumongous(), + err_msg("trying to add code root "INTPTR_FORMAT" in continuation of humongous region "HR_FORMAT + " starting at "HR_FORMAT, + (intptr_t)nm, HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()))); + hr->add_strong_code_root(nm); + } +} + +class G1EnsureLastRefToRegion : public OopClosure { + G1CollectedHeap* _g1h; + HeapRegion* _hr; + oop* _dst; + + bool _value; +public: + G1EnsureLastRefToRegion(G1CollectedHeap* g1h, HeapRegion* hr, oop* dst) : + _g1h(g1h), _hr(hr), _dst(dst), _value(true) {} + + void do_oop(oop* p) { + if (_value && p != _dst) { + oop obj = oopDesc::load_heap_oop(p); + if (obj != NULL) { + HeapRegion* hr = _g1h->heap_region_containing(obj); + if (hr == _hr) { + // Another reference to the same region. + _value = false; + } + } + } + } + void do_oop(narrowOop* p) { ShouldNotReachHere(); } + bool value() const { return _value; } +}; + +void G1SATBCardTableModRefBS::write_ref_nmethod_post(oop* dst, nmethod* nm) { + oop obj = oopDesc::load_heap_oop(dst); + if (obj != NULL) { + G1CollectedHeap* g1h = (G1CollectedHeap*)Universe::heap(); + HeapRegion* hr = g1h->heap_region_containing(obj); + assert(!hr->continuesHumongous(), + err_msg("trying to remove code root "INTPTR_FORMAT" in continuation of humongous region "HR_FORMAT + " starting at "HR_FORMAT, + (intptr_t)nm, HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()))); + G1EnsureLastRefToRegion ensure_last_ref(g1h, hr, dst); + nm->oops_do(&ensure_last_ref); + if (ensure_last_ref.value()) { + // Last reference to this region, remove the nmethod from the rset. + hr->remove_strong_code_root(nm); + } + } +}