author | dlong |
Fri, 22 Nov 2019 19:23:30 -0800 | |
changeset 59237 | 2601fc0874be |
parent 59053 | ba6c248cae19 |
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"), |
59237
2601fc0874be
8234432: AOT tests failing with 'used 'epsilon gc' is different from current 'g1 gc'' after CMS removal
dlong
parents:
59053
diff
changeset
|
235 |
CMS(true, "UseConcMarkSweepGC"), |
51436 | 236 |
G1(true, "UseG1GC"), |
237 |
||
238 |
// Unsupported GCs |
|
239 |
Epsilon(false, "UseEpsilonGC"), |
|
240 |
Z(false, "UseZGC"); |
|
241 |
||
242 |
HotSpotGC(boolean supported, String... flags) { |
|
243 |
this.supported = supported; |
|
244 |
this.flags = flags; |
|
245 |
} |
|
246 |
||
247 |
final boolean supported; |
|
248 |
private final String[] flags; |
|
249 |
||
250 |
public boolean isSelected(GraalHotSpotVMConfig config) { |
|
251 |
for (String flag : flags) { |
|
252 |
final boolean notPresent = false; |
|
253 |
if (config.getFlag(flag, Boolean.class, notPresent)) { |
|
254 |
return true; |
|
255 |
} |
|
256 |
} |
|
257 |
return false; |
|
258 |
} |
|
259 |
||
260 |
} |
|
261 |
||
262 |
private HotSpotGC getSelectedGC() throws GraalError { |
|
263 |
for (HotSpotGC gc : HotSpotGC.values()) { |
|
264 |
if (gc.isSelected(config)) { |
|
265 |
if (!gc.supported) { |
|
266 |
throw new GraalError(gc.name() + " garbage collector is not supported by Graal"); |
|
267 |
} |
|
268 |
return gc; |
|
269 |
} |
|
270 |
} |
|
271 |
// As of JDK 9, exactly one GC flag is guaranteed to be selected. |
|
272 |
// On JDK 8, the default GC is Serial when no GC flag is true. |
|
273 |
return HotSpotGC.Serial; |
|
274 |
} |
|
275 |
||
43972 | 276 |
private HotSpotBackend registerBackend(HotSpotBackend backend) { |
277 |
Class<? extends Architecture> arch = backend.getTarget().arch.getClass(); |
|
278 |
HotSpotBackend oldValue = backends.put(arch, backend); |
|
279 |
assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName(); |
|
280 |
return backend; |
|
281 |
} |
|
282 |
||
283 |
@Override |
|
284 |
public HotSpotProviders getHostProviders() { |
|
285 |
return getHostBackend().getProviders(); |
|
286 |
} |
|
287 |
||
288 |
@Override |
|
289 |
public GraalHotSpotVMConfig getVMConfig() { |
|
290 |
return config; |
|
291 |
} |
|
292 |
||
293 |
@Override |
|
52578 | 294 |
public DebugContext openDebugContext(OptionValues compilationOptions, CompilationIdentifier compilationId, Object compilable, Iterable<DebugHandlersFactory> factories, PrintStream logStream) { |
49873 | 295 |
if (management != null && management.poll(false) != null) { |
296 |
if (compilable instanceof HotSpotResolvedJavaMethod) { |
|
297 |
HotSpotResolvedObjectType type = ((HotSpotResolvedJavaMethod) compilable).getDeclaringClass(); |
|
298 |
if (type instanceof HotSpotResolvedJavaType) { |
|
50858 | 299 |
Class<?> clazz = runtime().getMirror(type); |
58533 | 300 |
if (clazz != null) { |
301 |
try { |
|
302 |
ClassLoader cl = clazz.getClassLoader(); |
|
303 |
if (cl != null) { |
|
304 |
loaders.add(cl); |
|
305 |
} |
|
306 |
} catch (SecurityException e) { |
|
307 |
// This loader can obviously not be used for resolving class names |
|
49873 | 308 |
} |
309 |
} |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
46640 | 313 |
Description description = new Description(compilable, compilationId.toString(CompilationIdentifier.Verbosity.ID)); |
52578 | 314 |
return DebugContext.create(compilationOptions, description, metricValues, logStream, factories); |
46640 | 315 |
} |
316 |
||
317 |
@Override |
|
46344 | 318 |
public OptionValues getOptions() { |
49873 | 319 |
return optionsRef.get(); |
46459 | 320 |
} |
321 |
||
322 |
@Override |
|
49873 | 323 |
public Group createSnippetCounterGroup(String groupName) { |
46344 | 324 |
if (snippetCounterGroups != null) { |
49873 | 325 |
Group group = new Group(groupName); |
46344 | 326 |
snippetCounterGroups.add(group); |
327 |
return group; |
|
328 |
} |
|
329 |
return null; |
|
330 |
} |
|
331 |
||
332 |
@Override |
|
43972 | 333 |
public String getName() { |
49873 | 334 |
return runtimeName; |
43972 | 335 |
} |
336 |
||
337 |
@SuppressWarnings("unchecked") |
|
338 |
@Override |
|
339 |
public <T> T getCapability(Class<T> clazz) { |
|
340 |
if (clazz == RuntimeProvider.class) { |
|
341 |
return (T) this; |
|
46344 | 342 |
} else if (clazz == OptionValues.class) { |
49873 | 343 |
return (T) optionsRef.get(); |
43972 | 344 |
} else if (clazz == StackIntrospection.class) { |
345 |
return (T) this; |
|
346 |
} else if (clazz == SnippetReflectionProvider.class) { |
|
347 |
return (T) getHostProviders().getSnippetReflection(); |
|
52956 | 348 |
} else if (clazz == GraalHotSpotVMConfig.class) { |
349 |
return (T) getVMConfig(); |
|
43972 | 350 |
} else if (clazz == StampProvider.class) { |
351 |
return (T) getHostProviders().getStampProvider(); |
|
52956 | 352 |
} else if (ForeignCallsProvider.class.isAssignableFrom(clazz)) { |
353 |
return (T) getHostProviders().getForeignCalls(); |
|
43972 | 354 |
} |
355 |
return null; |
|
356 |
} |
|
357 |
||
50858 | 358 |
public HotSpotGC getGarbageCollector() { |
359 |
return garbageCollector; |
|
360 |
} |
|
361 |
||
43972 | 362 |
@Override |
363 |
public HotSpotBackend getHostBackend() { |
|
364 |
return hostBackend; |
|
365 |
} |
|
366 |
||
367 |
@Override |
|
368 |
public <T extends Architecture> Backend getBackend(Class<T> arch) { |
|
369 |
assert arch != Architecture.class; |
|
370 |
return backends.get(arch); |
|
371 |
} |
|
372 |
||
50330 | 373 |
@Override |
374 |
public String getCompilerConfigurationName() { |
|
375 |
return compilerConfigurationName; |
|
376 |
} |
|
377 |
||
43972 | 378 |
private long runtimeStartTime; |
55509 | 379 |
|
380 |
/** |
|
381 |
* Called from compiler threads to check whether to bail out of a compilation. |
|
382 |
*/ |
|
383 |
private volatile boolean shutdown; |
|
43972 | 384 |
|
385 |
/** |
|
386 |
* Take action related to entering a new execution phase. |
|
387 |
* |
|
388 |
* @param phase the execution phase being entered |
|
389 |
*/ |
|
46344 | 390 |
void phaseTransition(String phase) { |
49873 | 391 |
if (Options.UseCompilationStatistics.getValue(optionsRef.get())) { |
46344 | 392 |
CompilationStatistics.clear(phase); |
393 |
} |
|
43972 | 394 |
} |
395 |
||
396 |
void shutdown() { |
|
46371 | 397 |
shutdown = true; |
49873 | 398 |
metricValues.print(optionsRef.get()); |
46640 | 399 |
|
43972 | 400 |
phaseTransition("final"); |
401 |
||
46344 | 402 |
if (snippetCounterGroups != null) { |
403 |
for (Group group : snippetCounterGroups) { |
|
404 |
TTY.out().out().println(group); |
|
405 |
} |
|
406 |
} |
|
49873 | 407 |
BenchmarkCounters.shutdown(runtime(), optionsRef.get(), runtimeStartTime); |
46371 | 408 |
|
46680 | 409 |
outputDirectory.close(); |
55509 | 410 |
|
411 |
shutdownLibGraal(); |
|
412 |
} |
|
413 |
||
414 |
/** |
|
415 |
* Substituted by |
|
416 |
* {@code com.oracle.svm.graal.hotspot.libgraal.Target_org_graalvm_compiler_hotspot_HotSpotGraalRuntime} |
|
417 |
* to call {@code org.graalvm.nativeimage.VMRuntime.shutdown()}. |
|
418 |
*/ |
|
419 |
private static void shutdownLibGraal() { |
|
43972 | 420 |
} |
421 |
||
46640 | 422 |
void clearMetrics() { |
423 |
metricValues.clear(); |
|
43972 | 424 |
} |
425 |
||
426 |
private final boolean bootstrapJVMCI; |
|
427 |
private boolean bootstrapFinished; |
|
428 |
||
429 |
public void notifyBootstrapFinished() { |
|
430 |
bootstrapFinished = true; |
|
431 |
} |
|
432 |
||
433 |
@Override |
|
434 |
public boolean isBootstrapping() { |
|
435 |
return bootstrapJVMCI && !bootstrapFinished; |
|
436 |
} |
|
46371 | 437 |
|
438 |
@Override |
|
439 |
public boolean isShutdown() { |
|
440 |
return shutdown; |
|
441 |
} |
|
442 |
||
443 |
@Override |
|
46680 | 444 |
public DiagnosticsOutputDirectory getOutputDirectory() { |
445 |
return outputDirectory; |
|
46371 | 446 |
} |
46807 | 447 |
|
448 |
@Override |
|
449 |
public Map<ExceptionAction, Integer> getCompilationProblemsPerAction() { |
|
450 |
return compilationProblemsPerAction; |
|
451 |
} |
|
47557
8b2054b7d02c
8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
47216
diff
changeset
|
452 |
|
49873 | 453 |
// ------- Management interface --------- |
454 |
||
455 |
private final HotSpotGraalManagementRegistration management; |
|
456 |
||
457 |
/** |
|
458 |
* @returns the management object for this runtime or {@code null} |
|
459 |
*/ |
|
460 |
public HotSpotGraalManagementRegistration getManagement() { |
|
461 |
return management; |
|
462 |
} |
|
463 |
||
464 |
/** |
|
465 |
* Set of weak references to {@link ClassLoader}s available for resolving class names present in |
|
466 |
* management {@linkplain #invokeManagementAction(String, Object[]) action} arguments. |
|
467 |
*/ |
|
468 |
private final WeakClassLoaderSet loaders = new WeakClassLoaderSet(ClassLoader.getSystemClassLoader()); |
|
469 |
||
470 |
/** |
|
471 |
* Sets or updates this object's {@linkplain #getOptions() options} from {@code names} and |
|
472 |
* {@code values}. |
|
473 |
* |
|
474 |
* @param values the values to set. The empty string represents {@code null} which resets an |
|
475 |
* option to its default value. For string type options, a non-empty value must be |
|
476 |
* enclosed in double quotes. |
|
477 |
* @return an array of Strings where the element at index i is {@code names[i]} if setting the |
|
478 |
* denoted option succeeded, {@code null} if the option is unknown otherwise an error |
|
479 |
* message describing the failure to set the option |
|
480 |
*/ |
|
481 |
public String[] setOptionValues(String[] names, String[] values) { |
|
482 |
EconomicMap<String, OptionDescriptor> optionDescriptors = getOptionDescriptors(); |
|
483 |
EconomicMap<OptionKey<?>, Object> newValues = EconomicMap.create(names.length); |
|
484 |
EconomicSet<OptionKey<?>> resetValues = EconomicSet.create(names.length); |
|
485 |
String[] result = new String[names.length]; |
|
486 |
for (int i = 0; i < names.length; i++) { |
|
487 |
String name = names[i]; |
|
488 |
OptionDescriptor option = optionDescriptors.get(name); |
|
489 |
if (option != null) { |
|
490 |
String svalue = values[i]; |
|
491 |
Class<?> optionValueType = option.getOptionValueType(); |
|
492 |
OptionKey<?> optionKey = option.getOptionKey(); |
|
493 |
if (svalue == null || svalue.isEmpty() && !(optionKey instanceof EnumOptionKey)) { |
|
494 |
resetValues.add(optionKey); |
|
495 |
result[i] = name; |
|
496 |
} else { |
|
497 |
String valueToParse; |
|
498 |
if (optionValueType == String.class) { |
|
499 |
if (svalue.length() < 2 || svalue.charAt(0) != '"' || svalue.charAt(svalue.length() - 1) != '"') { |
|
500 |
result[i] = "Invalid value for String option '" + name + "': must be the empty string or be enclosed in double quotes: " + svalue; |
|
501 |
continue; |
|
502 |
} else { |
|
503 |
valueToParse = svalue.substring(1, svalue.length() - 1); |
|
504 |
} |
|
505 |
} else { |
|
506 |
valueToParse = svalue; |
|
507 |
} |
|
508 |
try { |
|
509 |
OptionsParser.parseOption(name, valueToParse, newValues, OptionsParser.getOptionsLoader()); |
|
510 |
result[i] = name; |
|
511 |
} catch (IllegalArgumentException e) { |
|
512 |
result[i] = e.getMessage(); |
|
513 |
continue; |
|
514 |
} |
|
515 |
} |
|
516 |
} else { |
|
517 |
result[i] = null; |
|
518 |
} |
|
519 |
} |
|
520 |
||
521 |
OptionValues currentOptions; |
|
522 |
OptionValues newOptions; |
|
523 |
do { |
|
524 |
currentOptions = optionsRef.get(); |
|
525 |
UnmodifiableMapCursor<OptionKey<?>, Object> cursor = currentOptions.getMap().getEntries(); |
|
526 |
while (cursor.advance()) { |
|
527 |
OptionKey<?> key = cursor.getKey(); |
|
528 |
if (!resetValues.contains(key) && !newValues.containsKey(key)) { |
|
529 |
newValues.put(key, OptionValues.decodeNull(cursor.getValue())); |
|
530 |
} |
|
531 |
} |
|
532 |
newOptions = new OptionValues(newValues); |
|
533 |
} while (!optionsRef.compareAndSet(currentOptions, newOptions)); |
|
534 |
||
535 |
return result; |
|
536 |
} |
|
537 |
||
538 |
/** |
|
539 |
* Gets the values for the options corresponding to {@code names} encoded as strings. The empty |
|
540 |
* string represents {@code null}. For string type options, non-{@code null} values will be |
|
541 |
* enclosed in double quotes. |
|
542 |
* |
|
543 |
* @param names a list of option names |
|
544 |
* @return the values for each named option. If an element in {@code names} does not denote an |
|
545 |
* existing option, the corresponding element in the returned array will be {@code null} |
|
546 |
*/ |
|
547 |
public String[] getOptionValues(String... names) { |
|
548 |
String[] values = new String[names.length]; |
|
549 |
EconomicMap<String, OptionDescriptor> optionDescriptors = getOptionDescriptors(); |
|
550 |
for (int i = 0; i < names.length; i++) { |
|
551 |
OptionDescriptor option = optionDescriptors.get(names[i]); |
|
552 |
if (option != null) { |
|
553 |
OptionKey<?> optionKey = option.getOptionKey(); |
|
554 |
Object value = optionKey.getValue(getOptions()); |
|
555 |
String svalue; |
|
556 |
if (option.getOptionValueType() == String.class && value != null) { |
|
557 |
svalue = "\"" + value + "\""; |
|
558 |
} else if (value == null) { |
|
559 |
svalue = ""; |
|
560 |
} else { |
|
561 |
svalue = String.valueOf(value); |
|
562 |
} |
|
563 |
values[i] = svalue; |
|
564 |
} else { |
|
565 |
// null denotes the option does not exist |
|
566 |
values[i] = null; |
|
567 |
} |
|
568 |
} |
|
569 |
return values; |
|
570 |
} |
|
571 |
||
572 |
private static EconomicMap<String, OptionDescriptor> getOptionDescriptors() { |
|
573 |
EconomicMap<String, OptionDescriptor> result = EconomicMap.create(); |
|
574 |
for (OptionDescriptors set : OptionsParser.getOptionsLoader()) { |
|
575 |
for (OptionDescriptor option : set) { |
|
576 |
result.put(option.getName(), option); |
|
577 |
} |
|
578 |
} |
|
579 |
return result; |
|
580 |
} |
|
581 |
||
582 |
private void dumpMethod(String className, String methodName, String filter, String host, int port) throws Exception { |
|
583 |
EconomicSet<ClassNotFoundException> failures = EconomicSet.create(); |
|
584 |
EconomicSet<Class<?>> found = loaders.resolve(className, failures); |
|
585 |
if (found.isEmpty()) { |
|
586 |
ClassNotFoundException cause = failures.isEmpty() ? new ClassNotFoundException(className) : failures.iterator().next(); |
|
587 |
throw new Exception("Cannot find class " + className + " to schedule recompilation", cause); |
|
588 |
} |
|
589 |
for (Class<?> clazz : found) { |
|
590 |
ResolvedJavaType type = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaType(clazz); |
|
591 |
for (ResolvedJavaMethod method : type.getDeclaredMethods()) { |
|
592 |
if (methodName.equals(method.getName()) && method instanceof HotSpotResolvedJavaMethod) { |
|
593 |
HotSpotResolvedJavaMethod hotSpotMethod = (HotSpotResolvedJavaMethod) method; |
|
594 |
dumpMethod(hotSpotMethod, filter, host, port); |
|
595 |
} |
|
596 |
} |
|
597 |
} |
|
598 |
} |
|
599 |
||
600 |
private void dumpMethod(HotSpotResolvedJavaMethod hotSpotMethod, String filter, String host, int port) throws Exception { |
|
601 |
EconomicMap<OptionKey<?>, Object> extra = EconomicMap.create(); |
|
602 |
extra.put(DebugOptions.Dump, filter); |
|
603 |
extra.put(DebugOptions.PrintGraphHost, host); |
|
54084 | 604 |
extra.put(DebugOptions.PrintGraphPort, port); |
49873 | 605 |
OptionValues compileOptions = new OptionValues(getOptions(), extra); |
55509 | 606 |
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime().getCompiler(); |
49873 | 607 |
compiler.compileMethod(new HotSpotCompilationRequest(hotSpotMethod, -1, 0L), false, compileOptions); |
608 |
} |
|
609 |
||
610 |
public Object invokeManagementAction(String actionName, Object[] params) throws Exception { |
|
611 |
if ("dumpMethod".equals(actionName)) { |
|
612 |
if (params.length != 0 && params[0] instanceof HotSpotResolvedJavaMethod) { |
|
613 |
HotSpotResolvedJavaMethod method = param(params, 0, "method", HotSpotResolvedJavaMethod.class, null); |
|
614 |
String filter = param(params, 1, "filter", String.class, ":3"); |
|
615 |
String host = param(params, 2, "host", String.class, "localhost"); |
|
616 |
Number port = param(params, 3, "port", Number.class, 4445); |
|
617 |
dumpMethod(method, filter, host, port.intValue()); |
|
618 |
} else { |
|
619 |
String className = param(params, 0, "className", String.class, null); |
|
620 |
String methodName = param(params, 1, "methodName", String.class, null); |
|
621 |
String filter = param(params, 2, "filter", String.class, ":3"); |
|
622 |
String host = param(params, 3, "host", String.class, "localhost"); |
|
623 |
Number port = param(params, 4, "port", Number.class, 4445); |
|
624 |
dumpMethod(className, methodName, filter, host, port.intValue()); |
|
625 |
} |
|
626 |
} |
|
627 |
return null; |
|
628 |
} |
|
629 |
||
630 |
private static <T> T param(Object[] arr, int index, String name, Class<T> type, T defaultValue) { |
|
631 |
Object value = arr.length > index ? arr[index] : null; |
|
632 |
if (value == null || (value instanceof String && ((String) value).isEmpty())) { |
|
633 |
if (defaultValue == null) { |
|
634 |
throw new IllegalArgumentException(name + " must be specified"); |
|
635 |
} |
|
636 |
value = defaultValue; |
|
637 |
} |
|
638 |
if (type.isInstance(value)) { |
|
639 |
return type.cast(value); |
|
640 |
} |
|
641 |
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
|
642 |
} |
43972 | 643 |
} |