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 /* @test TestSelectiveBarrierFlags 26 * @summary Test selective barrier enabling works, by aggressively compiling HelloWorld with combinations 27 * of barrier flags 28 * @key gc 29 * @requires vm.gc.Shenandoah & !vm.graal.enabled 30 * @library /test/lib 31 * @run main/othervm TestSelectiveBarrierFlags -Xint 32 * @run main/othervm TestSelectiveBarrierFlags -Xbatch -XX:CompileThreshold=100 -XX:TieredStopAtLevel=1 33 * @run main/othervm TestSelectiveBarrierFlags -Xbatch -XX:CompileThreshold=100 -XX:-TieredCompilation -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers 34 */ 35 36 import java.util.*; 37 import java.util.concurrent.*; 38 39 import jdk.test.lib.process.ProcessTools; 40 import jdk.test.lib.process.OutputAnalyzer; 41 42 public class TestSelectiveBarrierFlags { 43 44 public static void main(String[] args) throws Exception { 45 String[][] opts = { 46 new String[] { "ShenandoahLoadRefBarrier" }, 47 new String[] { "ShenandoahSATBBarrier", "ShenandoahStoreValEnqueueBarrier" }, 48 new String[] { "ShenandoahCASBarrier" }, 49 new String[] { "ShenandoahCloneBarrier" }, 50 }; 51 52 int size = 1; 53 for (String[] l : opts) { 54 size *= (l.length + 1); 55 } 56 57 ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); 58 59 for (int c = 0; c < size; c++) { 60 int t = c; 61 62 List<String> conf = new ArrayList<>(); 63 conf.addAll(Arrays.asList(args)); 64 conf.add("-Xmx128m"); 65 conf.add("-XX:+UnlockDiagnosticVMOptions"); 66 conf.add("-XX:+UnlockExperimentalVMOptions"); 67 conf.add("-XX:+UseShenandoahGC"); 68 conf.add("-XX:ShenandoahGCMode=passive"); 69 70 StringBuilder sb = new StringBuilder(); 71 for (String[] l : opts) { 72 // Make a choice which flag to select from the group. 73 // Zero means no flag is selected from the group. 74 int choice = t % (l.length + 1); 75 for (int e = 0; e < l.length; e++) { 76 conf.add("-XX:" + ((choice == (e + 1)) ? "+" : "-") + l[e]); 77 } 78 t = t / (l.length + 1); 79 } 80 81 conf.add("TestSelectiveBarrierFlags$Test"); 82 83 pool.submit(() -> { 84 try { 85 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(conf.toArray(new String[0])); 86 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 87 output.shouldHaveExitValue(0); 88 } catch (Exception e) { 89 e.printStackTrace(); 90 System.exit(1); 91 } 92 }); 93 } 94 95 pool.shutdown(); 96 pool.awaitTermination(1, TimeUnit.HOURS); 97 } 98 99 public static class Test { 100 public static void main(String... args) { 101 System.out.println("HelloWorld"); 102 } 103 } 104 105 }