Test for the CC RegionSpace::WalkInternal crash.

Bug: 31712511
Bug: 12687968
Test: test-art-host with CC.
Change-Id: I5443ae24d76f710c7820530e91f47cacea126ff9
diff --git a/test/130-hprof/src/Main.java b/test/130-hprof/src/Main.java
index 57be3a7..c04bb86 100644
--- a/test/130-hprof/src/Main.java
+++ b/test/130-hprof/src/Main.java
@@ -87,6 +87,12 @@
     }
 
     public static void main(String[] args) throws Exception {
+        testBasicDump();
+        testAllocationTrackingAndClassUnloading();
+        testGcAndDump();
+    }
+
+    private static void testBasicDump() throws Exception {
         // Create some data.
         Object data[] = new Object[TEST_LENGTH];
         for (int i = 0; i < data.length; i++) {
@@ -103,8 +109,10 @@
             }
         }
         System.out.println("Generated data.");
-
         createDumpAndConv();
+    }
+
+    private static void testAllocationTrackingAndClassUnloading() throws Exception {
         Class<?> klass = Class.forName("org.apache.harmony.dalvik.ddmc.DdmVmInternal");
         if (klass == null) {
             throw new AssertionError("Couldn't find path class loader class");
@@ -123,6 +131,57 @@
         enableMethod.invoke(null, false);
     }
 
+    private static void testGcAndDump() throws Exception {
+        Allocator allocator = new Allocator();
+        Dumper dumper = new Dumper(allocator);
+        allocator.start();
+        dumper.start();
+        try {
+            allocator.join();
+            dumper.join();
+        } catch (InterruptedException e) {
+            System.err.println("join interrupted");
+        }
+    }
+
+    private static class Allocator extends Thread {
+        private static int ARRAY_SIZE = 1024;
+        public volatile boolean running = true;
+        public void run() {
+            Object[] array = new Object[ARRAY_SIZE];
+            int i = 0;
+            while (running) {
+                array[i] = new byte[1024];
+                if (i % ARRAY_SIZE == 0) {
+                    Main.sleep(100L);
+                }
+                i = (i + 1) % ARRAY_SIZE;
+            }
+        }
+    }
+
+    private static class Dumper extends Thread {
+        Dumper(Allocator allocator) {
+            this.allocator = allocator;
+        }
+        Allocator allocator;
+        public void run() {
+            for (int i = 0; i < 10; ++i) {
+                Main.sleep(1000L);
+                createDumpAndConv();
+            }
+            allocator.running = false;
+        }
+    }
+
+    public static void sleep(long ms) {
+        try {
+            Thread.sleep(ms);
+        } catch (InterruptedException e) {
+            System.err.println("sleep interrupted");
+        }
+    }
+
     private static File getHprofConf() {
         // Use the java.library.path. It points to the lib directory.
         File libDir = new File(System.getProperty("java.library.path").split(":")[0]);