1 /*
2 * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 /*
26 * @test id=default
27 * @summary Test clone barriers work correctly
28 * @requires vm.gc.Shenandoah
29 *
30 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
31 * -XX:+UseShenandoahGC
32 * TestClone
33 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
34 * -XX:+UseShenandoahGC
35 * -Xint
36 * TestClone
37 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
38 * -XX:+UseShenandoahGC
39 * -XX:-TieredCompilation
40 * TestClone
41 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
42 * -XX:+UseShenandoahGC
43 * -XX:TieredStopAtLevel=1
44 * TestClone
45 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
46 * -XX:+UseShenandoahGC
47 * -XX:TieredStopAtLevel=4
48 * TestClone
49 */
50
51 /*
52 * @test id=default-verify
53 * @summary Test clone barriers work correctly
54 * @requires vm.gc.Shenandoah
55 *
56 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
57 * -XX:+UseShenandoahGC
58 * -XX:+ShenandoahVerify
59 * TestClone
60 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
61 * -XX:+UseShenandoahGC
62 * -XX:+ShenandoahVerify
63 * -Xint
64 * TestClone
65 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
66 * -XX:+UseShenandoahGC
67 * -XX:+ShenandoahVerify
68 * -XX:-TieredCompilation
69 * TestClone
70 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
71 * -XX:+UseShenandoahGC
72 * -XX:+ShenandoahVerify
73 * -XX:TieredStopAtLevel=1
74 * TestClone
75 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
76 * -XX:+UseShenandoahGC
77 * -XX:+ShenandoahVerify
78 * -XX:TieredStopAtLevel=4
79 * TestClone
80 */
81
82 /*
83 * @test id=aggressive
84 * @summary Test clone barriers work correctly
85 * @requires vm.gc.Shenandoah
86 *
87 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
88 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
89 * TestClone
90 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
91 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
92 * -Xint
93 * TestClone
94 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
95 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
96 * -XX:-TieredCompilation
97 * TestClone
98 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
99 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
100 * -XX:TieredStopAtLevel=1
101 * TestClone
102 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
103 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
104 * -XX:TieredStopAtLevel=4
105 * TestClone
106 */
107
108 /*
109 * @test id=no-coops
110 * @summary Test clone barriers work correctly
111 * @requires vm.gc.Shenandoah
112 * @requires vm.bits == "64"
113 *
114 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
115 * -XX:-UseCompressedOops
116 * -XX:+UseShenandoahGC
117 * TestClone
118 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
119 * -XX:-UseCompressedOops
120 * -XX:+UseShenandoahGC
121 * -Xint
122 * TestClone
123 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
124 * -XX:-UseCompressedOops
125 * -XX:+UseShenandoahGC
126 * -XX:-TieredCompilation
127 * TestClone
128 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
129 * -XX:-UseCompressedOops
130 * -XX:+UseShenandoahGC
131 * -XX:TieredStopAtLevel=1
132 * TestClone
133 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
134 * -XX:-UseCompressedOops
135 * -XX:+UseShenandoahGC
136 * -XX:TieredStopAtLevel=4
137 * TestClone
138 */
139
140 /*
141 * @test id=no-coops-verify
142 * @summary Test clone barriers work correctly
143 * @requires vm.gc.Shenandoah
144 * @requires vm.bits == "64"
145 *
146 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
147 * -XX:-UseCompressedOops
148 * -XX:+UseShenandoahGC
149 * -XX:+ShenandoahVerify
150 * TestClone
151 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
152 * -XX:-UseCompressedOops
153 * -XX:+UseShenandoahGC
154 * -XX:+ShenandoahVerify
155 * -Xint
156 * TestClone
157 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
158 * -XX:-UseCompressedOops
159 * -XX:+UseShenandoahGC
160 * -XX:+ShenandoahVerify
161 * -XX:-TieredCompilation
162 * TestClone
163 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
164 * -XX:-UseCompressedOops
165 * -XX:+UseShenandoahGC
166 * -XX:+ShenandoahVerify
167 * -XX:TieredStopAtLevel=1
168 * TestClone
169 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
170 * -XX:-UseCompressedOops
171 * -XX:+UseShenandoahGC
172 * -XX:+ShenandoahVerify
173 * -XX:TieredStopAtLevel=4
174 * TestClone
175 */
176
177 /*
178 * @test id=no-coops-aggressive
179 * @summary Test clone barriers work correctly
180 * @requires vm.gc.Shenandoah
181 * @requires vm.bits == "64"
182 *
183 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
184 * -XX:-UseCompressedOops
185 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
186 * TestClone
187 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
188 * -XX:-UseCompressedOops
189 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
190 * -Xint
191 * TestClone
192 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
193 * -XX:-UseCompressedOops
194 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
195 * -XX:-TieredCompilation
196 * TestClone
197 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
198 * -XX:-UseCompressedOops
199 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
200 * -XX:TieredStopAtLevel=1
201 * TestClone
202 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
203 * -XX:-UseCompressedOops
204 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
205 * -XX:TieredStopAtLevel=4
206 * TestClone
207 */
208
209 /*
210 * @test id=generational
211 * @summary Test clone barriers work correctly
212 * @requires vm.gc.Shenandoah
213 *
214 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
215 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
216 * TestClone
217 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
218 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
219 * -Xint
220 * TestClone
221 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
222 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
223 * -XX:-TieredCompilation
224 * TestClone
225 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
226 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
227 * -XX:TieredStopAtLevel=1
228 * TestClone
229 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
230 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
231 * -XX:TieredStopAtLevel=4
232 * TestClone
233 */
234
235 /*
236 * @test id=generational-small-card-size
237 * @summary Test clone barriers work correctly
238 * @requires vm.gc.Shenandoah
239 *
240 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
241 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:GCCardSizeInBytes=128
242 * TestClone
243 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
244 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:GCCardSizeInBytes=128
245 * -Xint
246 * TestClone
247 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
248 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:GCCardSizeInBytes=128
249 * -XX:-TieredCompilation
250 * TestClone
251 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
252 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:GCCardSizeInBytes=128
253 * -XX:TieredStopAtLevel=1
254 * TestClone
255 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
256 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:GCCardSizeInBytes=128
257 * -XX:TieredStopAtLevel=4
258 * TestClone
259 */
260
261 /*
262 * @test id=generational-verify
263 * @summary Test clone barriers work correctly
264 * @requires vm.gc.Shenandoah
265 *
266 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
267 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
268 * -XX:+ShenandoahVerify
269 * TestClone
270 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
271 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
272 * -XX:+ShenandoahVerify
273 * -Xint
274 * TestClone
275 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
276 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
277 * -XX:+ShenandoahVerify
278 * -XX:-TieredCompilation
279 * TestClone
280 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
281 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
282 * -XX:+ShenandoahVerify
283 * -XX:TieredStopAtLevel=1
284 * TestClone
285 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
286 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
287 * -XX:+ShenandoahVerify
288 * -XX:TieredStopAtLevel=4
289 * TestClone
290 */
291
292 /*
293 * @test id=generational-no-coops
294 * @summary Test clone barriers work correctly
295 * @requires vm.gc.Shenandoah
296 * @requires vm.bits == "64"
297 *
298 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
299 * -XX:-UseCompressedOops
300 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
301 * TestClone
302 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
303 * -XX:-UseCompressedOops
304 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
305 * -Xint
306 * TestClone
307 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
308 * -XX:-UseCompressedOops
309 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
310 * -XX:-TieredCompilation
311 * TestClone
312 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
313 * -XX:-UseCompressedOops
314 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
315 * -XX:TieredStopAtLevel=1
316 * TestClone
317 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
318 * -XX:-UseCompressedOops
319 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
320 * -XX:TieredStopAtLevel=4
321 * TestClone
322 */
323
324 /*
325 * @test id=generational-no-coops-verify
326 * @summary Test clone barriers work correctly
327 * @requires vm.gc.Shenandoah
328 * @requires vm.bits == "64"
329 *
330 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
331 * -XX:-UseCompressedOops
332 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
333 * -XX:+ShenandoahVerify
334 * TestClone
335 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
336 * -XX:-UseCompressedOops
337 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
338 * -XX:+ShenandoahVerify
339 * -Xint
340 * TestClone
341 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
342 * -XX:-UseCompressedOops
343 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
344 * -XX:+ShenandoahVerify
345 * -XX:-TieredCompilation
346 * TestClone
347 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
348 * -XX:-UseCompressedOops
349 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
350 * -XX:+ShenandoahVerify
351 * -XX:TieredStopAtLevel=1
352 * TestClone
353 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
354 * -XX:-UseCompressedOops
355 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
356 * -XX:+ShenandoahVerify
357 * -XX:TieredStopAtLevel=4
358 * TestClone
359 */
360 public class TestClone {
361
362 public static void main(String[] args) throws Exception {
363 for (int i = 0; i < 10000; i++) {
364 Object[] src = new Object[i];
365 for (int c = 0; c < src.length; c++) {
366 src[c] = new Object();
367 }
368 testWith(src);
369 }
370 }
371
372 static void testWith(Object[] src) {
373 Object[] dst = src.clone();
374 int srcLen = src.length;
375 int dstLen = dst.length;
376 if (srcLen != dstLen) {
377 throw new IllegalStateException("Lengths do not match: " + srcLen + " vs " + dstLen);
378 }
379 for (int c = 0; c < src.length; c++) {
380 Object s = src[c];
381 Object d = dst[c];
382 if (s != d) {
383 throw new IllegalStateException("Elements do not match at " + c + ": " + s + " vs " + d);
384 }
385 }
386 }
387 }