1 /* 2 * Copyright (c) 2018, Red Hat, Inc. All rights reserved. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 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 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 /* @test TestWrongBarrierDisable 25 * @summary Test that disabling wrong barriers fails early 26 * @key gc 27 * @library /testlibrary 28 * @run main/othervm TestWrongBarrierDisable 29 */ 30 31 import java.util.*; 32 33 import com.oracle.java.testlibrary.*; 34 35 public class TestWrongBarrierDisable { 36 37 public static void main(String[] args) throws Exception { 38 String[] concurrent = { 39 "ShenandoahLoadRefBarrier", 40 "ShenandoahSATBBarrier", 41 "ShenandoahCASBarrier", 42 "ShenandoahCloneBarrier", 43 }; 44 String[] iu = { 45 "ShenandoahLoadRefBarrier", 46 "ShenandoahStoreValEnqueueBarrier", 47 "ShenandoahCASBarrier", 48 "ShenandoahCloneBarrier", 49 }; 50 51 shouldFailAll("-XX:ShenandoahGCHeuristics=adaptive", concurrent); 52 shouldFailAll("-XX:ShenandoahGCHeuristics=static", concurrent); 53 shouldFailAll("-XX:ShenandoahGCHeuristics=compact", concurrent); 54 shouldFailAll("-XX:ShenandoahGCHeuristics=aggressive", concurrent); 55 shouldFailAll("-XX:ShenandoahGCMode=iu", iu); 56 shouldPassAll("-XX:ShenandoahGCMode=passive", concurrent); 57 shouldPassAll("-XX:ShenandoahGCMode=passive", iu); 58 } 59 60 private static void shouldFailAll(String h, String[] barriers) throws Exception { 61 for (String b : barriers) { 62 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 63 "-Xmx128m", 64 "-XX:+UnlockDiagnosticVMOptions", 65 "-XX:+UnlockExperimentalVMOptions", 66 "-XX:+UseShenandoahGC", 67 h, 68 "-XX:-" + b, 69 "-version" 70 ); 71 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 72 output.shouldHaveExitValue(1); 73 output.shouldContain("GC mode needs "); 74 output.shouldContain("to work correctly"); 75 } 76 } 77 78 private static void shouldPassAll(String h, String[] barriers) throws Exception { 79 for (String b : barriers) { 80 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 81 "-Xmx128m", 82 "-XX:+UnlockDiagnosticVMOptions", 83 "-XX:+UnlockExperimentalVMOptions", 84 "-XX:+UseShenandoahGC", 85 h, 86 "-XX:-" + b, 87 "-version" 88 ); 89 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 90 output.shouldHaveExitValue(0); 91 } 92 } 93 94 }