58 private static final int NUM_GCS = 3;
59 private static final int THRESHOLD = 10;
60 private static volatile int numGCs = 0;
61
62 // semaphore to signal the arrival of a low memory notification
63 private static final Semaphore signals = new Semaphore(0);
64 // barrier for the main thread to wait until the checker thread
65 // finishes checking the low memory notification result
66 private static final CyclicBarrier barrier = new CyclicBarrier(2);
67
68 /**
69 * Run the test multiple times with different GC versions.
70 * First with default command line specified by the framework.
71 * Then with GC versions specified by the test.
72 */
73 public static void main(String a[]) throws Throwable {
74 final String main = "CollectionUsageThreshold$TestMain";
75 RunUtil.runTestKeepGcOpts(main);
76 RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC");
77 RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC");
78 RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC");
79 if (!Compiler.isGraalEnabled()) { // Graal does not support CMS
80 RunUtil.runTestClearGcOpts(main, "-XX:+UseConcMarkSweepGC");
81 }
82 }
83
84 static class PoolRecord {
85 private final MemoryPoolMXBean pool;
86 private final AtomicInteger listenerInvoked = new AtomicInteger(0);
87 private volatile long notifCount = 0;
88 PoolRecord(MemoryPoolMXBean p) {
89 this.pool = p;
90 }
91 int getListenerInvokedCount() {
92 return listenerInvoked.get();
93 }
94 long getNotifCount() {
95 return notifCount;
96 }
97 MemoryPoolMXBean getPool() {
98 return pool;
130 }
131 }
132
133 private static class TestMain {
134 public static void main(String args[]) throws Exception {
135 if (args.length > 0 && args[0].equals("trace")) {
136 trace = true;
137 }
138
139 List<MemoryPoolMXBean> pools = getMemoryPoolMXBeans();
140 List<MemoryManagerMXBean> managers = getMemoryManagerMXBeans();
141
142 if (trace) {
143 MemoryUtil.printMemoryPools(pools);
144 MemoryUtil.printMemoryManagers(managers);
145 }
146
147 // Find the Old generation which supports low memory detection
148 for (MemoryPoolMXBean p : pools) {
149 if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) {
150 if (p.getName().toLowerCase().contains("perm")) {
151 // if we have a "perm gen" pool increase the number of expected
152 // memory pools by one.
153 numMemoryPools++;
154 }
155 PoolRecord pr = new PoolRecord(p);
156 result.put(p.getName(), pr);
157 if (result.size() == numMemoryPools) {
158 break;
159 }
160 }
161 }
162 if (result.size() != numMemoryPools) {
163 throw new RuntimeException("Unexpected number of selected pools");
164 }
165
166 try {
167 // This test creates a checker thread responsible for checking
168 // the low memory notifications. It blocks until a permit
169 // from the signals semaphore is available.
170 Checker checker = new Checker("Checker thread");
171 checker.setDaemon(true);
172 checker.start();
173
174 for (PoolRecord pr : result.values()) {
|
58 private static final int NUM_GCS = 3;
59 private static final int THRESHOLD = 10;
60 private static volatile int numGCs = 0;
61
62 // semaphore to signal the arrival of a low memory notification
63 private static final Semaphore signals = new Semaphore(0);
64 // barrier for the main thread to wait until the checker thread
65 // finishes checking the low memory notification result
66 private static final CyclicBarrier barrier = new CyclicBarrier(2);
67
68 /**
69 * Run the test multiple times with different GC versions.
70 * First with default command line specified by the framework.
71 * Then with GC versions specified by the test.
72 */
73 public static void main(String a[]) throws Throwable {
74 final String main = "CollectionUsageThreshold$TestMain";
75 RunUtil.runTestKeepGcOpts(main);
76 RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC");
77 RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC");
78 RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC", "-XX:-G1UseLegacyMonitoring");
79 RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC", "-XX:+G1UseLegacyMonitoring");
80 if (!Compiler.isGraalEnabled()) { // Graal does not support CMS
81 RunUtil.runTestClearGcOpts(main, "-XX:+UseConcMarkSweepGC");
82 }
83 }
84
85 static class PoolRecord {
86 private final MemoryPoolMXBean pool;
87 private final AtomicInteger listenerInvoked = new AtomicInteger(0);
88 private volatile long notifCount = 0;
89 PoolRecord(MemoryPoolMXBean p) {
90 this.pool = p;
91 }
92 int getListenerInvokedCount() {
93 return listenerInvoked.get();
94 }
95 long getNotifCount() {
96 return notifCount;
97 }
98 MemoryPoolMXBean getPool() {
99 return pool;
131 }
132 }
133
134 private static class TestMain {
135 public static void main(String args[]) throws Exception {
136 if (args.length > 0 && args[0].equals("trace")) {
137 trace = true;
138 }
139
140 List<MemoryPoolMXBean> pools = getMemoryPoolMXBeans();
141 List<MemoryManagerMXBean> managers = getMemoryManagerMXBeans();
142
143 if (trace) {
144 MemoryUtil.printMemoryPools(pools);
145 MemoryUtil.printMemoryManagers(managers);
146 }
147
148 // Find the Old generation which supports low memory detection
149 for (MemoryPoolMXBean p : pools) {
150 if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) {
151 String poolName = p.getName().toLowerCase();
152 if (poolName.contains("perm")) {
153 // if we have a "perm gen" pool increase the number of expected
154 // memory pools by one.
155 numMemoryPools++;
156 }
157 if (poolName.contains("g1 humongous space")) {
158 // if we have a "g1 humongous space" pool increase the number of expected
159 // memory pools by one.
160 numMemoryPools++;
161 }
162 PoolRecord pr = new PoolRecord(p);
163 result.put(p.getName(), pr);
164 if (result.size() == numMemoryPools) {
165 break;
166 }
167 }
168 }
169 if (result.size() != numMemoryPools) {
170 throw new RuntimeException("Unexpected number of selected pools");
171 }
172
173 try {
174 // This test creates a checker thread responsible for checking
175 // the low memory notifications. It blocks until a permit
176 // from the signals semaphore is available.
177 Checker checker = new Checker("Checker thread");
178 checker.setDaemon(true);
179 checker.start();
180
181 for (PoolRecord pr : result.values()) {
|