changeset 55895:9c6d907cefac

8225550: Shenandoah: Prevent SH::object_iterate() call's side-effects Reviewed-by: shade
author zgu
date Fri, 14 Jun 2019 11:58:23 -0400
parents b444bbe5c45c
children 49ed5e31fe1e
files src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp
diffstat 3 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Fri Jun 14 16:47:58 2019 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp	Fri Jun 14 11:58:23 2019 -0400
@@ -1279,7 +1279,12 @@
   // First, we process all GC roots. This populates the work stack with initial objects.
   ShenandoahAllRootScanner rp(1, ShenandoahPhaseTimings::_num_phases);
   ObjectIterateScanRootClosure oops(&_aux_bit_map, &oop_stack);
-  rp.roots_do_unchecked(&oops);
+
+  if (unload_classes()) {
+    rp.strong_roots_do_unchecked(&oops);
+  } else {
+    rp.roots_do_unchecked(&oops);
+  }
 
   // Work through the oop stack to traverse heap.
   while (! oop_stack.is_empty()) {
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp	Fri Jun 14 16:47:58 2019 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp	Fri Jun 14 11:58:23 2019 -0400
@@ -148,6 +148,7 @@
   void roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure* tc = NULL);
   // For heap object iteration
   void roots_do_unchecked(OopClosure* cl);
+  void strong_roots_do_unchecked(OopClosure* cl);
 };
 
 typedef ShenandoahRootScanner<ShenandoahAllCodeRootsIterator> ShenandoahAllRootScanner;
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp	Fri Jun 14 16:47:58 2019 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp	Fri Jun 14 11:58:23 2019 -0400
@@ -126,6 +126,19 @@
 }
 
 template <typename ITR>
+void ShenandoahRootScanner<ITR>::strong_roots_do_unchecked(OopClosure* oops) {
+  CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
+  MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations);
+  ShenandoahParallelOopsDoThreadClosure tc_cl(oops, &code, NULL);
+  ResourceMark rm;
+
+  _serial_roots.oops_do(oops, 0);
+  _jni_roots.oops_do(oops, 0);
+  _cld_roots.clds_do(&clds, NULL, 0);
+  _thread_roots.threads_do(&tc_cl, 0);
+}
+
+template <typename ITR>
 void ShenandoahRootScanner<ITR>::strong_roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure* tc) {
   assert(ShenandoahHeap::heap()->unload_classes(), "Should be used during class unloading");
   ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc);