< prev index next >

src/hotspot/share/gc/z/zRootsIterator.cpp

Print this page




  24 #include "precompiled.hpp"
  25 #include "classfile/classLoaderDataGraph.hpp"
  26 #include "classfile/stringTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "compiler/oopMap.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/barrierSetNMethod.hpp"
  32 #include "gc/shared/oopStorageParState.inline.hpp"
  33 #include "gc/shared/suspendibleThreadSet.hpp"
  34 #include "gc/z/zBarrierSetNMethod.hpp"
  35 #include "gc/z/zGlobals.hpp"
  36 #include "gc/z/zNMethod.hpp"
  37 #include "gc/z/zOopClosures.inline.hpp"
  38 #include "gc/z/zRootsIterator.hpp"
  39 #include "gc/z/zStat.hpp"
  40 #include "gc/z/zThreadLocalData.hpp"
  41 #include "memory/resourceArea.hpp"
  42 #include "memory/universe.hpp"
  43 #include "prims/jvmtiExport.hpp"
  44 #include "prims/resolvedMethodTable.hpp"
  45 #include "runtime/atomic.hpp"
  46 #include "runtime/jniHandles.hpp"
  47 #include "runtime/thread.hpp"
  48 #include "runtime/safepoint.hpp"
  49 #include "runtime/synchronizer.hpp"
  50 #include "services/management.hpp"
  51 #include "utilities/debug.hpp"
  52 #if INCLUDE_JFR
  53 #include "jfr/jfr.hpp"
  54 #endif
  55 
  56 static const ZStatSubPhase ZSubPhasePauseRootsSetup("Pause Roots Setup");
  57 static const ZStatSubPhase ZSubPhasePauseRoots("Pause Roots");
  58 static const ZStatSubPhase ZSubPhasePauseRootsTeardown("Pause Roots Teardown");
  59 static const ZStatSubPhase ZSubPhasePauseRootsUniverse("Pause Roots Universe");
  60 static const ZStatSubPhase ZSubPhasePauseRootsObjectSynchronizer("Pause Roots ObjectSynchronizer");
  61 static const ZStatSubPhase ZSubPhasePauseRootsManagement("Pause Roots Management");
  62 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIExport("Pause Roots JVMTIExport");
  63 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIWeakExport("Pause Roots JVMTIWeakExport");
  64 static const ZStatSubPhase ZSubPhasePauseRootsSystemDictionary("Pause Roots SystemDictionary");
  65 static const ZStatSubPhase ZSubPhasePauseRootsThreads("Pause Roots Threads");
  66 static const ZStatSubPhase ZSubPhasePauseRootsCodeCache("Pause Roots CodeCache");
  67 
  68 static const ZStatSubPhase ZSubPhaseConcurrentRootsSetup("Concurrent Roots Setup");
  69 static const ZStatSubPhase ZSubPhaseConcurrentRoots("Concurrent Roots");
  70 static const ZStatSubPhase ZSubPhaseConcurrentRootsTeardown("Concurrent Roots Teardown");
  71 static const ZStatSubPhase ZSubPhaseConcurrentRootsJNIHandles("Concurrent Roots JNIHandles");
  72 static const ZStatSubPhase ZSubPhaseConcurrentRootsClassLoaderDataGraph("Concurrent Roots ClassLoaderDataGraph");
  73 
  74 static const ZStatSubPhase ZSubPhasePauseWeakRootsSetup("Pause Weak Roots Setup");
  75 static const ZStatSubPhase ZSubPhasePauseWeakRoots("Pause Weak Roots");
  76 static const ZStatSubPhase ZSubPhasePauseWeakRootsTeardown("Pause Weak Roots Teardown");
  77 static const ZStatSubPhase ZSubPhasePauseWeakRootsJVMTIWeakExport("Pause Weak Roots JVMTIWeakExport");
  78 static const ZStatSubPhase ZSubPhasePauseWeakRootsJFRWeak("Pause Weak Roots JFRWeak");
  79 
  80 static const ZStatSubPhase ZSubPhaseConcurrentWeakRoots("Concurrent Weak Roots");
  81 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsVMWeakHandles("Concurrent Weak Roots VMWeakHandles");
  82 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsJNIWeakHandles("Concurrent Weak Roots JNIWeakHandles");
  83 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsStringTable("Concurrent Weak Roots StringTable");
  84 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsResolvedMethodTable("Concurrent Weak Roots ResolvedMethodTable");
  85 
  86 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
  87 ZSerialOopsDo<T, F>::ZSerialOopsDo(T* iter) :
  88     _iter(iter),
  89     _claimed(false) {}
  90 
  91 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
  92 void ZSerialOopsDo<T, F>::oops_do(ZRootsIteratorClosure* cl) {
  93   if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
  94     (_iter->*F)(cl);
  95   }
  96 }
  97 
  98 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
  99 ZParallelOopsDo<T, F>::ZParallelOopsDo(T* iter) :
 100     _iter(iter),
 101     _completed(false) {}
 102 
 103 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
 104 void ZParallelOopsDo<T, F>::oops_do(ZRootsIteratorClosure* cl) {


 326   ZStatTimer timer(ZSubPhasePauseWeakRootsJFRWeak);
 327   Jfr::weak_oops_do(is_alive, cl);
 328 #endif
 329 }
 330 
 331 void ZWeakRootsIterator::weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl) {
 332   ZStatTimer timer(ZSubPhasePauseWeakRoots);
 333   _jvmti_weak_export.weak_oops_do(is_alive, cl);
 334   _jfr_weak.weak_oops_do(is_alive, cl);
 335 }
 336 
 337 void ZWeakRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
 338   AlwaysTrueClosure always_alive;
 339   weak_oops_do(&always_alive, cl);
 340 }
 341 
 342 ZConcurrentWeakRootsIterator::ZConcurrentWeakRootsIterator() :
 343     _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()),
 344     _jni_weak_handles_iter(JNIHandles::weak_global_handles()),
 345     _string_table_iter(StringTable::weak_storage()),
 346     _resolved_method_table_iter(ResolvedMethodTable::weak_storage()),
 347     _vm_weak_handles(this),
 348     _jni_weak_handles(this),
 349     _string_table(this),
 350     _resolved_method_table(this) {
 351   StringTable::reset_dead_counter();
 352   ResolvedMethodTable::reset_dead_counter();
 353 }
 354 
 355 ZConcurrentWeakRootsIterator::~ZConcurrentWeakRootsIterator() {
 356   StringTable::finish_dead_counter();
 357   ResolvedMethodTable::finish_dead_counter();
 358 }
 359 
 360 void ZConcurrentWeakRootsIterator::do_vm_weak_handles(ZRootsIteratorClosure* cl) {
 361   ZStatTimer timer(ZSubPhaseConcurrentWeakRootsVMWeakHandles);
 362   _vm_weak_handles_iter.oops_do(cl);
 363 }
 364 
 365 void ZConcurrentWeakRootsIterator::do_jni_weak_handles(ZRootsIteratorClosure* cl) {
 366   ZStatTimer timer(ZSubPhaseConcurrentWeakRootsJNIWeakHandles);
 367   _jni_weak_handles_iter.oops_do(cl);
 368 }
 369 
 370 template <class Container>
 371 class ZDeadCounterClosure : public ZRootsIteratorClosure  {
 372 private:
 373   ZRootsIteratorClosure* const _cl;
 374   size_t                       _ndead;
 375 
 376 public:
 377   ZDeadCounterClosure(ZRootsIteratorClosure* cl) :
 378       _cl(cl),
 379       _ndead(0) {}
 380 
 381   ~ZDeadCounterClosure() {
 382     Container::inc_dead_counter(_ndead);
 383   }
 384 
 385   virtual void do_oop(oop* p) {
 386     _cl->do_oop(p);
 387     if (*p == NULL) {
 388       _ndead++;
 389     }
 390   }
 391 
 392   virtual void do_oop(narrowOop* p) {
 393     ShouldNotReachHere();
 394   }
 395 };
 396 
 397 void ZConcurrentWeakRootsIterator::do_string_table(ZRootsIteratorClosure* cl) {
 398   ZStatTimer timer(ZSubPhaseConcurrentWeakRootsStringTable);
 399   ZDeadCounterClosure<StringTable> counter_cl(cl);
 400   _string_table_iter.oops_do(&counter_cl);
 401 }
 402 
 403 void ZConcurrentWeakRootsIterator::do_resolved_method_table(ZRootsIteratorClosure* cl) {
 404   ZStatTimer timer(ZSubPhaseConcurrentWeakRootsResolvedMethodTable);
 405   ZDeadCounterClosure<ResolvedMethodTable> counter_cl(cl);
 406   _resolved_method_table_iter.oops_do(&counter_cl);
 407 }
 408 
 409 void ZConcurrentWeakRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
 410   ZStatTimer timer(ZSubPhaseConcurrentWeakRoots);
 411   _vm_weak_handles.oops_do(cl);
 412   _jni_weak_handles.oops_do(cl);
 413   _string_table.oops_do(cl);
 414   _resolved_method_table.oops_do(cl);
 415 }
 416 
 417 ZThreadRootsIterator::ZThreadRootsIterator() :
 418     _threads(this) {
 419   assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
 420   ZStatTimer timer(ZSubPhasePauseRootsSetup);
 421   Threads::change_thread_claim_token();
 422 }
 423 
 424 ZThreadRootsIterator::~ZThreadRootsIterator() {
 425   ZStatTimer timer(ZSubPhasePauseRootsTeardown);
 426   Threads::assert_all_threads_claimed();
 427 }
 428 
 429 void ZThreadRootsIterator::do_threads(ZRootsIteratorClosure* cl) {
 430   ZStatTimer timer(ZSubPhasePauseRootsThreads);
 431   ResourceMark rm;
 432   Threads::possibly_parallel_oops_do(true, cl, NULL);
 433 }
 434 


  24 #include "precompiled.hpp"
  25 #include "classfile/classLoaderDataGraph.hpp"
  26 #include "classfile/stringTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "compiler/oopMap.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/barrierSetNMethod.hpp"
  32 #include "gc/shared/oopStorageParState.inline.hpp"
  33 #include "gc/shared/suspendibleThreadSet.hpp"
  34 #include "gc/z/zBarrierSetNMethod.hpp"
  35 #include "gc/z/zGlobals.hpp"
  36 #include "gc/z/zNMethod.hpp"
  37 #include "gc/z/zOopClosures.inline.hpp"
  38 #include "gc/z/zRootsIterator.hpp"
  39 #include "gc/z/zStat.hpp"
  40 #include "gc/z/zThreadLocalData.hpp"
  41 #include "memory/resourceArea.hpp"
  42 #include "memory/universe.hpp"
  43 #include "prims/jvmtiExport.hpp"

  44 #include "runtime/atomic.hpp"
  45 #include "runtime/jniHandles.hpp"
  46 #include "runtime/thread.hpp"
  47 #include "runtime/safepoint.hpp"
  48 #include "runtime/synchronizer.hpp"
  49 #include "services/management.hpp"
  50 #include "utilities/debug.hpp"
  51 #if INCLUDE_JFR
  52 #include "jfr/jfr.hpp"
  53 #endif
  54 
  55 static const ZStatSubPhase ZSubPhasePauseRootsSetup("Pause Roots Setup");
  56 static const ZStatSubPhase ZSubPhasePauseRoots("Pause Roots");
  57 static const ZStatSubPhase ZSubPhasePauseRootsTeardown("Pause Roots Teardown");
  58 static const ZStatSubPhase ZSubPhasePauseRootsUniverse("Pause Roots Universe");
  59 static const ZStatSubPhase ZSubPhasePauseRootsObjectSynchronizer("Pause Roots ObjectSynchronizer");
  60 static const ZStatSubPhase ZSubPhasePauseRootsManagement("Pause Roots Management");
  61 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIExport("Pause Roots JVMTIExport");
  62 static const ZStatSubPhase ZSubPhasePauseRootsJVMTIWeakExport("Pause Roots JVMTIWeakExport");
  63 static const ZStatSubPhase ZSubPhasePauseRootsSystemDictionary("Pause Roots SystemDictionary");
  64 static const ZStatSubPhase ZSubPhasePauseRootsThreads("Pause Roots Threads");
  65 static const ZStatSubPhase ZSubPhasePauseRootsCodeCache("Pause Roots CodeCache");
  66 
  67 static const ZStatSubPhase ZSubPhaseConcurrentRootsSetup("Concurrent Roots Setup");
  68 static const ZStatSubPhase ZSubPhaseConcurrentRoots("Concurrent Roots");
  69 static const ZStatSubPhase ZSubPhaseConcurrentRootsTeardown("Concurrent Roots Teardown");
  70 static const ZStatSubPhase ZSubPhaseConcurrentRootsJNIHandles("Concurrent Roots JNIHandles");
  71 static const ZStatSubPhase ZSubPhaseConcurrentRootsClassLoaderDataGraph("Concurrent Roots ClassLoaderDataGraph");
  72 
  73 static const ZStatSubPhase ZSubPhasePauseWeakRootsSetup("Pause Weak Roots Setup");
  74 static const ZStatSubPhase ZSubPhasePauseWeakRoots("Pause Weak Roots");
  75 static const ZStatSubPhase ZSubPhasePauseWeakRootsTeardown("Pause Weak Roots Teardown");
  76 static const ZStatSubPhase ZSubPhasePauseWeakRootsJVMTIWeakExport("Pause Weak Roots JVMTIWeakExport");
  77 static const ZStatSubPhase ZSubPhasePauseWeakRootsJFRWeak("Pause Weak Roots JFRWeak");
  78 
  79 static const ZStatSubPhase ZSubPhaseConcurrentWeakRoots("Concurrent Weak Roots");
  80 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsVMWeakHandles("Concurrent Weak Roots VMWeakHandles");
  81 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsJNIWeakHandles("Concurrent Weak Roots JNIWeakHandles");
  82 static const ZStatSubPhase ZSubPhaseConcurrentWeakRootsStringTable("Concurrent Weak Roots StringTable");

  83 
  84 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
  85 ZSerialOopsDo<T, F>::ZSerialOopsDo(T* iter) :
  86     _iter(iter),
  87     _claimed(false) {}
  88 
  89 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
  90 void ZSerialOopsDo<T, F>::oops_do(ZRootsIteratorClosure* cl) {
  91   if (!_claimed && Atomic::cmpxchg(true, &_claimed, false) == false) {
  92     (_iter->*F)(cl);
  93   }
  94 }
  95 
  96 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
  97 ZParallelOopsDo<T, F>::ZParallelOopsDo(T* iter) :
  98     _iter(iter),
  99     _completed(false) {}
 100 
 101 template <typename T, void (T::*F)(ZRootsIteratorClosure*)>
 102 void ZParallelOopsDo<T, F>::oops_do(ZRootsIteratorClosure* cl) {


 324   ZStatTimer timer(ZSubPhasePauseWeakRootsJFRWeak);
 325   Jfr::weak_oops_do(is_alive, cl);
 326 #endif
 327 }
 328 
 329 void ZWeakRootsIterator::weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl) {
 330   ZStatTimer timer(ZSubPhasePauseWeakRoots);
 331   _jvmti_weak_export.weak_oops_do(is_alive, cl);
 332   _jfr_weak.weak_oops_do(is_alive, cl);
 333 }
 334 
 335 void ZWeakRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
 336   AlwaysTrueClosure always_alive;
 337   weak_oops_do(&always_alive, cl);
 338 }
 339 
 340 ZConcurrentWeakRootsIterator::ZConcurrentWeakRootsIterator() :
 341     _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()),
 342     _jni_weak_handles_iter(JNIHandles::weak_global_handles()),
 343     _string_table_iter(StringTable::weak_storage()),

 344     _vm_weak_handles(this),
 345     _jni_weak_handles(this),
 346     _string_table(this) {

 347   StringTable::reset_dead_counter();

 348 }
 349 
 350 ZConcurrentWeakRootsIterator::~ZConcurrentWeakRootsIterator() {
 351   StringTable::finish_dead_counter();

 352 }
 353 
 354 void ZConcurrentWeakRootsIterator::do_vm_weak_handles(ZRootsIteratorClosure* cl) {
 355   ZStatTimer timer(ZSubPhaseConcurrentWeakRootsVMWeakHandles);
 356   _vm_weak_handles_iter.oops_do(cl);
 357 }
 358 
 359 void ZConcurrentWeakRootsIterator::do_jni_weak_handles(ZRootsIteratorClosure* cl) {
 360   ZStatTimer timer(ZSubPhaseConcurrentWeakRootsJNIWeakHandles);
 361   _jni_weak_handles_iter.oops_do(cl);
 362 }
 363 
 364 class ZStringTableDeadCounterClosure : public ZRootsIteratorClosure  {

 365 private:
 366   ZRootsIteratorClosure* const _cl;
 367   size_t                       _ndead;
 368 
 369 public:
 370   ZStringTableDeadCounterClosure(ZRootsIteratorClosure* cl) :
 371       _cl(cl),
 372       _ndead(0) {}
 373 
 374   ~ZStringTableDeadCounterClosure() {
 375     StringTable::inc_dead_counter(_ndead);
 376   }
 377 
 378   virtual void do_oop(oop* p) {
 379     _cl->do_oop(p);
 380     if (*p == NULL) {
 381       _ndead++;
 382     }
 383   }
 384 
 385   virtual void do_oop(narrowOop* p) {
 386     ShouldNotReachHere();
 387   }
 388 };
 389 
 390 void ZConcurrentWeakRootsIterator::do_string_table(ZRootsIteratorClosure* cl) {
 391   ZStatTimer timer(ZSubPhaseConcurrentWeakRootsStringTable);
 392   ZStringTableDeadCounterClosure counter_cl(cl);
 393   _string_table_iter.oops_do(&counter_cl);
 394 }
 395 






 396 void ZConcurrentWeakRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
 397   ZStatTimer timer(ZSubPhaseConcurrentWeakRoots);
 398   _vm_weak_handles.oops_do(cl);
 399   _jni_weak_handles.oops_do(cl);
 400   _string_table.oops_do(cl);

 401 }
 402 
 403 ZThreadRootsIterator::ZThreadRootsIterator() :
 404     _threads(this) {
 405   assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
 406   ZStatTimer timer(ZSubPhasePauseRootsSetup);
 407   Threads::change_thread_claim_token();
 408 }
 409 
 410 ZThreadRootsIterator::~ZThreadRootsIterator() {
 411   ZStatTimer timer(ZSubPhasePauseRootsTeardown);
 412   Threads::assert_all_threads_claimed();
 413 }
 414 
 415 void ZThreadRootsIterator::do_threads(ZRootsIteratorClosure* cl) {
 416   ZStatTimer timer(ZSubPhasePauseRootsThreads);
 417   ResourceMark rm;
 418   Threads::possibly_parallel_oops_do(true, cl, NULL);
 419 }
 420 
< prev index next >