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