22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test TestCompilerDirectivesCompatibilityBase |
25 * @test TestCompilerDirectivesCompatibilityBase |
26 * @bug 8137167 |
26 * @bug 8137167 |
27 * @library /testlibrary /test/lib |
27 * @library /testlibrary /test/lib / |
28 * @modules java.base/sun.misc |
28 * @modules java.base/sun.misc |
29 * java.compiler |
29 * java.compiler |
30 * java.management |
30 * java.management |
31 * @build jdk.test.lib.* |
31 * @build jdk.test.lib.* |
32 * @build jdk.test.lib.dcmd.* |
32 * jdk.test.lib.dcmd.* |
33 * @build sun.hotspot.WhiteBox |
33 * sun.hotspot.WhiteBox |
34 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
34 * compiler.testlibrary.CompilerUtils |
35 * sun.hotspot.WhiteBox$WhiteBoxPermission |
35 * @run driver ClassFileInstaller sun.hotspot.WhiteBox |
36 * @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestCompilerDirectivesCompatibilityBase |
36 * sun.hotspot.WhiteBox$WhiteBoxPermission |
|
37 * @run testng/othervm -Xbootclasspath/a:. -Xmixed -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestCompilerDirectivesCompatibilityBase |
37 * @summary Test compiler control compatibility with compile command |
38 * @summary Test compiler control compatibility with compile command |
38 */ |
39 */ |
39 |
40 |
|
41 import compiler.testlibrary.CompilerUtils; |
|
42 import compiler.whitebox.CompilerWhiteBoxTest; |
40 import jdk.test.lib.dcmd.CommandExecutor; |
43 import jdk.test.lib.dcmd.CommandExecutor; |
41 import jdk.test.lib.dcmd.JMXExecutor; |
44 import jdk.test.lib.dcmd.JMXExecutor; |
42 |
|
43 import org.testng.annotations.Test; |
45 import org.testng.annotations.Test; |
44 import org.testng.Assert; |
46 import org.testng.Assert; |
45 |
|
46 import sun.hotspot.WhiteBox; |
47 import sun.hotspot.WhiteBox; |
47 |
48 |
48 import java.io.BufferedReader; |
49 import java.io.BufferedReader; |
49 import java.io.File; |
50 import java.io.File; |
50 import java.io.StringReader; |
51 import java.io.StringReader; |
62 control_on = System.getProperty("test.src", ".") + File.separator + "control_on.txt"; |
63 control_on = System.getProperty("test.src", ".") + File.separator + "control_on.txt"; |
63 control_off = System.getProperty("test.src", ".") + File.separator + "control_off.txt"; |
64 control_off = System.getProperty("test.src", ".") + File.separator + "control_off.txt"; |
64 method = getMethod(TestCompilerDirectivesCompatibilityBase.class, "helper"); |
65 method = getMethod(TestCompilerDirectivesCompatibilityBase.class, "helper"); |
65 nomatch = getMethod(TestCompilerDirectivesCompatibilityBase.class, "another"); |
66 nomatch = getMethod(TestCompilerDirectivesCompatibilityBase.class, "another"); |
66 |
67 |
67 testCompatibility(executor); |
68 int[] levels = CompilerUtils.getAvailableCompilationLevels(); |
|
69 for (int complevel : levels) { |
|
70 // Only test the major compilers, ignore profiling levels |
|
71 if (complevel == CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE || complevel == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION){ |
|
72 testCompatibility(executor, complevel); |
|
73 } |
|
74 } |
68 } |
75 } |
69 |
76 |
70 public void testCompatibility(CommandExecutor executor) throws Exception { |
77 public void testCompatibility(CommandExecutor executor, int comp_level) throws Exception { |
71 |
78 |
72 // Call all validation twice to catch error when overwriting a directive |
79 // Call all validation twice to catch error when overwriting a directive |
73 // Flag is default off |
80 // Flag is default off |
74 expect(!WB.getBooleanVMFlag("PrintAssembly")); |
81 expect(!WB.getBooleanVMFlag("PrintAssembly")); |
75 expect(!WB.shouldPrintAssembly(method)); |
82 expect(!WB.shouldPrintAssembly(method, comp_level)); |
76 expect(!WB.shouldPrintAssembly(nomatch)); |
83 expect(!WB.shouldPrintAssembly(nomatch, comp_level)); |
77 expect(!WB.shouldPrintAssembly(method)); |
84 expect(!WB.shouldPrintAssembly(method, comp_level)); |
78 expect(!WB.shouldPrintAssembly(nomatch)); |
85 expect(!WB.shouldPrintAssembly(nomatch, comp_level)); |
79 |
86 |
80 // load directives that turn it on |
87 // load directives that turn it on |
81 executor.execute("Compiler.directives_add " + control_on); |
88 executor.execute("Compiler.directives_add " + control_on); |
82 expect(WB.shouldPrintAssembly(method)); |
89 expect(WB.shouldPrintAssembly(method, comp_level)); |
83 expect(!WB.shouldPrintAssembly(nomatch)); |
90 expect(!WB.shouldPrintAssembly(nomatch, comp_level)); |
84 expect(WB.shouldPrintAssembly(method)); |
91 expect(WB.shouldPrintAssembly(method, comp_level)); |
85 expect(!WB.shouldPrintAssembly(nomatch)); |
92 expect(!WB.shouldPrintAssembly(nomatch, comp_level)); |
86 |
93 |
87 // remove and see that it is true again |
94 // remove and see that it is true again |
88 executor.execute("Compiler.directives_remove"); |
95 executor.execute("Compiler.directives_remove"); |
89 expect(!WB.shouldPrintAssembly(method)); |
96 expect(!WB.shouldPrintAssembly(method, comp_level)); |
90 expect(!WB.shouldPrintAssembly(nomatch)); |
97 expect(!WB.shouldPrintAssembly(nomatch, comp_level)); |
91 expect(!WB.shouldPrintAssembly(method)); |
98 expect(!WB.shouldPrintAssembly(method, comp_level)); |
92 expect(!WB.shouldPrintAssembly(nomatch)); |
99 expect(!WB.shouldPrintAssembly(nomatch, comp_level)); |
93 } |
100 } |
94 |
101 |
95 public void expect(boolean test) throws Exception { |
102 public void expect(boolean test) throws Exception { |
96 if (!test) { |
103 if (!test) { |
97 throw new Exception("Test failed"); |
104 throw new Exception("Test failed"); |