1.1 --- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Fri Aug 29 13:08:01 2014 +0200 1.2 +++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp Fri Aug 29 13:12:21 2014 +0200 1.3 @@ -4580,6 +4580,56 @@ 1.4 } 1.5 }; 1.6 1.7 +class G1CodeBlobClosure : public CodeBlobClosure { 1.8 + class HeapRegionGatheringOopClosure : public OopClosure { 1.9 + G1CollectedHeap* _g1h; 1.10 + OopClosure* _work; 1.11 + nmethod* _nm; 1.12 + 1.13 + template <typename T> 1.14 + void do_oop_work(T* p) { 1.15 + _work->do_oop(p); 1.16 + T oop_or_narrowoop = oopDesc::load_heap_oop(p); 1.17 + if (!oopDesc::is_null(oop_or_narrowoop)) { 1.18 + oop o = oopDesc::decode_heap_oop_not_null(oop_or_narrowoop); 1.19 + HeapRegion* hr = _g1h->heap_region_containing_raw(o); 1.20 + assert(!_g1h->obj_in_cs(o) || hr->rem_set()->strong_code_roots_list_contains(_nm), "if o still in CS then evacuation failed and nm must already be in the remset"); 1.21 + hr->add_strong_code_root(_nm); 1.22 + } 1.23 + } 1.24 + 1.25 + public: 1.26 + HeapRegionGatheringOopClosure(OopClosure* oc) : _g1h(G1CollectedHeap::heap()), _work(oc), _nm(NULL) {} 1.27 + 1.28 + void do_oop(oop* o) { 1.29 + do_oop_work(o); 1.30 + } 1.31 + 1.32 + void do_oop(narrowOop* o) { 1.33 + do_oop_work(o); 1.34 + } 1.35 + 1.36 + void set_nm(nmethod* nm) { 1.37 + _nm = nm; 1.38 + } 1.39 + }; 1.40 + 1.41 + HeapRegionGatheringOopClosure _oc; 1.42 +public: 1.43 + G1CodeBlobClosure(OopClosure* oc) : _oc(oc) {} 1.44 + 1.45 + void do_code_blob(CodeBlob* cb) { 1.46 + nmethod* nm = cb->as_nmethod_or_null(); 1.47 + if (nm != NULL) { 1.48 + if (!nm->test_set_oops_do_mark()) { 1.49 + _oc.set_nm(nm); 1.50 + nm->oops_do(&_oc); 1.51 + nm->fix_oop_relocations(); 1.52 + } 1.53 + } 1.54 + } 1.55 +}; 1.56 + 1.57 class G1ParTask : public AbstractGangTask { 1.58 protected: 1.59 G1CollectedHeap* _g1h; 1.60 @@ -4648,22 +4698,6 @@ 1.61 } 1.62 }; 1.63 1.64 - class G1CodeBlobClosure: public CodeBlobClosure { 1.65 - OopClosure* _f; 1.66 - 1.67 - public: 1.68 - G1CodeBlobClosure(OopClosure* f) : _f(f) {} 1.69 - void do_code_blob(CodeBlob* blob) { 1.70 - nmethod* that = blob->as_nmethod_or_null(); 1.71 - if (that != NULL) { 1.72 - if (!that->test_set_oops_do_mark()) { 1.73 - that->oops_do(_f); 1.74 - that->fix_oop_relocations(); 1.75 - } 1.76 - } 1.77 - } 1.78 - }; 1.79 - 1.80 void work(uint worker_id) { 1.81 if (worker_id >= _n_workers) return; // no work needed this round 1.82 1.83 @@ -4854,7 +4888,7 @@ 1.84 g1_policy()->phase_times()->record_satb_filtering_time(worker_i, satb_filtering_ms); 1.85 1.86 // Now scan the complement of the collection set. 1.87 - MarkingCodeBlobClosure scavenge_cs_nmethods(scan_non_heap_weak_roots, CodeBlobToOopClosure::FixRelocations); 1.88 + G1CodeBlobClosure scavenge_cs_nmethods(scan_non_heap_weak_roots); 1.89 1.90 g1_rem_set()->oops_into_collection_set_do(scan_rs, &scavenge_cs_nmethods, worker_i); 1.91 1.92 @@ -5901,12 +5935,6 @@ 1.93 hot_card_cache->reset_hot_cache(); 1.94 hot_card_cache->set_use_cache(true); 1.95 1.96 - // Migrate the strong code roots attached to each region in 1.97 - // the collection set. Ideally we would like to do this 1.98 - // after we have finished the scanning/evacuation of the 1.99 - // strong code roots for a particular heap region. 1.100 - migrate_strong_code_roots(); 1.101 - 1.102 purge_code_root_memory(); 1.103 1.104 if (g1_policy()->during_initial_mark_pause()) { 1.105 @@ -6902,13 +6930,8 @@ 1.106 " starting at "HR_FORMAT, 1.107 _nm, HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()))); 1.108 1.109 - // HeapRegion::add_strong_code_root() avoids adding duplicate 1.110 - // entries but having duplicates is OK since we "mark" nmethods 1.111 - // as visited when we scan the strong code root lists during the GC. 1.112 - hr->add_strong_code_root(_nm); 1.113 - assert(hr->rem_set()->strong_code_roots_list_contains(_nm), 1.114 - err_msg("failed to add code root "PTR_FORMAT" to remembered set of region "HR_FORMAT, 1.115 - _nm, HR_FORMAT_PARAMS(hr))); 1.116 + // HeapRegion::add_strong_code_root_locked() avoids adding duplicate entries. 1.117 + hr->add_strong_code_root_locked(_nm); 1.118 } 1.119 } 1.120 1.121 @@ -6935,9 +6958,6 @@ 1.122 _nm, HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()))); 1.123 1.124 hr->remove_strong_code_root(_nm); 1.125 - assert(!hr->rem_set()->strong_code_roots_list_contains(_nm), 1.126 - err_msg("failed to remove code root "PTR_FORMAT" of region "HR_FORMAT, 1.127 - _nm, HR_FORMAT_PARAMS(hr))); 1.128 } 1.129 } 1.130 1.131 @@ -6965,28 +6985,9 @@ 1.132 nm->oops_do(®_cl, true); 1.133 } 1.134 1.135 -class MigrateCodeRootsHeapRegionClosure: public HeapRegionClosure { 1.136 -public: 1.137 - bool doHeapRegion(HeapRegion *hr) { 1.138 - assert(!hr->isHumongous(), 1.139 - err_msg("humongous region "HR_FORMAT" should not have been added to collection set", 1.140 - HR_FORMAT_PARAMS(hr))); 1.141 - hr->migrate_strong_code_roots(); 1.142 - return false; 1.143 - } 1.144 -}; 1.145 - 1.146 -void G1CollectedHeap::migrate_strong_code_roots() { 1.147 - MigrateCodeRootsHeapRegionClosure cl; 1.148 - double migrate_start = os::elapsedTime(); 1.149 - collection_set_iterate(&cl); 1.150 - double migration_time_ms = (os::elapsedTime() - migrate_start) * 1000.0; 1.151 - g1_policy()->phase_times()->record_strong_code_root_migration_time(migration_time_ms); 1.152 -} 1.153 - 1.154 void G1CollectedHeap::purge_code_root_memory() { 1.155 double purge_start = os::elapsedTime(); 1.156 - G1CodeRootSet::purge_chunks(G1CodeRootsChunkCacheKeepPercent); 1.157 + G1CodeRootSet::purge(); 1.158 double purge_time_ms = (os::elapsedTime() - purge_start) * 1000.0; 1.159 g1_policy()->phase_times()->record_strong_code_root_purge_time(purge_time_ms); 1.160 }