author | lkorinth |
Wed, 13 Nov 2019 11:37:29 +0100 | |
changeset 59053 | ba6c248cae19 |
parent 58533 | 46b0b7fe255c |
child 59237 | 2601fc0874be |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
58299 | 2 |
* Copyright (c) 2011, 2019, 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 |
*/ |
|
50858 | 23 |
|
24 |
||
43972 | 25 |
package org.graalvm.compiler.hotspot; |
26 |
||
46344 | 27 |
import static jdk.vm.ci.common.InitTimer.timer; |
28 |
import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; |
|
43972 | 29 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
46344 | 30 |
import static org.graalvm.compiler.core.common.GraalOptions.HotSpotPrintInlining; |
43972 | 31 |
|
52578 | 32 |
import java.io.PrintStream; |
46344 | 33 |
import java.util.ArrayList; |
46807 | 34 |
import java.util.EnumMap; |
46344 | 35 |
import java.util.List; |
46807 | 36 |
import java.util.Map; |
49873 | 37 |
import java.util.concurrent.atomic.AtomicReference; |
58533 | 38 |
import java.util.function.Supplier; |
43972 | 39 |
|
49873 | 40 |
import jdk.internal.vm.compiler.collections.EconomicMap; |
41 |
import jdk.internal.vm.compiler.collections.EconomicSet; |
|
42 |
import jdk.internal.vm.compiler.collections.Equivalence; |
|
43 |
import jdk.internal.vm.compiler.collections.UnmodifiableMapCursor; |
|
43972 | 44 |
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; |
45 |
import org.graalvm.compiler.api.runtime.GraalRuntime; |
|
46807 | 46 |
import org.graalvm.compiler.core.CompilationWrapper.ExceptionAction; |
46640 | 47 |
import org.graalvm.compiler.core.common.CompilationIdentifier; |
43972 | 48 |
import org.graalvm.compiler.core.common.GraalOptions; |
52956 | 49 |
import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; |
43972 | 50 |
import org.graalvm.compiler.core.target.Backend; |
46640 | 51 |
import org.graalvm.compiler.debug.DebugContext; |
52 |
import org.graalvm.compiler.debug.DebugContext.Description; |
|
46680 | 53 |
import org.graalvm.compiler.debug.DebugHandlersFactory; |
49873 | 54 |
import org.graalvm.compiler.debug.DebugOptions; |
46680 | 55 |
import org.graalvm.compiler.debug.DiagnosticsOutputDirectory; |
46640 | 56 |
import org.graalvm.compiler.debug.GlobalMetrics; |
43972 | 57 |
import org.graalvm.compiler.debug.GraalError; |
58 |
import org.graalvm.compiler.debug.TTY; |
|
46344 | 59 |
import org.graalvm.compiler.hotspot.CompilationStatistics.Options; |
43972 | 60 |
import org.graalvm.compiler.hotspot.CompilerConfigurationFactory.BackendMap; |
61 |
import org.graalvm.compiler.hotspot.debug.BenchmarkCounters; |
|
62 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
|
63 |
import org.graalvm.compiler.nodes.spi.StampProvider; |
|
49873 | 64 |
import org.graalvm.compiler.options.EnumOptionKey; |
65 |
import org.graalvm.compiler.options.OptionDescriptor; |
|
66 |
import org.graalvm.compiler.options.OptionDescriptors; |
|
67 |
import org.graalvm.compiler.options.OptionKey; |
|
46344 | 68 |
import org.graalvm.compiler.options.OptionValues; |
49873 | 69 |
import org.graalvm.compiler.options.OptionsParser; |
43972 | 70 |
import org.graalvm.compiler.phases.tiers.CompilerConfiguration; |
71 |
import org.graalvm.compiler.replacements.SnippetCounter; |
|
46344 | 72 |
import org.graalvm.compiler.replacements.SnippetCounter.Group; |
43972 | 73 |
import org.graalvm.compiler.runtime.RuntimeProvider; |
49873 | 74 |
import org.graalvm.compiler.serviceprovider.GraalServices; |
43972 | 75 |
|
76 |
import jdk.vm.ci.code.Architecture; |
|
77 |
import jdk.vm.ci.code.stack.StackIntrospection; |
|
78 |
import jdk.vm.ci.common.InitTimer; |
|
49873 | 79 |
import jdk.vm.ci.hotspot.HotSpotCompilationRequest; |
43972 | 80 |
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; |
49873 | 81 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
82 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaType; |
|
83 |
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
|
43972 | 84 |
import jdk.vm.ci.hotspot.HotSpotVMConfigStore; |
85 |
import jdk.vm.ci.meta.JavaKind; |
|
50858 | 86 |
import jdk.vm.ci.meta.MetaAccessProvider; |
46459 | 87 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
49873 | 88 |
import jdk.vm.ci.meta.ResolvedJavaType; |
89 |
import jdk.vm.ci.runtime.JVMCI; |
|
43972 | 90 |
import jdk.vm.ci.runtime.JVMCIBackend; |
54328 | 91 |
import jdk.vm.ci.services.Services; |
43972 | 92 |
|
93 |
//JaCoCo Exclude |
|
94 |
||
95 |
/** |
|
96 |
* Singleton class holding the instance of the {@link GraalRuntime}. |
|
97 |
*/ |
|
98 |
public final class HotSpotGraalRuntime implements HotSpotGraalRuntimeProvider { |
|
99 |
||
54328 | 100 |
private static final boolean IS_AOT = Boolean.parseBoolean(Services.getSavedProperties().get("com.oracle.graalvm.isaot")); |
58533 | 101 |
/** |
102 |
* A factory for {@link HotSpotGraalManagementRegistration} injected by {@code LibGraalFeature}. |
|
103 |
*/ |
|
104 |
private static final Supplier<HotSpotGraalManagementRegistration> AOT_INJECTED_MANAGEMENT = null; |
|
54084 | 105 |
|
50858 | 106 |
private static boolean checkArrayIndexScaleInvariants(MetaAccessProvider metaAccess) { |
107 |
assert metaAccess.getArrayIndexScale(JavaKind.Byte) == 1; |
|
108 |
assert metaAccess.getArrayIndexScale(JavaKind.Boolean) == 1; |
|
109 |
assert metaAccess.getArrayIndexScale(JavaKind.Char) == 2; |
|
110 |
assert metaAccess.getArrayIndexScale(JavaKind.Short) == 2; |
|
111 |
assert metaAccess.getArrayIndexScale(JavaKind.Int) == 4; |
|
112 |
assert metaAccess.getArrayIndexScale(JavaKind.Long) == 8; |
|
113 |
assert metaAccess.getArrayIndexScale(JavaKind.Float) == 4; |
|
114 |
assert metaAccess.getArrayIndexScale(JavaKind.Double) == 8; |
|
43972 | 115 |
return true; |
116 |
} |
|
117 |
||
49873 | 118 |
private final String runtimeName; |
50330 | 119 |
private final String compilerConfigurationName; |
43972 | 120 |
private final HotSpotBackend hostBackend; |
58299 | 121 |
|
122 |
public GlobalMetrics getMetricValues() { |
|
123 |
return metricValues; |
|
124 |
} |
|
125 |
||
46640 | 126 |
private final GlobalMetrics metricValues = new GlobalMetrics(); |
46344 | 127 |
private final List<SnippetCounter.Group> snippetCounterGroups; |
50858 | 128 |
private final HotSpotGC garbageCollector; |
43972 | 129 |
|
46344 | 130 |
private final EconomicMap<Class<? extends Architecture>, HotSpotBackend> backends = EconomicMap.create(Equivalence.IDENTITY); |
43972 | 131 |
|
132 |
private final GraalHotSpotVMConfig config; |
|
133 |
||
49873 | 134 |
/** |
135 |
* The options can be {@linkplain #setOptionValues(String[], String[]) updated} by external |
|
136 |
* interfaces such as JMX. This comes with the risk that inconsistencies can arise as an |
|
137 |
* {@link OptionValues} object can be cached by various parts of Graal instead of always |
|
138 |
* obtaining them from this object. However, concurrent updates are never lost. |
|
139 |
*/ |
|
140 |
private AtomicReference<OptionValues> optionsRef = new AtomicReference<>(); |
|
141 |
||
46680 | 142 |
private final DiagnosticsOutputDirectory outputDirectory; |
46807 | 143 |
private final Map<ExceptionAction, Integer> compilationProblemsPerAction; |
46344 | 144 |
|
43972 | 145 |
/** |
49873 | 146 |
* @param nameQualifier a qualifier to be added to this runtime's {@linkplain #getName() name} |
43972 | 147 |
* @param compilerConfigurationFactory factory for the compiler configuration |
46344 | 148 |
* {@link CompilerConfigurationFactory#selectFactory(String, OptionValues)} |
43972 | 149 |
*/ |
150 |
@SuppressWarnings("try") |
|
49873 | 151 |
HotSpotGraalRuntime(String nameQualifier, HotSpotJVMCIRuntime jvmciRuntime, CompilerConfigurationFactory compilerConfigurationFactory, OptionValues initialOptions) { |
152 |
this.runtimeName = getClass().getSimpleName() + ":" + nameQualifier; |
|
43972 | 153 |
HotSpotVMConfigStore store = jvmciRuntime.getConfigStore(); |
46344 | 154 |
config = GeneratePIC.getValue(initialOptions) ? new AOTGraalHotSpotVMConfig(store) : new GraalHotSpotVMConfig(store); |
43972 | 155 |
|
156 |
// Only set HotSpotPrintInlining if it still has its default value (false). |
|
46344 | 157 |
if (GraalOptions.HotSpotPrintInlining.getValue(initialOptions) == false && config.printInlining) { |
49873 | 158 |
optionsRef.set(new OptionValues(initialOptions, HotSpotPrintInlining, true)); |
46344 | 159 |
} else { |
49873 | 160 |
optionsRef.set(initialOptions); |
161 |
} |
|
162 |
OptionValues options = optionsRef.get(); |
|
163 |
||
51436 | 164 |
garbageCollector = getSelectedGC(); |
43972 | 165 |
|
46680 | 166 |
outputDirectory = new DiagnosticsOutputDirectory(options); |
46807 | 167 |
compilationProblemsPerAction = new EnumMap<>(ExceptionAction.class); |
46344 | 168 |
snippetCounterGroups = GraalOptions.SnippetCounters.getValue(options) ? new ArrayList<>() : null; |
43972 | 169 |
CompilerConfiguration compilerConfiguration = compilerConfigurationFactory.createCompilerConfiguration(); |
50330 | 170 |
compilerConfigurationName = compilerConfigurationFactory.getName(); |
46536 | 171 |
|
54084 | 172 |
if (IS_AOT) { |
58533 | 173 |
management = AOT_INJECTED_MANAGEMENT == null ? null : AOT_INJECTED_MANAGEMENT.get(); |
54084 | 174 |
} else { |
175 |
management = GraalServices.loadSingle(HotSpotGraalManagementRegistration.class, false); |
|
58533 | 176 |
} |
177 |
if (management != null) { |
|
178 |
management.initialize(this, config); |
|
49873 | 179 |
} |
46536 | 180 |
|
43972 | 181 |
BackendMap backendMap = compilerConfigurationFactory.createBackendMap(); |
182 |
||
183 |
JVMCIBackend hostJvmciBackend = jvmciRuntime.getHostJVMCIBackend(); |
|
184 |
Architecture hostArchitecture = hostJvmciBackend.getTarget().arch; |
|
185 |
try (InitTimer t = timer("create backend:", hostArchitecture)) { |
|
186 |
HotSpotBackendFactory factory = backendMap.getBackendFactory(hostArchitecture); |
|
187 |
if (factory == null) { |
|
188 |
throw new GraalError("No backend available for host architecture \"%s\"", hostArchitecture); |
|
189 |
} |
|
190 |
hostBackend = registerBackend(factory.createBackend(this, compilerConfiguration, jvmciRuntime, null)); |
|
191 |
} |
|
192 |
||
193 |
for (JVMCIBackend jvmciBackend : jvmciRuntime.getJVMCIBackends().values()) { |
|
194 |
if (jvmciBackend == hostJvmciBackend) { |
|
195 |
continue; |
|
196 |
} |
|
197 |
||
198 |
Architecture gpuArchitecture = jvmciBackend.getTarget().arch; |
|
199 |
HotSpotBackendFactory factory = backendMap.getBackendFactory(gpuArchitecture); |
|
200 |
if (factory == null) { |
|
201 |
throw new GraalError("No backend available for specified GPU architecture \"%s\"", gpuArchitecture); |
|
202 |
} |
|
203 |
try (InitTimer t = timer("create backend:", gpuArchitecture)) { |
|
204 |
registerBackend(factory.createBackend(this, compilerConfiguration, null, hostBackend)); |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
// Complete initialization of backends |
|
209 |
try (InitTimer st = timer(hostBackend.getTarget().arch.getName(), ".completeInitialization")) { |
|
46344 | 210 |
hostBackend.completeInitialization(jvmciRuntime, options); |
43972 | 211 |
} |
46344 | 212 |
for (HotSpotBackend backend : backends.getValues()) { |
43972 | 213 |
if (backend != hostBackend) { |
214 |
try (InitTimer st = timer(backend.getTarget().arch.getName(), ".completeInitialization")) { |
|
46344 | 215 |
backend.completeInitialization(jvmciRuntime, options); |
43972 | 216 |
} |
217 |
} |
|
218 |
} |
|
219 |
||
46344 | 220 |
BenchmarkCounters.initialize(jvmciRuntime, options); |
43972 | 221 |
|
50858 | 222 |
assert checkArrayIndexScaleInvariants(hostJvmciBackend.getMetaAccess()); |
43972 | 223 |
|
224 |
runtimeStartTime = System.nanoTime(); |
|
225 |
bootstrapJVMCI = config.getFlag("BootstrapJVMCI", Boolean.class); |
|
226 |
} |
|
227 |
||
51436 | 228 |
/** |
229 |
* Constants denoting the GC algorithms available in HotSpot. |
|
230 |
*/ |
|
231 |
public enum HotSpotGC { |
|
232 |
// Supported GCs |
|
233 |
Serial(true, "UseSerialGC"), |
|
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
58533
diff
changeset
|
234 |
Parallel(true, "UseParallelGC", "UseParallelOldGC"), |
51436 | 235 |
G1(true, "UseG1GC"), |
236 |
||
237 |
// Unsupported GCs |
|
238 |
Epsilon(false, "UseEpsilonGC"), |
|
239 |
Z(false, "UseZGC"); |
|
240 |
||
241 |
HotSpotGC(boolean supported, String... flags) { |
|
242 |
this.supported = supported; |
|
243 |
this.flags = flags; |
|
244 |
} |
|
245 |
||
246 |
final boolean supported; |
|
247 |
private final String[] flags; |
|
248 |
||
249 |
public boolean isSelected(GraalHotSpotVMConfig config) { |
|
250 |
for (String flag : flags) { |
|
251 |
final boolean notPresent = false; |
|
252 |
if (config.getFlag(flag, Boolean.class, notPresent)) { |
|
253 |
return true; |
|
254 |
} |
|
255 |
} |
|
256 |
return false; |
|
257 |
} |
|
258 |
||
259 |
} |
|
260 |
||
261 |
private HotSpotGC getSelectedGC() throws GraalError { |
|
262 |
for (HotSpotGC gc : HotSpotGC.values()) { |
|
263 |
if (gc.isSelected(config)) { |
|
264 |
if (!gc.supported) { |
|
265 |
throw new GraalError(gc.name() + " garbage collector is not supported by Graal"); |
|
266 |
} |
|
267 |
return gc; |
|
268 |
} |
|
269 |
} |
|
270 |
// As of JDK 9, exactly one GC flag is guaranteed to be selected. |
|
271 |
// On JDK 8, the default GC is Serial when no GC flag is true. |
|
272 |
return HotSpotGC.Serial; |
|
273 |
} |
|
274 |
||
43972 | 275 |
private HotSpotBackend registerBackend(HotSpotBackend backend) { |
276 |
Class<? extends Architecture> arch = backend.getTarget().arch.getClass(); |
|
277 |
HotSpotBackend oldValue = backends.put(arch, backend); |
|
278 |
assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName(); |
|
279 |
return backend; |
|
280 |
} |
|
281 |
||
282 |
@Override |
|
283 |
public HotSpotProviders getHostProviders() { |
|
284 |
return getHostBackend().getProviders(); |
|
285 |
} |
|
286 |
||
287 |
@Override |
|
288 |
public GraalHotSpotVMConfig getVMConfig() { |
|
289 |
return config; |
|
290 |
} |
|
291 |
||
292 |
@Override |
|
52578 | 293 |
public DebugContext openDebugContext(OptionValues compilationOptions, CompilationIdentifier compilationId, Object compilable, Iterable<DebugHandlersFactory> factories, PrintStream logStream) { |
49873 | 294 |
if (management != null && management.poll(false) != null) { |
295 |
if (compilable instanceof HotSpotResolvedJavaMethod) { |
|
296 |
HotSpotResolvedObjectType type = ((HotSpotResolvedJavaMethod) compilable).getDeclaringClass(); |
|
297 |
if (type instanceof HotSpotResolvedJavaType) { |
|
50858 | 298 |
Class<?> clazz = runtime().getMirror(type); |
58533 | 299 |
if (clazz != null) { |
300 |
try { |
|
301 |
ClassLoader cl = clazz.getClassLoader(); |
|
302 |
if (cl != null) { |
|
303 |
loaders.add(cl); |
|
304 |
} |
|
305 |
} catch (SecurityException e) { |
|
306 |
// This loader can obviously not be used for resolving class names |
|
49873 | 307 |
} |
308 |
} |
|
309 |
} |
|
310 |
} |
|
311 |
} |
|
46640 | 312 |
Description description = new Description(compilable, compilationId.toString(CompilationIdentifier.Verbosity.ID)); |
52578 | 313 |
return DebugContext.create(compilationOptions, description, metricValues, logStream, factories); |
46640 | 314 |
} |
315 |
||
316 |
@Override |
|
46344 | 317 |
public OptionValues getOptions() { |
49873 | 318 |
return optionsRef.get(); |
46459 | 319 |
} |
320 |
||
321 |
@Override |
|
49873 | 322 |
public Group createSnippetCounterGroup(String groupName) { |
46344 | 323 |
if (snippetCounterGroups != null) { |
49873 | 324 |
Group group = new Group(groupName); |
46344 | 325 |
snippetCounterGroups.add(group); |
326 |
return group; |
|
327 |
} |
|
328 |
return null; |
|
329 |
} |
|
330 |
||
331 |
@Override |
|
43972 | 332 |
public String getName() { |
49873 | 333 |
return runtimeName; |
43972 | 334 |
} |
335 |
||
336 |
@SuppressWarnings("unchecked") |
|
337 |
@Override |
|
338 |
public <T> T getCapability(Class<T> clazz) { |
|
339 |
if (clazz == RuntimeProvider.class) { |
|
340 |
return (T) this; |
|
46344 | 341 |
} else if (clazz == OptionValues.class) { |
49873 | 342 |
return (T) optionsRef.get(); |
43972 | 343 |
} else if (clazz == StackIntrospection.class) { |
344 |
return (T) this; |
|
345 |
} else if (clazz == SnippetReflectionProvider.class) { |
|
346 |
return (T) getHostProviders().getSnippetReflection(); |
|
52956 | 347 |
} else if (clazz == GraalHotSpotVMConfig.class) { |
348 |
return (T) getVMConfig(); |
|
43972 | 349 |
} else if (clazz == StampProvider.class) { |
350 |
return (T) getHostProviders().getStampProvider(); |
|
52956 | 351 |
} else if (ForeignCallsProvider.class.isAssignableFrom(clazz)) { |
352 |
return (T) getHostProviders().getForeignCalls(); |
|
43972 | 353 |
} |
354 |
return null; |
|
355 |
} |
|
356 |
||
50858 | 357 |
public HotSpotGC getGarbageCollector() { |
358 |
return garbageCollector; |
|
359 |
} |
|
360 |
||
43972 | 361 |
@Override |
362 |
public HotSpotBackend getHostBackend() { |
|
363 |
return hostBackend; |
|
364 |
} |
|
365 |
||
366 |
@Override |
|
367 |
public <T extends Architecture> Backend getBackend(Class<T> arch) { |
|
368 |
assert arch != Architecture.class; |
|
369 |
return backends.get(arch); |
|
370 |
} |
|
371 |
||
50330 | 372 |
@Override |
373 |
public String getCompilerConfigurationName() { |
|
374 |
return compilerConfigurationName; |
|
375 |
} |
|
376 |
||
43972 | 377 |
private long runtimeStartTime; |
55509 | 378 |
|
379 |
/** |
|
380 |
* Called from compiler threads to check whether to bail out of a compilation. |
|
381 |
*/ |
|
382 |
private volatile boolean shutdown; |
|
43972 | 383 |
|
384 |
/** |
|
385 |
* Take action related to entering a new execution phase. |
|
386 |
* |
|
387 |
* @param phase the execution phase being entered |
|
388 |
*/ |
|
46344 | 389 |
void phaseTransition(String phase) { |
49873 | 390 |
if (Options.UseCompilationStatistics.getValue(optionsRef.get())) { |
46344 | 391 |
CompilationStatistics.clear(phase); |
392 |
} |
|
43972 | 393 |
} |
394 |
||
395 |
void shutdown() { |
|
46371 | 396 |
shutdown = true; |
49873 | 397 |
metricValues.print(optionsRef.get()); |
46640 | 398 |
|
43972 | 399 |
phaseTransition("final"); |
400 |
||
46344 | 401 |
if (snippetCounterGroups != null) { |
402 |
for (Group group : snippetCounterGroups) { |
|
403 |
TTY.out().out().println(group); |
|
404 |
} |
|
405 |
} |
|
49873 | 406 |
BenchmarkCounters.shutdown(runtime(), optionsRef.get(), runtimeStartTime); |
46371 | 407 |
|
46680 | 408 |
outputDirectory.close(); |
55509 | 409 |
|
410 |
shutdownLibGraal(); |
|
411 |
} |
|
412 |
||
413 |
/** |
|
414 |
* Substituted by |
|
415 |
* {@code com.oracle.svm.graal.hotspot.libgraal.Target_org_graalvm_compiler_hotspot_HotSpotGraalRuntime} |
|
416 |
* to call {@code org.graalvm.nativeimage.VMRuntime.shutdown()}. |
|
417 |
*/ |
|
418 |
private static void shutdownLibGraal() { |
|
43972 | 419 |
} |
420 |
||
46640 | 421 |
void clearMetrics() { |
422 |
metricValues.clear(); |
|
43972 | 423 |
} |
424 |
||
425 |
private final boolean bootstrapJVMCI; |
|
426 |
private boolean bootstrapFinished; |
|
427 |
||
428 |
public void notifyBootstrapFinished() { |
|
429 |
bootstrapFinished = true; |
|
430 |
} |
|
431 |
||
432 |
@Override |
|
433 |
public boolean isBootstrapping() { |
|
434 |
return bootstrapJVMCI && !bootstrapFinished; |
|
435 |
} |
|
46371 | 436 |
|
437 |
@Override |
|
438 |
public boolean isShutdown() { |
|
439 |
return shutdown; |
|
440 |
} |
|
441 |
||
442 |
@Override |
|
46680 | 443 |
public DiagnosticsOutputDirectory getOutputDirectory() { |
444 |
return outputDirectory; |
|
46371 | 445 |
} |
46807 | 446 |
|
447 |
@Override |
|
448 |
public Map<ExceptionAction, Integer> getCompilationProblemsPerAction() { |
|
449 |
return compilationProblemsPerAction; |
|
450 |
} |
|
47557
8b2054b7d02c
8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
47216
diff
changeset
|
451 |
|
49873 | 452 |
// ------- Management interface --------- |
453 |
||
454 |
private final HotSpotGraalManagementRegistration management; |
|
455 |
||
456 |
/** |
|
457 |
* @returns the management object for this runtime or {@code null} |
|
458 |
*/ |
|
459 |
public HotSpotGraalManagementRegistration getManagement() { |
|
460 |
return management; |
|
461 |
} |
|
462 |
||
463 |
/** |
|
464 |
* Set of weak references to {@link ClassLoader}s available for resolving class names present in |
|
465 |
* management {@linkplain #invokeManagementAction(String, Object[]) action} arguments. |
|
466 |
*/ |
|
467 |
private final WeakClassLoaderSet loaders = new WeakClassLoaderSet(ClassLoader.getSystemClassLoader()); |
|
468 |
||
469 |
/** |
|
470 |
* Sets or updates this object's {@linkplain #getOptions() options} from {@code names} and |
|
471 |
* {@code values}. |
|
472 |
* |
|
473 |
* @param values the values to set. The empty string represents {@code null} which resets an |
|
474 |
* option to its default value. For string type options, a non-empty value must be |
|
475 |
* enclosed in double quotes. |
|
476 |
* @return an array of Strings where the element at index i is {@code names[i]} if setting the |
|
477 |
* denoted option succeeded, {@code null} if the option is unknown otherwise an error |
|
478 |
* message describing the failure to set the option |
|
479 |
*/ |
|
480 |
public String[] setOptionValues(String[] names, String[] values) { |
|
481 |
EconomicMap<String, OptionDescriptor> optionDescriptors = getOptionDescriptors(); |
|
482 |
EconomicMap<OptionKey<?>, Object> newValues = EconomicMap.create(names.length); |
|
483 |
EconomicSet<OptionKey<?>> resetValues = EconomicSet.create(names.length); |
|
484 |
String[] result = new String[names.length]; |
|
485 |
for (int i = 0; i < names.length; i++) { |
|
486 |
String name = names[i]; |
|
487 |
OptionDescriptor option = optionDescriptors.get(name); |
|
488 |
if (option != null) { |
|
489 |
String svalue = values[i]; |
|
490 |
Class<?> optionValueType = option.getOptionValueType(); |
|
491 |
OptionKey<?> optionKey = option.getOptionKey(); |
|
492 |
if (svalue == null || svalue.isEmpty() && !(optionKey instanceof EnumOptionKey)) { |
|
493 |
resetValues.add(optionKey); |
|
494 |
result[i] = name; |
|
495 |
} else { |
|
496 |
String valueToParse; |
|
497 |
if (optionValueType == String.class) { |
|
498 |
if (svalue.length() < 2 || svalue.charAt(0) != '"' || svalue.charAt(svalue.length() - 1) != '"') { |
|
499 |
result[i] = "Invalid value for String option '" + name + "': must be the empty string or be enclosed in double quotes: " + svalue; |
|
500 |
continue; |
|
501 |
} else { |
|
502 |
valueToParse = svalue.substring(1, svalue.length() - 1); |
|
503 |
} |
|
504 |
} else { |
|
505 |
valueToParse = svalue; |
|
506 |
} |
|
507 |
try { |
|
508 |
OptionsParser.parseOption(name, valueToParse, newValues, OptionsParser.getOptionsLoader()); |
|
509 |
result[i] = name; |
|
510 |
} catch (IllegalArgumentException e) { |
|
511 |
result[i] = e.getMessage(); |
|
512 |
continue; |
|
513 |
} |
|
514 |
} |
|
515 |
} else { |
|
516 |
result[i] = null; |
|
517 |
} |
|
518 |
} |
|
519 |
||
520 |
OptionValues currentOptions; |
|
521 |
OptionValues newOptions; |
|
522 |
do { |
|
523 |
currentOptions = optionsRef.get(); |
|
524 |
UnmodifiableMapCursor<OptionKey<?>, Object> cursor = currentOptions.getMap().getEntries(); |
|
525 |
while (cursor.advance()) { |
|
526 |
OptionKey<?> key = cursor.getKey(); |
|
527 |
if (!resetValues.contains(key) && !newValues.containsKey(key)) { |
|
528 |
newValues.put(key, OptionValues.decodeNull(cursor.getValue())); |
|
529 |
} |
|
530 |
} |
|
531 |
newOptions = new OptionValues(newValues); |
|
532 |
} while (!optionsRef.compareAndSet(currentOptions, newOptions)); |
|
533 |
||
534 |
return result; |
|
535 |
} |
|
536 |
||
537 |
/** |
|
538 |
* Gets the values for the options corresponding to {@code names} encoded as strings. The empty |
|
539 |
* string represents {@code null}. For string type options, non-{@code null} values will be |
|
540 |
* enclosed in double quotes. |
|
541 |
* |
|
542 |
* @param names a list of option names |
|
543 |
* @return the values for each named option. If an element in {@code names} does not denote an |
|
544 |
* existing option, the corresponding element in the returned array will be {@code null} |
|
545 |
*/ |
|
546 |
public String[] getOptionValues(String... names) { |
|
547 |
String[] values = new String[names.length]; |
|
548 |
EconomicMap<String, OptionDescriptor> optionDescriptors = getOptionDescriptors(); |
|
549 |
for (int i = 0; i < names.length; i++) { |
|
550 |
OptionDescriptor option = optionDescriptors.get(names[i]); |
|
551 |
if (option != null) { |
|
552 |
OptionKey<?> optionKey = option.getOptionKey(); |
|
553 |
Object value = optionKey.getValue(getOptions()); |
|
554 |
String svalue; |
|
555 |
if (option.getOptionValueType() == String.class && value != null) { |
|
556 |
svalue = "\"" + value + "\""; |
|
557 |
} else if (value == null) { |
|
558 |
svalue = ""; |
|
559 |
} else { |
|
560 |
svalue = String.valueOf(value); |
|
561 |
} |
|
562 |
values[i] = svalue; |
|
563 |
} else { |
|
564 |
// null denotes the option does not exist |
|
565 |
values[i] = null; |
|
566 |
} |
|
567 |
} |
|
568 |
return values; |
|
569 |
} |
|
570 |
||
571 |
private static EconomicMap<String, OptionDescriptor> getOptionDescriptors() { |
|
572 |
EconomicMap<String, OptionDescriptor> result = EconomicMap.create(); |
|
573 |
for (OptionDescriptors set : OptionsParser.getOptionsLoader()) { |
|
574 |
for (OptionDescriptor option : set) { |
|
575 |
result.put(option.getName(), option); |
|
576 |
} |
|
577 |
} |
|
578 |
return result; |
|
579 |
} |
|
580 |
||
581 |
private void dumpMethod(String className, String methodName, String filter, String host, int port) throws Exception { |
|
582 |
EconomicSet<ClassNotFoundException> failures = EconomicSet.create(); |
|
583 |
EconomicSet<Class<?>> found = loaders.resolve(className, failures); |
|
584 |
if (found.isEmpty()) { |
|
585 |
ClassNotFoundException cause = failures.isEmpty() ? new ClassNotFoundException(className) : failures.iterator().next(); |
|
586 |
throw new Exception("Cannot find class " + className + " to schedule recompilation", cause); |
|
587 |
} |
|
588 |
for (Class<?> clazz : found) { |
|
589 |
ResolvedJavaType type = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaType(clazz); |
|
590 |
for (ResolvedJavaMethod method : type.getDeclaredMethods()) { |
|
591 |
if (methodName.equals(method.getName()) && method instanceof HotSpotResolvedJavaMethod) { |
|
592 |
HotSpotResolvedJavaMethod hotSpotMethod = (HotSpotResolvedJavaMethod) method; |
|
593 |
dumpMethod(hotSpotMethod, filter, host, port); |
|
594 |
} |
|
595 |
} |
|
596 |
} |
|
597 |
} |
|
598 |
||
599 |
private void dumpMethod(HotSpotResolvedJavaMethod hotSpotMethod, String filter, String host, int port) throws Exception { |
|
600 |
EconomicMap<OptionKey<?>, Object> extra = EconomicMap.create(); |
|
601 |
extra.put(DebugOptions.Dump, filter); |
|
602 |
extra.put(DebugOptions.PrintGraphHost, host); |
|
54084 | 603 |
extra.put(DebugOptions.PrintGraphPort, port); |
49873 | 604 |
OptionValues compileOptions = new OptionValues(getOptions(), extra); |
55509 | 605 |
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime().getCompiler(); |
49873 | 606 |
compiler.compileMethod(new HotSpotCompilationRequest(hotSpotMethod, -1, 0L), false, compileOptions); |
607 |
} |
|
608 |
||
609 |
public Object invokeManagementAction(String actionName, Object[] params) throws Exception { |
|
610 |
if ("dumpMethod".equals(actionName)) { |
|
611 |
if (params.length != 0 && params[0] instanceof HotSpotResolvedJavaMethod) { |
|
612 |
HotSpotResolvedJavaMethod method = param(params, 0, "method", HotSpotResolvedJavaMethod.class, null); |
|
613 |
String filter = param(params, 1, "filter", String.class, ":3"); |
|
614 |
String host = param(params, 2, "host", String.class, "localhost"); |
|
615 |
Number port = param(params, 3, "port", Number.class, 4445); |
|
616 |
dumpMethod(method, filter, host, port.intValue()); |
|
617 |
} else { |
|
618 |
String className = param(params, 0, "className", String.class, null); |
|
619 |
String methodName = param(params, 1, "methodName", String.class, null); |
|
620 |
String filter = param(params, 2, "filter", String.class, ":3"); |
|
621 |
String host = param(params, 3, "host", String.class, "localhost"); |
|
622 |
Number port = param(params, 4, "port", Number.class, 4445); |
|
623 |
dumpMethod(className, methodName, filter, host, port.intValue()); |
|
624 |
} |
|
625 |
} |
|
626 |
return null; |
|
627 |
} |
|
628 |
||
629 |
private static <T> T param(Object[] arr, int index, String name, Class<T> type, T defaultValue) { |
|
630 |
Object value = arr.length > index ? arr[index] : null; |
|
631 |
if (value == null || (value instanceof String && ((String) value).isEmpty())) { |
|
632 |
if (defaultValue == null) { |
|
633 |
throw new IllegalArgumentException(name + " must be specified"); |
|
634 |
} |
|
635 |
value = defaultValue; |
|
636 |
} |
|
637 |
if (type.isInstance(value)) { |
|
638 |
return type.cast(value); |
|
639 |
} |
|
640 |
throw new IllegalArgumentException("Expecting " + type.getName() + " for " + name + " but was " + value); |
|
47557
8b2054b7d02c
8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
47216
diff
changeset
|
641 |
} |
43972 | 642 |
} |