src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp

Print this page




6639 
6640   VerifyRegionListsClosure cl(&_old_set, &_humongous_set, &_free_list);
6641   heap_region_iterate(&cl);
6642 
6643   _old_set.verify_end();
6644   _humongous_set.verify_end();
6645   _free_list.verify_end();
6646 }
6647 
6648 // Optimized nmethod scanning
6649 
6650 class RegisterNMethodOopClosure: public OopClosure {
6651   G1CollectedHeap* _g1h;
6652   nmethod* _nm;
6653 
6654   template <class T> void do_oop_work(T* p) {
6655     T heap_oop = oopDesc::load_heap_oop(p);
6656     if (!oopDesc::is_null(heap_oop)) {
6657       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
6658       HeapRegion* hr = _g1h->heap_region_containing(obj);
6659       assert(!hr->isHumongous(), "code root in humongous region?");
6660 
6661       // HeapRegion::add_strong_code_root() avoids adding duplicate
6662       // entries but having duplicates is  OK since we "mark" nmethods
6663       // as visited when we scan the strong code root lists during the GC.
6664       hr->add_strong_code_root(_nm);
6665       assert(hr->rem_set()->strong_code_roots_list_contains(_nm), "add failed?");
6666     }
6667   }
6668 
6669 public:
6670   RegisterNMethodOopClosure(G1CollectedHeap* g1h, nmethod* nm) :
6671     _g1h(g1h), _nm(nm) {}
6672 
6673   void do_oop(oop* p)       { do_oop_work(p); }
6674   void do_oop(narrowOop* p) { do_oop_work(p); }
6675 };
6676 
6677 class UnregisterNMethodOopClosure: public OopClosure {
6678   G1CollectedHeap* _g1h;
6679   nmethod* _nm;
6680 
6681   template <class T> void do_oop_work(T* p) {
6682     T heap_oop = oopDesc::load_heap_oop(p);
6683     if (!oopDesc::is_null(heap_oop)) {
6684       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
6685       HeapRegion* hr = _g1h->heap_region_containing(obj);
6686       assert(!hr->isHumongous(), "code root in humongous region?");
6687       hr->remove_strong_code_root(_nm);
6688       assert(!hr->rem_set()->strong_code_roots_list_contains(_nm), "remove failed?");
6689     }
6690   }
6691 
6692 public:
6693   UnregisterNMethodOopClosure(G1CollectedHeap* g1h, nmethod* nm) :
6694     _g1h(g1h), _nm(nm) {}
6695 
6696   void do_oop(oop* p)       { do_oop_work(p); }
6697   void do_oop(narrowOop* p) { do_oop_work(p); }
6698 };
6699 
6700 void G1CollectedHeap::register_nmethod(nmethod* nm) {
6701   CollectedHeap::register_nmethod(nm);
6702 
6703   guarantee(nm != NULL, "sanity");
6704   RegisterNMethodOopClosure reg_cl(this, nm);
6705   nm->oops_do(&reg_cl);
6706 }


6779     _oop_cl(cm, hr, worker_id) {}
6780 
6781   void do_code_blob(CodeBlob* cb) {
6782     nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
6783     if (nm != NULL) {
6784       nm->oops_do(&_oop_cl);
6785     }
6786   }
6787 };
6788 
6789 class MarkStrongCodeRootsHRClosure: public HeapRegionClosure {
6790   G1CollectedHeap* _g1h;
6791   uint _worker_id;
6792 
6793 public:
6794   MarkStrongCodeRootsHRClosure(G1CollectedHeap* g1h, uint worker_id) :
6795     _g1h(g1h), _worker_id(worker_id) {}
6796 
6797   bool doHeapRegion(HeapRegion *hr) {
6798     HeapRegionRemSet* hrrs = hr->rem_set();
6799     if (hr->isHumongous()) {
6800       // Code roots should never be attached to a humongous region
6801       assert(hrrs->strong_code_roots_list_length() == 0, "sanity");
6802       return false;
6803     }
6804 
6805     if (hr->in_collection_set()) {
6806       // Don't mark code roots into regions in the collection set here.
6807       // They will be marked when we scan them.
6808       return false;
6809     }
6810 
6811     MarkStrongCodeRootCodeBlobClosure cb_cl(_g1h->concurrent_mark(), hr, _worker_id);
6812     hr->strong_code_roots_do(&cb_cl);
6813     return false;
6814   }
6815 };
6816 
6817 void G1CollectedHeap::mark_strong_code_roots(uint worker_id) {
6818   MarkStrongCodeRootsHRClosure cl(this, worker_id);
6819   if (G1CollectedHeap::use_parallel_gc_threads()) {
6820     heap_region_par_iterate_chunked(&cl,




6639 
6640   VerifyRegionListsClosure cl(&_old_set, &_humongous_set, &_free_list);
6641   heap_region_iterate(&cl);
6642 
6643   _old_set.verify_end();
6644   _humongous_set.verify_end();
6645   _free_list.verify_end();
6646 }
6647 
6648 // Optimized nmethod scanning
6649 
6650 class RegisterNMethodOopClosure: public OopClosure {
6651   G1CollectedHeap* _g1h;
6652   nmethod* _nm;
6653 
6654   template <class T> void do_oop_work(T* p) {
6655     T heap_oop = oopDesc::load_heap_oop(p);
6656     if (!oopDesc::is_null(heap_oop)) {
6657       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
6658       HeapRegion* hr = _g1h->heap_region_containing(obj);
6659       assert(!hr->continuesHumongous(), "code root in continuation of humongous region?");
6660 
6661       // HeapRegion::add_strong_code_root() avoids adding duplicate
6662       // entries but having duplicates is  OK since we "mark" nmethods
6663       // as visited when we scan the strong code root lists during the GC.
6664       hr->add_strong_code_root(_nm);
6665       assert(hr->rem_set()->strong_code_roots_list_contains(_nm), "add failed?");
6666     }
6667   }
6668 
6669 public:
6670   RegisterNMethodOopClosure(G1CollectedHeap* g1h, nmethod* nm) :
6671     _g1h(g1h), _nm(nm) {}
6672 
6673   void do_oop(oop* p)       { do_oop_work(p); }
6674   void do_oop(narrowOop* p) { do_oop_work(p); }
6675 };
6676 
6677 class UnregisterNMethodOopClosure: public OopClosure {
6678   G1CollectedHeap* _g1h;
6679   nmethod* _nm;
6680 
6681   template <class T> void do_oop_work(T* p) {
6682     T heap_oop = oopDesc::load_heap_oop(p);
6683     if (!oopDesc::is_null(heap_oop)) {
6684       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
6685       HeapRegion* hr = _g1h->heap_region_containing(obj);
6686       assert(!hr->continuesHumongous(), "code root in continuation of humongous region?");
6687       hr->remove_strong_code_root(_nm);
6688       assert(!hr->rem_set()->strong_code_roots_list_contains(_nm), "remove failed?");
6689     }
6690   }
6691 
6692 public:
6693   UnregisterNMethodOopClosure(G1CollectedHeap* g1h, nmethod* nm) :
6694     _g1h(g1h), _nm(nm) {}
6695 
6696   void do_oop(oop* p)       { do_oop_work(p); }
6697   void do_oop(narrowOop* p) { do_oop_work(p); }
6698 };
6699 
6700 void G1CollectedHeap::register_nmethod(nmethod* nm) {
6701   CollectedHeap::register_nmethod(nm);
6702 
6703   guarantee(nm != NULL, "sanity");
6704   RegisterNMethodOopClosure reg_cl(this, nm);
6705   nm->oops_do(&reg_cl);
6706 }


6779     _oop_cl(cm, hr, worker_id) {}
6780 
6781   void do_code_blob(CodeBlob* cb) {
6782     nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
6783     if (nm != NULL) {
6784       nm->oops_do(&_oop_cl);
6785     }
6786   }
6787 };
6788 
6789 class MarkStrongCodeRootsHRClosure: public HeapRegionClosure {
6790   G1CollectedHeap* _g1h;
6791   uint _worker_id;
6792 
6793 public:
6794   MarkStrongCodeRootsHRClosure(G1CollectedHeap* g1h, uint worker_id) :
6795     _g1h(g1h), _worker_id(worker_id) {}
6796 
6797   bool doHeapRegion(HeapRegion *hr) {
6798     HeapRegionRemSet* hrrs = hr->rem_set();
6799     if (hr->continuesHumongous()) {
6800       // Code roots should never be attached to a continuation of a humongous region
6801       assert(hrrs->strong_code_roots_list_length() == 0, "sanity");
6802       return false;
6803     }
6804 
6805     if (hr->in_collection_set()) {
6806       // Don't mark code roots into regions in the collection set here.
6807       // They will be marked when we scan them.
6808       return false;
6809     }
6810 
6811     MarkStrongCodeRootCodeBlobClosure cb_cl(_g1h->concurrent_mark(), hr, _worker_id);
6812     hr->strong_code_roots_do(&cb_cl);
6813     return false;
6814   }
6815 };
6816 
6817 void G1CollectedHeap::mark_strong_code_roots(uint worker_id) {
6818   MarkStrongCodeRootsHRClosure cl(this, worker_id);
6819   if (G1CollectedHeap::use_parallel_gc_threads()) {
6820     heap_region_par_iterate_chunked(&cl,