< prev index next >

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

Print this page
rev 55921 : 8229213: Shenandoah: Allow VM global oop storage to be processed concurrently


  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   _oops_do(oops_do), _phase(phase) {
  45 }
  46 
  47 void ShenandoahSerialRoot::oops_do(OopClosure* cl, uint worker_id) {
  48   if (_claimed.try_set()) {
  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 // Default the second argument for SD::oops_do.
  56 static void system_dictionary_oops_do(OopClosure* cl) {
  57   SystemDictionary::oops_do(cl);
  58 }
  59 
  60 ShenandoahSerialRoots::ShenandoahSerialRoots() :
  61   _universe_root(&Universe::oops_do, ShenandoahPhaseTimings::UniverseRoots),
  62   _object_synchronizer_root(&ObjectSynchronizer::oops_do, ShenandoahPhaseTimings::ObjectSynchronizerRoots),
  63   _management_root(&Management::oops_do, ShenandoahPhaseTimings::ManagementRoots),
  64   _system_dictionary_root(&system_dictionary_oops_do, ShenandoahPhaseTimings::SystemDictionaryRoots),
  65   _jvmti_root(&JvmtiExport::oops_do, ShenandoahPhaseTimings::JVMTIRoots) {
  66 }
  67 
  68 void ShenandoahSerialRoots::oops_do(OopClosure* cl, uint worker_id) {
  69   _universe_root.oops_do(cl, worker_id);
  70   _object_synchronizer_root.oops_do(cl, worker_id);
  71   _management_root.oops_do(cl, worker_id);
  72   _system_dictionary_root.oops_do(cl, worker_id);
  73   _jvmti_root.oops_do(cl, worker_id);
  74 }
  75 
  76 ShenandoahWeakSerialRoot::ShenandoahWeakSerialRoot(ShenandoahWeakSerialRoot::WeakOopsDo weak_oops_do, ShenandoahPhaseTimings::GCParPhases phase) :
  77   _weak_oops_do(weak_oops_do), _phase(phase) {


 156 
 157 ShenandoahRootProcessor::~ShenandoahRootProcessor() {
 158   assert(SafepointSynchronize::is_at_safepoint(), "Must at safepoint");
 159   _heap->phase_timings()->record_workers_end(_phase);
 160 }
 161 
 162 ShenandoahRootEvacuator::ShenandoahRootEvacuator(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool include_concurrent_roots) :
 163   ShenandoahRootProcessor(phase),
 164   _thread_roots(n_workers > 1),
 165   _include_concurrent_roots(include_concurrent_roots) {
 166 }
 167 
 168 void ShenandoahRootEvacuator::roots_do(uint worker_id, OopClosure* oops) {
 169   MarkingCodeBlobClosure blobsCl(oops, CodeBlobToOopClosure::FixRelocations);
 170   AlwaysTrueClosure always_true;
 171 
 172   _serial_roots.oops_do(oops, worker_id);
 173   _serial_weak_roots.weak_oops_do(oops, worker_id);
 174   if (_include_concurrent_roots) {
 175     CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
 176     _jni_roots.oops_do<OopClosure>(oops, worker_id);
 177     _cld_roots.cld_do(&clds, worker_id);
 178     _weak_roots.oops_do<OopClosure>(oops, worker_id);
 179   }
 180 
 181   _thread_roots.oops_do(oops, NULL, worker_id);
 182   _code_roots.code_blobs_do(&blobsCl, worker_id);
 183 
 184   _dedup_roots.oops_do(&always_true, oops, worker_id);
 185 }
 186 
 187 ShenandoahRootUpdater::ShenandoahRootUpdater(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool update_code_cache) :
 188   ShenandoahRootProcessor(phase),
 189   _thread_roots(n_workers > 1),
 190   _update_code_cache(update_code_cache) {
 191 }
 192 
 193 ShenandoahRootAdjuster::ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTimings::Phase phase) :
 194   ShenandoahRootProcessor(phase),
 195   _thread_roots(n_workers > 1) {
 196   assert(ShenandoahHeap::heap()->is_full_gc_in_progress(), "Full GC only");
 197 }
 198 
 199 void ShenandoahRootAdjuster::roots_do(uint worker_id, OopClosure* oops) {
 200   CodeBlobToOopClosure adjust_code_closure(oops, CodeBlobToOopClosure::FixRelocations);
 201   CLDToOopClosure adjust_cld_closure(oops, ClassLoaderData::_claim_strong);
 202   AlwaysTrueClosure always_true;
 203 
 204   _serial_roots.oops_do(oops, worker_id);
 205   _jni_roots.oops_do(oops, worker_id);
 206 
 207   _thread_roots.oops_do(oops, NULL, worker_id);
 208   _cld_roots.cld_do(&adjust_cld_closure, worker_id);
 209   _code_roots.code_blobs_do(&adjust_code_closure, worker_id);
 210 
 211   _serial_weak_roots.weak_oops_do(oops, worker_id);
 212   _weak_roots.oops_do<OopClosure>(oops, worker_id);
 213   _dedup_roots.oops_do(&always_true, oops, worker_id);
 214 }
 215 
 216  ShenandoahHeapIterationRootScanner::ShenandoahHeapIterationRootScanner() :
 217    ShenandoahRootProcessor(ShenandoahPhaseTimings::_num_phases),
 218    _thread_roots(false /*is par*/) {
 219  }
 220 
 221  void ShenandoahHeapIterationRootScanner::roots_do(OopClosure* oops) {
 222    assert(Thread::current()->is_VM_thread(), "Only by VM thread");
 223    // Must use _claim_none to avoid interfering with concurrent CLDG iteration
 224    CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
 225    MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations);
 226    ShenandoahParallelOopsDoThreadClosure tc_cl(oops, &code, NULL);
 227    ResourceMark rm;
 228 
 229    _serial_roots.oops_do(oops, 0);
 230    _jni_roots.oops_do(oops, 0);
 231    _cld_roots.cld_do(&clds, 0);
 232    _thread_roots.threads_do(&tc_cl, 0);
 233    _code_roots.code_blobs_do(&code, 0);
 234  }
 235 
 236  void ShenandoahHeapIterationRootScanner::strong_roots_do(OopClosure* oops) {
 237    assert(Thread::current()->is_VM_thread(), "Only by VM thread");
 238    // Must use _claim_none to avoid interfering with concurrent CLDG iteration
 239    CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
 240    MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations);
 241    ShenandoahParallelOopsDoThreadClosure tc_cl(oops, &code, NULL);
 242    ResourceMark rm;
 243 
 244    _serial_roots.oops_do(oops, 0);
 245    _jni_roots.oops_do(oops, 0);
 246    _cld_roots.always_strong_cld_do(&clds, 0);
 247    _thread_roots.threads_do(&tc_cl, 0);
 248  }


  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   _oops_do(oops_do), _phase(phase) {
  45 }
  46 
  47 void ShenandoahSerialRoot::oops_do(OopClosure* cl, uint worker_id) {
  48   if (_claimed.try_set()) {
  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 // Overwrite the second argument for SD::oops_do, don't include vm global oop storage.
  56 static void system_dictionary_oops_do(OopClosure* cl) {
  57   SystemDictionary::oops_do(cl, false);
  58 }
  59 
  60 ShenandoahSerialRoots::ShenandoahSerialRoots() :
  61   _universe_root(&Universe::oops_do, ShenandoahPhaseTimings::UniverseRoots),
  62   _object_synchronizer_root(&ObjectSynchronizer::oops_do, ShenandoahPhaseTimings::ObjectSynchronizerRoots),
  63   _management_root(&Management::oops_do, ShenandoahPhaseTimings::ManagementRoots),
  64   _system_dictionary_root(&system_dictionary_oops_do, ShenandoahPhaseTimings::SystemDictionaryRoots),
  65   _jvmti_root(&JvmtiExport::oops_do, ShenandoahPhaseTimings::JVMTIRoots) {
  66 }
  67 
  68 void ShenandoahSerialRoots::oops_do(OopClosure* cl, uint worker_id) {
  69   _universe_root.oops_do(cl, worker_id);
  70   _object_synchronizer_root.oops_do(cl, worker_id);
  71   _management_root.oops_do(cl, worker_id);
  72   _system_dictionary_root.oops_do(cl, worker_id);
  73   _jvmti_root.oops_do(cl, worker_id);
  74 }
  75 
  76 ShenandoahWeakSerialRoot::ShenandoahWeakSerialRoot(ShenandoahWeakSerialRoot::WeakOopsDo weak_oops_do, ShenandoahPhaseTimings::GCParPhases phase) :
  77   _weak_oops_do(weak_oops_do), _phase(phase) {


 156 
 157 ShenandoahRootProcessor::~ShenandoahRootProcessor() {
 158   assert(SafepointSynchronize::is_at_safepoint(), "Must at safepoint");
 159   _heap->phase_timings()->record_workers_end(_phase);
 160 }
 161 
 162 ShenandoahRootEvacuator::ShenandoahRootEvacuator(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool include_concurrent_roots) :
 163   ShenandoahRootProcessor(phase),
 164   _thread_roots(n_workers > 1),
 165   _include_concurrent_roots(include_concurrent_roots) {
 166 }
 167 
 168 void ShenandoahRootEvacuator::roots_do(uint worker_id, OopClosure* oops) {
 169   MarkingCodeBlobClosure blobsCl(oops, CodeBlobToOopClosure::FixRelocations);
 170   AlwaysTrueClosure always_true;
 171 
 172   _serial_roots.oops_do(oops, worker_id);
 173   _serial_weak_roots.weak_oops_do(oops, worker_id);
 174   if (_include_concurrent_roots) {
 175     CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
 176     _vm_roots.oops_do<OopClosure>(oops, worker_id);
 177     _cld_roots.cld_do(&clds, worker_id);
 178     _weak_roots.oops_do<OopClosure>(oops, worker_id);
 179   }
 180 
 181   _thread_roots.oops_do(oops, NULL, worker_id);
 182   _code_roots.code_blobs_do(&blobsCl, worker_id);
 183 
 184   _dedup_roots.oops_do(&always_true, oops, worker_id);
 185 }
 186 
 187 ShenandoahRootUpdater::ShenandoahRootUpdater(uint n_workers, ShenandoahPhaseTimings::Phase phase, bool update_code_cache) :
 188   ShenandoahRootProcessor(phase),
 189   _thread_roots(n_workers > 1),
 190   _update_code_cache(update_code_cache) {
 191 }
 192 
 193 ShenandoahRootAdjuster::ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTimings::Phase phase) :
 194   ShenandoahRootProcessor(phase),
 195   _thread_roots(n_workers > 1) {
 196   assert(ShenandoahHeap::heap()->is_full_gc_in_progress(), "Full GC only");
 197 }
 198 
 199 void ShenandoahRootAdjuster::roots_do(uint worker_id, OopClosure* oops) {
 200   CodeBlobToOopClosure adjust_code_closure(oops, CodeBlobToOopClosure::FixRelocations);
 201   CLDToOopClosure adjust_cld_closure(oops, ClassLoaderData::_claim_strong);
 202   AlwaysTrueClosure always_true;
 203 
 204   _serial_roots.oops_do(oops, worker_id);
 205   _vm_roots.oops_do(oops, worker_id);
 206 
 207   _thread_roots.oops_do(oops, NULL, worker_id);
 208   _cld_roots.cld_do(&adjust_cld_closure, worker_id);
 209   _code_roots.code_blobs_do(&adjust_code_closure, worker_id);
 210 
 211   _serial_weak_roots.weak_oops_do(oops, worker_id);
 212   _weak_roots.oops_do<OopClosure>(oops, worker_id);
 213   _dedup_roots.oops_do(&always_true, oops, worker_id);
 214 }
 215 
 216  ShenandoahHeapIterationRootScanner::ShenandoahHeapIterationRootScanner() :
 217    ShenandoahRootProcessor(ShenandoahPhaseTimings::_num_phases),
 218    _thread_roots(false /*is par*/) {
 219  }
 220 
 221  void ShenandoahHeapIterationRootScanner::roots_do(OopClosure* oops) {
 222    assert(Thread::current()->is_VM_thread(), "Only by VM thread");
 223    // Must use _claim_none to avoid interfering with concurrent CLDG iteration
 224    CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
 225    MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations);
 226    ShenandoahParallelOopsDoThreadClosure tc_cl(oops, &code, NULL);
 227    ResourceMark rm;
 228 
 229    _serial_roots.oops_do(oops, 0);
 230    _vm_roots.oops_do(oops, 0);
 231    _cld_roots.cld_do(&clds, 0);
 232    _thread_roots.threads_do(&tc_cl, 0);
 233    _code_roots.code_blobs_do(&code, 0);
 234  }
 235 
 236  void ShenandoahHeapIterationRootScanner::strong_roots_do(OopClosure* oops) {
 237    assert(Thread::current()->is_VM_thread(), "Only by VM thread");
 238    // Must use _claim_none to avoid interfering with concurrent CLDG iteration
 239    CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
 240    MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations);
 241    ShenandoahParallelOopsDoThreadClosure tc_cl(oops, &code, NULL);
 242    ResourceMark rm;
 243 
 244    _serial_roots.oops_do(oops, 0);
 245    _vm_roots.oops_do(oops, 0);
 246    _cld_roots.always_strong_cld_do(&clds, 0);
 247    _thread_roots.threads_do(&tc_cl, 0);
 248  }
< prev index next >