< prev index next >

test/gc/g1/TestDynamicGCThreadsStats.java

Print this page




  50     public static void runTest() throws Exception {
  51         final String[] arguments = {
  52             "-Xbootclasspath/a:.",
  53             "-XX:+UnlockExperimentalVMOptions",
  54             "-XX:+UnlockDiagnosticVMOptions",
  55             "-XX:+UseDynamicNumberOfGCThreads",
  56             "-XX:+WhiteBoxAPI",
  57             "-XX:+UseG1GC",
  58             "-Xlog:gc*=trace",
  59             "-Xmx10M",
  60             GCTest.class.getName()
  61             };
  62 
  63         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
  64         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  65 
  66         output.shouldHaveExitValue(0);
  67 
  68         // Looking for: 
  69         //        [0.234s][debug  ][gc,phases            ] GC(0)    Evacuate Collection Set: 3.7 ms
  70         String parallel_phase_leader = "Evacuate Collection Set: \\d+\\.\\d+ms";
  71         String std_out = output.getStdout();
  72         Matcher m = Pattern.compile(parallel_phase_leader, Pattern.MULTILINE).matcher(std_out);
  73     
  74         if (!m.find()) {
  75           throw new Exception("Could not find correct output for Evacuate Collection Set: in stdout," +
  76             " should match the pattern \"" + parallel_phase_leader + "\", but stdout is \n" + output.getStdout());
  77         } else {
  78             // Find data with per thread times.
  79             // Any of the metrics with per thread times can be used.
  80             // Chose: 
  81             //        [0.234s][debug  ][gc,phases            ] GC(0)       Ext Root Scanning:        Min:  0.6, Avg:  1.1, Max:  1.6, Diff:  1.0, Sum:  2.2
  82             String stats = "Ext Root Scanning \\(ms\\):";
  83             Pattern stats_pattern = Pattern.compile(stats);
  84             m.usePattern(stats_pattern);
  85             if (!m.find()) {
  86               throw new Exception("Could not find correct output for chosen statistics in stdout," +
  87               " should match the pattern \"" + stats + "\", but stdout is \n" + output.getStdout());
  88             } else {
  89               // Find the printed average from the log.
  90               Pattern avg_pattern = Pattern.compile("(Avg: +)(\\d+\\.\\d+)(,)");
  91               m.usePattern(avg_pattern);

  92               if (!m.find()) {
  93                 throw new Exception("Could not find Avg: dd.d in stdout\n," + output.getStdout());
  94               } else {
  95                 String value_string = m.group(2);
  96                 // Count the decimal places in the printed average.  The
  97                 // number of decimal places will be used to calculate the
  98                 // rounding error when the per thread values are summed in
  99                 // this test.
 100                 DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
 101                 char decimal_symbol = symbols.getDecimalSeparator();
 102                 String decimal_places_string = value_string.substring(value_string.indexOf(decimal_symbol) + 1);
 103                 int decimal_points = decimal_places_string.length();
 104                 double avg_value = 0.0;
 105                 try {
 106                   avg_value = Double.parseDouble(value_string);
 107                 } catch (java.lang.NumberFormatException e) {
 108                    System.out.println("Non Number Format - " + value_string);
 109                 }
 110                 // Go to the next line which will have a "GC" in it.  For
 111                 // example:
 112                 //     [0.234s][trace  ][gc,phases            ] GC(0)                                  1.58  0.58
 113                 Pattern GC_pattern = Pattern.compile("GC");
 114                 m.usePattern(GC_pattern);


 119                   int workers = 0;
 120                   Double sum = 0.0;
 121                   // Count and sum the values.  Note that each parsed value has rounding error in it.
 122                   while (value_m.find()) {
 123                     try {
 124                       Double value = Double.parseDouble(value_m.group());
 125                       sum += value;
 126                       workers++;
 127                     } catch (java.lang.NumberFormatException e) {
 128                       System.out.println("Non Number Format - " + m.group());
 129                     }
 130                   }
 131                   if (workers > 0) {
 132                     Double calculated_avg = sum / workers;
 133                     // Rounding error in per thread data
 134                     Double rounding_error = workers * 0.5 * Math.pow(10.0,  -decimal_points);
 135                     if (Math.abs(calculated_avg - avg_value) > rounding_error) {
 136                       throw new Exception("Average from log " + avg_value + " and average calculated by test " + 
 137                         calculated_avg + " can differ by rounding error " + rounding_error);
 138                     } else {
 139 
 140                       System.err.println("PASSED: Average from log " + avg_value + " and average calculated by test " + 
 141                         calculated_avg + " can differ by rounding error " + rounding_error);
 142                     }
 143                   }
 144                 }
 145                 System.out.println(output.getStdout());
 146               }
 147             }
 148         }
 149     }
 150 
 151     public static void main(String[] args) throws Exception {
 152         runTest();
 153     }
 154 
 155     static class GCTest {
 156         public static void main(String [] args) {
 157             int numGCs = 4;
 158 
 159             // Perform the requested amount of GCs.
 160             WhiteBox wb = WhiteBox.getWhiteBox();
 161             for (int i = 0; i < numGCs - 1; i++) {
 162                 wb.youngGC();
 163             }
 164             if (numGCs > 0) {
 165               wb.fullGC();
 166             }


  50     public static void runTest() throws Exception {
  51         final String[] arguments = {
  52             "-Xbootclasspath/a:.",
  53             "-XX:+UnlockExperimentalVMOptions",
  54             "-XX:+UnlockDiagnosticVMOptions",
  55             "-XX:+UseDynamicNumberOfGCThreads",
  56             "-XX:+WhiteBoxAPI",
  57             "-XX:+UseG1GC",
  58             "-Xlog:gc*=trace",
  59             "-Xmx10M",
  60             GCTest.class.getName()
  61             };
  62 
  63         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
  64         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  65 
  66         output.shouldHaveExitValue(0);
  67 
  68         // Looking for: 
  69         //        [0.234s][debug  ][gc,phases            ] GC(0)    Evacuate Collection Set: 3.7 ms
  70         output.shouldMatch("Evacuate Collection Set: \\d+\\.\\d+ms");







  71         // Find data with per thread times.
  72         // Any of the metrics with per thread times can be used.
  73         // Chose: 
  74         //        [0.234s][debug  ][gc,phases            ] GC(0)       Ext Root Scanning:        Min:  0.6, Avg:  1.1, Max:  1.6, Diff:  1.0, Sum:  2.2
  75         String stats = "Ext Root Scanning \\(ms\\):";
  76         Pattern stats_pattern = Pattern.compile(stats);
  77         output.shouldMatch("Ext Root Scanning \\(ms\\):");




  78         // Find the printed average from the log.
  79         String std_out = output.getStdout();
  80         String avg_line = "(Avg: +)(\\d+\\.\\d+)(,)";
  81         Matcher m = Pattern.compile(avg_line, Pattern.MULTILINE).matcher(std_out);
  82         if (!m.find()) {
  83             throw new Exception("Could not find Avg: dd.d in stdout\n," + output.getStdout());
  84         }
  85         String value_string = m.group(2);
  86         // Count the decimal places in the printed average.  The
  87         // number of decimal places will be used to calculate the
  88         // rounding error when the per thread values are summed in
  89         // this test.
  90         DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
  91         char decimal_symbol = symbols.getDecimalSeparator();
  92         String decimal_places_string = value_string.substring(value_string.indexOf(decimal_symbol) + 1);
  93         int decimal_points = decimal_places_string.length();
  94         double avg_value = 0.0;
  95         try {
  96             avg_value = Double.parseDouble(value_string);
  97         } catch (java.lang.NumberFormatException e) {
  98             System.out.println("Non Number Format - " + value_string);
  99         }
 100         // Go to the next line which will have a "GC" in it.  For
 101         // example:
 102         //     [0.234s][trace  ][gc,phases            ] GC(0)                                  1.58  0.58 
 103         Pattern GC_pattern = Pattern.compile("GC");
 104         m.usePattern(GC_pattern);


 109             int workers = 0;
 110             Double sum = 0.0;
 111             // Count and sum the values.  Note that each parsed value has rounding error in it.
 112             while (value_m.find()) {
 113                 try {
 114                     Double value = Double.parseDouble(value_m.group());
 115                     sum += value;
 116                     workers++;
 117                 } catch (java.lang.NumberFormatException e) {
 118                     System.out.println("Non Number Format - " + m.group());
 119                 }
 120             }
 121             if (workers > 0) {
 122                 Double calculated_avg = sum / workers;
 123                 // Rounding error in per thread data
 124                 Double rounding_error = workers * 0.5 * Math.pow(10.0,  -decimal_points);
 125                 if (Math.abs(calculated_avg - avg_value) > rounding_error) {
 126                   throw new Exception("Average from log " + avg_value + " and average calculated by test " + 
 127                     calculated_avg + " can differ by rounding error " + rounding_error);
 128                 } else {

 129                     System.err.println("PASSED: Average from log " + avg_value + " and average calculated by test " + 
 130                     calculated_avg + " can differ by rounding error " + rounding_error);
 131                 }




 132             }
 133         }
 134     }
 135 
 136     public static void main(String[] args) throws Exception {
 137         runTest();
 138     }
 139 
 140     static class GCTest {
 141         public static void main(String [] args) {
 142             int numGCs = 4;
 143 
 144             // Perform the requested amount of GCs.
 145             WhiteBox wb = WhiteBox.getWhiteBox();
 146             for (int i = 0; i < numGCs - 1; i++) {
 147                 wb.youngGC();
 148             }
 149             if (numGCs > 0) {
 150               wb.fullGC();
 151             }
< prev index next >