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