1 /* 2 * Copyright (c) 2017, 2018, 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 /* 26 * @test TestVerifyJCStress 27 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 28 * @key gc 29 * @requires vm.gc.Shenandoah & !vm.graal.enabled 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 TestVerifyJCStress 46 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 47 * @key gc 48 * @requires vm.gc.Shenandoah & !vm.graal.enabled 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:+IgnoreUnrecognizedVMOptions -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:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers 60 * TestVerifyJCStress 61 */ 62 63 /* 64 * @test TestVerifyJCStress 65 * @summary Tests that we pass at least one jcstress-like test with all verification turned on 66 * @key gc 67 * @requires vm.gc.Shenandoah & !vm.graal.enabled 68 * @modules java.base/jdk.internal.misc 69 * java.management 70 * 71 * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions 72 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 73 * -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers 74 * TestVerifyJCStress 75 */ 76 77 import java.util.*; 78 import java.util.concurrent.*; 79 import java.util.concurrent.locks.*; 80 81 public class TestVerifyJCStress { 82 83 public static void main(String[] args) throws Exception { 84 ExecutorService service = Executors.newFixedThreadPool( 85 2, 86 r -> { 87 Thread t = new Thread(r); 88 t.setDaemon(true); 89 return t; 90 } 91 ); 92 93 for (int c = 0; c < 10000; c++) { 94 final Test[] tests = new Test[10000]; 95 for (int t = 0; t < tests.length; t++) { 96 tests[t] = new Test(); 97 } 98 99 Future<?> f1 = service.submit(() -> { 100 IntResult2 r = new IntResult2(); 101 for (Test test : tests) { 102 test.RL_Us(r); 103 } 104 }); 105 Future<?> f2 = service.submit(() -> { 106 for (Test test : tests) { 107 test.WLI_Us(); 108 } 109 }); 110 111 f1.get(); 112 f2.get(); 113 } 114 } 115 116 public static class IntResult2 { 117 int r1, r2; 118 } 119 120 public static class Test { 121 final StampedLock lock = new StampedLock(); 122 123 int x, y; 124 125 public void RL_Us(IntResult2 r) { 126 StampedLock lock = this.lock; 127 long stamp = lock.readLock(); 128 r.r1 = x; 129 r.r2 = y; 130 lock.unlock(stamp); 131 } 132 133 public void WLI_Us() { 134 try { 135 StampedLock lock = this.lock; 136 long stamp = lock.writeLockInterruptibly(); 137 x = 1; 138 y = 2; 139 lock.unlock(stamp); 140 } catch (InterruptedException e) { 141 throw new RuntimeException(e); 142 } 143 } 144 } 145 146 }