< 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:


 125         verifyCollection("Pause Remark", false, true, false, output.getStdout());
 126         verifyCollection("Pause Cleanup", false, true, false, output.getStdout());
 127         verifyCollection("Pause Full", true, true, true, output.getStdout());
 128     }
 129 
 130     private static void testUnsupportedCollector() throws Exception {
 131         OutputAnalyzer output;
 132         // Test bad gc
 133         output = testWithBadGC();
 134         output.shouldHaveExitValue(0);
 135         output.shouldMatch("VerifyGCType is not supported by this collector.");
 136     }
 137 
 138     private static OutputAnalyzer testWithVerificationType(String[] types) throws Exception {
 139         ArrayList<String> basicOpts = new ArrayList<>();
 140         Collections.addAll(basicOpts, new String[] {
 141                                        "-Xbootclasspath/a:.",
 142                                        "-XX:+UnlockDiagnosticVMOptions",
 143                                        "-XX:+UseG1GC",
 144                                        "-XX:+WhiteBoxAPI",
 145                                        "-XX:+ExplicitGCInvokesConcurrent",
 146                                        "-Xlog:gc,gc+start,gc+verify=info",


 147                                        "-XX:+VerifyBeforeGC",
 148                                        "-XX:+VerifyAfterGC",
 149                                        "-XX:+VerifyDuringGC"});
 150 
 151         for(String verifyType : types) {
 152             basicOpts.add("-XX:VerifyGCType="+verifyType);
 153         }
 154 
 155         basicOpts.add(TriggerGCs.class.getName());
 156 
 157         ProcessBuilder procBuilder =  ProcessTools.createJavaProcessBuilder(basicOpts.toArray(
 158                                                                             new String[basicOpts.size()]));
 159         OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
 160         return analyzer;
 161     }
 162 
 163     private static OutputAnalyzer testWithBadGC() throws Exception {
 164         ProcessBuilder procBuilder =  ProcessTools.createJavaProcessBuilder(new String[] {
 165                 "-XX:+UseParallelGC",
 166                 "-XX:+UnlockDiagnosticVMOptions",
 167                 "-XX:VerifyGCType=full",
 168                 "-version"});
 169 
 170         OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
 171         return analyzer;
 172     }
 173 
 174     private static void verifyCollection(String name, boolean expectBefore, boolean expectDuring, boolean expectAfter, String data) {
 175         CollectionInfo ci = CollectionInfo.parseFirst(name, data);
 176         Asserts.assertTrue(ci != null, "Expected GC not found: " + name);
 177 
 178         // Verify Before
 179         verifyType(ci, expectBefore, VERIFY_BEFORE);
 180         // Verify During
 181         verifyType(ci, expectDuring, VERIFY_DURING);
 182         // Verify After
 183         verifyType(ci, expectAfter, VERIFY_AFTER);
 184     }
 185 
 186     private static void verifyType(CollectionInfo ci, boolean shouldExist, String pattern) {
 187         if (shouldExist) {
 188             Asserts.assertTrue(ci.containsVerification(pattern), "Missing expected verification for: " + ci.getName());
 189         } else {
 190             Asserts.assertFalse(ci.containsVerification(pattern), "Found unexpected verification for: " + ci.getName());
 191         }
 192     }
 193 
 194     public static class CollectionInfo {
 195         String name;
 196         ArrayList<String> verification;


 226             }
 227             int nextIndex = data.indexOf(name, firstIndex + 1);
 228             if (nextIndex == -1) {
 229                 return result;
 230             }
 231             // Found an entry for this name
 232             result = new CollectionInfo(name);
 233             String collectionData = data.substring(firstIndex, nextIndex + name.length());
 234             for (String line : collectionData.split(System.getProperty("line.separator"))) {
 235                 if (line.contains(VERIFY_TAG)) {
 236                     result.addVerification(line);
 237                 }
 238             }
 239             return result;
 240         }
 241     }
 242 
 243     public static class TriggerGCs {
 244         public static void main(String args[]) throws Exception {
 245             WhiteBox wb = WhiteBox.getWhiteBox();



 246             // Trigger the different GCs using the WhiteBox API and System.gc()
 247             // to start a concurrent cycle with -XX:+ExplicitGCInvokesConcurrent.
 248             wb.fullGC();  // full
 249             System.gc();  // initial-mark, remark and cleanup





 250             // Sleep to make sure concurrent cycle is done

 251             Thread.sleep(1000);



 252             wb.youngGC(); // young-only
 253             wb.youngGC(); // mixed
















 254         }
 255     }
 256 }


 125         verifyCollection("Pause Remark", false, true, false, output.getStdout());
 126         verifyCollection("Pause Cleanup", false, true, false, output.getStdout());
 127         verifyCollection("Pause Full", true, true, true, output.getStdout());
 128     }
 129 
 130     private static void testUnsupportedCollector() throws Exception {
 131         OutputAnalyzer output;
 132         // Test bad gc
 133         output = testWithBadGC();
 134         output.shouldHaveExitValue(0);
 135         output.shouldMatch("VerifyGCType is not supported by this collector.");
 136     }
 137 
 138     private static OutputAnalyzer testWithVerificationType(String[] types) throws Exception {
 139         ArrayList<String> basicOpts = new ArrayList<>();
 140         Collections.addAll(basicOpts, new String[] {
 141                                        "-Xbootclasspath/a:.",
 142                                        "-XX:+UnlockDiagnosticVMOptions",
 143                                        "-XX:+UseG1GC",
 144                                        "-XX:+WhiteBoxAPI",

 145                                        "-Xlog:gc,gc+start,gc+verify=info",
 146                                        "-Xms16m",
 147                                        "-Xmx16m",
 148                                        "-XX:+VerifyBeforeGC",
 149                                        "-XX:+VerifyAfterGC",
 150                                        "-XX:+VerifyDuringGC"});
 151 
 152         for(String verifyType : types) {
 153             basicOpts.add("-XX:VerifyGCType="+verifyType);
 154         }
 155 
 156         basicOpts.add(TriggerGCs.class.getName());
 157 
 158         ProcessBuilder procBuilder =  ProcessTools.createJavaProcessBuilder(basicOpts.toArray(
 159                                                                             new String[basicOpts.size()]));
 160         OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
 161         return analyzer;
 162     }
 163 
 164     private static OutputAnalyzer testWithBadGC() throws Exception {
 165         ProcessBuilder procBuilder =  ProcessTools.createJavaProcessBuilder(new String[] {
 166                 "-XX:+UseParallelGC",
 167                 "-XX:+UnlockDiagnosticVMOptions",
 168                 "-XX:VerifyGCType=full",
 169                 "-version"});
 170 
 171         OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
 172         return analyzer;
 173     }
 174 
 175     private static void verifyCollection(String name, boolean expectBefore, boolean expectDuring, boolean expectAfter, String data) {
 176         CollectionInfo ci = CollectionInfo.parseFirst(name, data);
 177         Asserts.assertTrue(ci != null, "Expected GC not found: " + name + "\n" + data);
 178 
 179         // Verify Before
 180         verifyType(ci, expectBefore, VERIFY_BEFORE);
 181         // Verify During
 182         verifyType(ci, expectDuring, VERIFY_DURING);
 183         // Verify After
 184         verifyType(ci, expectAfter, VERIFY_AFTER);
 185     }
 186 
 187     private static void verifyType(CollectionInfo ci, boolean shouldExist, String pattern) {
 188         if (shouldExist) {
 189             Asserts.assertTrue(ci.containsVerification(pattern), "Missing expected verification for: " + ci.getName());
 190         } else {
 191             Asserts.assertFalse(ci.containsVerification(pattern), "Found unexpected verification for: " + ci.getName());
 192         }
 193     }
 194 
 195     public static class CollectionInfo {
 196         String name;
 197         ArrayList<String> verification;


 227             }
 228             int nextIndex = data.indexOf(name, firstIndex + 1);
 229             if (nextIndex == -1) {
 230                 return result;
 231             }
 232             // Found an entry for this name
 233             result = new CollectionInfo(name);
 234             String collectionData = data.substring(firstIndex, nextIndex + name.length());
 235             for (String line : collectionData.split(System.getProperty("line.separator"))) {
 236                 if (line.contains(VERIFY_TAG)) {
 237                     result.addVerification(line);
 238                 }
 239             }
 240             return result;
 241         }
 242     }
 243 
 244     public static class TriggerGCs {
 245         public static void main(String args[]) throws Exception {
 246             WhiteBox wb = WhiteBox.getWhiteBox();
 247             // Allocate some memory that can be turned into garbage.
 248             Object[] used = alloc1M();
 249 
 250             // Trigger the different GCs using the WhiteBox API and System.gc()
 251             // to start a concurrent cycle with -XX:+ExplicitGCInvokesConcurrent.
 252             wb.fullGC();  // full
 253 
 254             // Memory have been promoted to old by full GC. Free
 255             // some memory to be reclaimed by concurrent cycle.
 256             partialFree(used);
 257             wb.g1StartConcMarkCycle(); // initial-mark, remark and cleanup
 258 
 259             // Sleep to make sure concurrent cycle is done
 260             while (wb.g1InConcurrentMark()) {
 261                 Thread.sleep(1000);
 262             }
 263 
 264             // Trigger two young GCs, first will be young-only, second will be mixed.
 265             wb.youngGC(); // young-only
 266             wb.youngGC(); // mixed
 267         }
 268 
 269         private static Object[] alloc1M() {
 270             Object[] ret = new Object[1024];
 271             // Alloc 1024 1k byte arrays (~1M)
 272             for (int i = 0; i < ret.length; i++) {
 273                 ret[i] = new byte[1024];
 274             }
 275             return ret;
 276         }
 277 
 278         private static void partialFree(Object[] array) {
 279             // Free every other element
 280             for (int i = 0; i < array.length; i+=2) {
 281                 array[i] = null;
 282             }
 283         }
 284     }
 285 }
< prev index next >