author | lkorinth |
Wed, 13 Nov 2019 11:37:29 +0100 | |
changeset 59053 | ba6c248cae19 |
parent 52731 | 157c1130b46e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
52731
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
26 |
* @bug 4959889 6992968 |
2 | 27 |
* @summary Basic unit test of memory management testing: |
28 |
* 1) setCollectionUsageThreshold() and getCollectionUsageThreshold() |
|
29 |
* 2) test notification emitted for two different memory pools. |
|
30 |
* |
|
31 |
* @author Mandy Chung |
|
32 |
* |
|
52731
157c1130b46e
8214431: tests failed because can't find jdk.testlibrary.* in test directory or libraries
mli
parents:
50455
diff
changeset
|
33 |
* @library /test/lib |
37890
f6cb5112c878
8156695: Fix @modules in tests in java/lang/management
shurailine
parents:
30376
diff
changeset
|
34 |
* @modules jdk.management |
52731
157c1130b46e
8214431: tests failed because can't find jdk.testlibrary.* in test directory or libraries
mli
parents:
50455
diff
changeset
|
35 |
* @build CollectionUsageThreshold MemoryUtil RunUtil |
28427
208a556546d3
8066122: CollectionUsageThreshold.java times out when run with -XX:+ExplicitGCInvokesConcurrent
vlivanov
parents:
24366
diff
changeset
|
36 |
* @requires vm.opt.ExplicitGCInvokesConcurrent == "false" | vm.opt.ExplicitGCInvokesConcurrent == "null" |
50455
2b73cce96dce
8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents:
47216
diff
changeset
|
37 |
* @build sun.hotspot.WhiteBox |
2b73cce96dce
8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents:
47216
diff
changeset
|
38 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission |
2b73cce96dce
8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents:
47216
diff
changeset
|
39 |
* @run main/othervm/timeout=300 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CollectionUsageThreshold |
2 | 40 |
*/ |
41 |
||
42 |
import java.util.*; |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
43 |
import java.util.concurrent.*; |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
44 |
import java.util.concurrent.atomic.AtomicInteger; |
2 | 45 |
import javax.management.*; |
46 |
import javax.management.openmbean.CompositeData; |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
47 |
import java.lang.management.*; |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
48 |
import static java.lang.management.MemoryNotificationInfo.*;; |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
49 |
import static java.lang.management.ManagementFactory.*; |
2 | 50 |
|
50455
2b73cce96dce
8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents:
47216
diff
changeset
|
51 |
import sun.hotspot.code.Compiler; |
2b73cce96dce
8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents:
47216
diff
changeset
|
52 |
|
2 | 53 |
public class CollectionUsageThreshold { |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
54 |
private static final MemoryMXBean mm = getMemoryMXBean(); |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
55 |
private static final Map<String, PoolRecord> result = new HashMap<>(); |
2 | 56 |
private static boolean trace = false; |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
57 |
private static volatile int numMemoryPools = 1; |
2 | 58 |
private static final int NUM_GCS = 3; |
59 |
private static final int THRESHOLD = 10; |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
60 |
private static volatile int numGCs = 0; |
2 | 61 |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
62 |
// semaphore to signal the arrival of a low memory notification |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
63 |
private static final Semaphore signals = new Semaphore(0); |
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
64 |
// barrier for the main thread to wait until the checker thread |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
65 |
// finishes checking the low memory notification result |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
66 |
private static final CyclicBarrier barrier = new CyclicBarrier(2); |
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
67 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
68 |
/** |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
69 |
* Run the test multiple times with different GC versions. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
70 |
* First with default command line specified by the framework. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
71 |
* Then with GC versions specified by the test. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
72 |
*/ |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
73 |
public static void main(String a[]) throws Throwable { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
74 |
final String main = "CollectionUsageThreshold$TestMain"; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
75 |
RunUtil.runTestKeepGcOpts(main); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
76 |
RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
77 |
RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
78 |
RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
79 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
80 |
|
2 | 81 |
static class PoolRecord { |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
82 |
private final MemoryPoolMXBean pool; |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
83 |
private final AtomicInteger listenerInvoked = new AtomicInteger(0); |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
84 |
private volatile long notifCount = 0; |
2 | 85 |
PoolRecord(MemoryPoolMXBean p) { |
86 |
this.pool = p; |
|
87 |
} |
|
88 |
int getListenerInvokedCount() { |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
89 |
return listenerInvoked.get(); |
2 | 90 |
} |
91 |
long getNotifCount() { |
|
92 |
return notifCount; |
|
93 |
} |
|
94 |
MemoryPoolMXBean getPool() { |
|
95 |
return pool; |
|
96 |
} |
|
97 |
void addNotification(MemoryNotificationInfo minfo) { |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
98 |
listenerInvoked.incrementAndGet(); |
2 | 99 |
notifCount = minfo.getCount(); |
100 |
} |
|
101 |
} |
|
102 |
||
103 |
static class SensorListener implements NotificationListener { |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
104 |
@Override |
2 | 105 |
public void handleNotification(Notification notif, Object handback) { |
106 |
String type = notif.getType(); |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
107 |
if (MEMORY_THRESHOLD_EXCEEDED.equals(type) || |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
108 |
MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(type)) { |
2 | 109 |
MemoryNotificationInfo minfo = MemoryNotificationInfo. |
110 |
from((CompositeData) notif.getUserData()); |
|
111 |
||
112 |
MemoryUtil.printMemoryNotificationInfo(minfo, type); |
|
113 |
PoolRecord pr = (PoolRecord) result.get(minfo.getPoolName()); |
|
114 |
if (pr == null) { |
|
115 |
throw new RuntimeException("Pool " + minfo.getPoolName() + |
|
116 |
" is not selected"); |
|
117 |
} |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
118 |
if (!MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(type)) { |
2 | 119 |
throw new RuntimeException("Pool " + minfo.getPoolName() + |
120 |
" got unexpected notification type: " + |
|
121 |
type); |
|
122 |
} |
|
123 |
pr.addNotification(minfo); |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
124 |
System.out.println("notifying the checker thread to check result"); |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
125 |
signals.release(); |
2 | 126 |
} |
127 |
} |
|
128 |
} |
|
129 |
||
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
130 |
private static class TestMain { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
131 |
public static void main(String args[]) throws Exception { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
132 |
if (args.length > 0 && args[0].equals("trace")) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
133 |
trace = true; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
134 |
} |
2 | 135 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
136 |
List<MemoryPoolMXBean> pools = getMemoryPoolMXBeans(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
137 |
List<MemoryManagerMXBean> managers = getMemoryManagerMXBeans(); |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
138 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
139 |
if (trace) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
140 |
MemoryUtil.printMemoryPools(pools); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
141 |
MemoryUtil.printMemoryManagers(managers); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
142 |
} |
2 | 143 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
144 |
// Find the Old generation which supports low memory detection |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
145 |
for (MemoryPoolMXBean p : pools) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
146 |
if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
147 |
if (p.getName().toLowerCase().contains("perm")) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
148 |
// if we have a "perm gen" pool increase the number of expected |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
149 |
// memory pools by one. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
150 |
numMemoryPools++; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
151 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
152 |
PoolRecord pr = new PoolRecord(p); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
153 |
result.put(p.getName(), pr); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
154 |
if (result.size() == numMemoryPools) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
155 |
break; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
156 |
} |
2 | 157 |
} |
158 |
} |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
159 |
if (result.size() != numMemoryPools) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
160 |
throw new RuntimeException("Unexpected number of selected pools"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
161 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
162 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
163 |
try { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
164 |
// This test creates a checker thread responsible for checking |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
165 |
// the low memory notifications. It blocks until a permit |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
166 |
// from the signals semaphore is available. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
167 |
Checker checker = new Checker("Checker thread"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
168 |
checker.setDaemon(true); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
169 |
checker.start(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
170 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
171 |
for (PoolRecord pr : result.values()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
172 |
pr.getPool().setCollectionUsageThreshold(THRESHOLD); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
173 |
System.out.println("Collection usage threshold of " + |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
174 |
pr.getPool().getName() + " set to " + THRESHOLD); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
175 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
176 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
177 |
SensorListener listener = new SensorListener(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
178 |
NotificationEmitter emitter = (NotificationEmitter) mm; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
179 |
emitter.addNotificationListener(listener, null, null); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
180 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
181 |
// The main thread invokes GC to trigger the VM to perform |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
182 |
// low memory detection and then waits until the checker thread |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
183 |
// finishes its work to check for a low-memory notification. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
184 |
// |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
185 |
// At GC time, VM will issue low-memory notification and invoke |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
186 |
// the listener which will release a permit to the signals semaphore. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
187 |
// When the checker thread acquires the permit and finishes |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
188 |
// checking the low-memory notification, it will also call |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
189 |
// barrier.await() to signal the main thread to resume its work. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
190 |
for (int i = 0; i < NUM_GCS; i++) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
191 |
invokeGC(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
192 |
barrier.await(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
193 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
194 |
} finally { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
195 |
// restore the default |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
196 |
for (PoolRecord pr : result.values()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
197 |
pr.getPool().setCollectionUsageThreshold(0); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
198 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
199 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
200 |
System.out.println(RunUtil.successMessage); |
2 | 201 |
} |
202 |
||
5808
3a1f603c5ca7
6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents:
5506
diff
changeset
|
203 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
204 |
private static void invokeGC() { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
205 |
System.out.println("Calling System.gc()"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
206 |
numGCs++; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
207 |
mm.gc(); |
2 | 208 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
209 |
if (trace) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
210 |
for (PoolRecord pr : result.values()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
211 |
System.out.println("Usage after GC for: " + pr.getPool().getName()); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
212 |
MemoryUtil.printMemoryUsage(pr.getPool().getUsage()); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
213 |
} |
2 | 214 |
} |
215 |
} |
|
216 |
} |
|
217 |
||
218 |
static class Checker extends Thread { |
|
219 |
Checker(String name) { |
|
220 |
super(name); |
|
221 |
}; |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
222 |
@Override |
2 | 223 |
public void run() { |
224 |
while (true) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
225 |
try { |
13784 | 226 |
signals.acquire(numMemoryPools); |
2 | 227 |
checkResult(); |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
228 |
} catch (InterruptedException | BrokenBarrierException e) { |
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
229 |
throw new RuntimeException(e); |
2 | 230 |
} |
231 |
} |
|
232 |
} |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
233 |
private void checkResult() throws InterruptedException, BrokenBarrierException { |
5808
3a1f603c5ca7
6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents:
5506
diff
changeset
|
234 |
for (PoolRecord pr : result.values()) { |
2 | 235 |
if (pr.getListenerInvokedCount() != numGCs) { |
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
236 |
fail("Listeners invoked count = " + |
2 | 237 |
pr.getListenerInvokedCount() + " expected to be " + |
238 |
numGCs); |
|
239 |
} |
|
240 |
if (pr.getNotifCount() != numGCs) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
241 |
fail("Notif Count = " + |
2 | 242 |
pr.getNotifCount() + " expected to be " + |
243 |
numGCs); |
|
244 |
} |
|
245 |
||
246 |
long count = pr.getPool().getCollectionUsageThresholdCount(); |
|
247 |
if (count != numGCs) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
248 |
fail("CollectionUsageThresholdCount = " + |
2 | 249 |
count + " expected to be " + numGCs); |
250 |
} |
|
251 |
if (!pr.getPool().isCollectionUsageThresholdExceeded()) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
252 |
fail("isCollectionUsageThresholdExceeded" + |
2 | 253 |
" expected to be true"); |
254 |
} |
|
255 |
} |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
256 |
// wait until the main thread is waiting for notification |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
257 |
barrier.await(); |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
258 |
System.out.println("notifying main thread to continue - result checking finished"); |
2 | 259 |
} |
260 |
||
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
261 |
private void fail(String msg) { |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
262 |
// reset the barrier to cause BrokenBarrierException to avoid hanging |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
263 |
barrier.reset(); |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
264 |
throw new RuntimeException(msg); |
2 | 265 |
} |
266 |
} |
|
267 |
} |