use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.
the class AssemblerTest method assembleMethod.
@SuppressWarnings("try")
protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
OptionValues options = getInitialOptions();
DebugContext debug = getDebugContext(options);
try (DebugContext.Scope s = debug.scope("assembleMethod", method, codeCache)) {
RegisterConfig registerConfig = codeCache.getRegisterConfig();
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
CallingConvention cc = backend.newLIRGenerationResult(compilationId, null, null, graph, null).getCallingConvention();
CompilationResult compResult = new CompilationResult(graph.compilationId());
byte[] targetCode = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
compResult.setTargetCode(targetCode, targetCode.length);
compResult.setTotalFrameSize(0);
compResult.close();
InstalledCode code = backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compResult);
for (DisassemblerProvider dis : GraalServices.load(DisassemblerProvider.class)) {
String disasm1 = dis.disassembleCompiledCode(codeCache, compResult);
Assert.assertTrue(compResult.toString(), disasm1 == null || disasm1.length() > 0);
String disasm2 = dis.disassembleInstalledCode(codeCache, compResult, code);
Assert.assertTrue(code.toString(), disasm2 == null || disasm2.length() > 0);
}
return code;
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.
the class GraalTruffleRuntime method doCompile.
@SuppressWarnings("try")
protected void doCompile(OptionValues options, OptimizedCallTarget callTarget, Cancellable task) {
listeners.onCompilationStarted(callTarget);
TruffleCompiler compiler = getTruffleCompiler();
TruffleInlining inlining = new TruffleInlining(callTarget, new DefaultInliningPolicy());
CompilationIdentifier compilationId = compiler.getCompilationIdentifier(callTarget);
try (DebugContext debug = compilationId != null ? compiler.openDebugContext(options, compilationId, callTarget) : null) {
try (Scope s = debug != null ? debug.scope("Truffle", new TruffleDebugJavaMethod(callTarget)) : null) {
maybeDumpTruffleTree(debug, options, callTarget, inlining);
compiler.doCompile(debug, compilationId, options, callTarget, inlining, task, listeners.isEmpty() ? null : listeners);
} catch (RuntimeException | Error e) {
throw e;
} catch (Throwable e) {
throw new InternalError(e);
}
}
dequeueInlinedCallSites(inlining, callTarget);
}
use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.
the class HotSpotGraalCompilerTest method compileAndInstallSubstitution.
protected InstalledCode compileAndInstallSubstitution(Class<?> c, String methodName) {
ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(getMethod(c, methodName));
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) JVMCI.getRuntime().getCompiler();
HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class);
HotSpotProviders providers = rt.getHostBackend().getProviders();
CompilationIdentifier compilationId = runtime().getHostBackend().getCompilationIdentifier(method);
OptionValues options = getInitialOptions();
StructuredGraph graph = compiler.getIntrinsicGraph(method, providers, compilationId, options, getDebugContext(options));
if (graph != null) {
return getCode(method, graph, true, true, graph.getOptions());
}
return null;
}
use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.
the class GraalCompilerTest method getCode.
/**
* Gets installed code for a given method and graph, compiling it first if necessary.
*
* @param installedCodeOwner the method the compiled code will be associated with when installed
* @param graph the graph to be compiled. If null, a graph will be obtained from
* {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}.
* @param forceCompile specifies whether to ignore any previous code cached for the (method,
* key) pair
* @param installAsDefault specifies whether to install as the default implementation
* @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)}
*/
@SuppressWarnings("try")
protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
boolean useCache = !forceCompile && getArgumentToBind() == null;
if (useCache && graph == null) {
InstalledCode cached = cache.get(installedCodeOwner);
if (cached != null) {
if (cached.isValid()) {
return cached;
}
}
}
// loop for retrying compilation
for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
InstalledCode installedCode = null;
StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
DebugContext debug = graphToCompile.getDebug();
try (AllocSpy spy = AllocSpy.open(installedCodeOwner);
DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(graphToCompile.compilationId()), id, options);
printer.finish(compResult);
try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
DebugContext.Activation a = debug.activate()) {
try {
if (installAsDefault) {
installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
} else {
installedCode = addMethod(debug, installedCodeOwner, compResult);
}
if (installedCode == null) {
throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
}
} catch (BailoutException e) {
if (retry < BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) {
// retry (if there is no predefined graph)
TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id));
continue;
}
throw e;
}
} catch (Throwable e) {
throw debug.handle(e);
}
} catch (Throwable e) {
throw debug.handle(e);
}
if (useCache) {
cache.put(installedCodeOwner, installedCode);
}
return installedCode;
}
throw GraalError.shouldNotReachHere();
}
use of org.graalvm.compiler.core.common.CompilationIdentifier in project graal by oracle.
the class LoopPartialUnrollTest method buildGraph.
@SuppressWarnings("try")
public StructuredGraph buildGraph(String name, boolean partialUnroll) {
CompilationIdentifier id = new CompilationIdentifier() {
@Override
public String toString(Verbosity verbosity) {
return name;
}
};
ResolvedJavaMethod method = getResolvedJavaMethod(name);
OptionValues options = new OptionValues(getInitialOptions(), DefaultLoopPolicies.Options.UnrollMaxIterations, 2);
StructuredGraph graph = parse(builder(method, StructuredGraph.AllowAssumptions.YES, id, options), getEagerGraphBuilderSuite());
try (DebugContext.Scope buildScope = graph.getDebug().scope(name, method, graph)) {
MidTierContext context = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, null);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
canonicalizer.apply(graph, context);
new RemoveValueProxyPhase().apply(graph);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new FloatingReadPhase().apply(graph);
new DeadCodeEliminationPhase().apply(graph);
new ConditionalEliminationPhase(true).apply(graph, context);
ComputeLoopFrequenciesClosure.compute(graph);
new GuardLoweringPhase().apply(graph, context);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
new FrameStateAssignmentPhase().apply(graph);
new DeoptimizationGroupingPhase().apply(graph, context);
canonicalizer.apply(graph, context);
new ConditionalEliminationPhase(true).apply(graph, context);
if (partialUnroll) {
LoopsData dataCounted = new LoopsData(graph);
dataCounted.detectedCountedLoops();
for (LoopEx loop : dataCounted.countedLoops()) {
LoopFragmentInside newSegment = loop.inside().duplicate();
newSegment.insertWithinAfter(loop, false);
}
canonicalizer.apply(graph, getDefaultMidTierContext());
}
new DeadCodeEliminationPhase().apply(graph);
canonicalizer.apply(graph, context);
graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "before compare");
return graph;
} catch (Throwable e) {
throw getDebugContext().handle(e);
}
}
Aggregations