Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/TestVerifyJCStress.java
32284 views
/*1* Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223/*24* @test TestVerifyJCStress25* @summary Tests that we pass at least one jcstress-like test with all verification turned on26* @key gc27*28* @run main/othervm -Xmx1g -Xms1g -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions29* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive30* -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify -XX:+VerifyObjectEquals31* TestVerifyJCStress32*33* @run main/othervm -Xmx1g -Xms1g -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions34* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive35* -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify -XX:+VerifyObjectEquals36* TestVerifyJCStress37*/3839/*40* @test TestVerifyJCStress41* @summary Tests that we pass at least one jcstress-like test with all verification turned on42* @key gc43*44* @run main/othervm -Xmx1g -Xms1g -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions45* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive46* -XX:+ShenandoahVerify -XX:+VerifyObjectEquals -XX:+ShenandoahVerifyOptoBarriers47* TestVerifyJCStress48*49* @run main/othervm -Xmx1g -Xms1g -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions50* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact51* -XX:+ShenandoahVerify -XX:+VerifyObjectEquals -XX:+ShenandoahVerifyOptoBarriers52* TestVerifyJCStress53*/5455/*56* @test TestVerifyJCStress57* @summary Tests that we pass at least one jcstress-like test with all verification turned on58* @key gc59*60* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions61* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu62* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers63* TestVerifyJCStress64*/6566import java.util.*;67import java.util.concurrent.*;68import java.util.concurrent.locks.*;6970public class TestVerifyJCStress {7172public static void main(String[] args) throws Exception {73ExecutorService service = Executors.newFixedThreadPool(742,75r -> {76Thread t = new Thread(r);77t.setDaemon(true);78return t;79}80);8182for (int c = 0; c < 10000; c++) {83final Test[] tests = new Test[10000];84for (int t = 0; t < tests.length; t++) {85tests[t] = new Test();86}8788Future<?> f1 = service.submit(() -> {89IntResult2 r = new IntResult2();90for (Test test : tests) {91test.RL_Us(r);92}93});94Future<?> f2 = service.submit(() -> {95for (Test test : tests) {96test.WLI_Us();97}98});99100f1.get();101f2.get();102}103}104105public static class IntResult2 {106int r1, r2;107}108109public static class Test {110final StampedLock lock = new StampedLock();111112int x, y;113114public void RL_Us(IntResult2 r) {115StampedLock lock = this.lock;116long stamp = lock.readLock();117r.r1 = x;118r.r2 = y;119lock.unlock(stamp);120}121122public void WLI_Us() {123try {124StampedLock lock = this.lock;125long stamp = lock.writeLockInterruptibly();126x = 1;127y = 2;128lock.unlock(stamp);129} catch (InterruptedException e) {130throw new RuntimeException(e);131}132}133}134135}136137138