42 import java.util.ArrayList; 43 import java.util.Arrays; 44 import sun.hotspot.WhiteBox; 45 46 public class TestCMSClassUnloadingEnabledHWM { 47 private static long MetaspaceSize = 32 * 1024 * 1024; 48 private static long YoungGenSize = 32 * 1024 * 1024; 49 50 private static OutputAnalyzer run(boolean enableUnloading) throws Exception { 51 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 52 "-Xbootclasspath/a:.", 53 "-XX:+UnlockDiagnosticVMOptions", 54 "-XX:+WhiteBoxAPI", 55 "-Xmx128m", 56 "-XX:CMSMaxAbortablePrecleanTime=1", 57 "-XX:CMSWaitDuration=50", 58 "-XX:MetaspaceSize=" + MetaspaceSize, 59 "-Xmn" + YoungGenSize, 60 "-XX:+UseConcMarkSweepGC", 61 "-XX:" + (enableUnloading ? "+" : "-") + "CMSClassUnloadingEnabled", 62 "-XX:+PrintHeapAtGC", 63 "-XX:+PrintGCDetails", 64 "-XX:+PrintGCTimeStamps", 65 TestCMSClassUnloadingEnabledHWM.AllocateBeyondMetaspaceSize.class.getName(), 66 "" + MetaspaceSize); 67 return new OutputAnalyzer(pb.start()); 68 } 69 70 public static OutputAnalyzer runWithCMSClassUnloading() throws Exception { 71 return run(true); 72 } 73 74 public static OutputAnalyzer runWithoutCMSClassUnloading() throws Exception { 75 return run(false); 76 } 77 78 public static void testWithoutCMSClassUnloading() throws Exception { 79 // -XX:-CMSClassUnloadingEnabled is used, so we expect a full GC instead of a concurrent cycle. 80 OutputAnalyzer out = runWithoutCMSClassUnloading(); 81 82 out.shouldMatch(".*Full GC.*"); 83 out.shouldNotMatch(".*CMS Initial Mark.*"); 84 } 85 86 public static void testWithCMSClassUnloading() throws Exception { 87 // -XX:+CMSClassUnloadingEnabled is used, so we expect a concurrent cycle instead of a full GC. 88 OutputAnalyzer out = runWithCMSClassUnloading(); 89 90 out.shouldMatch(".*CMS Initial Mark.*"); 91 out.shouldNotMatch(".*Full GC.*"); 92 } 93 94 public static void main(String args[]) throws Exception { 95 testWithCMSClassUnloading(); 96 testWithoutCMSClassUnloading(); 97 } 98 99 public static class AllocateBeyondMetaspaceSize { 100 public static void main(String [] args) throws Exception { 101 if (args.length != 1) { 102 throw new IllegalArgumentException("Usage: <MetaspaceSize>"); 103 } 104 105 WhiteBox wb = WhiteBox.getWhiteBox(); 106 107 // Allocate past the MetaspaceSize limit. 108 long metaspaceSize = Long.parseLong(args[0]); 109 long allocationBeyondMetaspaceSize = metaspaceSize * 2; 110 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize); 111 | 42 import java.util.ArrayList; 43 import java.util.Arrays; 44 import sun.hotspot.WhiteBox; 45 46 public class TestCMSClassUnloadingEnabledHWM { 47 private static long MetaspaceSize = 32 * 1024 * 1024; 48 private static long YoungGenSize = 32 * 1024 * 1024; 49 50 private static OutputAnalyzer run(boolean enableUnloading) throws Exception { 51 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 52 "-Xbootclasspath/a:.", 53 "-XX:+UnlockDiagnosticVMOptions", 54 "-XX:+WhiteBoxAPI", 55 "-Xmx128m", 56 "-XX:CMSMaxAbortablePrecleanTime=1", 57 "-XX:CMSWaitDuration=50", 58 "-XX:MetaspaceSize=" + MetaspaceSize, 59 "-Xmn" + YoungGenSize, 60 "-XX:+UseConcMarkSweepGC", 61 "-XX:" + (enableUnloading ? "+" : "-") + "CMSClassUnloadingEnabled", 62 "-Xlog:gc", 63 TestCMSClassUnloadingEnabledHWM.AllocateBeyondMetaspaceSize.class.getName(), 64 "" + MetaspaceSize); 65 return new OutputAnalyzer(pb.start()); 66 } 67 68 public static OutputAnalyzer runWithCMSClassUnloading() throws Exception { 69 return run(true); 70 } 71 72 public static OutputAnalyzer runWithoutCMSClassUnloading() throws Exception { 73 return run(false); 74 } 75 76 public static void testWithoutCMSClassUnloading() throws Exception { 77 // -XX:-CMSClassUnloadingEnabled is used, so we expect a full GC instead of a concurrent cycle. 78 OutputAnalyzer out = runWithoutCMSClassUnloading(); 79 80 out.shouldMatch(".*Pause Full.*"); 81 out.shouldNotMatch(".*Pause Initial Mark.*"); 82 } 83 84 public static void testWithCMSClassUnloading() throws Exception { 85 // -XX:+CMSClassUnloadingEnabled is used, so we expect a concurrent cycle instead of a full GC. 86 OutputAnalyzer out = runWithCMSClassUnloading(); 87 88 out.shouldMatch(".*Pause Initial Mark.*"); 89 out.shouldNotMatch(".*Pause Full.*"); 90 } 91 92 public static void main(String args[]) throws Exception { 93 testWithCMSClassUnloading(); 94 testWithoutCMSClassUnloading(); 95 } 96 97 public static class AllocateBeyondMetaspaceSize { 98 public static void main(String [] args) throws Exception { 99 if (args.length != 1) { 100 throw new IllegalArgumentException("Usage: <MetaspaceSize>"); 101 } 102 103 WhiteBox wb = WhiteBox.getWhiteBox(); 104 105 // Allocate past the MetaspaceSize limit. 106 long metaspaceSize = Long.parseLong(args[0]); 107 long allocationBeyondMetaspaceSize = metaspaceSize * 2; 108 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize); 109 |