< prev index next >

test/gc/class_unloading/TestG1ClassUnloadingHWM.java

Print this page




  37 
  38 import jdk.test.lib.OutputAnalyzer;
  39 import jdk.test.lib.ProcessTools;
  40 import java.util.ArrayList;
  41 import java.util.Arrays;
  42 import sun.hotspot.WhiteBox;
  43 
  44 public class TestG1ClassUnloadingHWM {
  45   private static long MetaspaceSize = 32 * 1024 * 1024;
  46   private static long YoungGenSize  = 32 * 1024 * 1024;
  47 
  48   private static OutputAnalyzer run(boolean enableUnloading) throws Exception {
  49     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  50       "-Xbootclasspath/a:.",
  51       "-XX:+UnlockDiagnosticVMOptions",
  52       "-XX:+WhiteBoxAPI",
  53       "-XX:MetaspaceSize=" + MetaspaceSize,
  54       "-Xmn" + YoungGenSize,
  55       "-XX:+UseG1GC",
  56       "-XX:" + (enableUnloading ? "+" : "-") + "ClassUnloadingWithConcurrentMark",
  57       "-XX:+PrintHeapAtGC",
  58       "-XX:+PrintGCDetails",
  59       TestG1ClassUnloadingHWM.AllocateBeyondMetaspaceSize.class.getName(),
  60       "" + MetaspaceSize,
  61       "" + YoungGenSize);
  62     return new OutputAnalyzer(pb.start());
  63   }
  64 
  65   public static OutputAnalyzer runWithG1ClassUnloading() throws Exception {
  66     return run(true);
  67   }
  68 
  69   public static OutputAnalyzer runWithoutG1ClassUnloading() throws Exception {
  70     return run(false);
  71   }
  72 
  73   public static void testWithoutG1ClassUnloading() throws Exception {
  74     // -XX:-ClassUnloadingWithConcurrentMark is used, so we expect a full GC instead of a concurrent cycle.
  75     OutputAnalyzer out = runWithoutG1ClassUnloading();
  76 
  77     out.shouldMatch(".*Full GC.*");
  78     out.shouldNotMatch(".*initial-mark.*");
  79   }
  80 
  81   public static void testWithG1ClassUnloading() throws Exception {
  82     // -XX:+ClassUnloadingWithConcurrentMark is used, so we expect a concurrent cycle instead of a full GC.
  83     OutputAnalyzer out = runWithG1ClassUnloading();
  84 
  85     out.shouldMatch(".*initial-mark.*");
  86     out.shouldNotMatch(".*Full GC.*");
  87   }
  88 
  89   public static void main(String args[]) throws Exception {
  90     testWithG1ClassUnloading();
  91     testWithoutG1ClassUnloading();
  92   }
  93 
  94   public static class AllocateBeyondMetaspaceSize {
  95     public static Object dummy;
  96 
  97     public static void main(String [] args) throws Exception {
  98       if (args.length != 2) {
  99         throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
 100       }
 101 
 102       WhiteBox wb = WhiteBox.getWhiteBox();
 103 
 104       // Allocate past the MetaspaceSize limit
 105       long metaspaceSize = Long.parseLong(args[0]);
 106       long allocationBeyondMetaspaceSize  = metaspaceSize * 2;


  37 
  38 import jdk.test.lib.OutputAnalyzer;
  39 import jdk.test.lib.ProcessTools;
  40 import java.util.ArrayList;
  41 import java.util.Arrays;
  42 import sun.hotspot.WhiteBox;
  43 
  44 public class TestG1ClassUnloadingHWM {
  45   private static long MetaspaceSize = 32 * 1024 * 1024;
  46   private static long YoungGenSize  = 32 * 1024 * 1024;
  47 
  48   private static OutputAnalyzer run(boolean enableUnloading) throws Exception {
  49     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  50       "-Xbootclasspath/a:.",
  51       "-XX:+UnlockDiagnosticVMOptions",
  52       "-XX:+WhiteBoxAPI",
  53       "-XX:MetaspaceSize=" + MetaspaceSize,
  54       "-Xmn" + YoungGenSize,
  55       "-XX:+UseG1GC",
  56       "-XX:" + (enableUnloading ? "+" : "-") + "ClassUnloadingWithConcurrentMark",
  57       "-Xlog:gc",

  58       TestG1ClassUnloadingHWM.AllocateBeyondMetaspaceSize.class.getName(),
  59       "" + MetaspaceSize,
  60       "" + YoungGenSize);
  61     return new OutputAnalyzer(pb.start());
  62   }
  63 
  64   public static OutputAnalyzer runWithG1ClassUnloading() throws Exception {
  65     return run(true);
  66   }
  67 
  68   public static OutputAnalyzer runWithoutG1ClassUnloading() throws Exception {
  69     return run(false);
  70   }
  71 
  72   public static void testWithoutG1ClassUnloading() throws Exception {
  73     // -XX:-ClassUnloadingWithConcurrentMark is used, so we expect a full GC instead of a concurrent cycle.
  74     OutputAnalyzer out = runWithoutG1ClassUnloading();
  75 
  76     out.shouldMatch(".*Pause Full.*");
  77     out.shouldNotMatch(".*Pause Initial Mark.*");
  78   }
  79 
  80   public static void testWithG1ClassUnloading() throws Exception {
  81     // -XX:+ClassUnloadingWithConcurrentMark is used, so we expect a concurrent cycle instead of a full GC.
  82     OutputAnalyzer out = runWithG1ClassUnloading();
  83 
  84     out.shouldMatch(".*Pause Initial Mark.*");
  85     out.shouldNotMatch(".*Pause Full.*");
  86   }
  87 
  88   public static void main(String args[]) throws Exception {
  89     testWithG1ClassUnloading();
  90     testWithoutG1ClassUnloading();
  91   }
  92 
  93   public static class AllocateBeyondMetaspaceSize {
  94     public static Object dummy;
  95 
  96     public static void main(String [] args) throws Exception {
  97       if (args.length != 2) {
  98         throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
  99       }
 100 
 101       WhiteBox wb = WhiteBox.getWhiteBox();
 102 
 103       // Allocate past the MetaspaceSize limit
 104       long metaspaceSize = Long.parseLong(args[0]);
 105       long allocationBeyondMetaspaceSize  = metaspaceSize * 2;
< prev index next >