57607
|
1 |
/*
|
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
|
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 |
*
|
|
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.
|
|
22 |
*/
|
|
23 |
|
|
24 |
package gc.stress.gclocker;
|
|
25 |
|
|
26 |
/*
|
|
27 |
* @test TestExcessGCLockerCollections
|
|
28 |
* @key gc
|
|
29 |
* @bug 8048556
|
|
30 |
* @summary Check for GC Locker initiated GCs that immediately follow another
|
|
31 |
* GC and so have very little needing to be collected.
|
|
32 |
* @requires vm.gc != "Z"
|
|
33 |
* @requires vm.gc != "Epsilon"
|
|
34 |
* @requires vm.gc != "Shenandoah"
|
|
35 |
* @library /test/lib
|
|
36 |
* @modules java.base/jdk.internal.misc
|
|
37 |
* @run driver/timeout=1000 gc.stress.gclocker.TestExcessGCLockerCollections 300 4 2
|
|
38 |
*/
|
|
39 |
|
|
40 |
import java.util.HashMap;
|
|
41 |
import java.util.Map;
|
|
42 |
|
|
43 |
import java.util.zip.Deflater;
|
|
44 |
|
|
45 |
import java.util.ArrayList;
|
|
46 |
import java.util.Arrays;
|
|
47 |
|
|
48 |
import jdk.test.lib.Asserts;
|
|
49 |
import jdk.test.lib.process.ProcessTools;
|
|
50 |
import jdk.test.lib.process.OutputAnalyzer;
|
|
51 |
|
|
52 |
class TestExcessGCLockerCollectionsAux {
|
|
53 |
static private final int LARGE_MAP_SIZE = 64 * 1024;
|
|
54 |
|
|
55 |
static private final int MAP_ARRAY_LENGTH = 4;
|
|
56 |
static private final int MAP_SIZE = 1024;
|
|
57 |
|
|
58 |
static private final int BYTE_ARRAY_LENGTH = 128 * 1024;
|
|
59 |
|
|
60 |
static private void println(String str) { System.out.println(str); }
|
|
61 |
|
|
62 |
static private volatile boolean keepRunning = true;
|
|
63 |
|
|
64 |
static Map<Integer,String> populateMap(int size) {
|
|
65 |
Map<Integer,String> map = new HashMap<Integer,String>();
|
|
66 |
for (int i = 0; i < size; i += 1) {
|
|
67 |
Integer keyInt = Integer.valueOf(i);
|
|
68 |
String valStr = "value is [" + i + "]";
|
|
69 |
map.put(keyInt,valStr);
|
|
70 |
}
|
|
71 |
return map;
|
|
72 |
}
|
|
73 |
|
|
74 |
static private class AllocatingWorker implements Runnable {
|
|
75 |
private final Object[] array = new Object[MAP_ARRAY_LENGTH];
|
|
76 |
private int arrayIndex = 0;
|
|
77 |
|
|
78 |
private void doStep() {
|
|
79 |
Map<Integer,String> map = populateMap(MAP_SIZE);
|
|
80 |
array[arrayIndex] = map;
|
|
81 |
arrayIndex = (arrayIndex + 1) % MAP_ARRAY_LENGTH;
|
|
82 |
}
|
|
83 |
|
|
84 |
public void run() {
|
|
85 |
while (keepRunning) {
|
|
86 |
doStep();
|
|
87 |
}
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
static private class JNICriticalWorker implements Runnable {
|
|
92 |
private int count;
|
|
93 |
|
|
94 |
private void doStep() {
|
|
95 |
byte[] inputArray = new byte[BYTE_ARRAY_LENGTH];
|
|
96 |
for (int i = 0; i < inputArray.length; i += 1) {
|
|
97 |
inputArray[i] = (byte) (count + i);
|
|
98 |
}
|
|
99 |
|
|
100 |
Deflater deflater = new Deflater();
|
|
101 |
deflater.setInput(inputArray);
|
|
102 |
deflater.finish();
|
|
103 |
|
|
104 |
byte[] outputArray = new byte[2 * inputArray.length];
|
|
105 |
deflater.deflate(outputArray);
|
|
106 |
|
|
107 |
count += 1;
|
|
108 |
}
|
|
109 |
|
|
110 |
public void run() {
|
|
111 |
while (keepRunning) {
|
|
112 |
doStep();
|
|
113 |
}
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
static public Map<Integer,String> largeMap;
|
|
118 |
|
|
119 |
static public void main(String args[]) {
|
|
120 |
long durationSec = Long.parseLong(args[0]);
|
|
121 |
int allocThreadNum = Integer.parseInt(args[1]);
|
|
122 |
int jniCriticalThreadNum = Integer.parseInt(args[2]);
|
|
123 |
|
|
124 |
println("Running for " + durationSec + " secs");
|
|
125 |
|
|
126 |
largeMap = populateMap(LARGE_MAP_SIZE);
|
|
127 |
|
|
128 |
println("Starting " + allocThreadNum + " allocating threads");
|
|
129 |
for (int i = 0; i < allocThreadNum; i += 1) {
|
|
130 |
new Thread(new AllocatingWorker()).start();
|
|
131 |
}
|
|
132 |
|
|
133 |
println("Starting " + jniCriticalThreadNum + " jni critical threads");
|
|
134 |
for (int i = 0; i < jniCriticalThreadNum; i += 1) {
|
|
135 |
new Thread(new JNICriticalWorker()).start();
|
|
136 |
}
|
|
137 |
|
|
138 |
long durationMS = (long) (1000 * durationSec);
|
|
139 |
long start = System.currentTimeMillis();
|
|
140 |
long now = start;
|
|
141 |
long soFar = now - start;
|
|
142 |
while (soFar < durationMS) {
|
|
143 |
try {
|
|
144 |
Thread.sleep(durationMS - soFar);
|
|
145 |
} catch (Exception e) {
|
|
146 |
}
|
|
147 |
now = System.currentTimeMillis();
|
|
148 |
soFar = now - start;
|
|
149 |
}
|
|
150 |
println("Done.");
|
|
151 |
keepRunning = false;
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
public class TestExcessGCLockerCollections {
|
|
156 |
private static final String locker =
|
|
157 |
"\\[gc\\s*\\] .* \\(GCLocker Initiated GC\\)";
|
|
158 |
private static final String ANY_LOCKER = locker + " [1-9][0-9]*M";
|
|
159 |
private static final String BAD_LOCKER = locker + " [1-9][0-9]?M";
|
|
160 |
|
|
161 |
private static final String[] COMMON_OPTIONS = new String[] {
|
|
162 |
"-Xmx1G", "-Xms1G", "-Xmn256M", "-Xlog:gc" };
|
|
163 |
|
|
164 |
public static void main(String args[]) throws Exception {
|
|
165 |
if (args.length < 3) {
|
|
166 |
System.out.println("usage: TestExcessGCLockerCollectionsAux" +
|
|
167 |
" <duration sec> <alloc threads>" +
|
|
168 |
" <jni critical threads>");
|
|
169 |
throw new RuntimeException("Invalid arguments");
|
|
170 |
}
|
|
171 |
|
|
172 |
ArrayList<String> finalArgs = new ArrayList<String>();
|
|
173 |
finalArgs.addAll(Arrays.asList(COMMON_OPTIONS));
|
|
174 |
finalArgs.add(TestExcessGCLockerCollectionsAux.class.getName());
|
|
175 |
finalArgs.addAll(Arrays.asList(args));
|
|
176 |
|
|
177 |
// GC and other options obtained from test framework.
|
|
178 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
|
179 |
true, finalArgs.toArray(new String[0]));
|
|
180 |
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
|
181 |
output.shouldHaveExitValue(0);
|
|
182 |
//System.out.println("------------- begin stdout ----------------");
|
|
183 |
//System.out.println(output.getStdout());
|
|
184 |
//System.out.println("------------- end stdout ----------------");
|
|
185 |
output.stdoutShouldMatch(ANY_LOCKER);
|
|
186 |
output.stdoutShouldNotMatch(BAD_LOCKER);
|
|
187 |
}
|
|
188 |
}
|