author | stefank |
Tue, 19 Aug 2014 12:18:09 +0200 | |
changeset 25999 | 1e494b91a5a5 |
parent 24366 | 57c0a8b7a936 |
child 26459 | fa5576f930e6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2003, 2010, 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 |
|
26 |
* @bug 4530538 |
|
27 |
* @summary Basic unit test of memory management testing: |
|
28 |
* 1) setUsageThreshold() and getUsageThreshold() |
|
29 |
* 2) test low memory detection on the old generation. |
|
30 |
* |
|
31 |
* @author Mandy Chung |
|
32 |
* |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
33 |
* @library /lib/testlibrary/ |
24366
57c0a8b7a936
8034960: Serviceability tests using @library failing with java.lang.NoClassDefFoundError
ykantser
parents:
23933
diff
changeset
|
34 |
* @build jdk.testlibrary.* LowMemoryTest MemoryUtil RunUtil |
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
35 |
* @run main/timeout=600 LowMemoryTest |
2 | 36 |
*/ |
37 |
||
38 |
import java.lang.management.*; |
|
39 |
import java.util.*; |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
40 |
import java.util.concurrent.Phaser; |
2 | 41 |
import javax.management.*; |
42 |
import javax.management.openmbean.CompositeData; |
|
43 |
||
44 |
public class LowMemoryTest { |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
45 |
private static final MemoryMXBean mm = ManagementFactory.getMemoryMXBean(); |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
46 |
private static final List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
47 |
private static final Phaser phaser = new Phaser(2); |
2 | 48 |
private static MemoryPoolMXBean mpool = null; |
49 |
private static boolean trace = false; |
|
50 |
private static boolean testFailed = false; |
|
51 |
private static final int NUM_TRIGGERS = 5; |
|
52 |
private static final int NUM_CHUNKS = 2; |
|
25999
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
53 |
private static final int YOUNG_GEN_SIZE = 8 * 1024 * 1024; |
2 | 54 |
private static long chunkSize; |
55 |
||
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
56 |
/** |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
57 |
* 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:
22075
diff
changeset
|
58 |
* 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:
22075
diff
changeset
|
59 |
* Then with GC versions specified by the test. |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
60 |
*/ |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
61 |
public static void main(String a[]) throws Throwable { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
62 |
final String main = "LowMemoryTest$TestMain"; |
25999
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
63 |
// Use a low young gen size to ensure that the |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
64 |
// allocated objects are put in the old gen. |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
65 |
final String nmFlag = "-Xmn" + YOUNG_GEN_SIZE; |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
66 |
RunUtil.runTestKeepGcOpts(main, nmFlag); |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
67 |
RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseSerialGC"); |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
68 |
RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseParallelGC"); |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
69 |
RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseG1GC"); |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
70 |
RunUtil.runTestClearGcOpts(main, nmFlag, "-XX:+UseConcMarkSweepGC"); |
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
71 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
72 |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
73 |
private static volatile boolean listenerInvoked = false; |
2 | 74 |
static class SensorListener implements NotificationListener { |
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
75 |
@Override |
2 | 76 |
public void handleNotification(Notification notif, Object handback) { |
77 |
String type = notif.getType(); |
|
78 |
if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) || |
|
79 |
type.equals(MemoryNotificationInfo. |
|
80 |
MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) { |
|
81 |
||
82 |
MemoryNotificationInfo minfo = MemoryNotificationInfo. |
|
83 |
from((CompositeData) notif.getUserData()); |
|
84 |
||
85 |
MemoryUtil.printMemoryNotificationInfo(minfo, type); |
|
86 |
listenerInvoked = true; |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
static class TestListener implements NotificationListener { |
|
92 |
private int triggers = 0; |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
93 |
private final long[] count = new long[NUM_TRIGGERS * 2]; |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
94 |
private final long[] usedMemory = new long[NUM_TRIGGERS * 2]; |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
95 |
@Override |
2 | 96 |
public void handleNotification(Notification notif, Object handback) { |
97 |
MemoryNotificationInfo minfo = MemoryNotificationInfo. |
|
98 |
from((CompositeData) notif.getUserData()); |
|
99 |
count[triggers] = minfo.getCount(); |
|
100 |
usedMemory[triggers] = minfo.getUsage().getUsed(); |
|
101 |
triggers++; |
|
102 |
} |
|
103 |
public void checkResult() throws Exception { |
|
104 |
if (triggers != NUM_TRIGGERS) { |
|
105 |
throw new RuntimeException("Unexpected number of triggers = " + |
|
106 |
triggers + " but expected to be " + NUM_TRIGGERS); |
|
107 |
} |
|
108 |
||
109 |
for (int i = 0; i < triggers; i++) { |
|
110 |
if (count[i] != i+1) { |
|
111 |
throw new RuntimeException("Unexpected count of" + |
|
112 |
" notification #" + i + |
|
113 |
" count = " + count[i] + |
|
114 |
" but expected to be " + (i+1)); |
|
115 |
} |
|
116 |
if (usedMemory[i] < newThreshold) { |
|
117 |
throw new RuntimeException("Used memory = " + |
|
118 |
usedMemory[i] + " is less than the threshold = " + |
|
119 |
newThreshold); |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
private static long newThreshold; |
|
126 |
||
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
127 |
private static class TestMain { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
128 |
public static void main(String args[]) throws Exception { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
129 |
if (args.length > 0 && args[0].equals("trace")) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
130 |
trace = true; |
2 | 131 |
} |
132 |
||
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
133 |
// 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:
22075
diff
changeset
|
134 |
ListIterator iter = pools.listIterator(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
135 |
while (iter.hasNext()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
136 |
MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
137 |
if (p.getType() == MemoryType.HEAP && |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
138 |
p.isUsageThresholdSupported()) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
139 |
mpool = p; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
140 |
if (trace) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
141 |
System.out.println("Selected memory pool for low memory " + |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
142 |
"detection."); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
143 |
MemoryUtil.printMemoryPool(mpool); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
144 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
145 |
break; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
146 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
147 |
} |
2 | 148 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
149 |
TestListener listener = new TestListener(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
150 |
SensorListener l2 = new SensorListener(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
151 |
NotificationEmitter emitter = (NotificationEmitter) mm; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
152 |
emitter.addNotificationListener(listener, null, null); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
153 |
emitter.addNotificationListener(l2, null, null); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
154 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
155 |
Thread allocator = new AllocatorThread(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
156 |
Thread sweeper = new SweeperThread(); |
2 | 157 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
158 |
// Now set threshold |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
159 |
MemoryUsage mu = mpool.getUsage(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
160 |
chunkSize = (mu.getMax() - mu.getUsed()) / 20; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
161 |
newThreshold = mu.getUsed() + (chunkSize * NUM_CHUNKS); |
2 | 162 |
|
25999
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
163 |
// Sanity check. Make sure the chunkSize is large than the YOUNG_GEN_SIZE |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
164 |
// If the chunkSize are lower than the YOUNG_GEN_SIZE, we will get intermittent |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
165 |
// failures when objects end up in the young gen instead of the old gen. |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
166 |
// Tweak the test if this fails. |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
167 |
if (chunkSize < YOUNG_GEN_SIZE) { |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
168 |
throw new RuntimeException("TEST FAILED: " + |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
169 |
" chunkSize: " + chunkSize + " is less than YOUNG_GEN_SIZE: " + YOUNG_GEN_SIZE + |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
170 |
" max: " + mu.getMax() + " used: " + mu.getUsed() + " newThreshold: " + newThreshold); |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
171 |
} |
1e494b91a5a5
8035939: java/lang/management/MemoryMXBean/MemoryManagement.java timed out on Linux-amd64
stefank
parents:
24366
diff
changeset
|
172 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
173 |
System.out.println("Setting threshold for " + mpool.getName() + |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
174 |
" from " + mpool.getUsageThreshold() + " to " + newThreshold + |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
175 |
". Current used = " + mu.getUsed()); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
176 |
mpool.setUsageThreshold(newThreshold); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
177 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
178 |
if (mpool.getUsageThreshold() != newThreshold) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
179 |
throw new RuntimeException("TEST FAILED: " + |
2 | 180 |
"Threshold for Memory pool " + mpool.getName() + |
181 |
"is " + mpool.getUsageThreshold() + " but expected to be" + |
|
182 |
newThreshold); |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
183 |
} |
2 | 184 |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
185 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
186 |
allocator.start(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
187 |
// Force Allocator start first |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
188 |
phaser.arriveAndAwaitAdvance(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
189 |
sweeper.start(); |
2 | 190 |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
191 |
|
23933
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
192 |
try { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
193 |
allocator.join(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
194 |
// Wait until AllocatorThread's done |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
195 |
phaser.arriveAndAwaitAdvance(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
196 |
sweeper.join(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
197 |
} catch (InterruptedException e) { |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
198 |
System.out.println("Unexpected exception:" + e); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
199 |
testFailed = true; |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
200 |
} |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
201 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
202 |
listener.checkResult(); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
203 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
204 |
if (testFailed) |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
205 |
throw new RuntimeException("TEST FAILED."); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
206 |
|
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
207 |
System.out.println(RunUtil.successMessage); |
754ee146b623
8030628: Update java/lang/management/MemoryMXBean tests to ignore GC setting by jtreg
mtobiass
parents:
22075
diff
changeset
|
208 |
|
2 | 209 |
} |
210 |
} |
|
211 |
||
212 |
private static void goSleep(long ms) { |
|
213 |
try { |
|
214 |
Thread.sleep(ms); |
|
215 |
} catch (InterruptedException e) { |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
216 |
System.out.println("Unexpected exception:" + e); |
2 | 217 |
testFailed = true; |
218 |
} |
|
219 |
} |
|
220 |
||
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
221 |
private static final List<Object> objectPool = new ArrayList<>(); |
2 | 222 |
static class AllocatorThread extends Thread { |
223 |
public void doTask() { |
|
224 |
int iterations = 0; |
|
225 |
int numElements = (int) (chunkSize / 4); // minimal object size |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
226 |
while (!listenerInvoked || mpool.getUsage().getUsed() < mpool.getUsageThreshold()) { |
2 | 227 |
iterations++; |
228 |
if (trace) { |
|
229 |
System.out.println(" Iteration " + iterations + |
|
230 |
": before allocation " + |
|
231 |
mpool.getUsage().getUsed()); |
|
232 |
} |
|
233 |
||
234 |
Object[] o = new Object[numElements]; |
|
235 |
if (iterations <= NUM_CHUNKS) { |
|
236 |
// only hold a reference to the first NUM_CHUNKS |
|
237 |
// allocated objects |
|
238 |
objectPool.add(o); |
|
239 |
} |
|
240 |
||
241 |
if (trace) { |
|
242 |
System.out.println(" " + |
|
243 |
" after allocation " + |
|
244 |
mpool.getUsage().getUsed()); |
|
245 |
} |
|
246 |
goSleep(100); |
|
247 |
} |
|
248 |
} |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
249 |
@Override |
2 | 250 |
public void run() { |
251 |
for (int i = 1; i <= NUM_TRIGGERS; i++) { |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
252 |
// Sync with SweeperThread's second phase. |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
253 |
phaser.arriveAndAwaitAdvance(); |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
254 |
System.out.println("AllocatorThread is doing task " + i + |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
255 |
" phase " + phaser.getPhase()); |
2 | 256 |
doTask(); |
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
257 |
// Sync with SweeperThread's first phase. |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
258 |
phaser.arriveAndAwaitAdvance(); |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
259 |
System.out.println("AllocatorThread done task " + i + |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
260 |
" phase " + phaser.getPhase()); |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
261 |
if (testFailed) { |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
262 |
return; |
2 | 263 |
} |
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
static class SweeperThread extends Thread { |
|
269 |
private void doTask() { |
|
270 |
for (; mpool.getUsage().getUsed() >= |
|
271 |
mpool.getUsageThreshold();) { |
|
272 |
// clear all allocated objects and invoke GC |
|
273 |
objectPool.clear(); |
|
274 |
mm.gc(); |
|
275 |
goSleep(100); |
|
276 |
} |
|
277 |
} |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
278 |
@Override |
2 | 279 |
public void run() { |
280 |
for (int i = 1; i <= NUM_TRIGGERS; i++) { |
|
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
281 |
// Sync with AllocatorThread's first phase. |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
282 |
phaser.arriveAndAwaitAdvance(); |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
283 |
System.out.println("SweepThread is doing task " + i + |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
284 |
" phase " + phaser.getPhase()); |
2 | 285 |
doTask(); |
286 |
||
287 |
listenerInvoked = false; |
|
288 |
||
22075
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
289 |
// Sync with AllocatorThread's second phase. |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
290 |
phaser.arriveAndAwaitAdvance(); |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
291 |
System.out.println("SweepThread done task " + i + |
4c204174a8d9
8029346: LowMemoryTestConcMarkSweepGC.sh fails intermittently with timeout
mchung
parents:
7668
diff
changeset
|
292 |
" phase " + phaser.getPhase()); |
2 | 293 |
if (testFailed) return; |
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
} |