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-verify
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
242  *                   -XX:+ShenandoahVerify
243  *                   TestClone
244  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
245  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
246  *                   -XX:+ShenandoahVerify
247  *                   -Xint
248  *                   TestClone
249  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
250  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
251  *                   -XX:+ShenandoahVerify
252  *                   -XX:-TieredCompilation
253  *                   TestClone
254  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
255  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
256  *                   -XX:+ShenandoahVerify
257  *                   -XX:TieredStopAtLevel=1
258  *                   TestClone
259  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
260  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
261  *                   -XX:+ShenandoahVerify
262  *                   -XX:TieredStopAtLevel=4
263  *                   TestClone
264  */
265 
266  /*
267   * @test id=generational-no-coops
268   * @summary Test clone barriers work correctly
269   * @requires vm.gc.Shenandoah
270   * @requires vm.bits == "64"
271   *
272   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
273   *                   -XX:-UseCompressedOops
274   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
275   *                   TestClone
276   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
277   *                   -XX:-UseCompressedOops
278   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
279   *                   -Xint
280   *                   TestClone
281   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
282   *                   -XX:-UseCompressedOops
283   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
284   *                   -XX:-TieredCompilation
285   *                   TestClone
286   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
287   *                   -XX:-UseCompressedOops
288   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
289   *                   -XX:TieredStopAtLevel=1
290   *                   TestClone
291   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
292   *                   -XX:-UseCompressedOops
293   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
294   *                   -XX:TieredStopAtLevel=4
295   *                   TestClone
296   */
297 
298  /*
299   * @test id=generational-no-coops-verify
300   * @summary Test clone barriers work correctly
301   * @requires vm.gc.Shenandoah
302   * @requires vm.bits == "64"
303   *
304   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
305   *                   -XX:-UseCompressedOops
306   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
307   *                   -XX:+ShenandoahVerify
308   *                   TestClone
309   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
310   *                   -XX:-UseCompressedOops
311   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
312   *                   -XX:+ShenandoahVerify
313   *                   -Xint
314   *                   TestClone
315   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
316   *                   -XX:-UseCompressedOops
317   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
318   *                   -XX:+ShenandoahVerify
319   *                   -XX:-TieredCompilation
320   *                   TestClone
321   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
322   *                   -XX:-UseCompressedOops
323   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
324   *                   -XX:+ShenandoahVerify
325   *                   -XX:TieredStopAtLevel=1
326   *                   TestClone
327   * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
328   *                   -XX:-UseCompressedOops
329   *                   -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
330   *                   -XX:+ShenandoahVerify
331   *                   -XX:TieredStopAtLevel=4
332   *                   TestClone
333   */
334 public class TestClone {
335 
336     public static void main(String[] args) throws Exception {
337         for (int i = 0; i < 10000; i++) {
338             Object[] src = new Object[i];
339             for (int c = 0; c < src.length; c++) {
340                 src[c] = new Object();
341             }
342             testWith(src);
343         }
344     }
345 
346     static void testWith(Object[] src) {
347         Object[] dst = src.clone();
348         int srcLen = src.length;
349         int dstLen = dst.length;
350         if (srcLen != dstLen) {
351             throw new IllegalStateException("Lengths do not match: " + srcLen + " vs " + dstLen);
352         }
353         for (int c = 0; c < src.length; c++) {
354             Object s = src[c];
355             Object d = dst[c];
356             if (s != d) {
357                 throw new IllegalStateException("Elements do not match at " + c + ": " + s + " vs " + d);
358             }
359         }
360     }
361 }