< prev index next >

test/hotspot/jtreg/gc/g1/TestVerifyGCType.java

Print this page
rev 48154 : 8192983: gc/g1/TestVerifyGCType.java might fail on loaded machines
Reviewed-by:

@@ -140,12 +140,13 @@
         Collections.addAll(basicOpts, new String[] {
                                        "-Xbootclasspath/a:.",
                                        "-XX:+UnlockDiagnosticVMOptions",
                                        "-XX:+UseG1GC",
                                        "-XX:+WhiteBoxAPI",
-                                       "-XX:+ExplicitGCInvokesConcurrent",
                                        "-Xlog:gc,gc+start,gc+verify=info",
+                                       "-Xms16m",
+                                       "-Xmx16m",
                                        "-XX:+VerifyBeforeGC",
                                        "-XX:+VerifyAfterGC",
                                        "-XX:+VerifyDuringGC"});
 
         for(String verifyType : types) {

@@ -171,11 +172,11 @@
         return analyzer;
     }
 
     private static void verifyCollection(String name, boolean expectBefore, boolean expectDuring, boolean expectAfter, String data) {
         CollectionInfo ci = CollectionInfo.parseFirst(name, data);
-        Asserts.assertTrue(ci != null, "Expected GC not found: " + name);
+        Asserts.assertTrue(ci != null, "Expected GC not found: " + name + "\n" + data);
 
         // Verify Before
         verifyType(ci, expectBefore, VERIFY_BEFORE);
         // Verify During
         verifyType(ci, expectDuring, VERIFY_DURING);

@@ -241,16 +242,44 @@
     }
 
     public static class TriggerGCs {
         public static void main(String args[]) throws Exception {
             WhiteBox wb = WhiteBox.getWhiteBox();
+            // Allocate some memory that can be turned into garbage.
+            Object[] used = alloc1M();
+
             // Trigger the different GCs using the WhiteBox API and System.gc()
             // to start a concurrent cycle with -XX:+ExplicitGCInvokesConcurrent.
             wb.fullGC();  // full
-            System.gc();  // initial-mark, remark and cleanup
+
+            // Memory have been promoted to old by full GC. Free
+            // some memory to be reclaimed by concurrent cycle.
+            partialFree(used);
+            wb.g1StartConcMarkCycle(); // initial-mark, remark and cleanup
+
             // Sleep to make sure concurrent cycle is done
+            while (wb.g1InConcurrentMark()) {
             Thread.sleep(1000);
+            }
+
+            // Trigger two young GCs, first will be young-only, second will be mixed.
             wb.youngGC(); // young-only
             wb.youngGC(); // mixed
         }
+
+        private static Object[] alloc1M() {
+            Object[] ret = new Object[1024];
+            // Alloc 1024 1k byte arrays (~1M)
+            for (int i = 0; i < ret.length; i++) {
+                ret[i] = new byte[1024];
+            }
+            return ret;
+        }
+
+        private static void partialFree(Object[] array) {
+            // Free every other element
+            for (int i = 0; i < array.length; i+=2) {
+                array[i] = null;
+            }
+        }
     }
 }
< prev index next >