test/hotspot/jtreg/gc/g1/TestVerifyGCType.java
changeset 48306 89f4d858f09f
parent 48179 34fe70d22e9c
child 48791 6e079ff6c83c
equal deleted inserted replaced
48305:522601e6dd0d 48306:89f4d858f09f
   140         Collections.addAll(basicOpts, new String[] {
   140         Collections.addAll(basicOpts, new String[] {
   141                                        "-Xbootclasspath/a:.",
   141                                        "-Xbootclasspath/a:.",
   142                                        "-XX:+UnlockDiagnosticVMOptions",
   142                                        "-XX:+UnlockDiagnosticVMOptions",
   143                                        "-XX:+UseG1GC",
   143                                        "-XX:+UseG1GC",
   144                                        "-XX:+WhiteBoxAPI",
   144                                        "-XX:+WhiteBoxAPI",
   145                                        "-XX:+ExplicitGCInvokesConcurrent",
       
   146                                        "-Xlog:gc,gc+start,gc+verify=info",
   145                                        "-Xlog:gc,gc+start,gc+verify=info",
       
   146                                        "-Xms16m",
       
   147                                        "-Xmx16m",
   147                                        "-XX:+VerifyBeforeGC",
   148                                        "-XX:+VerifyBeforeGC",
   148                                        "-XX:+VerifyAfterGC",
   149                                        "-XX:+VerifyAfterGC",
   149                                        "-XX:+VerifyDuringGC"});
   150                                        "-XX:+VerifyDuringGC"});
   150 
   151 
   151         for(String verifyType : types) {
   152         for(String verifyType : types) {
   171         return analyzer;
   172         return analyzer;
   172     }
   173     }
   173 
   174 
   174     private static void verifyCollection(String name, boolean expectBefore, boolean expectDuring, boolean expectAfter, String data) {
   175     private static void verifyCollection(String name, boolean expectBefore, boolean expectDuring, boolean expectAfter, String data) {
   175         CollectionInfo ci = CollectionInfo.parseFirst(name, data);
   176         CollectionInfo ci = CollectionInfo.parseFirst(name, data);
   176         Asserts.assertTrue(ci != null, "Expected GC not found: " + name);
   177         Asserts.assertTrue(ci != null, "Expected GC not found: " + name + "\n" + data);
   177 
   178 
   178         // Verify Before
   179         // Verify Before
   179         verifyType(ci, expectBefore, VERIFY_BEFORE);
   180         verifyType(ci, expectBefore, VERIFY_BEFORE);
   180         // Verify During
   181         // Verify During
   181         verifyType(ci, expectDuring, VERIFY_DURING);
   182         verifyType(ci, expectDuring, VERIFY_DURING);
   241     }
   242     }
   242 
   243 
   243     public static class TriggerGCs {
   244     public static class TriggerGCs {
   244         public static void main(String args[]) throws Exception {
   245         public static void main(String args[]) throws Exception {
   245             WhiteBox wb = WhiteBox.getWhiteBox();
   246             WhiteBox wb = WhiteBox.getWhiteBox();
   246             // Trigger the different GCs using the WhiteBox API and System.gc()
   247             // Allocate some memory that can be turned into garbage.
   247             // to start a concurrent cycle with -XX:+ExplicitGCInvokesConcurrent.
   248             Object[] used = alloc1M();
       
   249 
       
   250             // Trigger the different GCs using the WhiteBox API.
   248             wb.fullGC();  // full
   251             wb.fullGC();  // full
   249             System.gc();  // initial-mark, remark and cleanup
   252 
       
   253             // Memory have been promoted to old by full GC. Free
       
   254             // some memory to be reclaimed by concurrent cycle.
       
   255             partialFree(used);
       
   256             wb.g1StartConcMarkCycle(); // initial-mark, remark and cleanup
       
   257 
   250             // Sleep to make sure concurrent cycle is done
   258             // Sleep to make sure concurrent cycle is done
   251             Thread.sleep(1000);
   259             while (wb.g1InConcurrentMark()) {
       
   260                 Thread.sleep(1000);
       
   261             }
       
   262 
       
   263             // Trigger two young GCs, first will be young-only, second will be mixed.
   252             wb.youngGC(); // young-only
   264             wb.youngGC(); // young-only
   253             wb.youngGC(); // mixed
   265             wb.youngGC(); // mixed
   254         }
   266         }
       
   267 
       
   268         private static Object[] alloc1M() {
       
   269             Object[] ret = new Object[1024];
       
   270             // Alloc 1024 1k byte arrays (~1M)
       
   271             for (int i = 0; i < ret.length; i++) {
       
   272                 ret[i] = new byte[1024];
       
   273             }
       
   274             return ret;
       
   275         }
       
   276 
       
   277         private static void partialFree(Object[] array) {
       
   278             // Free every other element
       
   279             for (int i = 0; i < array.length; i+=2) {
       
   280                 array[i] = null;
       
   281             }
       
   282         }
   255     }
   283     }
   256 }
   284 }