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