--- old/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp 2020-05-28 21:49:27.242475720 +0200 +++ new/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp 2020-05-28 21:49:26.926474898 +0200 @@ -223,17 +223,20 @@ "Expect class unloading when Shenandoah cycle is running"); ResourceMark rm; - _serial_roots.oops_do(oops, worker_id); - _vm_roots.oops_do(oops, worker_id); - assert(clds != NULL, "Only possible with CLD closure"); - _cld_roots.cld_do(clds, worker_id); - ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc); - _thread_roots.threads_do(&tc_cl, worker_id); + // Process serial-claiming roots first + _serial_roots.oops_do(oops, worker_id); + _cld_roots.cld_do(clds, worker_id); + // Process light-weight parallel roots then + _vm_roots.oops_do(oops, worker_id); AlwaysTrueClosure always_true; _dedup_roots.oops_do(&always_true, oops, worker_id); + + // Process heavy-weight parallel roots the last + ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc); + _thread_roots.threads_do(&tc_cl, worker_id); } void ShenandoahRootScanner::strong_roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure* tc) { @@ -241,9 +244,14 @@ ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc); ResourceMark rm; + // Process serial-claiming roots first _serial_roots.oops_do(oops, worker_id); - _vm_roots.oops_do(oops, worker_id); _cld_roots.always_strong_cld_do(clds, worker_id); + + // Process light-weight parallel roots then + _vm_roots.oops_do(oops, worker_id); + + // Process heavy-weight parallel roots the last _thread_roots.threads_do(&tc_cl, worker_id); } @@ -272,17 +280,23 @@ static_cast(&blobsCl); AlwaysTrueClosure always_true; + // Process serial-claiming roots first _serial_roots.oops_do(oops, worker_id); _serial_weak_roots.weak_oops_do(oops, worker_id); + if (_stw_class_unloading) { + CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong); + _cld_roots.cld_do(&clds, worker_id); + } + + // Process light-weight parallel roots then if (_stw_roots_processing) { _vm_roots.oops_do(oops, worker_id); _weak_roots.oops_do(oops, worker_id); _dedup_roots.oops_do(&always_true, oops, worker_id); } + // Process heavy-weight parallel roots the last if (_stw_class_unloading) { - CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong); - _cld_roots.cld_do(&clds, worker_id); _code_roots.code_blobs_do(codes_cl, worker_id); _thread_roots.oops_do(oops, NULL, worker_id); } else { @@ -324,16 +338,19 @@ CLDToOopClosure adjust_cld_closure(oops, ClassLoaderData::_claim_strong); AlwaysTrueClosure always_true; + // Process serial-claiming roots first _serial_roots.oops_do(oops, worker_id); - _vm_roots.oops_do(oops, worker_id); - - _thread_roots.oops_do(oops, NULL, worker_id); + _serial_weak_roots.weak_oops_do(oops, worker_id); _cld_roots.cld_do(&adjust_cld_closure, worker_id); - _code_roots.code_blobs_do(adjust_code_closure, worker_id); - _serial_weak_roots.weak_oops_do(oops, worker_id); + // Process light-weight parallel roots then + _vm_roots.oops_do(oops, worker_id); _weak_roots.oops_do(oops, worker_id); _dedup_roots.oops_do(&always_true, oops, worker_id); + + // Process heavy-weight parallel roots the last + _code_roots.code_blobs_do(adjust_code_closure, worker_id); + _thread_roots.oops_do(oops, NULL, worker_id); } ShenandoahHeapIterationRootScanner::ShenandoahHeapIterationRootScanner() : @@ -356,13 +373,17 @@ AlwaysTrueClosure always_true; ResourceMark rm; + // Process serial-claiming roots first _serial_roots.oops_do(oops, 0); - _vm_roots.oops_do(oops, 0); + _serial_weak_roots.weak_oops_do(oops, 0); _cld_roots.cld_do(&clds, 0); - _thread_roots.threads_do(&tc_cl, 0); - _code_roots.code_blobs_do(&code, 0); - _serial_weak_roots.weak_oops_do(oops, 0); + // Process light-weight parallel roots then + _vm_roots.oops_do(oops, 0); _weak_roots.oops_do(oops, 0); _dedup_roots.oops_do(&always_true, oops, 0); + + // Process heavy-weight parallel roots the last + _code_roots.code_blobs_do(&code, 0); + _thread_roots.threads_do(&tc_cl, 0); }