< prev index next >

test/jdk/java/lang/management/MemoryMXBean/LowMemoryTest.java

Print this page




  66 
  67     /**
  68      * Run the test multiple times with different GC versions.
  69      * First with default command line specified by the framework.
  70      * Then with GC versions specified by the test.
  71      */
  72     public static void main(String a[]) throws Throwable {
  73         // Use a low young gen size to ensure that the
  74         // allocated objects are put in the old gen.
  75         final String nmFlag = "-Xmn" + YOUNG_GEN_SIZE;
  76         // Using large pages will change the young gen size,
  77         // make sure we don't use them for this test.
  78         final String lpFlag = "-XX:-UseLargePages";
  79         // Prevent G1 from selecting a large heap region size,
  80         // since that would change the young gen size.
  81         final String g1Flag = "-XX:G1HeapRegionSize=1m";
  82 
  83         // Runs the test collecting subprocess I/O while it's running.
  84         traceTest(classMain + ", -XX:+UseSerialGC", nmFlag, lpFlag, "-XX:+UseSerialGC");
  85         traceTest(classMain + ", -XX:+UseParallelGC", nmFlag, lpFlag, "-XX:+UseParallelGC");
  86         traceTest(classMain + ", -XX:+UseG1GC", nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);



  87         if (!Compiler.isGraalEnabled()) { // Graal does not support CMS
  88             traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC");

  89         }
  90     }
  91 
  92     /*
  93      * Creating command-line for running subprocess JVM:
  94      *
  95      * JVM command line is like:
  96      * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
  97      *
  98      * {defaultopts} are the default java options set by the framework.
  99      *
 100      * @param testOpts java options specified by the test.
 101      */
 102     private static List<String> buildCommandLine(String... testOpts) {
 103         List<String> opts = new ArrayList<>();
 104         opts.add(JDKToolFinder.getJDKTool("java"));
 105         opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
 106         opts.add("-cp");
 107         opts.add(System.getProperty("test.class.path", "test.class.path"));
 108         opts.add("-Xlog:gc*=debug");


 215             if (!isRelaxed) {
 216                 return value == target;
 217             } else {
 218                 return value >= target;
 219             }
 220         }
 221     }
 222 
 223     private static long newThreshold;
 224 
 225     private static class TestMain {
 226         public static void main(String args[]) throws Exception {
 227             if (args.length > 0 && args[0].equals("trace")) {
 228                 trace = true;
 229             }
 230 
 231             // Find the Old generation which supports low memory detection
 232             ListIterator iter = pools.listIterator();
 233             while (iter.hasNext()) {
 234                 MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();



 235                 if (p.getType() == MemoryType.HEAP &&
 236                     p.isUsageThresholdSupported()) {















 237                     mpool = p;
 238                     if (trace) {
 239                         System.out.println("Selected memory pool for low memory " +
 240                             "detection.");
 241                         MemoryUtil.printMemoryPool(mpool);
 242                     }
 243                     break;
 244                 }
 245             }




 246 
 247             TestListener listener = new TestListener();
 248             SensorListener l2 = new SensorListener();
 249             NotificationEmitter emitter = (NotificationEmitter) mm;
 250             emitter.addNotificationListener(listener, null, null);
 251             emitter.addNotificationListener(l2, null, null);
 252 
 253             Thread allocator = new AllocatorThread();
 254             Thread sweeper = new SweeperThread();
 255 
 256             // The chunk size needs to be larger than YOUNG_GEN_SIZE,
 257             // otherwise we will get intermittent failures when objects
 258             // end up in the young gen instead of the old gen.
 259             final long epsilon = 1024;
 260             chunkSize = YOUNG_GEN_SIZE + epsilon;
 261 
 262             MemoryUsage mu = mpool.getUsage();
 263             newThreshold = mu.getUsed() + (chunkSize * NUM_CHUNKS);
 264 
 265             // Sanity check. Make sure the new threshold isn't too large.




  66 
  67     /**
  68      * Run the test multiple times with different GC versions.
  69      * First with default command line specified by the framework.
  70      * Then with GC versions specified by the test.
  71      */
  72     public static void main(String a[]) throws Throwable {
  73         // Use a low young gen size to ensure that the
  74         // allocated objects are put in the old gen.
  75         final String nmFlag = "-Xmn" + YOUNG_GEN_SIZE;
  76         // Using large pages will change the young gen size,
  77         // make sure we don't use them for this test.
  78         final String lpFlag = "-XX:-UseLargePages";
  79         // Prevent G1 from selecting a large heap region size,
  80         // since that would change the young gen size.
  81         final String g1Flag = "-XX:G1HeapRegionSize=1m";
  82 
  83         // Runs the test collecting subprocess I/O while it's running.
  84         traceTest(classMain + ", -XX:+UseSerialGC", nmFlag, lpFlag, "-XX:+UseSerialGC");
  85         traceTest(classMain + ", -XX:+UseParallelGC", nmFlag, lpFlag, "-XX:+UseParallelGC");
  86         traceTest(classMain + ", -XX:+UseG1GC -XX:-G1UseLegacyMonitoring", nmFlag, lpFlag,
  87                   "-XX:+UseG1GC", "-XX:-G1UseLegacyMonitoring", g1Flag);
  88         traceTest(classMain + ", -XX:+UseG1GC -XX:+G1UseLegacyMonitoring", nmFlag, lpFlag,
  89                   "-XX:+UseG1GC", "-XX:+G1UseLegacyMonitoring", g1Flag);
  90         if (!Compiler.isGraalEnabled()) { // Graal does not support CMS
  91              traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag,
  92                        "-XX:+UseConcMarkSweepGC");
  93         }
  94     }
  95 
  96     /*
  97      * Creating command-line for running subprocess JVM:
  98      *
  99      * JVM command line is like:
 100      * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
 101      *
 102      * {defaultopts} are the default java options set by the framework.
 103      *
 104      * @param testOpts java options specified by the test.
 105      */
 106     private static List<String> buildCommandLine(String... testOpts) {
 107         List<String> opts = new ArrayList<>();
 108         opts.add(JDKToolFinder.getJDKTool("java"));
 109         opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
 110         opts.add("-cp");
 111         opts.add(System.getProperty("test.class.path", "test.class.path"));
 112         opts.add("-Xlog:gc*=debug");


 219             if (!isRelaxed) {
 220                 return value == target;
 221             } else {
 222                 return value >= target;
 223             }
 224         }
 225     }
 226 
 227     private static long newThreshold;
 228 
 229     private static class TestMain {
 230         public static void main(String args[]) throws Exception {
 231             if (args.length > 0 && args[0].equals("trace")) {
 232                 trace = true;
 233             }
 234 
 235             // Find the Old generation which supports low memory detection
 236             ListIterator iter = pools.listIterator();
 237             while (iter.hasNext()) {
 238                 MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
 239                 // Only check heap pools that support a usage threshold.
 240                 // This is typically only the old generation space
 241                 // since the other spaces are expected to get filled up.
 242                 if (p.getType() == MemoryType.HEAP &&
 243                     p.isUsageThresholdSupported()) {
 244                     // In all collectors except G1, only the old generation supports a
 245                     // usage threshold. The G1 legacy mode "G1 Old Gen" also does. In
 246                     // G1 default mode, both the old space ("G1 Old Space": it's not
 247                     // really a generation in the non-G1 collector sense) and the
 248                     // humongous space ("G1 Humongous Space"), support a usage threshold.
 249                     // So, the following condition is true for all non-G1 old generations,
 250                     // for the G1 legacy old gen, and for the G1 default humongous space.
 251                     // It is not true for the G1 default old gen.
 252                     //
 253                     // We're allocating humongous objects in this test, so the G1 default
 254                     // mode "G1 Old Space" occupancy doesn't change, because humongous
 255                     // objects are allocated in the "G1 Humongous Space". If we allowed
 256                     // the G1 default mode "G1 Old Space", notification would never
 257                     // happen because no objects are allocated there.
 258                     if (!p.getName().equals("G1 Old Space")) {
 259                         mpool = p;
 260                         if (trace) {
 261                             System.out.println("Selected memory pool for low memory " +
 262                                                "detection.");
 263                             MemoryUtil.printMemoryPool(mpool);
 264                         }
 265                         break;
 266                     }
 267                 }
 268             }
 269             if (mpool == null) {
 270                 throw new RuntimeException("TEST FAILED: No heap pool found");
 271             }
 272 
 273             TestListener listener = new TestListener();
 274             SensorListener l2 = new SensorListener();
 275             NotificationEmitter emitter = (NotificationEmitter) mm;
 276             emitter.addNotificationListener(listener, null, null);
 277             emitter.addNotificationListener(l2, null, null);
 278 
 279             Thread allocator = new AllocatorThread();
 280             Thread sweeper = new SweeperThread();
 281 
 282             // The chunk size needs to be larger than YOUNG_GEN_SIZE,
 283             // otherwise we will get intermittent failures when objects
 284             // end up in the young gen instead of the old gen.
 285             final long epsilon = 1024;
 286             chunkSize = YOUNG_GEN_SIZE + epsilon;
 287 
 288             MemoryUsage mu = mpool.getUsage();
 289             newThreshold = mu.getUsed() + (chunkSize * NUM_CHUNKS);
 290 
 291             // Sanity check. Make sure the new threshold isn't too large.


< prev index next >