< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp

Print this page
rev 55429 : 8226311: Shenandoah: Concurrent evacuation of OopStorage backed weak roots


  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 
  26 #include "classfile/classLoaderDataGraph.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
  31 #include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
  32 #include "gc/shenandoah/shenandoahHeap.hpp"
  33 #include "gc/shenandoah/shenandoahHeuristics.hpp"
  34 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  35 #include "gc/shenandoah/shenandoahStringDedup.hpp"
  36 #include "gc/shenandoah/shenandoahTimingTracker.hpp"
  37 #include "gc/shenandoah/shenandoahVMOperations.hpp"
  38 #include "gc/shared/weakProcessor.inline.hpp"
  39 #include "memory/allocation.inline.hpp"
  40 #include "memory/iterator.hpp"
  41 #include "memory/resourceArea.hpp"
  42 #include "memory/universe.hpp"
  43 #include "runtime/thread.hpp"
  44 #include "services/management.hpp"
  45 
  46 ShenandoahSerialRoot::ShenandoahSerialRoot(ShenandoahSerialRoot::OopsDo oops_do, ShenandoahPhaseTimings::GCParPhases phase) :
  47   _claimed(false), _oops_do(oops_do), _phase(phase) {
  48 }
  49 
  50 void ShenandoahSerialRoot::oops_do(OopClosure* cl, uint worker_id) {
  51   if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
  52     ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  53     ShenandoahWorkerTimingsTracker timer(worker_times, _phase, worker_id);
  54     _oops_do(cl);
  55   }
  56 }
  57 
  58 ShenandoahSerialRoots::ShenandoahSerialRoots() :
  59   _universe_root(&Universe::oops_do, ShenandoahPhaseTimings::UniverseRoots),
  60   _object_synchronizer_root(&ObjectSynchronizer::oops_do, ShenandoahPhaseTimings::ObjectSynchronizerRoots),
  61   _management_root(&Management::oops_do, ShenandoahPhaseTimings::ManagementRoots),
  62   _system_dictionary_root(&SystemDictionary::oops_do, ShenandoahPhaseTimings::SystemDictionaryRoots),
  63   _jvmti_root(&JvmtiExport::oops_do, ShenandoahPhaseTimings::JVMTIRoots) {
  64 }
  65 
  66 void ShenandoahSerialRoots::oops_do(OopClosure* cl, uint worker_id) {
  67   _universe_root.oops_do(cl, worker_id);
  68   _object_synchronizer_root.oops_do(cl, worker_id);
  69   _management_root.oops_do(cl, worker_id);
  70   _system_dictionary_root.oops_do(cl, worker_id);
  71   _jvmti_root.oops_do(cl, worker_id);
  72 }
  73 


































  74 ShenandoahThreadRoots::ShenandoahThreadRoots(bool is_par) : _is_par(is_par) {
  75   Threads::change_thread_claim_token();
  76 }
  77 
  78 void ShenandoahThreadRoots::oops_do(OopClosure* oops_cl, CodeBlobClosure* code_cl, uint worker_id) {
  79   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  80   ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ThreadRoots, worker_id);
  81   ResourceMark rm;
  82   Threads::possibly_parallel_oops_do(_is_par, oops_cl, code_cl);
  83 }
  84 
  85 void ShenandoahThreadRoots::threads_do(ThreadClosure* tc, uint worker_id) {
  86   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  87   ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ThreadRoots, worker_id);
  88   ResourceMark rm;
  89   Threads::possibly_parallel_threads_do(_is_par, tc);
  90 }
  91 
  92 ShenandoahThreadRoots::~ShenandoahThreadRoots() {
  93   Threads::assert_all_threads_claimed();
  94 }
  95 
  96 ShenandoahWeakRoots::ShenandoahWeakRoots(uint n_workers) :
  97   _process_timings(n_workers),
  98   _task(&_process_timings, n_workers) {
  99 }
 100 
 101 ShenandoahWeakRoots::~ShenandoahWeakRoots() {
 102   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
 103   ShenandoahTimingConverter::weak_processing_timing_to_shenandoah_timing(&_process_timings,
 104                                                                          worker_times);
 105 }
 106 
 107 ShenandoahStringDedupRoots::ShenandoahStringDedupRoots() {
 108   if (ShenandoahStringDedup::is_enabled()) {
 109     StringDedup::gc_prologue(false);
 110   }
 111 }
 112 
 113 ShenandoahStringDedupRoots::~ShenandoahStringDedupRoots() {
 114   if (ShenandoahStringDedup::is_enabled()) {
 115     StringDedup::gc_epilogue();
 116   }
 117 }
 118 
 119 void ShenandoahStringDedupRoots::oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, uint worker_id) {
 120   if (ShenandoahStringDedup::is_enabled()) {
 121     ShenandoahStringDedup::parallel_oops_do(is_alive, keep_alive, worker_id);
 122   }
 123 }
 124 
 125 ShenandoahClassLoaderDataRoots::ShenandoahClassLoaderDataRoots() {
 126   ClassLoaderDataGraph::clear_claimed_marks();


 130   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
 131   ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CLDGRoots, worker_id);
 132   ClassLoaderDataGraph::roots_cld_do(strong_clds, weak_clds);
 133 }
 134 
 135 ShenandoahRootProcessor::ShenandoahRootProcessor(ShenandoahPhaseTimings::Phase phase) :
 136   _heap(ShenandoahHeap::heap()),
 137   _phase(phase) {
 138   assert(SafepointSynchronize::is_at_safepoint(), "Must at safepoint");
 139   _heap->phase_timings()->record_workers_start(_phase);
 140 }
 141 
 142 ShenandoahRootProcessor::~ShenandoahRootProcessor() {
 143   assert(SafepointSynchronize::is_at_safepoint(), "Must at safepoint");
 144   _heap->phase_timings()->record_workers_end(_phase);
 145 }
 146 
 147 ShenandoahRootEvacuator::ShenandoahRootEvacuator(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool include_concurrent_roots) :
 148   ShenandoahRootProcessor(phase),
 149   _thread_roots(n_workers > 1),
 150   _weak_roots(n_workers),
 151   _include_concurrent_roots(include_concurrent_roots) {
 152 }
 153 
 154 void ShenandoahRootEvacuator::roots_do(uint worker_id, OopClosure* oops) {
 155   MarkingCodeBlobClosure blobsCl(oops, CodeBlobToOopClosure::FixRelocations);
 156   CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
 157   AlwaysTrueClosure always_true;
 158 
 159   _serial_roots.oops_do(oops, worker_id);

 160   if (_include_concurrent_roots) {
 161     _jni_roots.oops_do<OopClosure>(oops, worker_id);

 162   }
 163 
 164   _thread_roots.oops_do(oops, NULL, worker_id);
 165   _cld_roots.clds_do(&clds, &clds, worker_id);
 166   _code_roots.code_blobs_do(&blobsCl, worker_id);
 167 
 168   _weak_roots.oops_do<AlwaysTrueClosure, OopClosure>(&always_true, oops, worker_id);
 169   _dedup_roots.oops_do(&always_true, oops, worker_id);
 170 }
 171 
 172 ShenandoahRootUpdater::ShenandoahRootUpdater(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool update_code_cache) :
 173   ShenandoahRootProcessor(phase),
 174   _thread_roots(n_workers > 1),
 175   _weak_roots(n_workers),
 176   _update_code_cache(update_code_cache) {
 177 }
 178 
 179 ShenandoahRootAdjuster::ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTimings::Phase phase) :
 180   ShenandoahRootProcessor(phase),
 181   _thread_roots(n_workers > 1),
 182   _weak_roots(n_workers) {
 183   assert(ShenandoahHeap::heap()->is_full_gc_in_progress(), "Full GC only");
 184 }
 185 
 186 void ShenandoahRootAdjuster::roots_do(uint worker_id, OopClosure* oops) {
 187   CodeBlobToOopClosure adjust_code_closure(oops, CodeBlobToOopClosure::FixRelocations);
 188   CLDToOopClosure adjust_cld_closure(oops, ClassLoaderData::_claim_strong);
 189   AlwaysTrueClosure always_true;
 190 
 191   _serial_roots.oops_do(oops, worker_id);
 192   _jni_roots.oops_do(oops, worker_id);
 193 
 194   _thread_roots.oops_do(oops, NULL, worker_id);
 195   _cld_roots.clds_do(&adjust_cld_closure, NULL, worker_id);
 196   _code_roots.code_blobs_do(&adjust_code_closure, worker_id);
 197 
 198   _weak_roots.oops_do<AlwaysTrueClosure, OopClosure>(&always_true, oops, worker_id);

 199   _dedup_roots.oops_do(&always_true, oops, worker_id);
 200 }


  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 
  26 #include "classfile/classLoaderDataGraph.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "code/codeCache.hpp"

  30 #include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
  31 #include "gc/shenandoah/shenandoahHeap.hpp"

  32 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  33 #include "gc/shenandoah/shenandoahStringDedup.hpp"
  34 #include "gc/shenandoah/shenandoahTimingTracker.hpp"
  35 #include "gc/shenandoah/shenandoahVMOperations.hpp"
  36 #include "jfr/jfr.hpp"

  37 #include "memory/iterator.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "memory/universe.hpp"
  40 #include "runtime/thread.hpp"
  41 #include "services/management.hpp"
  42 
  43 ShenandoahSerialRoot::ShenandoahSerialRoot(ShenandoahSerialRoot::OopsDo oops_do, ShenandoahPhaseTimings::GCParPhases phase) :
  44   _claimed(false), _oops_do(oops_do), _phase(phase) {
  45 }
  46 
  47 void ShenandoahSerialRoot::oops_do(OopClosure* cl, uint worker_id) {
  48   if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
  49     ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  50     ShenandoahWorkerTimingsTracker timer(worker_times, _phase, worker_id);
  51     _oops_do(cl);
  52   }
  53 }
  54 
  55 ShenandoahSerialRoots::ShenandoahSerialRoots() :
  56   _universe_root(&Universe::oops_do, ShenandoahPhaseTimings::UniverseRoots),
  57   _object_synchronizer_root(&ObjectSynchronizer::oops_do, ShenandoahPhaseTimings::ObjectSynchronizerRoots),
  58   _management_root(&Management::oops_do, ShenandoahPhaseTimings::ManagementRoots),
  59   _system_dictionary_root(&SystemDictionary::oops_do, ShenandoahPhaseTimings::SystemDictionaryRoots),
  60   _jvmti_root(&JvmtiExport::oops_do, ShenandoahPhaseTimings::JVMTIRoots) {
  61 }
  62 
  63 void ShenandoahSerialRoots::oops_do(OopClosure* cl, uint worker_id) {
  64   _universe_root.oops_do(cl, worker_id);
  65   _object_synchronizer_root.oops_do(cl, worker_id);
  66   _management_root.oops_do(cl, worker_id);
  67   _system_dictionary_root.oops_do(cl, worker_id);
  68   _jvmti_root.oops_do(cl, worker_id);
  69 }
  70 
  71 ShenandoahWeakSerialRoot::ShenandoahWeakSerialRoot(ShenandoahWeakSerialRoot::WeakOopsDo weak_oops_do, ShenandoahPhaseTimings::GCParPhases phase) :
  72   _weak_oops_do(weak_oops_do), _phase(phase) {
  73 }
  74 
  75 void ShenandoahWeakSerialRoot::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, uint worker_id) {
  76   if (_claimed.try_set()) {
  77     ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  78     ShenandoahWorkerTimingsTracker timer(worker_times, _phase, worker_id);
  79     _weak_oops_do(is_alive, keep_alive);
  80   }
  81 }
  82 
  83 #if INCLUDE_JVMTI
  84 ShenandoahJVMTIWeakRoot::ShenandoahJVMTIWeakRoot() :
  85   ShenandoahWeakSerialRoot(&JvmtiExport::weak_oops_do, ShenandoahPhaseTimings::JVMTIWeakRoots) {
  86 }
  87 #endif // INCLUDE_JVMTI
  88 
  89 #if INCLUDE_JFR
  90 ShenandoahJFRWeakRoot::ShenandoahJFRWeakRoot() :
  91   ShenandoahWeakSerialRoot(&Jfr::weak_oops_do, ShenandoahPhaseTimings::JFRWeakRoots) {
  92 }
  93 #endif // INCLUDE_JFR
  94 
  95 void ShenandoahSerialWeakRoots::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, uint worker_id) {
  96   JVMTI_ONLY(_jvmti_weak_roots.weak_oops_do(is_alive, keep_alive, worker_id);)
  97   JFR_ONLY(_jfr_weak_roots.weak_oops_do(is_alive, keep_alive, worker_id);)
  98 }
  99 
 100 void ShenandoahSerialWeakRoots::weak_oops_do(OopClosure* cl, uint worker_id) {
 101   AlwaysTrueClosure always_true;
 102   weak_oops_do(&always_true, cl, worker_id);
 103 }
 104 
 105 ShenandoahThreadRoots::ShenandoahThreadRoots(bool is_par) : _is_par(is_par) {
 106   Threads::change_thread_claim_token();
 107 }
 108 
 109 void ShenandoahThreadRoots::oops_do(OopClosure* oops_cl, CodeBlobClosure* code_cl, uint worker_id) {
 110   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
 111   ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ThreadRoots, worker_id);
 112   ResourceMark rm;
 113   Threads::possibly_parallel_oops_do(_is_par, oops_cl, code_cl);
 114 }
 115 
 116 void ShenandoahThreadRoots::threads_do(ThreadClosure* tc, uint worker_id) {
 117   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
 118   ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ThreadRoots, worker_id);
 119   ResourceMark rm;
 120   Threads::possibly_parallel_threads_do(_is_par, tc);
 121 }
 122 
 123 ShenandoahThreadRoots::~ShenandoahThreadRoots() {
 124   Threads::assert_all_threads_claimed();
 125 }
 126 











 127 ShenandoahStringDedupRoots::ShenandoahStringDedupRoots() {
 128   if (ShenandoahStringDedup::is_enabled()) {
 129     StringDedup::gc_prologue(false);
 130   }
 131 }
 132 
 133 ShenandoahStringDedupRoots::~ShenandoahStringDedupRoots() {
 134   if (ShenandoahStringDedup::is_enabled()) {
 135     StringDedup::gc_epilogue();
 136   }
 137 }
 138 
 139 void ShenandoahStringDedupRoots::oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, uint worker_id) {
 140   if (ShenandoahStringDedup::is_enabled()) {
 141     ShenandoahStringDedup::parallel_oops_do(is_alive, keep_alive, worker_id);
 142   }
 143 }
 144 
 145 ShenandoahClassLoaderDataRoots::ShenandoahClassLoaderDataRoots() {
 146   ClassLoaderDataGraph::clear_claimed_marks();


 150   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
 151   ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CLDGRoots, worker_id);
 152   ClassLoaderDataGraph::roots_cld_do(strong_clds, weak_clds);
 153 }
 154 
 155 ShenandoahRootProcessor::ShenandoahRootProcessor(ShenandoahPhaseTimings::Phase phase) :
 156   _heap(ShenandoahHeap::heap()),
 157   _phase(phase) {
 158   assert(SafepointSynchronize::is_at_safepoint(), "Must at safepoint");
 159   _heap->phase_timings()->record_workers_start(_phase);
 160 }
 161 
 162 ShenandoahRootProcessor::~ShenandoahRootProcessor() {
 163   assert(SafepointSynchronize::is_at_safepoint(), "Must at safepoint");
 164   _heap->phase_timings()->record_workers_end(_phase);
 165 }
 166 
 167 ShenandoahRootEvacuator::ShenandoahRootEvacuator(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool include_concurrent_roots) :
 168   ShenandoahRootProcessor(phase),
 169   _thread_roots(n_workers > 1),

 170   _include_concurrent_roots(include_concurrent_roots) {
 171 }
 172 
 173 void ShenandoahRootEvacuator::roots_do(uint worker_id, OopClosure* oops) {
 174   MarkingCodeBlobClosure blobsCl(oops, CodeBlobToOopClosure::FixRelocations);
 175   CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
 176   AlwaysTrueClosure always_true;
 177 
 178   _serial_roots.oops_do(oops, worker_id);
 179   _serial_weak_roots.weak_oops_do(oops, worker_id);
 180   if (_include_concurrent_roots) {
 181     _jni_roots.oops_do<OopClosure>(oops, worker_id);
 182     _weak_roots.oops_do<OopClosure>(oops, worker_id);
 183   }
 184 
 185   _thread_roots.oops_do(oops, NULL, worker_id);
 186   _cld_roots.clds_do(&clds, &clds, worker_id);
 187   _code_roots.code_blobs_do(&blobsCl, worker_id);
 188 

 189   _dedup_roots.oops_do(&always_true, oops, worker_id);
 190 }
 191 
 192 ShenandoahRootUpdater::ShenandoahRootUpdater(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool update_code_cache) :
 193   ShenandoahRootProcessor(phase),
 194   _thread_roots(n_workers > 1),

 195   _update_code_cache(update_code_cache) {
 196 }
 197 
 198 ShenandoahRootAdjuster::ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTimings::Phase phase) :
 199   ShenandoahRootProcessor(phase),
 200   _thread_roots(n_workers > 1) {

 201   assert(ShenandoahHeap::heap()->is_full_gc_in_progress(), "Full GC only");
 202 }
 203 
 204 void ShenandoahRootAdjuster::roots_do(uint worker_id, OopClosure* oops) {
 205   CodeBlobToOopClosure adjust_code_closure(oops, CodeBlobToOopClosure::FixRelocations);
 206   CLDToOopClosure adjust_cld_closure(oops, ClassLoaderData::_claim_strong);
 207   AlwaysTrueClosure always_true;
 208 
 209   _serial_roots.oops_do(oops, worker_id);
 210   _jni_roots.oops_do(oops, worker_id);
 211 
 212   _thread_roots.oops_do(oops, NULL, worker_id);
 213   _cld_roots.clds_do(&adjust_cld_closure, NULL, worker_id);
 214   _code_roots.code_blobs_do(&adjust_code_closure, worker_id);
 215 
 216   _serial_weak_roots.weak_oops_do(oops, worker_id);
 217   _weak_roots.oops_do<OopClosure>(oops, worker_id);
 218   _dedup_roots.oops_do(&always_true, oops, worker_id);
 219 }
< prev index next >