8225014: Separate ShenandoahRootScanner method for object_iterate

Reviewed-by: shade
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
index 1f46a7e..25aeeaa 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
@@ -1279,7 +1279,7 @@
   // 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(0, &oops);
+  rp.roots_do_unchecked(&oops);
 
   // Work through the oop stack to traverse heap.
   while (! oop_stack.is_empty()) {
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp
index 87a9070..fa5e09d 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp
@@ -141,6 +141,8 @@
   // roots when class unloading is disabled during this cycle
   void roots_do(uint worker_id, OopClosure* cl);
   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);
 };
 
 typedef ShenandoahRootScanner<ShenandoahAllCodeRootsIterator> ShenandoahAllRootScanner;
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp
index a2ea946..f016a21 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp
@@ -111,6 +111,19 @@
 }
 
 template <typename ITR>
+void ShenandoahRootScanner<ITR>::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);
+  _cld_roots.clds_do(&clds, &clds, 0);
+  _thread_roots.threads_do(&tc_cl, 0);
+  _code_roots.code_blobs_do(&code, 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);
diff --git a/test/hotspot/jtreg/gc/shenandoah/TestObjItrWithHeapDump.java b/test/hotspot/jtreg/gc/shenandoah/TestObjItrWithHeapDump.java
new file mode 100644
index 0000000..bac04ae
--- /dev/null
+++ b/test/hotspot/jtreg/gc/shenandoah/TestObjItrWithHeapDump.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test TestObjIterWithHeapDump
+ * @summary Test heap dump triggered heap object iteration
+ * @key gc
+ * @bug 8225014
+ * @requires vm.gc.Shenandoah & !vm.graal.enabled
+ * @library /test/lib
+ * @run driver TestObjItrWithHeapDump
+ */
+
+import java.util.*;
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+public class TestObjItrWithHeapDump {
+    public static void testWith(String... args) throws Exception {
+        String[] cmds = Arrays.copyOf(args, args.length + 2);
+        cmds[args.length] = TestObjItrWithHeapDump.class.getName();
+        cmds[args.length + 1] = "test";
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds);
+
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldHaveExitValue(0);
+        output.shouldContain("Class Histogram (before full gc)");
+        output.shouldContain("Class Histogram (after full gc)");
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (args.length > 0 && args[0].equals("test")) {
+            System.gc();
+            System.exit(0);
+        }
+
+        String[] heuristics = new String[] {
+                "adaptive",
+                "compact",
+                "static",
+                "aggressive",
+                "passive",
+                "traversal",
+        };
+
+        for (String h : heuristics) {
+            testWith("-XX:+UnlockDiagnosticVMOptions",
+                     "-XX:+UnlockExperimentalVMOptions",
+                     "-XX:+UseShenandoahGC",
+                     "-XX:-ShenandoahDegeneratedGC",
+                     "-XX:ShenandoahGCHeuristics=" + h,
+                     "-Xlog:gc+classhisto=trace",
+                     "-XX:-ExplicitGCInvokesConcurrent",
+                     "-Xmx512M"
+            );
+        }
+    }
+}