Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/share/actions/CompileAction.java
41161 views
1
/*
2
* Copyright (c) 2015, 2020, 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
package compiler.compilercontrol.share.actions;
25
26
import compiler.compilercontrol.share.pool.PoolHelper;
27
import compiler.compilercontrol.share.scenario.State;
28
import compiler.testlibrary.CompilerUtils;
29
import jdk.test.lib.Asserts;
30
import jdk.test.lib.util.Pair;
31
import jdk.test.lib.Utils;
32
import sun.hotspot.WhiteBox;
33
34
import java.lang.reflect.Executable;
35
import java.util.List;
36
import java.util.concurrent.Callable;
37
38
public class CompileAction {
39
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
40
private static final int[] COMP_LEVELS;
41
private static final List<Pair<Executable, Callable<?>>> METHODS
42
= new PoolHelper().getAllMethods();
43
private static final int EXEC_AMOUNT = 100;
44
45
static {
46
COMP_LEVELS = CompilerUtils.getAvailableCompilationLevels();
47
if (COMP_LEVELS.length == 0) {
48
throw new Error("TESTBUG: test requires JIT " +
49
"compiler to be available");
50
}
51
}
52
53
/**
54
* Checks executable if it could be compiled
55
*
56
* @param executable given executable to check
57
* @param state method compilation state
58
*/
59
public static void checkCompiled(Executable executable,
60
State state) {
61
{ // Dumping the state being checked
62
System.out.println("Checking expected compilation state: {");
63
System.out.println(" method: " + executable);
64
state.toString().lines()
65
.map(line -> " " + line).forEach(System.out::println);
66
System.out.println("}");
67
}
68
int first = COMP_LEVELS[0];
69
if (first < 4) {
70
checkCompilation(executable, first, state.isC1Compilable());
71
}
72
int last = COMP_LEVELS[COMP_LEVELS.length - 1];
73
if (last == 4) {
74
checkCompilation(executable, last, state.isC2Compilable());
75
}
76
}
77
78
private static void checkCompilation(Executable executable,
79
int level,
80
boolean expectedCompiled) {
81
execute(executable);
82
WHITE_BOX.enqueueMethodForCompilation(executable, level);
83
Utils.waitForCondition(
84
() -> {
85
execute(executable);
86
return !WHITE_BOX.isMethodQueuedForCompilation(executable);
87
}, 100L);
88
execute(executable);
89
boolean isCompilable = WHITE_BOX.isMethodCompilable(executable, level);
90
Asserts.assertEQ(isCompilable, expectedCompiled,
91
String.format("FAILED: method %s compilable: %b, but should: %b"
92
+ " on required level: %d", executable, isCompilable,
93
expectedCompiled, level));
94
}
95
96
private static void execute(Executable executable) {
97
Callable<?> callable = getCallableFor(executable);
98
try {
99
for (int i = 0; i < EXEC_AMOUNT; i++) {
100
callable.call();
101
}
102
} catch (Exception e) {
103
throw new Error("Got exception during execution", e);
104
}
105
}
106
107
private static Callable<?> getCallableFor(Executable executable) {
108
for (Pair<Executable, Callable<?>> pair : METHODS) {
109
if (pair.first == executable) {
110
return pair.second;
111
}
112
}
113
throw new Error("TESTBUG: wrong executable: " + executable);
114
}
115
}
116
117