author | lkorinth |
Mon, 28 Jan 2019 15:53:56 +0100 | |
changeset 53523 | 4c5184c56dc2 |
parent 48883 | 0f1be3c7b6b2 |
permissions | -rw-r--r-- |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
1 |
/* |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48883
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
4 |
* |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
8 |
* |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
13 |
* accompanied this code). |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
14 |
* |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
18 |
* |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
21 |
* questions. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
22 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
23 |
|
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48883
diff
changeset
|
24 |
package gc.stress; |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48883
diff
changeset
|
25 |
|
42578
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
26 |
/* |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
27 |
* @test TestStressG1Humongous |
48883
0f1be3c7b6b2
8197113: combine multiple @key tags in jtreg tests
iignatyev
parents:
47216
diff
changeset
|
28 |
* @key gc stress |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
29 |
* @summary Stress G1 by humongous allocations in situation near OOM |
39414
4adf52148100
8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents:
39294
diff
changeset
|
30 |
* @requires vm.gc.G1 |
39294
4be906c4ad95
8158412: [TESTBUG] TestIHOPErgo and TestStressG1Humongous should not be executed when JFR is enabled
mchernov
parents:
38085
diff
changeset
|
31 |
* @requires !vm.flightRecorder |
43409
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
32 |
* @library /test/lib |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
33 |
* @modules java.base/jdk.internal.misc |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48883
diff
changeset
|
34 |
* @run driver/timeout=1300 gc.stress.TestStressG1Humongous |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
35 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
36 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
37 |
import java.util.ArrayList; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
38 |
import java.util.List; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
39 |
import java.util.Collections; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
40 |
import java.util.concurrent.CountDownLatch; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
41 |
import java.util.concurrent.atomic.AtomicInteger; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
42 |
|
43409
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
43 |
import jdk.test.lib.Platform; |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
44 |
import jdk.test.lib.Utils; |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
45 |
import jdk.test.lib.process.ProcessTools; |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
46 |
import jdk.test.lib.process.OutputAnalyzer; |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
47 |
|
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
48 |
public class TestStressG1Humongous{ |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
49 |
|
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
50 |
public static void main(String[] args) throws Exception { |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
51 |
// Limit heap size on 32-bit platforms |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
52 |
int heapSize = Platform.is32bit() ? 512 : 1024; |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
53 |
// Heap size, region size, threads, humongous size, timeout |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
54 |
run(heapSize, 4, 3, 1.1, 120); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
55 |
run(heapSize, 16, 5, 2.1, 120); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
56 |
run(heapSize, 32, 4, 0.6, 120); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
57 |
run(heapSize, 1, 7, 0.6, 600); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
58 |
} |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
59 |
|
43409
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
60 |
private static void run(int heapSize, int regionSize, int threads, double humongousSize, int timeout) |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
61 |
throws Exception { |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
62 |
ArrayList<String> options = new ArrayList<>(); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
63 |
Collections.addAll(options, Utils.getTestJavaOpts()); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
64 |
Collections.addAll(options, |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
65 |
"-Xlog:gc=debug", |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
66 |
"-Xmx" + heapSize + "m", |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
67 |
"-XX:+UseG1GC", |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
68 |
"-XX:G1HeapRegionSize=" + regionSize + "m", |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
69 |
"-Dtimeout=" + timeout, |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
70 |
"-Dthreads=" + threads, |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
71 |
"-Dhumongoussize=" + humongousSize, |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
72 |
"-Dregionsize=" + regionSize, |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
73 |
TestStressG1HumongousImpl.class.getName() |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
74 |
); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
75 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(options.toArray(new String[options.size()])); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
76 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
77 |
output.shouldHaveExitValue(0); |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
78 |
} |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
79 |
} |
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
80 |
|
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
81 |
class TestStressG1HumongousImpl { |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
82 |
// Timeout in seconds |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
83 |
private static final int TIMEOUT = Integer.getInteger("timeout", 60); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
84 |
private static final int THREAD_COUNT = Integer.getInteger("threads", 2); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
85 |
private static final int REGION_SIZE = Integer.getInteger("regionsize", 1) * 1024 * 1024; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
86 |
private static final int HUMONGOUS_SIZE = (int) (REGION_SIZE * Double.parseDouble(System.getProperty("humongoussize", "1.5"))); |
39981
eb1282859915
8160827: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39978
diff
changeset
|
87 |
private static final int NUMBER_OF_FREE_REGIONS = 2; |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
88 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
89 |
private volatile boolean isRunning; |
42578
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
90 |
private final Thread[] threads; |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
91 |
private final AtomicInteger alocatedObjectsCount; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
92 |
private CountDownLatch countDownLatch; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
93 |
public static final List<Object> GARBAGE = Collections.synchronizedList(new ArrayList<>()); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
94 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
95 |
public static void main(String[] args) throws InterruptedException { |
43409
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
96 |
new TestStressG1HumongousImpl().run(); |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
97 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
98 |
|
43409
c14391b636c9
8171045: gc/stress/TestStressG1Humongous.java fails to allocate the heap
mchernov
parents:
42578
diff
changeset
|
99 |
public TestStressG1HumongousImpl() { |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
100 |
isRunning = true; |
42578
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
101 |
threads = new Thread[THREAD_COUNT]; |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
102 |
alocatedObjectsCount = new AtomicInteger(0); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
103 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
104 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
105 |
private void run() throws InterruptedException { |
42578
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
106 |
new Thread(new Timer()).start(); |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
107 |
int checkedAmountOfHObjects = getExpectedAmountOfObjects(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
108 |
while (isRunning()) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
109 |
countDownLatch = new CountDownLatch(THREAD_COUNT); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
110 |
startAllocationThreads(checkedAmountOfHObjects); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
111 |
countDownLatch.await(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
112 |
GARBAGE.clear(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
113 |
System.out.println("Allocated " + alocatedObjectsCount.get() + " objects."); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
114 |
alocatedObjectsCount.set(0); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
115 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
116 |
System.out.println("Done!"); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
117 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
118 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
119 |
/** |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
120 |
* Tries to fill available memory with humongous objects to get expected amount. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
121 |
* @return expected amount of humongous objects |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
122 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
123 |
private int getExpectedAmountOfObjects() { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
124 |
long maxMem = Runtime.getRuntime().maxMemory(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
125 |
int expectedHObjects = (int) (maxMem / HUMONGOUS_SIZE); |
39981
eb1282859915
8160827: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39978
diff
changeset
|
126 |
// Will allocate NUMBER_OF_FREE_REGIONS region less to give some free space for VM. |
eb1282859915
8160827: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39978
diff
changeset
|
127 |
int checkedAmountOfHObjects = checkHeapCapacity(expectedHObjects) - NUMBER_OF_FREE_REGIONS; |
eb1282859915
8160827: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39978
diff
changeset
|
128 |
if (checkedAmountOfHObjects <= 0) { |
eb1282859915
8160827: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39978
diff
changeset
|
129 |
throw new RuntimeException("Cannot start testing because selected maximum heap " |
eb1282859915
8160827: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39978
diff
changeset
|
130 |
+ "is not large enough to contain more than " + NUMBER_OF_FREE_REGIONS + " regions"); |
eb1282859915
8160827: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39978
diff
changeset
|
131 |
} |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
132 |
return checkedAmountOfHObjects; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
133 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
134 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
135 |
/** |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
136 |
* Starts several threads to allocate the requested amount of humongous objects. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
137 |
* @param totalObjects total amount of object that will be created |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
138 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
139 |
private void startAllocationThreads(int totalObjects) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
140 |
int objectsPerThread = totalObjects / THREAD_COUNT; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
141 |
int objectsForLastThread = objectsPerThread + totalObjects % THREAD_COUNT; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
142 |
for (int i = 0; i < THREAD_COUNT - 1; ++i) { |
42578
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
143 |
threads[i] = new Thread(new AllocationThread(countDownLatch, objectsPerThread, alocatedObjectsCount)); |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
144 |
} |
42578
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
145 |
threads[THREAD_COUNT - 1] = new Thread(new AllocationThread(countDownLatch, objectsForLastThread, alocatedObjectsCount)); |
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
146 |
for (int i = 0; i < THREAD_COUNT; ++i) { |
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
147 |
threads[i].start(); |
97304d7c80fe
8166719: gc/stress/TestStressG1Humongous.java fails with OOME
mchernov
parents:
39981
diff
changeset
|
148 |
} |
38085
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
149 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
150 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
151 |
/** |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
152 |
* Creates a humongous object of the predefined size. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
153 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
154 |
private void createObject() { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
155 |
GARBAGE.add(new byte[HUMONGOUS_SIZE]); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
156 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
157 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
158 |
/** |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
159 |
* Tries to create the requested amount of humongous objects. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
160 |
* In case of OOME, stops creating and cleans the created garbage. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
161 |
* @param expectedObjects amount of objects based on heap size |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
162 |
* @return amount of created objects |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
163 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
164 |
private int checkHeapCapacity(int expectedObjects) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
165 |
int allocated = 0; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
166 |
try { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
167 |
while (isRunning() && allocated < expectedObjects) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
168 |
createObject(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
169 |
++allocated; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
170 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
171 |
} catch (OutOfMemoryError oome) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
172 |
GARBAGE.clear(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
173 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
174 |
return allocated; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
175 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
176 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
177 |
private void setDone() { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
178 |
isRunning = false; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
179 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
180 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
181 |
private boolean isRunning() { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
182 |
return isRunning; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
183 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
184 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
185 |
/** |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
186 |
* Thread which allocates requested amount of humongous objects. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
187 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
188 |
private class AllocationThread implements Runnable { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
189 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
190 |
private final int totalObjects; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
191 |
private final CountDownLatch cdl; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
192 |
private final AtomicInteger allocationCounter; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
193 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
194 |
/** |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
195 |
* Creates allocation thread |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
196 |
* @param cdl CountDownLatch |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
197 |
* @param objects amount of objects to allocate |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
198 |
* @param counter |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
199 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
200 |
public AllocationThread(CountDownLatch cdl, int objects, AtomicInteger counter) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
201 |
totalObjects = objects; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
202 |
this.cdl = cdl; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
203 |
allocationCounter = counter; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
204 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
205 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
206 |
@Override |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
207 |
public void run() { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
208 |
int allocatedObjects = 0; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
209 |
try { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
210 |
while (isRunning && allocatedObjects < totalObjects) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
211 |
createObject(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
212 |
allocatedObjects++; |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
213 |
allocationCounter.incrementAndGet(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
214 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
215 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
216 |
} catch (OutOfMemoryError oome) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
217 |
GARBAGE.clear(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
218 |
System.out.print("OOME was caught."); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
219 |
System.out.println(" Allocated in thread: " + allocatedObjects + " . Totally allocated: " + allocationCounter.get() + "."); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
220 |
} finally { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
221 |
cdl.countDown(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
222 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
223 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
224 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
225 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
226 |
/** |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
227 |
* Simple Runnable which waits TIMEOUT and sets isRunning to false. |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
228 |
*/ |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
229 |
class Timer implements Runnable { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
230 |
|
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
231 |
@Override |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
232 |
public void run() { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
233 |
try { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
234 |
Thread.sleep(TIMEOUT * 1000); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
235 |
} catch (InterruptedException ex) { |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
236 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
237 |
setDone(); |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
238 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
239 |
} |
795e6a867668
8154341: [TESTBUG] G1 stress test for humongous objects allocation
mchernov
parents:
diff
changeset
|
240 |
} |