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"); 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"); 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 if (p.getType() == MemoryType.HEAP && 240 p.isUsageThresholdSupported()) { 241 if (!p.getName().equals("G1 Old Space")) { 242 // In G1, humongous objects are tracked in the old space only in 243 // legacy monitoring mode. In default mode, G1 tracks humongous 244 // objects in the humongous space, which latter also supports a 245 // usage threshold. Since we're allocating humongous objects in 246 // this test, in default mode the old space doesn't change. For 247 // this test, we use the old space in legacy mode (it's called 248 // "G1 Old Gen" and the humongous space in default mode. If we 249 // used "G1 Old Space" in default mode, notification would never 250 // happen. 251 mpool = p; 252 if (trace) { 253 System.out.println("Selected memory pool for low memory " + 254 "detection."); 255 MemoryUtil.printMemoryPool(mpool); 256 } 257 break; 258 } 259 } 260 } 261 if (mpool == null) { 262 throw new RuntimeException("TEST FAILED: No heap pool found"); 263 } 264 265 TestListener listener = new TestListener(); 266 SensorListener l2 = new SensorListener(); 267 NotificationEmitter emitter = (NotificationEmitter) mm; 268 emitter.addNotificationListener(listener, null, null); 269 emitter.addNotificationListener(l2, null, null); 270 271 Thread allocator = new AllocatorThread(); 272 Thread sweeper = new SweeperThread(); 273 274 // The chunk size needs to be larger than YOUNG_GEN_SIZE, 275 // otherwise we will get intermittent failures when objects 276 // end up in the young gen instead of the old gen. 277 final long epsilon = 1024; 278 chunkSize = YOUNG_GEN_SIZE + epsilon; 279 280 MemoryUsage mu = mpool.getUsage(); 281 newThreshold = mu.getUsed() + (chunkSize * NUM_CHUNKS); 282 283 // Sanity check. Make sure the new threshold isn't too large. |