1 /*
  2  * Copyright (c) 2019, Red Hat, Inc. 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 /*
 25  * @test id=default
 26  * @summary Test clone barriers work correctly
 27  * @requires vm.gc.Shenandoah
 28  *
 29  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 30  *                   -XX:+UseShenandoahGC
 31  *                   TestClone
 32  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 33  *                   -XX:+UseShenandoahGC
 34  *                   -Xint
 35  *                   TestClone
 36  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 37  *                   -XX:+UseShenandoahGC
 38  *                   -XX:-TieredCompilation
 39  *                   TestClone
 40  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 41  *                   -XX:+UseShenandoahGC
 42  *                   -XX:TieredStopAtLevel=1
 43  *                   TestClone
 44  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 45  *                   -XX:+UseShenandoahGC
 46  *                   -XX:TieredStopAtLevel=4
 47  *                   TestClone
 48  */
 49 
 50 /*
 51  * @test id=default-verify
 52  * @summary Test clone barriers work correctly
 53  * @requires vm.gc.Shenandoah
 54  *
 55  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 56  *                   -XX:+UseShenandoahGC
 57  *                   -XX:+ShenandoahVerify
 58  *                   TestClone
 59  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 60  *                   -XX:+UseShenandoahGC
 61  *                   -XX:+ShenandoahVerify
 62  *                   -Xint
 63  *                   TestClone
 64  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 65  *                   -XX:+UseShenandoahGC
 66  *                   -XX:+ShenandoahVerify
 67  *                   -XX:-TieredCompilation
 68  *                   TestClone
 69  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 70  *                   -XX:+UseShenandoahGC
 71  *                   -XX:+ShenandoahVerify
 72  *                   -XX:TieredStopAtLevel=1
 73  *                   TestClone
 74  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 75  *                   -XX:+UseShenandoahGC
 76  *                   -XX:+ShenandoahVerify
 77  *                   -XX:TieredStopAtLevel=4
 78  *                   TestClone
 79  */
 80 
 81 /*
 82  * @test id=aggressive
 83  * @summary Test clone barriers work correctly
 84  * @requires vm.gc.Shenandoah
 85  *
 86  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 87  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 88  *                   TestClone
 89  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 90  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 91  *                   -Xint
 92  *                   TestClone
 93  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 94  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 95  *                   -XX:-TieredCompilation
 96  *                   TestClone
 97  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 98  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 99  *                   -XX:TieredStopAtLevel=1
100  *                   TestClone
101  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
102  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
103  *                   -XX:TieredStopAtLevel=4
104  *                   TestClone
105  */
106 
107 /*
108  * @test id=no-coops
109  * @summary Test clone barriers work correctly
110  * @requires vm.gc.Shenandoah
111  * @requires vm.bits == "64"
112  *
113  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
114  *                   -XX:-UseCompressedOops
115  *                   -XX:+UseShenandoahGC
116  *                   TestClone
117  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
118  *                   -XX:-UseCompressedOops
119  *                   -XX:+UseShenandoahGC
120  *                   -Xint
121  *                   TestClone
122  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
123  *                   -XX:-UseCompressedOops
124  *                   -XX:+UseShenandoahGC
125  *                   -XX:-TieredCompilation
126  *                   TestClone
127  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
128  *                   -XX:-UseCompressedOops
129  *                   -XX:+UseShenandoahGC
130  *                   -XX:TieredStopAtLevel=1
131  *                   TestClone
132  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
133  *                   -XX:-UseCompressedOops
134  *                   -XX:+UseShenandoahGC
135  *                   -XX:TieredStopAtLevel=4
136  *                   TestClone
137  */
138 
139 /*
140  * @test id=no-coops-verify
141  * @summary Test clone barriers work correctly
142  * @requires vm.gc.Shenandoah
143  * @requires vm.bits == "64"
144  *
145  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
146  *                   -XX:-UseCompressedOops
147  *                   -XX:+UseShenandoahGC
148  *                   -XX:+ShenandoahVerify
149  *                   TestClone
150  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
151  *                   -XX:-UseCompressedOops
152  *                   -XX:+UseShenandoahGC
153  *                   -XX:+ShenandoahVerify
154  *                   -Xint
155  *                   TestClone
156  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
157  *                   -XX:-UseCompressedOops
158  *                   -XX:+UseShenandoahGC
159  *                   -XX:+ShenandoahVerify
160  *                   -XX:-TieredCompilation
161  *                   TestClone
162  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
163  *                   -XX:-UseCompressedOops
164  *                   -XX:+UseShenandoahGC
165  *                   -XX:+ShenandoahVerify
166  *                   -XX:TieredStopAtLevel=1
167  *                   TestClone
168  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
169  *                   -XX:-UseCompressedOops
170  *                   -XX:+UseShenandoahGC
171  *                   -XX:+ShenandoahVerify
172  *                   -XX:TieredStopAtLevel=4
173  *                   TestClone
174  */
175 
176 /*
177  * @test id=no-coops-aggressive
178  * @summary Test clone barriers work correctly
179  * @requires vm.gc.Shenandoah
180  * @requires vm.bits == "64"
181  *
182  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
183  *                   -XX:-UseCompressedOops
184  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
185  *                   TestClone
186  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
187  *                   -XX:-UseCompressedOops
188  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
189  *                   -Xint
190  *                   TestClone
191  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
192  *                   -XX:-UseCompressedOops
193  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
194  *                   -XX:-TieredCompilation
195  *                   TestClone
196  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
197  *                   -XX:-UseCompressedOops
198  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
199  *                   -XX:TieredStopAtLevel=1
200  *                   TestClone
201  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
202  *                   -XX:-UseCompressedOops
203  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
204  *                   -XX:TieredStopAtLevel=4
205  *                   TestClone
206  */
207 
208 
209 public class TestClone {
210 
211     public static void main(String[] args) throws Exception {
212         for (int i = 0; i < 10000; i++) {
213             Object[] src = new Object[i];
214             for (int c = 0; c < src.length; c++) {
215                 src[c] = new Object();
216             }
217             testWith(src);
218         }
219     }
220 
221     static void testWith(Object[] src) {
222         Object[] dst = src.clone();
223         int srcLen = src.length;
224         int dstLen = dst.length;
225         if (srcLen != dstLen) {
226             throw new IllegalStateException("Lengths do not match: " + srcLen + " vs " + dstLen);
227         }
228         for (int c = 0; c < src.length; c++) {
229             Object s = src[c];
230             Object d = dst[c];
231             if (s != d) {
232                 throw new IllegalStateException("Elements do not match at " + c + ": " + s + " vs " + d);
233             }
234         }
235     }
236 }