Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/TestCompilerDirectivesCompatibilityBase.java
41149 views
1
/*
2
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. 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 TestCompilerDirectivesCompatibilityBase
26
* @bug 8137167
27
* @summary Test compiler control compatibility with compile command
28
* @library /test/lib /
29
* @modules java.base/jdk.internal.misc
30
* java.compiler
31
* java.management
32
*
33
* @build sun.hotspot.WhiteBox
34
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35
* @run testng/othervm -Xbootclasspath/a:. -Xmixed -XX:+UnlockDiagnosticVMOptions
36
* -XX:+WhiteBoxAPI
37
* compiler.compilercontrol.TestCompilerDirectivesCompatibilityBase
38
*/
39
40
package compiler.compilercontrol;
41
42
import compiler.testlibrary.CompilerUtils;
43
import compiler.whitebox.CompilerWhiteBoxTest;
44
import jdk.test.lib.dcmd.CommandExecutor;
45
import jdk.test.lib.dcmd.JMXExecutor;
46
import org.testng.annotations.Test;
47
import sun.hotspot.WhiteBox;
48
49
import java.io.File;
50
import java.lang.reflect.Method;
51
52
public class TestCompilerDirectivesCompatibilityBase {
53
54
public static final WhiteBox WB = WhiteBox.getWhiteBox();
55
public static String control_on, control_off;
56
Method method, nomatch;
57
58
public void run(CommandExecutor executor) throws Exception {
59
60
control_on = System.getProperty("test.src", ".") + File.separator + "control_on.txt";
61
control_off = System.getProperty("test.src", ".") + File.separator + "control_off.txt";
62
method = getMethod(TestCompilerDirectivesCompatibilityBase.class, "helper");
63
nomatch = getMethod(TestCompilerDirectivesCompatibilityBase.class, "another");
64
65
int[] levels = CompilerUtils.getAvailableCompilationLevels();
66
for (int complevel : levels) {
67
// Only test the major compilers, ignore profiling levels
68
if (complevel == CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE || complevel == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION){
69
testCompatibility(executor, complevel);
70
}
71
}
72
}
73
74
public void testCompatibility(CommandExecutor executor, int comp_level) throws Exception {
75
76
// Call all validation twice to catch error when overwriting a directive
77
// Flag is default off
78
expect(!WB.getBooleanVMFlag("PrintAssembly"));
79
expect(!WB.shouldPrintAssembly(method, comp_level));
80
expect(!WB.shouldPrintAssembly(nomatch, comp_level));
81
expect(!WB.shouldPrintAssembly(method, comp_level));
82
expect(!WB.shouldPrintAssembly(nomatch, comp_level));
83
84
// load directives that turn it on
85
executor.execute("Compiler.directives_add " + control_on);
86
expect(WB.shouldPrintAssembly(method, comp_level));
87
expect(!WB.shouldPrintAssembly(nomatch, comp_level));
88
expect(WB.shouldPrintAssembly(method, comp_level));
89
expect(!WB.shouldPrintAssembly(nomatch, comp_level));
90
91
// remove and see that it is true again
92
executor.execute("Compiler.directives_remove");
93
expect(!WB.shouldPrintAssembly(method, comp_level));
94
expect(!WB.shouldPrintAssembly(nomatch, comp_level));
95
expect(!WB.shouldPrintAssembly(method, comp_level));
96
expect(!WB.shouldPrintAssembly(nomatch, comp_level));
97
}
98
99
public void expect(boolean test) throws Exception {
100
if (!test) {
101
throw new Exception("Test failed");
102
}
103
}
104
105
public void expect(boolean test, String msg) throws Exception {
106
if (!test) {
107
throw new Exception(msg);
108
}
109
}
110
111
@Test
112
public void jmx() throws Exception {
113
run(new JMXExecutor());
114
}
115
116
public void helper() {
117
}
118
119
public void another() {
120
}
121
122
public static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {
123
try {
124
return klass.getDeclaredMethod(name, parameterTypes);
125
} catch (NoSuchMethodException | SecurityException e) {
126
throw new RuntimeException("exception on getting method Helper." + name, e);
127
}
128
}
129
}
130
131