8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources
authordfazunen
Thu, 28 Aug 2014 18:38:31 +0400
changeset 26328 8a3e0337bbb5
parent 26324 6b9c12e15535
child 26330 0621bea60fad
8050464: G1 string deduplication tests hang/timeout and leave running processes consuming all resources Reviewed-by: jmasa
hotspot/test/gc/g1/TestStringDeduplicationTools.java
--- a/hotspot/test/gc/g1/TestStringDeduplicationTools.java	Wed Aug 27 09:47:06 2014 +0200
+++ b/hotspot/test/gc/g1/TestStringDeduplicationTools.java	Thu Aug 28 18:38:31 2014 +0400
@@ -129,8 +129,19 @@
         return list;
     }
 
+    /**
+     * Verifies that the given list contains expected number of unique strings.
+     * It's possible that deduplication hasn't completed yet, so the method
+     * will perform several attempts to check with a little pause between.
+     * The method throws RuntimeException to signal that verification failed.
+     *
+     * @param list strings to check
+     * @param uniqueExpected expected number of unique strings
+     * @throws RuntimeException if check fails
+     */
     private static void verifyStrings(ArrayList<String> list, int uniqueExpected) {
-        for (;;) {
+        boolean passed = false;
+        for (int attempts = 0; attempts < 10; attempts++) {
             // Check number of deduplicated strings
             ArrayList<Object> unique = new ArrayList<Object>(uniqueExpected);
             for (String string: list) {
@@ -153,11 +164,11 @@
                                ", uniqueExpected=" + uniqueExpected);
 
             if (unique.size() == uniqueExpected) {
-                System.out.println("Deduplication completed");
+                System.out.println("Deduplication completed (as fast as " + attempts + " iterations)");
+                passed = true;
                 break;
             } else {
                 System.out.println("Deduplication not completed, waiting...");
-
                 // Give the deduplication thread time to complete
                 try {
                     Thread.sleep(1000);
@@ -166,6 +177,9 @@
                 }
             }
         }
+        if (!passed) {
+            throw new RuntimeException("String verification failed");
+        }
     }
 
     private static OutputAnalyzer runTest(String... extraArgs) throws Exception {
@@ -247,14 +261,20 @@
             forceDeduplication(ageThreshold, FullGC);
 
             // Wait for deduplication to occur
-            while (getValue(dupString1) != getValue(baseString)) {
+            for (int attempts = 0; attempts < 10; attempts++) {
+                if (getValue(dupString1) == getValue(baseString)) {
+                    break;
+                }
                 System.out.println("Waiting...");
                 try {
-                    Thread.sleep(100);
+                    Thread.sleep(1000);
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
             }
+            if (getValue(dupString1) != getValue(baseString)) {
+                throw new RuntimeException("Deduplication has not occurred");
+            }
 
             // Create a new duplicate of baseString
             StringBuilder sb2 = new StringBuilder(baseString);