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  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  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 TestClone
  52  * @summary Test clone barriers work correctly
  53  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  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 TestClone
  83  * @summary Test clone barriers work correctly
  84  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  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 TestClone
 109  * @summary Test clone barriers work correctly
 110  * @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
 111  *
 112  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 113  *                   -XX:-UseCompressedOops
 114  *                   -XX:+UseShenandoahGC
 115  *                   TestClone
 116  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 117  *                   -XX:-UseCompressedOops
 118  *                   -XX:+UseShenandoahGC
 119  *                   -Xint
 120  *                   TestClone
 121  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 122  *                   -XX:-UseCompressedOops
 123  *                   -XX:+UseShenandoahGC
 124  *                   -XX:-TieredCompilation
 125  *                   TestClone
 126  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 127  *                   -XX:-UseCompressedOops
 128  *                   -XX:+UseShenandoahGC
 129  *                   -XX:TieredStopAtLevel=1
 130  *                   TestClone
 131  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 132  *                   -XX:-UseCompressedOops
 133  *                   -XX:+UseShenandoahGC
 134  *                   -XX:TieredStopAtLevel=4
 135  *                   TestClone
 136  */
 137 
 138 /*
 139  * @test TestClone
 140  * @summary Test clone barriers work correctly
 141  * @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
 142  *
 143  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 144  *                   -XX:-UseCompressedOops
 145  *                   -XX:+UseShenandoahGC
 146  *                   -XX:+ShenandoahVerify
 147  *                   TestClone
 148  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 149  *                   -XX:-UseCompressedOops
 150  *                   -XX:+UseShenandoahGC
 151  *                   -XX:+ShenandoahVerify
 152  *                   -Xint
 153  *                   TestClone
 154  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 155  *                   -XX:-UseCompressedOops
 156  *                   -XX:+UseShenandoahGC
 157  *                   -XX:+ShenandoahVerify
 158  *                   -XX:-TieredCompilation
 159  *                   TestClone
 160  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 161  *                   -XX:-UseCompressedOops
 162  *                   -XX:+UseShenandoahGC
 163  *                   -XX:+ShenandoahVerify
 164  *                   -XX:TieredStopAtLevel=1
 165  *                   TestClone
 166  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 167  *                   -XX:-UseCompressedOops
 168  *                   -XX:+UseShenandoahGC
 169  *                   -XX:+ShenandoahVerify
 170  *                   -XX:TieredStopAtLevel=4
 171  *                   TestClone
 172  */
 173 
 174 /*
 175  * @test TestClone
 176  * @summary Test clone barriers work correctly
 177  * @requires vm.gc.Shenandoah & !vm.graal.enabled & (vm.bits == "64")
 178  *
 179  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 180  *                   -XX:-UseCompressedOops
 181  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 182  *                   TestClone
 183  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 184  *                   -XX:-UseCompressedOops
 185  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 186  *                   -Xint
 187  *                   TestClone
 188  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 189  *                   -XX:-UseCompressedOops
 190  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 191  *                   -XX:-TieredCompilation
 192  *                   TestClone
 193  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 194  *                   -XX:-UseCompressedOops
 195  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 196  *                   -XX:TieredStopAtLevel=1
 197  *                   TestClone
 198  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xms1g -Xmx1g
 199  *                   -XX:-UseCompressedOops
 200  *                   -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 201  *                   -XX:TieredStopAtLevel=4
 202  *                   TestClone
 203  */
 204 
 205 
 206 public class TestClone {
 207 
 208     public static void main(String[] args) throws Exception {
 209         for (int i = 0; i < 10000; i++) {
 210             Object[] src = new Object[i];
 211             for (int c = 0; c < src.length; c++) {
 212                 src[c] = new Object();
 213             }
 214             testWith(src);
 215         }
 216     }
 217 
 218     static void testWith(Object[] src) {
 219         Object[] dst = src.clone();
 220         int srcLen = src.length;
 221         int dstLen = dst.length;
 222         if (srcLen != dstLen) {
 223             throw new IllegalStateException("Lengths do not match: " + srcLen + " vs " + dstLen);
 224         }
 225         for (int c = 0; c < src.length; c++) {
 226             Object s = src[c];
 227             Object d = dst[c];
 228             if (s != d) {
 229                 throw new IllegalStateException("Elements do not match at " + c + ": " + s + " vs " + d);
 230             }
 231         }
 232     }
 233 }