author | mtobiass |
Wed, 16 Apr 2014 12:40:19 -0700 | |
changeset 23933 | 754ee146b623 |
parent 21973 | 1c152053cba6 |
child 24366 | 57c0a8b7a936 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, 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 |
* |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
33 |
* @library /lib/testlibrary/ |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
34 |
* @build CollectionUsageThreshold MemoryUtil RunUtil |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
35 |
* @run main/timeout=300 CollectionUsageThreshold |
2 | 36 |
*/ |
37 |
||
38 |
import java.util.*; |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
39 |
import java.util.concurrent.*; |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
40 |
import java.util.concurrent.atomic.AtomicInteger; |
2 | 41 |
import javax.management.*; |
42 |
import javax.management.openmbean.CompositeData; |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
43 |
import java.lang.management.*; |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
44 |
import static java.lang.management.MemoryNotificationInfo.*;; |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
45 |
import static java.lang.management.ManagementFactory.*; |
2 | 46 |
|
47 |
public class CollectionUsageThreshold { |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
48 |
private static final MemoryMXBean mm = getMemoryMXBean(); |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
49 |
private static final Map<String, PoolRecord> result = new HashMap<>(); |
2 | 50 |
private static boolean trace = false; |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
51 |
private static volatile int numMemoryPools = 1; |
2 | 52 |
private static final int NUM_GCS = 3; |
53 |
private static final int THRESHOLD = 10; |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
54 |
private static volatile int numGCs = 0; |
2 | 55 |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
56 |
// 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
|
57 |
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
|
58 |
// 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
|
59 |
// finishes checking the low memory notification result |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
60 |
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
|
61 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
62 |
/** |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
63 |
* 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
|
64 |
* 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
|
65 |
* 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
|
66 |
*/ |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
67 |
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
|
68 |
final String main = "CollectionUsageThreshold$TestMain"; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
69 |
RunUtil.runTestKeepGcOpts(main); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
70 |
RunUtil.runTestClearGcOpts(main, "-XX:+UseSerialGC"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
71 |
RunUtil.runTestClearGcOpts(main, "-XX:+UseParallelGC"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
72 |
RunUtil.runTestClearGcOpts(main, "-XX:+UseG1GC"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
73 |
RunUtil.runTestClearGcOpts(main, "-XX:+UseConcMarkSweepGC"); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
74 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
75 |
|
2 | 76 |
static class PoolRecord { |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
77 |
private final MemoryPoolMXBean pool; |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
78 |
private final AtomicInteger listenerInvoked = new AtomicInteger(0); |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
79 |
private volatile long notifCount = 0; |
2 | 80 |
PoolRecord(MemoryPoolMXBean p) { |
81 |
this.pool = p; |
|
82 |
} |
|
83 |
int getListenerInvokedCount() { |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
84 |
return listenerInvoked.get(); |
2 | 85 |
} |
86 |
long getNotifCount() { |
|
87 |
return notifCount; |
|
88 |
} |
|
89 |
MemoryPoolMXBean getPool() { |
|
90 |
return pool; |
|
91 |
} |
|
92 |
void addNotification(MemoryNotificationInfo minfo) { |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
93 |
listenerInvoked.incrementAndGet(); |
2 | 94 |
notifCount = minfo.getCount(); |
95 |
} |
|
96 |
} |
|
97 |
||
98 |
static class SensorListener implements NotificationListener { |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
99 |
@Override |
2 | 100 |
public void handleNotification(Notification notif, Object handback) { |
101 |
String type = notif.getType(); |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
102 |
if (MEMORY_THRESHOLD_EXCEEDED.equals(type) || |
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
103 |
MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(type)) { |
2 | 104 |
MemoryNotificationInfo minfo = MemoryNotificationInfo. |
105 |
from((CompositeData) notif.getUserData()); |
|
106 |
||
107 |
MemoryUtil.printMemoryNotificationInfo(minfo, type); |
|
108 |
PoolRecord pr = (PoolRecord) result.get(minfo.getPoolName()); |
|
109 |
if (pr == null) { |
|
110 |
throw new RuntimeException("Pool " + minfo.getPoolName() + |
|
111 |
" is not selected"); |
|
112 |
} |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
113 |
if (!MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(type)) { |
2 | 114 |
throw new RuntimeException("Pool " + minfo.getPoolName() + |
115 |
" got unexpected notification type: " + |
|
116 |
type); |
|
117 |
} |
|
118 |
pr.addNotification(minfo); |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
119 |
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
|
120 |
signals.release(); |
2 | 121 |
} |
122 |
} |
|
123 |
} |
|
124 |
||
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
125 |
private static class TestMain { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
trace = true; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
129 |
} |
2 | 130 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
131 |
List<MemoryPoolMXBean> pools = getMemoryPoolMXBeans(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
132 |
List<MemoryManagerMXBean> managers = getMemoryManagerMXBeans(); |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
133 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
134 |
if (trace) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
135 |
MemoryUtil.printMemoryPools(pools); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
136 |
MemoryUtil.printMemoryManagers(managers); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
137 |
} |
2 | 138 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
139 |
// 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
|
140 |
for (MemoryPoolMXBean p : pools) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
141 |
if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
142 |
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
|
143 |
// 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
|
144 |
// memory pools by one. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
145 |
numMemoryPools++; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
146 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
147 |
PoolRecord pr = new PoolRecord(p); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
148 |
result.put(p.getName(), pr); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
149 |
if (result.size() == numMemoryPools) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
150 |
break; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
151 |
} |
2 | 152 |
} |
153 |
} |
|
23933
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 |
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
|
156 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
157 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
158 |
try { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
159 |
// 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
|
160 |
// 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
|
161 |
// 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
|
162 |
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
|
163 |
checker.setDaemon(true); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
164 |
checker.start(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
165 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
166 |
for (PoolRecord pr : result.values()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
167 |
pr.getPool().setCollectionUsageThreshold(THRESHOLD); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
171 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
172 |
SensorListener listener = new SensorListener(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
173 |
NotificationEmitter emitter = (NotificationEmitter) mm; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
174 |
emitter.addNotificationListener(listener, null, null); |
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 |
// 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
|
177 |
// 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
|
178 |
// 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
|
179 |
// |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
180 |
// 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
|
181 |
// 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
|
182 |
// 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
|
183 |
// 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
|
184 |
// 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
|
185 |
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
|
186 |
invokeGC(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
187 |
barrier.await(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
188 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
189 |
} finally { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
190 |
// restore the default |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
191 |
for (PoolRecord pr : result.values()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
192 |
pr.getPool().setCollectionUsageThreshold(0); |
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 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
195 |
System.out.println(RunUtil.successMessage); |
2 | 196 |
} |
197 |
||
5808
3a1f603c5ca7
6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents:
5506
diff
changeset
|
198 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
199 |
private static void invokeGC() { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
200 |
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
|
201 |
numGCs++; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
202 |
mm.gc(); |
2 | 203 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
204 |
if (trace) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
205 |
for (PoolRecord pr : result.values()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
206 |
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
|
207 |
MemoryUtil.printMemoryUsage(pr.getPool().getUsage()); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
21973
diff
changeset
|
208 |
} |
2 | 209 |
} |
210 |
} |
|
211 |
} |
|
212 |
||
213 |
static class Checker extends Thread { |
|
214 |
Checker(String name) { |
|
215 |
super(name); |
|
216 |
}; |
|
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
217 |
@Override |
2 | 218 |
public void run() { |
219 |
while (true) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
220 |
try { |
13784 | 221 |
signals.acquire(numMemoryPools); |
2 | 222 |
checkResult(); |
21973
1c152053cba6
7067973: test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java hanging intermittently
mchung
parents:
14342
diff
changeset
|
223 |
} catch (InterruptedException | BrokenBarrierException e) { |
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
224 |
throw new RuntimeException(e); |
2 | 225 |
} |
226 |
} |
|
227 |
} |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
228 |
private void checkResult() throws InterruptedException, BrokenBarrierException { |
5808
3a1f603c5ca7
6961894: TEST_BUG: jdk_lang tests fail in samevm mode
mchung
parents:
5506
diff
changeset
|
229 |
for (PoolRecord pr : result.values()) { |
2 | 230 |
if (pr.getListenerInvokedCount() != numGCs) { |
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
231 |
fail("Listeners invoked count = " + |
2 | 232 |
pr.getListenerInvokedCount() + " expected to be " + |
233 |
numGCs); |
|
234 |
} |
|
235 |
if (pr.getNotifCount() != numGCs) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
236 |
fail("Notif Count = " + |
2 | 237 |
pr.getNotifCount() + " expected to be " + |
238 |
numGCs); |
|
239 |
} |
|
240 |
||
241 |
long count = pr.getPool().getCollectionUsageThresholdCount(); |
|
242 |
if (count != numGCs) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
243 |
fail("CollectionUsageThresholdCount = " + |
2 | 244 |
count + " expected to be " + numGCs); |
245 |
} |
|
246 |
if (!pr.getPool().isCollectionUsageThresholdExceeded()) { |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
247 |
fail("isCollectionUsageThresholdExceeded" + |
2 | 248 |
" expected to be true"); |
249 |
} |
|
250 |
} |
|
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
251 |
// 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
|
252 |
barrier.await(); |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
253 |
System.out.println("notifying main thread to continue - result checking finished"); |
2 | 254 |
} |
255 |
||
7019
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
256 |
private void fail(String msg) { |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
257 |
// 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
|
258 |
barrier.reset(); |
f2f6b61d34ac
6992968: test/java/lang/management/MemoryMXBean/CollectionUsageThresholdConcMarkSweepGC.sh should not hang
mchung
parents:
5808
diff
changeset
|
259 |
throw new RuntimeException(msg); |
2 | 260 |
} |
261 |
} |
|
262 |
} |