1 /* 2 * Copyright (c) 2017, 2020, 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 /* 27 * @test id=passive 28 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 29 * @requires vm.gc.Shenandoah 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * 33 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 34 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 35 * -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify 36 * TestVerifyJCStress 37 * 38 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 39 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 40 * -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify 41 * TestVerifyJCStress 42 */ 43 44 /* 45 * @test id=default-debug 46 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 47 * @requires vm.gc.Shenandoah 48 * @requires vm.debug 49 * @modules java.base/jdk.internal.misc 50 * java.management 51 * 52 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 53 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive 54 * -XX:+ShenandoahVerify -XX:+ShenandoahVerifyOptoBarriers 55 * TestVerifyJCStress 56 * 57 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 58 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact 59 * -XX:+ShenandoahVerify -XX:+ShenandoahVerifyOptoBarriers 60 * TestVerifyJCStress 61 * 62 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 63 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational 64 * -XX:+ShenandoahVerify -XX:+ShenandoahVerifyOptoBarriers 65 * TestVerifyJCStress 66 */ 67 68 /* 69 * @test id=default 70 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 71 * @requires vm.gc.Shenandoah 72 * @requires !vm.debug 73 * @modules java.base/jdk.internal.misc 74 * java.management 75 * 76 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 77 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive 78 * -XX:+ShenandoahVerify 79 * TestVerifyJCStress 80 * 81 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 82 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact 83 * -XX:+ShenandoahVerify 84 * TestVerifyJCStress 85 * 86 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 87 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational 88 * -XX:+ShenandoahVerify 89 * TestVerifyJCStress 90 */ 91 92 /* 93 * @test id=iu-debug 94 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 95 * @requires vm.gc.Shenandoah 96 * @requires vm.debug 97 * @modules java.base/jdk.internal.misc 98 * java.management 99 * 100 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 101 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 102 * -XX:+ShenandoahVerify -XX:+ShenandoahVerifyOptoBarriers 103 * TestVerifyJCStress 104 */ 105 106 /* 107 * @test id=iu 108 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 109 * @requires vm.gc.Shenandoah 110 * @requires !vm.debug 111 * @modules java.base/jdk.internal.misc 112 * java.management 113 * 114 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 115 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 116 * -XX:+ShenandoahVerify 117 * TestVerifyJCStress 118 */ 119 120 /* 121 * @test id=iu-c1 122 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 123 * @requires vm.gc.Shenandoah 124 * @modules java.base/jdk.internal.misc 125 * java.management 126 * 127 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 128 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 129 * -XX:+ShenandoahVerify -XX:TieredStopAtLevel=1 130 * TestVerifyJCStress 131 */ 132 133 134 import java.util.*; 135 import java.util.concurrent.*; 136 import java.util.concurrent.locks.*; 137 138 public class TestVerifyJCStress { 139 140 public static void main(String[] args) throws Exception { 141 ExecutorService service = Executors.newFixedThreadPool( 142 2, 143 r -> { 144 Thread t = new Thread(r); 145 t.setDaemon(true); 146 return t; 147 } 148 ); 149 150 for (int c = 0; c < 10000; c++) { 151 final Test[] tests = new Test[10000]; 152 for (int t = 0; t < tests.length; t++) { 153 tests[t] = new Test(); 154 } 155 156 Future<?> f1 = service.submit(() -> { 157 IntResult2 r = new IntResult2(); 158 for (Test test : tests) { 159 test.RL_Us(r); 160 } 161 }); 162 Future<?> f2 = service.submit(() -> { 163 for (Test test : tests) { 164 test.WLI_Us(); 165 } 166 }); 167 168 f1.get(); 169 f2.get(); 170 } 171 } 172 173 public static class IntResult2 { 174 int r1, r2; 175 } 176 177 public static class Test { 178 final StampedLock lock = new StampedLock(); 179 180 int x, y; 181 182 public void RL_Us(IntResult2 r) { 183 StampedLock lock = this.lock; 184 long stamp = lock.readLock(); 185 r.r1 = x; 186 r.r2 = y; 187 lock.unlock(stamp); 188 } 189 190 public void WLI_Us() { 191 try { 192 StampedLock lock = this.lock; 193 long stamp = lock.writeLockInterruptibly(); 194 x = 1; 195 y = 2; 196 lock.unlock(stamp); 197 } catch (InterruptedException e) { 198 throw new RuntimeException(e); 199 } 200 } 201 } 202 203 }