Path: blob/master/test/hotspot/jtreg/gc/shenandoah/TestVerifyJCStress.java
40942 views
/*1* Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/*25* @test TestVerifyJCStress26* @summary Tests that we pass at least one jcstress-like test with all verification turned on27* @requires vm.gc.Shenandoah28* @modules java.base/jdk.internal.misc29* java.management30*31* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions32* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive33* -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify34* TestVerifyJCStress35*36* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions37* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive38* -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify39* TestVerifyJCStress40*/4142/*43* @test TestVerifyJCStress44* @summary Tests that we pass at least one jcstress-like test with all verification turned on45* @requires vm.gc.Shenandoah46* @modules java.base/jdk.internal.misc47* java.management48*49* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions50* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive51* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers52* TestVerifyJCStress53*54* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions55* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact56* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers57* TestVerifyJCStress58*/5960/*61* @test TestVerifyJCStress62* @summary Tests that we pass at least one jcstress-like test with all verification turned on63* @requires vm.gc.Shenandoah64* @modules java.base/jdk.internal.misc65* java.management66*67* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions68* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu69* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers70* TestVerifyJCStress71*72* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions73* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu74* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:TieredStopAtLevel=175* TestVerifyJCStress76*/7778import java.util.*;79import java.util.concurrent.*;80import java.util.concurrent.locks.*;8182public class TestVerifyJCStress {8384public static void main(String[] args) throws Exception {85ExecutorService service = Executors.newFixedThreadPool(862,87r -> {88Thread t = new Thread(r);89t.setDaemon(true);90return t;91}92);9394for (int c = 0; c < 10000; c++) {95final Test[] tests = new Test[10000];96for (int t = 0; t < tests.length; t++) {97tests[t] = new Test();98}99100Future<?> f1 = service.submit(() -> {101IntResult2 r = new IntResult2();102for (Test test : tests) {103test.RL_Us(r);104}105});106Future<?> f2 = service.submit(() -> {107for (Test test : tests) {108test.WLI_Us();109}110});111112f1.get();113f2.get();114}115}116117public static class IntResult2 {118int r1, r2;119}120121public static class Test {122final StampedLock lock = new StampedLock();123124int x, y;125126public void RL_Us(IntResult2 r) {127StampedLock lock = this.lock;128long stamp = lock.readLock();129r.r1 = x;130r.r2 = y;131lock.unlock(stamp);132}133134public void WLI_Us() {135try {136StampedLock lock = this.lock;137long stamp = lock.writeLockInterruptibly();138x = 1;139y = 2;140lock.unlock(stamp);141} catch (InterruptedException e) {142throw new RuntimeException(e);143}144}145}146147}148149150