Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/AbstractCommandBuilder.java
41161 views
1
/*
2
* Copyright (c) 2015, 2016, 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.scenario;
25
26
import compiler.compilercontrol.share.method.MethodDescriptor;
27
import compiler.compilercontrol.share.pool.PoolHelper;
28
import jdk.test.lib.util.Pair;
29
30
import java.lang.reflect.Executable;
31
import java.util.ArrayList;
32
import java.util.Collections;
33
import java.util.HashMap;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.concurrent.Callable;
37
38
/**
39
* An abstract class that builds states by applying
40
* commands one after another
41
*/
42
public abstract class AbstractCommandBuilder
43
implements StateBuilder<CompileCommand> {
44
protected static final List<Pair<Executable, Callable<?>>> METHODS
45
= new PoolHelper().getAllMethods();
46
protected final List<CompileCommand> compileCommands = new ArrayList<>();
47
48
@Override
49
public void add(CompileCommand command) {
50
compileCommands.add(command);
51
CommandStateBuilder.getInstance().add(command);
52
}
53
54
@Override
55
public Map<Executable, State> getStates() {
56
return CommandStateBuilder.getInstance().getStates();
57
}
58
59
@Override
60
public List<CompileCommand> getCompileCommands() {
61
return Collections.unmodifiableList(compileCommands);
62
}
63
64
@Override
65
public boolean isValid() {
66
boolean isValid = true;
67
for (CompileCommand cmd : compileCommands) {
68
isValid &= cmd.isValid();
69
}
70
return isValid;
71
}
72
73
/*
74
* This is an internal class used to build states for commands given from
75
* options and a file. As all commands are added into a single set in
76
* CompilerOracle, we need a class that builds states in the same manner
77
*/
78
private static class CommandStateBuilder {
79
private static final CommandStateBuilder INSTANCE
80
= new CommandStateBuilder();
81
private final List<CompileCommand> optionCommands = new ArrayList<>();
82
private final List<CompileCommand> fileCommands = new ArrayList<>();
83
84
private CommandStateBuilder() { }
85
86
public static CommandStateBuilder getInstance() {
87
return INSTANCE;
88
}
89
90
public void add(CompileCommand command) {
91
switch (command.type) {
92
case OPTION:
93
optionCommands.add(command);
94
break;
95
case FILE:
96
fileCommands.add(command);
97
break;
98
default:
99
throw new Error("TESTBUG: wrong type: " + command.type);
100
}
101
}
102
103
public Map<Executable, State> getStates() {
104
List<CompileCommand> commandList = new ArrayList<>();
105
commandList.addAll(optionCommands);
106
commandList.addAll(fileCommands);
107
Map<Executable, State> states = new HashMap<>();
108
for (Pair<Executable, Callable<?>> pair : METHODS) {
109
Executable exec = pair.first;
110
State state = getState(commandList, exec);
111
states.put(exec, state);
112
}
113
return states;
114
}
115
116
private State getState(List<CompileCommand> commandList,
117
Executable exec) {
118
State state = new State();
119
MethodDescriptor execDesc = new MethodDescriptor(exec);
120
for (CompileCommand compileCommand : commandList) {
121
if (compileCommand.isValid()) {
122
// Create a copy without compiler set
123
CompileCommand cc = new CompileCommand(
124
compileCommand.command,
125
compileCommand.methodDescriptor,
126
/* CompileCommand option and file doesn't support
127
compiler setting */
128
null,
129
compileCommand.type);
130
MethodDescriptor md = cc.methodDescriptor;
131
// if executable matches regex then apply the state
132
if (execDesc.getCanonicalString().matches(md.getRegexp())) {
133
if (cc.command == Command.COMPILEONLY
134
&& !state.isCompilable()) {
135
/* if the method was already excluded it will not
136
be compilable again */
137
} else {
138
state.apply(cc);
139
}
140
}
141
}
142
}
143
144
/*
145
* Set compilation states for methods that don't match
146
* any compileonly command. Such methods should be excluded
147
* from compilation
148
*/
149
for (CompileCommand compileCommand : commandList) {
150
if (compileCommand.isValid()
151
&& (compileCommand.command == Command.COMPILEONLY)) {
152
MethodDescriptor md = compileCommand.methodDescriptor;
153
if (!execDesc.getCanonicalString().matches(md.getRegexp())
154
// if compilation state wasn't set before
155
&& (!state.getCompilableOptional(
156
// no matter C1, C2 or both
157
Scenario.Compiler.C2).isPresent())) {
158
/* compileonly excludes only methods that haven't been
159
already set to be compilable or excluded */
160
state.setC1Compilable(false);
161
state.setC2Compilable(false);
162
}
163
}
164
}
165
return state;
166
}
167
}
168
}
169
170