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