author | dnsimon |
Tue, 06 Mar 2018 16:02:04 -0800 | |
changeset 49351 | 8bb47943a8dd |
parent 47216 | 71c04702a3d5 |
child 50858 | 2d3e99a72541 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
49351
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
43972 | 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 |
package jdk.vm.ci.hotspot; |
|
24 |
||
25 |
import static jdk.vm.ci.common.InitTimer.timer; |
|
26 |
||
27 |
import java.io.IOException; |
|
28 |
import java.io.OutputStream; |
|
29 |
import java.io.PrintStream; |
|
30 |
import java.util.Collections; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Map; |
|
34 |
import java.util.Objects; |
|
44836 | 35 |
import java.util.ServiceLoader; |
43972 | 36 |
import java.util.TreeMap; |
37 |
||
38 |
import jdk.internal.misc.VM; |
|
39 |
import jdk.vm.ci.code.Architecture; |
|
40 |
import jdk.vm.ci.code.CompilationRequestResult; |
|
41 |
import jdk.vm.ci.code.CompiledCode; |
|
42 |
import jdk.vm.ci.code.InstalledCode; |
|
43 |
import jdk.vm.ci.common.InitTimer; |
|
44 |
import jdk.vm.ci.common.JVMCIError; |
|
45 |
import jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory.CompilationLevel; |
|
46 |
import jdk.vm.ci.meta.JavaKind; |
|
47 |
import jdk.vm.ci.meta.JavaType; |
|
48 |
import jdk.vm.ci.meta.ResolvedJavaType; |
|
49 |
import jdk.vm.ci.runtime.JVMCI; |
|
50 |
import jdk.vm.ci.runtime.JVMCIBackend; |
|
51 |
import jdk.vm.ci.runtime.JVMCICompiler; |
|
52 |
import jdk.vm.ci.runtime.JVMCICompilerFactory; |
|
53 |
import jdk.vm.ci.services.JVMCIServiceLocator; |
|
54 |
||
55 |
/** |
|
56 |
* HotSpot implementation of a JVMCI runtime. |
|
57 |
* |
|
58 |
* The initialization of this class is very fragile since it's initialized both through |
|
59 |
* {@link JVMCI#initialize()} or through calling {@link HotSpotJVMCIRuntime#runtime()} and |
|
60 |
* {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class |
|
61 |
* can't have a static initializer and any required initialization must be done as part of |
|
62 |
* {@link #runtime()}. This allows the initialization to funnel back through |
|
63 |
* {@link JVMCI#initialize()} without deadlocking. |
|
64 |
*/ |
|
65 |
public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider { |
|
66 |
||
67 |
@SuppressWarnings("try") |
|
68 |
static class DelayedInit { |
|
69 |
private static final HotSpotJVMCIRuntime instance; |
|
70 |
||
71 |
static { |
|
72 |
try (InitTimer t = timer("HotSpotJVMCIRuntime.<init>")) { |
|
73 |
instance = new HotSpotJVMCIRuntime(); |
|
49351
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
74 |
|
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
75 |
// Can only do eager initialization of the JVMCI compiler |
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
76 |
// once the singleton instance is available. |
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
77 |
if (instance.config.getFlag("EagerJVMCI", Boolean.class)) { |
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
78 |
instance.getCompiler(); |
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
79 |
} |
43972 | 80 |
} |
81 |
} |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Gets the singleton {@link HotSpotJVMCIRuntime} object. |
|
86 |
*/ |
|
87 |
public static HotSpotJVMCIRuntime runtime() { |
|
88 |
JVMCI.initialize(); |
|
89 |
return DelayedInit.instance; |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* A list of all supported JVMCI options. |
|
94 |
*/ |
|
95 |
public enum Option { |
|
96 |
// @formatter:off |
|
44836 | 97 |
Compiler(String.class, null, "Selects the system compiler. This must match the getCompilerName() value returned " + |
98 |
"by a jdk.vm.ci.runtime.JVMCICompilerFactory provider. " + |
|
99 |
"An empty string or the value \"null\" selects a compiler " + |
|
100 |
"that will raise an exception upon receiving a compilation request."), |
|
43972 | 101 |
// Note: The following one is not used (see InitTimer.ENABLED). It is added here |
102 |
// so that -XX:+JVMCIPrintProperties shows the option. |
|
103 |
InitTimer(Boolean.class, false, "Specifies if initialization timing is enabled."), |
|
104 |
PrintConfig(Boolean.class, false, "Prints VM configuration available via JVMCI."), |
|
105 |
TraceMethodDataFilter(String.class, null, |
|
106 |
"Enables tracing of profiling info when read by JVMCI.", |
|
107 |
"Empty value: trace all methods", |
|
108 |
"Non-empty value: trace methods whose fully qualified name contains the value."), |
|
109 |
UseProfilingInformation(Boolean.class, true, ""); |
|
110 |
// @formatter:on |
|
111 |
||
112 |
/** |
|
113 |
* The prefix for system properties that are JVMCI options. |
|
114 |
*/ |
|
115 |
private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci."; |
|
116 |
||
117 |
/** |
|
118 |
* Marker for uninitialized flags. |
|
119 |
*/ |
|
120 |
private static final String UNINITIALIZED = "UNINITIALIZED"; |
|
121 |
||
122 |
private final Class<?> type; |
|
123 |
private Object value; |
|
124 |
private final Object defaultValue; |
|
125 |
private boolean isDefault; |
|
126 |
private final String[] helpLines; |
|
127 |
||
128 |
Option(Class<?> type, Object defaultValue, String... helpLines) { |
|
129 |
assert Character.isUpperCase(name().charAt(0)) : "Option name must start with upper-case letter: " + name(); |
|
130 |
this.type = type; |
|
131 |
this.value = UNINITIALIZED; |
|
132 |
this.defaultValue = defaultValue; |
|
133 |
this.helpLines = helpLines; |
|
134 |
} |
|
135 |
||
136 |
@SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "sentinel must be String since it's a static final in an enum") |
|
137 |
private Object getValue() { |
|
138 |
if (value == UNINITIALIZED) { |
|
139 |
String propertyValue = VM.getSavedProperty(getPropertyName()); |
|
140 |
if (propertyValue == null) { |
|
141 |
this.value = defaultValue; |
|
142 |
this.isDefault = true; |
|
143 |
} else { |
|
144 |
if (type == Boolean.class) { |
|
145 |
this.value = Boolean.parseBoolean(propertyValue); |
|
146 |
} else if (type == String.class) { |
|
147 |
this.value = propertyValue; |
|
148 |
} else { |
|
149 |
throw new JVMCIError("Unexpected option type " + type); |
|
150 |
} |
|
151 |
this.isDefault = false; |
|
152 |
} |
|
153 |
// Saved properties should not be interned - let's be sure |
|
154 |
assert value != UNINITIALIZED; |
|
155 |
} |
|
156 |
return value; |
|
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
* Gets the name of system property from which this option gets its value. |
|
161 |
*/ |
|
162 |
public String getPropertyName() { |
|
163 |
return JVMCI_OPTION_PROPERTY_PREFIX + name(); |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Returns the option's value as boolean. |
|
168 |
* |
|
169 |
* @return option's value |
|
170 |
*/ |
|
171 |
public boolean getBoolean() { |
|
172 |
return (boolean) getValue(); |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Returns the option's value as String. |
|
177 |
* |
|
178 |
* @return option's value |
|
179 |
*/ |
|
180 |
public String getString() { |
|
181 |
return (String) getValue(); |
|
182 |
} |
|
183 |
||
184 |
private static final int PROPERTY_LINE_WIDTH = 80; |
|
185 |
private static final int PROPERTY_HELP_INDENT = 10; |
|
186 |
||
187 |
/** |
|
188 |
* Prints a description of the properties used to configure shared JVMCI code. |
|
189 |
* |
|
190 |
* @param out stream to print to |
|
191 |
*/ |
|
192 |
public static void printProperties(PrintStream out) { |
|
193 |
out.println("[JVMCI properties]"); |
|
194 |
Option[] values = values(); |
|
195 |
for (Option option : values) { |
|
196 |
Object value = option.getValue(); |
|
197 |
if (value instanceof String) { |
|
198 |
value = '"' + String.valueOf(value) + '"'; |
|
199 |
} |
|
200 |
||
201 |
String name = option.getPropertyName(); |
|
202 |
String assign = option.isDefault ? "=" : ":="; |
|
203 |
String typeName = option.type.getSimpleName(); |
|
204 |
String linePrefix = String.format("%s %s %s ", name, assign, value); |
|
205 |
int typeStartPos = PROPERTY_LINE_WIDTH - typeName.length(); |
|
206 |
int linePad = typeStartPos - linePrefix.length(); |
|
207 |
if (linePad > 0) { |
|
208 |
out.printf("%s%-" + linePad + "s[%s]%n", linePrefix, "", typeName); |
|
209 |
} else { |
|
210 |
out.printf("%s[%s]%n", linePrefix, typeName); |
|
211 |
} |
|
212 |
for (String line : option.helpLines) { |
|
213 |
out.printf("%" + PROPERTY_HELP_INDENT + "s%s%n", "", line); |
|
214 |
} |
|
215 |
} |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
public static HotSpotJVMCIBackendFactory findFactory(String architecture) { |
|
44836 | 220 |
for (HotSpotJVMCIBackendFactory factory : ServiceLoader.load(HotSpotJVMCIBackendFactory.class, ClassLoader.getSystemClassLoader())) { |
43972 | 221 |
if (factory.getArchitecture().equalsIgnoreCase(architecture)) { |
222 |
return factory; |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture); |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend. |
|
231 |
*/ |
|
232 |
public static JavaKind getHostWordKind() { |
|
233 |
return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind; |
|
234 |
} |
|
235 |
||
236 |
protected final CompilerToVM compilerToVm; |
|
237 |
||
238 |
protected final HotSpotVMConfigStore configStore; |
|
239 |
protected final HotSpotVMConfig config; |
|
240 |
private final JVMCIBackend hostBackend; |
|
241 |
||
242 |
private final JVMCICompilerFactory compilerFactory; |
|
243 |
private final HotSpotJVMCICompilerFactory hsCompilerFactory; |
|
244 |
private volatile JVMCICompiler compiler; |
|
245 |
protected final HotSpotJVMCIMetaAccessContext metaAccessContext; |
|
246 |
||
247 |
/** |
|
248 |
* Stores the result of {@link HotSpotJVMCICompilerFactory#getCompilationLevelAdjustment} so |
|
249 |
* that it can be read from the VM. |
|
250 |
*/ |
|
251 |
@SuppressWarnings("unused") private final int compilationLevelAdjustment; |
|
252 |
||
253 |
private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>(); |
|
254 |
||
255 |
private volatile List<HotSpotVMEventListener> vmEventListeners; |
|
256 |
||
257 |
private Iterable<HotSpotVMEventListener> getVmEventListeners() { |
|
258 |
if (vmEventListeners == null) { |
|
259 |
synchronized (this) { |
|
260 |
if (vmEventListeners == null) { |
|
261 |
vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class); |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
return vmEventListeners; |
|
266 |
} |
|
267 |
||
268 |
/** |
|
269 |
* Stores the result of {@link HotSpotJVMCICompilerFactory#getTrivialPrefixes()} so that it can |
|
270 |
* be read from the VM. |
|
271 |
*/ |
|
272 |
@SuppressWarnings("unused") private final String[] trivialPrefixes; |
|
273 |
||
274 |
@SuppressWarnings("try") |
|
275 |
private HotSpotJVMCIRuntime() { |
|
276 |
compilerToVm = new CompilerToVM(); |
|
277 |
||
278 |
try (InitTimer t = timer("HotSpotVMConfig<init>")) { |
|
279 |
configStore = new HotSpotVMConfigStore(compilerToVm); |
|
280 |
config = new HotSpotVMConfig(configStore); |
|
281 |
} |
|
282 |
||
283 |
String hostArchitecture = config.getHostArchitectureName(); |
|
284 |
||
285 |
HotSpotJVMCIBackendFactory factory; |
|
286 |
try (InitTimer t = timer("find factory:", hostArchitecture)) { |
|
287 |
factory = findFactory(hostArchitecture); |
|
288 |
} |
|
289 |
||
290 |
try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) { |
|
291 |
hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); |
|
292 |
} |
|
293 |
||
294 |
metaAccessContext = new HotSpotJVMCIMetaAccessContext(); |
|
295 |
||
296 |
compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); |
|
297 |
if (compilerFactory instanceof HotSpotJVMCICompilerFactory) { |
|
298 |
hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory; |
|
299 |
trivialPrefixes = hsCompilerFactory.getTrivialPrefixes(); |
|
300 |
switch (hsCompilerFactory.getCompilationLevelAdjustment()) { |
|
301 |
case None: |
|
302 |
compilationLevelAdjustment = config.compLevelAdjustmentNone; |
|
303 |
break; |
|
304 |
case ByHolder: |
|
305 |
compilationLevelAdjustment = config.compLevelAdjustmentByHolder; |
|
306 |
break; |
|
307 |
case ByFullSignature: |
|
308 |
compilationLevelAdjustment = config.compLevelAdjustmentByFullSignature; |
|
309 |
break; |
|
310 |
default: |
|
311 |
compilationLevelAdjustment = config.compLevelAdjustmentNone; |
|
312 |
break; |
|
313 |
} |
|
314 |
} else { |
|
315 |
hsCompilerFactory = null; |
|
316 |
trivialPrefixes = null; |
|
317 |
compilationLevelAdjustment = config.compLevelAdjustmentNone; |
|
318 |
} |
|
319 |
||
320 |
if (config.getFlag("JVMCIPrintProperties", Boolean.class)) { |
|
321 |
PrintStream out = new PrintStream(getLogStream()); |
|
322 |
Option.printProperties(out); |
|
323 |
compilerFactory.printProperties(out); |
|
324 |
System.exit(0); |
|
325 |
} |
|
326 |
||
327 |
if (Option.PrintConfig.getBoolean()) { |
|
328 |
printConfig(configStore, compilerToVm); |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
private JVMCIBackend registerBackend(JVMCIBackend backend) { |
|
333 |
Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass(); |
|
334 |
JVMCIBackend oldValue = backends.put(arch, backend); |
|
335 |
assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName(); |
|
336 |
return backend; |
|
337 |
} |
|
338 |
||
339 |
public ResolvedJavaType fromClass(Class<?> javaClass) { |
|
340 |
return metaAccessContext.fromClass(javaClass); |
|
341 |
} |
|
342 |
||
343 |
public HotSpotVMConfigStore getConfigStore() { |
|
344 |
return configStore; |
|
345 |
} |
|
346 |
||
347 |
public HotSpotVMConfig getConfig() { |
|
348 |
return config; |
|
349 |
} |
|
350 |
||
351 |
public CompilerToVM getCompilerToVM() { |
|
352 |
return compilerToVm; |
|
353 |
} |
|
354 |
||
355 |
public JVMCICompiler getCompiler() { |
|
356 |
if (compiler == null) { |
|
357 |
synchronized (this) { |
|
358 |
if (compiler == null) { |
|
359 |
compiler = compilerFactory.createCompiler(this); |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
return compiler; |
|
364 |
} |
|
365 |
||
366 |
public JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve) { |
|
367 |
Objects.requireNonNull(accessingType, "cannot resolve type without an accessing class"); |
|
368 |
// If the name represents a primitive type we can short-circuit the lookup. |
|
369 |
if (name.length() == 1) { |
|
370 |
JavaKind kind = JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); |
|
371 |
return fromClass(kind.toJavaClass()); |
|
372 |
} |
|
373 |
||
374 |
// Resolve non-primitive types in the VM. |
|
375 |
HotSpotResolvedObjectTypeImpl hsAccessingType = (HotSpotResolvedObjectTypeImpl) accessingType; |
|
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
376 |
try { |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
377 |
final HotSpotResolvedObjectTypeImpl klass = compilerToVm.lookupType(name, hsAccessingType.mirror(), resolve); |
43972 | 378 |
|
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
379 |
if (klass == null) { |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
380 |
assert resolve == false; |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
381 |
return HotSpotUnresolvedJavaType.create(this, name); |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
382 |
} |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
383 |
return klass; |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
384 |
} catch (ClassNotFoundException e) { |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
385 |
throw (NoClassDefFoundError) new NoClassDefFoundError().initCause(e); |
43972 | 386 |
} |
387 |
} |
|
388 |
||
389 |
public JVMCIBackend getHostJVMCIBackend() { |
|
390 |
return hostBackend; |
|
391 |
} |
|
392 |
||
393 |
public <T extends Architecture> JVMCIBackend getJVMCIBackend(Class<T> arch) { |
|
394 |
assert arch != Architecture.class; |
|
395 |
return backends.get(arch); |
|
396 |
} |
|
397 |
||
398 |
public Map<Class<? extends Architecture>, JVMCIBackend> getJVMCIBackends() { |
|
399 |
return Collections.unmodifiableMap(backends); |
|
400 |
} |
|
401 |
||
402 |
/** |
|
403 |
* Called from the VM. |
|
404 |
*/ |
|
405 |
@SuppressWarnings({"unused"}) |
|
406 |
private int adjustCompilationLevel(Class<?> declaringClass, String name, String signature, boolean isOsr, int level) { |
|
407 |
CompilationLevel curLevel; |
|
408 |
if (level == config.compilationLevelNone) { |
|
409 |
curLevel = CompilationLevel.None; |
|
410 |
} else if (level == config.compilationLevelSimple) { |
|
411 |
curLevel = CompilationLevel.Simple; |
|
412 |
} else if (level == config.compilationLevelLimitedProfile) { |
|
413 |
curLevel = CompilationLevel.LimitedProfile; |
|
414 |
} else if (level == config.compilationLevelFullProfile) { |
|
415 |
curLevel = CompilationLevel.FullProfile; |
|
416 |
} else if (level == config.compilationLevelFullOptimization) { |
|
417 |
curLevel = CompilationLevel.FullOptimization; |
|
418 |
} else { |
|
419 |
throw JVMCIError.shouldNotReachHere(); |
|
420 |
} |
|
421 |
||
422 |
switch (hsCompilerFactory.adjustCompilationLevel(declaringClass, name, signature, isOsr, curLevel)) { |
|
423 |
case None: |
|
424 |
return config.compilationLevelNone; |
|
425 |
case Simple: |
|
426 |
return config.compilationLevelSimple; |
|
427 |
case LimitedProfile: |
|
428 |
return config.compilationLevelLimitedProfile; |
|
429 |
case FullProfile: |
|
430 |
return config.compilationLevelFullProfile; |
|
431 |
case FullOptimization: |
|
432 |
return config.compilationLevelFullOptimization; |
|
433 |
default: |
|
434 |
return level; |
|
435 |
} |
|
436 |
} |
|
437 |
||
438 |
/** |
|
439 |
* Called from the VM. |
|
440 |
*/ |
|
441 |
@SuppressWarnings({"unused"}) |
|
442 |
private HotSpotCompilationRequestResult compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id) { |
|
443 |
CompilationRequestResult result = getCompiler().compileMethod(new HotSpotCompilationRequest(method, entryBCI, jvmciEnv, id)); |
|
444 |
assert result != null : "compileMethod must always return something"; |
|
445 |
HotSpotCompilationRequestResult hsResult; |
|
446 |
if (result instanceof HotSpotCompilationRequestResult) { |
|
447 |
hsResult = (HotSpotCompilationRequestResult) result; |
|
448 |
} else { |
|
449 |
Object failure = result.getFailure(); |
|
450 |
if (failure != null) { |
|
451 |
boolean retry = false; // Be conservative with unknown compiler |
|
452 |
hsResult = HotSpotCompilationRequestResult.failure(failure.toString(), retry); |
|
453 |
} else { |
|
454 |
int inlinedBytecodes = -1; |
|
455 |
hsResult = HotSpotCompilationRequestResult.success(inlinedBytecodes); |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
return hsResult; |
|
460 |
} |
|
461 |
||
462 |
/** |
|
463 |
* Shuts down the runtime. |
|
464 |
* |
|
465 |
* Called from the VM. |
|
466 |
*/ |
|
467 |
@SuppressWarnings({"unused"}) |
|
468 |
private void shutdown() throws Exception { |
|
469 |
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) { |
|
470 |
vmEventListener.notifyShutdown(); |
|
471 |
} |
|
472 |
} |
|
473 |
||
474 |
/** |
|
475 |
* Notify on completion of a bootstrap. |
|
476 |
* |
|
477 |
* Called from the VM. |
|
478 |
*/ |
|
479 |
@SuppressWarnings({"unused"}) |
|
480 |
private void bootstrapFinished() throws Exception { |
|
481 |
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) { |
|
482 |
vmEventListener.notifyBootstrapFinished(); |
|
483 |
} |
|
484 |
} |
|
485 |
||
486 |
/** |
|
487 |
* Notify on successful install into the CodeCache. |
|
488 |
* |
|
489 |
* @param hotSpotCodeCacheProvider |
|
490 |
* @param installedCode |
|
491 |
* @param compiledCode |
|
492 |
*/ |
|
493 |
void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, InstalledCode installedCode, CompiledCode compiledCode) { |
|
494 |
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) { |
|
495 |
vmEventListener.notifyInstall(hotSpotCodeCacheProvider, installedCode, compiledCode); |
|
496 |
} |
|
497 |
} |
|
498 |
||
499 |
@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "no localization here please!") |
|
500 |
private static void printConfigLine(CompilerToVM vm, String format, Object... args) { |
|
501 |
String line = String.format(format, args); |
|
502 |
byte[] lineBytes = line.getBytes(); |
|
503 |
vm.writeDebugOutput(lineBytes, 0, lineBytes.length); |
|
504 |
vm.flushDebugOutput(); |
|
505 |
} |
|
506 |
||
507 |
private static void printConfig(HotSpotVMConfigStore store, CompilerToVM vm) { |
|
508 |
TreeMap<String, VMField> fields = new TreeMap<>(store.getFields()); |
|
509 |
for (VMField field : fields.values()) { |
|
510 |
if (!field.isStatic()) { |
|
511 |
printConfigLine(vm, "[vmconfig:instance field] %s %s {offset=%d[0x%x]}%n", field.type, field.name, field.offset, field.offset); |
|
512 |
} else { |
|
513 |
String value = field.value == null ? "null" : field.value instanceof Boolean ? field.value.toString() : String.format("%d[0x%x]", field.value, field.value); |
|
514 |
printConfigLine(vm, "[vmconfig:static field] %s %s = %s {address=0x%x}%n", field.type, field.name, value, field.address); |
|
515 |
} |
|
516 |
} |
|
517 |
TreeMap<String, VMFlag> flags = new TreeMap<>(store.getFlags()); |
|
518 |
for (VMFlag flag : flags.values()) { |
|
519 |
printConfigLine(vm, "[vmconfig:flag] %s %s = %s%n", flag.type, flag.name, flag.value); |
|
520 |
} |
|
521 |
TreeMap<String, Long> addresses = new TreeMap<>(store.getAddresses()); |
|
522 |
for (Map.Entry<String, Long> e : addresses.entrySet()) { |
|
523 |
printConfigLine(vm, "[vmconfig:address] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); |
|
524 |
} |
|
525 |
TreeMap<String, Long> constants = new TreeMap<>(store.getConstants()); |
|
526 |
for (Map.Entry<String, Long> e : constants.entrySet()) { |
|
527 |
printConfigLine(vm, "[vmconfig:constant] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); |
|
528 |
} |
|
529 |
for (VMIntrinsicMethod e : store.getIntrinsics()) { |
|
530 |
printConfigLine(vm, "[vmconfig:intrinsic] %d = %s.%s %s%n", e.id, e.declaringClass, e.name, e.descriptor); |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
public OutputStream getLogStream() { |
|
535 |
return new OutputStream() { |
|
536 |
||
537 |
@Override |
|
538 |
public void write(byte[] b, int off, int len) throws IOException { |
|
539 |
if (b == null) { |
|
540 |
throw new NullPointerException(); |
|
541 |
} else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length || (off + len) < 0) { |
|
542 |
throw new IndexOutOfBoundsException(); |
|
543 |
} else if (len == 0) { |
|
544 |
return; |
|
545 |
} |
|
546 |
compilerToVm.writeDebugOutput(b, off, len); |
|
547 |
} |
|
548 |
||
549 |
@Override |
|
550 |
public void write(int b) throws IOException { |
|
551 |
write(new byte[]{(byte) b}, 0, 1); |
|
552 |
} |
|
553 |
||
554 |
@Override |
|
555 |
public void flush() throws IOException { |
|
556 |
compilerToVm.flushDebugOutput(); |
|
557 |
} |
|
558 |
}; |
|
559 |
} |
|
560 |
||
561 |
/** |
|
562 |
* Collects the current values of all JVMCI benchmark counters, summed up over all threads. |
|
563 |
*/ |
|
564 |
public long[] collectCounters() { |
|
565 |
return compilerToVm.collectCounters(); |
|
566 |
} |
|
567 |
} |