< prev index next >

test/gc/g1/mixedgc/TestLogging.java

Print this page




  51 public class TestLogging {
  52     private static final String[] COMMON_OPTIONS = new String[]{
  53             "-Xbootclasspath/a:.", "-XX:+UseG1GC",
  54             "-XX:+UnlockExperimentalVMOptions",
  55             "-XX:+UnlockDiagnosticVMOptions",
  56             "-XX:+WhiteBoxAPI",
  57             "-XX:SurvivorRatio=1", // Survivor-to-eden ratio is 1:1
  58             "-Xms10M", "-Xmx10M",
  59             "-XX:MaxTenuringThreshold=1", // promote objects after first gc
  60             "-XX:InitiatingHeapOccupancyPercent=0", // marking cycle happens
  61             // each time
  62             "-XX:G1MixedGCCountTarget=4",
  63             "-XX:MaxGCPauseMillis=30000", // to have enough time
  64             "-XX:G1HeapRegionSize=1m", "-XX:G1HeapWastePercent=0",
  65             "-XX:G1MixedGCLiveThresholdPercent=100"};
  66 
  67     public static final int ALLOCATION_SIZE = 20000;
  68     public static final int ALLOCATION_COUNT = 15;
  69 
  70     public static void main(String args[]) throws Exception {
  71         // Test turns logging on by giving -XX:+PrintGC flag
  72         test("-XX:+PrintGC");
  73         // Test turns logging on by giving -XX:+PrintGCDetails
  74         test("-XX:+PrintGCDetails");
  75     }
  76 
  77     private static void test(String vmFlag) throws Exception {
  78         System.out.println(String.format("%s: running with %s flag", TestLogging.class.getSimpleName(), vmFlag));
  79         OutputAnalyzer output = spawnMixedGCProvoker(vmFlag);
  80         System.out.println(output.getStdout());
  81         output.shouldHaveExitValue(0);
  82         output.shouldContain("GC pause (G1 Evacuation Pause) (mixed)");
  83     }
  84 
  85     /**
  86      * Method spawns MixedGCProvoker with addition flags set
  87      *
  88      * @parameter extraFlags -flags to be added to the common options set
  89      */
  90     private static OutputAnalyzer spawnMixedGCProvoker(String... extraFlags)
  91             throws Exception {
  92         List<String> testOpts = new ArrayList<>();
  93         Collections.addAll(testOpts, COMMON_OPTIONS);
  94         Collections.addAll(testOpts, extraFlags);
  95         testOpts.add(MixedGCProvoker.class.getName());
  96         System.out.println(testOpts);
  97         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false,
  98                 testOpts.toArray(new String[testOpts.size()]));
  99         return new OutputAnalyzer(pb.start());
 100     }
 101 }
 102 




  51 public class TestLogging {
  52     private static final String[] COMMON_OPTIONS = new String[]{
  53             "-Xbootclasspath/a:.", "-XX:+UseG1GC",
  54             "-XX:+UnlockExperimentalVMOptions",
  55             "-XX:+UnlockDiagnosticVMOptions",
  56             "-XX:+WhiteBoxAPI",
  57             "-XX:SurvivorRatio=1", // Survivor-to-eden ratio is 1:1
  58             "-Xms10M", "-Xmx10M",
  59             "-XX:MaxTenuringThreshold=1", // promote objects after first gc
  60             "-XX:InitiatingHeapOccupancyPercent=0", // marking cycle happens
  61             // each time
  62             "-XX:G1MixedGCCountTarget=4",
  63             "-XX:MaxGCPauseMillis=30000", // to have enough time
  64             "-XX:G1HeapRegionSize=1m", "-XX:G1HeapWastePercent=0",
  65             "-XX:G1MixedGCLiveThresholdPercent=100"};
  66 
  67     public static final int ALLOCATION_SIZE = 20000;
  68     public static final int ALLOCATION_COUNT = 15;
  69 
  70     public static void main(String args[]) throws Exception {
  71         // Test turns logging on by giving -Xlog:gc flag
  72         test("-Xlog:gc");
  73         // Test turns logging on by giving -Xlog:gc=debug flag
  74         test("-Xlog:gc=debug");
  75     }
  76 
  77     private static void test(String vmFlag) throws Exception {
  78         System.out.println(String.format("%s: running with %s flag", TestLogging.class.getSimpleName(), vmFlag));
  79         OutputAnalyzer output = spawnMixedGCProvoker(vmFlag);
  80         System.out.println(output.getStdout());
  81         output.shouldHaveExitValue(0);
  82         output.shouldContain("Pause Mixed (G1 Evacuation Pause)");
  83     }
  84 
  85     /**
  86      * Method spawns MixedGCProvoker with addition flags set
  87      *
  88      * @parameter extraFlags -flags to be added to the common options set
  89      */
  90     private static OutputAnalyzer spawnMixedGCProvoker(String... extraFlags)
  91             throws Exception {
  92         List<String> testOpts = new ArrayList<>();
  93         Collections.addAll(testOpts, COMMON_OPTIONS);
  94         Collections.addAll(testOpts, extraFlags);
  95         testOpts.add(MixedGCProvoker.class.getName());
  96         System.out.println(testOpts);
  97         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false,
  98                 testOpts.toArray(new String[testOpts.size()]));
  99         return new OutputAnalyzer(pb.start());
 100     }
 101 }
 102 


< prev index next >