--- old/src/share/vm/gc_implementation/g1/heapRegion.cpp 2013-06-26 14:24:01.302914463 -0700 +++ new/src/share/vm/gc_implementation/g1/heapRegion.cpp 2013-06-26 14:24:01.085033719 -0700 @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "code/nmethod.hpp" #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" #include "gc_implementation/g1/g1OopClosures.inline.hpp" @@ -32,7 +33,6 @@ #include "memory/genOopClosures.inline.hpp" #include "memory/iterator.hpp" #include "oops/oop.inline.hpp" -#include "utilities/growableArray.hpp" int HeapRegion::LogOfHRGrainBytes = 0; int HeapRegion::LogOfHRGrainWords = 0; @@ -226,20 +226,13 @@ if (!par) { // If this is parallel, this will be done later. HeapRegionRemSet* hrrs = rem_set(); - if (hrrs != NULL) hrrs->clear(); + hrrs->clear(); _claimed = InitialClaimValue; } zero_marked_bytes(); _offsets.resize(HeapRegion::GrainWords); init_top_at_mark_start(); - - if (_strong_code_root_list != NULL) { - delete _strong_code_root_list; - } - _strong_code_root_list = new (ResourceObj::C_HEAP, mtGC) - GrowableArray(10, 0, NULL, true); - if (clear_space) clear(SpaceDecorator::Mangle); } @@ -368,8 +361,9 @@ #endif // ASSERT _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1), _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0), - _predicted_bytes_to_copy(0), _strong_code_root_list(NULL) + _predicted_bytes_to_copy(0) { + _rem_set = new HeapRegionRemSet(sharedOffsetArray, this); _orig_end = mr.end(); // Note that initialize() will set the start of the unmarked area of the // region. @@ -377,8 +371,6 @@ set_top(bottom()); set_saved_mark(); - _rem_set = new HeapRegionRemSet(sharedOffsetArray, this); - assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant."); } @@ -601,111 +593,26 @@ // Code roots support void HeapRegion::add_strong_code_root(nmethod* nm) { - assert(nm != NULL, "sanity"); - // Search for the code blob from the RHS to avoid - // duplicate entries as much as possible - if (_strong_code_root_list->find_from_end(nm) < 0) { - // Code blob isn't already in the list - _strong_code_root_list->push(nm); - } + HeapRegionRemSet* hrrs = rem_set(); + hrrs->add_strong_code_root(nm); } void HeapRegion::remove_strong_code_root(nmethod* nm) { - assert(nm != NULL, "sanity"); - int idx = _strong_code_root_list->find(nm); - while (idx >= 0) { - _strong_code_root_list->remove_at(idx); - idx = _strong_code_root_list->find(nm); - } + HeapRegionRemSet* hrrs = rem_set(); + hrrs->remove_strong_code_root(nm); } -class NMethodMigrationOopClosure : public OopClosure { - G1CollectedHeap* _g1h; - HeapRegion* _from; - nmethod* _nm; - - uint _num_self_forwarded; - - template void do_oop_work(T* p) { - T heap_oop = oopDesc::load_heap_oop(p); - if (!oopDesc::is_null(heap_oop)) { - oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); - if (_from->is_in(obj)) { - // Reference still points into the source region. - // Since roots are immediately evacuated this means that - // we must have self forwarded the object - assert(obj->is_forwarded(), - err_msg("code roots should be immediately evacuated. " - "Ref: "PTR_FORMAT", " - "Obj: "PTR_FORMAT", " - "Region: "HR_FORMAT, - p, (void*) obj, HR_FORMAT_PARAMS(_from))); - assert(obj->forwardee() == obj, - err_msg("not self forwarded? obj = "PTR_FORMAT, (void*)obj)); - - // The object has been self forwarded. - // Note, if we're during an initial mark pause, there is - // no need to explicitly mark object. It will be marked - // during the regular evacuation failure handling code. - _num_self_forwarded++; - } else { - // The reference points into a promotion or to-space region - HeapRegion* to = _g1h->heap_region_containing(obj); - to->add_strong_code_root(_nm); - } - } - } - -public: - NMethodMigrationOopClosure(G1CollectedHeap* g1h, HeapRegion* from, nmethod* nm): - _g1h(g1h), _from(from), _nm(nm), _num_self_forwarded(0) {} - - void do_oop(narrowOop* p) { do_oop_work(p); } - void do_oop(oop* p) { do_oop_work(p); } - - uint retain() { return _num_self_forwarded > 0; } -}; - void HeapRegion::migrate_strong_code_roots() { assert(in_collection_set(), "only collection set regions"); assert(!isHumongous(), "not humongous regions"); - ResourceMark rm; - - // List of code blobs to retain for this region - GrowableArray to_be_retained(10); - G1CollectedHeap* g1h = G1CollectedHeap::heap(); - - while (strong_code_root_list()->is_nonempty()) { - nmethod *nm = strong_code_root_list()->pop(); - if (nm != NULL) { - NMethodMigrationOopClosure oop_cl(g1h, this, nm); - nm->oops_do(&oop_cl); - if (oop_cl.retain()) { - to_be_retained.push(nm); - } - } - } - - // Now push any code roots we need to retain - // FIXME: assert that region got an evacuation failure if non-empty - while (to_be_retained.is_nonempty()) { - nmethod* nm = to_be_retained.pop(); - assert(nm != NULL, "sanity"); - add_strong_code_root(nm); - } + HeapRegionRemSet* hrrs = rem_set(); + hrrs->migrate_strong_code_roots(); } void HeapRegion::strong_code_roots_do(CodeBlobClosure* blk) const { - for (int i = 0; i < _strong_code_root_list->length(); i += 1) { - nmethod* nm = _strong_code_root_list->at(i); - blk->do_code_blob(nm); - } -} - -size_t HeapRegion::strong_code_root_mem_size() { - return sizeof(GrowableArray) + - _strong_code_root_list->max_length() * sizeof(nmethod*); + HeapRegionRemSet* hrrs = rem_set(); + hrrs->strong_code_roots_do(blk); } class VerifyStrongCodeRootOopClosure: public OopClosure { @@ -803,13 +710,16 @@ return; } + HeapRegionRemSet* hrrs = rem_set(); + int strong_code_roots_length = hrrs->strong_code_roots_list_length(); + // if this region is empty then there should be no entries // on its strong code root list if (is_empty()) { - if (!_strong_code_root_list->is_empty()) { + if (strong_code_roots_length > 0) { gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is empty " "but has "INT32_FORMAT" code root entries", - bottom(), end(), _strong_code_root_list->length()); + bottom(), end(), strong_code_roots_length); *failures = true; } return; @@ -817,10 +727,10 @@ // An H-region should have an empty strong code root list if (isHumongous()) { - if (!_strong_code_root_list->is_empty()) { + if (strong_code_roots_length > 0) { gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous " "but has "INT32_FORMAT" code root entries", - bottom(), end(), _strong_code_root_list->length()); + bottom(), end(), strong_code_roots_length); *failures = true; } return;