Mercurial > hg > truffle
comparison test/gc/class_unloading/TestCMSClassUnloadingEnabledHWM.java @ 20524:85f4c4ecc963
8058475: TestCMSClassUnloadingEnabledHWM.java fails with '.*CMS Initial Mark.*' missing from stdout/stderr
Reviewed-by: mgerdin, tschatzl, brutisso
author | stefank |
---|---|
date | Tue, 16 Sep 2014 10:13:45 +0200 |
parents | 8a7429682242 |
children |
comparison
equal
deleted
inserted
replaced
20523:1b61c1b7b519 | 20524:85f4c4ecc963 |
---|---|
24 /* | 24 /* |
25 * @test | 25 * @test |
26 * @key gc | 26 * @key gc |
27 * @bug 8049831 | 27 * @bug 8049831 |
28 * @library /testlibrary /testlibrary/whitebox | 28 * @library /testlibrary /testlibrary/whitebox |
29 * @build TestCMSClassUnloadingEnabledHWM AllocateBeyondMetaspaceSize | 29 * @build TestCMSClassUnloadingEnabledHWM |
30 * @run main ClassFileInstaller sun.hotspot.WhiteBox | 30 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
31 * @run driver TestCMSClassUnloadingEnabledHWM | 31 * @run driver TestCMSClassUnloadingEnabledHWM |
32 * @summary Test that -XX:-CMSClassUnloadingEnabled will trigger a Full GC when more than MetaspaceSize metadata is allocated. | 32 * @summary Test that -XX:-CMSClassUnloadingEnabled will trigger a Full GC when more than MetaspaceSize metadata is allocated. |
33 */ | 33 */ |
34 | 34 |
35 import com.oracle.java.testlibrary.OutputAnalyzer; | 35 import com.oracle.java.testlibrary.OutputAnalyzer; |
36 import com.oracle.java.testlibrary.ProcessTools; | 36 import com.oracle.java.testlibrary.ProcessTools; |
37 | 37 import java.lang.management.GarbageCollectorMXBean; |
38 import java.lang.management.ManagementFactory; | |
38 import java.util.ArrayList; | 39 import java.util.ArrayList; |
39 import java.util.Arrays; | 40 import java.util.Arrays; |
41 import sun.hotspot.WhiteBox; | |
40 | 42 |
41 public class TestCMSClassUnloadingEnabledHWM { | 43 public class TestCMSClassUnloadingEnabledHWM { |
42 private static long MetaspaceSize = 32 * 1024 * 1024; | 44 private static long MetaspaceSize = 32 * 1024 * 1024; |
43 private static long YoungGenSize = 32 * 1024 * 1024; | 45 private static long YoungGenSize = 32 * 1024 * 1024; |
44 | 46 |
45 private static OutputAnalyzer run(boolean enableUnloading) throws Exception { | 47 private static OutputAnalyzer run(boolean enableUnloading) throws Exception { |
46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( | 48 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
47 "-Xbootclasspath/a:.", | 49 "-Xbootclasspath/a:.", |
48 "-XX:+UnlockDiagnosticVMOptions", | 50 "-XX:+UnlockDiagnosticVMOptions", |
49 "-XX:+WhiteBoxAPI", | 51 "-XX:+WhiteBoxAPI", |
52 "-Xmx128m", | |
53 "-XX:CMSMaxAbortablePrecleanTime=1", | |
54 "-XX:CMSWaitDuration=50", | |
50 "-XX:MetaspaceSize=" + MetaspaceSize, | 55 "-XX:MetaspaceSize=" + MetaspaceSize, |
51 "-Xmn" + YoungGenSize, | 56 "-Xmn" + YoungGenSize, |
52 "-XX:+UseConcMarkSweepGC", | 57 "-XX:+UseConcMarkSweepGC", |
53 "-XX:" + (enableUnloading ? "+" : "-") + "CMSClassUnloadingEnabled", | 58 "-XX:" + (enableUnloading ? "+" : "-") + "CMSClassUnloadingEnabled", |
54 "-XX:+PrintHeapAtGC", | 59 "-XX:+PrintHeapAtGC", |
55 "-XX:+PrintGCDetails", | 60 "-XX:+PrintGCDetails", |
56 "AllocateBeyondMetaspaceSize", | 61 "-XX:+PrintGCTimeStamps", |
57 "" + MetaspaceSize, | 62 TestCMSClassUnloadingEnabledHWM.AllocateBeyondMetaspaceSize.class.getName(), |
58 "" + YoungGenSize); | 63 "" + MetaspaceSize); |
59 return new OutputAnalyzer(pb.start()); | 64 return new OutputAnalyzer(pb.start()); |
60 } | 65 } |
61 | 66 |
62 public static OutputAnalyzer runWithCMSClassUnloading() throws Exception { | 67 public static OutputAnalyzer runWithCMSClassUnloading() throws Exception { |
63 return run(true); | 68 return run(true); |
85 | 90 |
86 public static void main(String args[]) throws Exception { | 91 public static void main(String args[]) throws Exception { |
87 testWithCMSClassUnloading(); | 92 testWithCMSClassUnloading(); |
88 testWithoutCMSClassUnloading(); | 93 testWithoutCMSClassUnloading(); |
89 } | 94 } |
95 | |
96 public static class AllocateBeyondMetaspaceSize { | |
97 public static void main(String [] args) throws Exception { | |
98 if (args.length != 1) { | |
99 throw new IllegalArgumentException("Usage: <MetaspaceSize>"); | |
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; | |
107 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize); | |
108 | |
109 // Wait for at least one GC to occur. The caller will parse the log files produced. | |
110 GarbageCollectorMXBean cmsGCBean = getCMSGCBean(); | |
111 while (cmsGCBean.getCollectionCount() == 0) { | |
112 Thread.sleep(100); | |
113 } | |
114 | |
115 wb.freeMetaspace(null, metaspace, metaspace); | |
116 } | |
117 | |
118 private static GarbageCollectorMXBean getCMSGCBean() { | |
119 for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) { | |
120 if (gcBean.getObjectName().toString().equals("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep")) { | |
121 return gcBean; | |
122 } | |
123 } | |
124 return null; | |
125 } | |
126 } | |
90 } | 127 } |
91 | 128 |