use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class GraalCompilerState method prepareRequest.
/**
* Copies the {@link #originalGraph original graph} and prepares the {@link #request}.
*
* The {@link Suites} can be changed by overriding {@link #createSuites}. {@link LIRSuites} can
* be changed by overriding {@link #createLIRSuites}.
*/
protected final void prepareRequest() {
assert originalGraph != null : "call initialzeMethod first";
CompilationIdentifier compilationId = backend.getCompilationIdentifier(originalGraph.method());
graph = originalGraph.copyWithIdentifier(compilationId, originalGraph.getDebug());
assert !graph.isFrozen();
ResolvedJavaMethod installedCodeOwner = graph.method();
request = new Request<>(graph, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(getOptions()), createLIRSuites(getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
}
use of org.graalvm.compiler.code.CompilationResult 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.code.CompilationResult in project graal by oracle.
the class TruffleCompilationResultBuilderFactory method createBuilder.
@Override
public CompilationResultBuilder createBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, DataBuilder dataBuilder, FrameContext frameContext, OptionValues options, DebugContext debug, CompilationResult compilationResult) {
return new CompilationResultBuilder(codeCache, foreignCalls, frameMap, asm, dataBuilder, frameContext, options, debug, compilationResult) {
@Override
protected void closeCompilationResult() {
CompilationResult result = this.compilationResult;
result.setMethods(graph.method(), graph.getMethods());
result.setBytecodeSize(graph.getBytecodeSize());
Set<Assumption> newAssumptions = new HashSet<>();
for (Assumption assumption : graph.getAssumptions()) {
TruffleCompilationResultBuilderFactory.processAssumption(newAssumptions, assumption, validAssumptions);
}
if (result.getAssumptions() != null) {
for (Assumption assumption : result.getAssumptions()) {
TruffleCompilationResultBuilderFactory.processAssumption(newAssumptions, assumption, validAssumptions);
}
}
result.setAssumptions(newAssumptions.toArray(new Assumption[newAssumptions.size()]));
super.closeCompilationResult();
}
};
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class TruffleCompilerImpl method compileAST.
/**
* Compiles a Truffle AST. If compilation succeeds, the AST will have compiled code associated
* with it that can be executed instead of interpreting the AST.
*
* @param compilable representation of the AST to be compiled
* @param inliningPlan
* @param compilationId identifier to be used for the compilation
* @param cancellable an object polled during the compilation process to
* {@linkplain CancellationBailoutException abort} early if the thread owning the
* cancellable requests it
* @param listener
*/
@SuppressWarnings("try")
public void compileAST(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, CompilationIdentifier compilationId, Cancellable cancellable, TruffleCompilerListener listener) {
final CompilationPrinter printer = CompilationPrinter.begin(TruffleCompilerOptions.getOptions(), compilationId, new TruffleDebugJavaMethod(compilable), INVOCATION_ENTRY_BCI);
StructuredGraph graph = null;
try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(TruffleCompilerOptions.getOptions())) {
PhaseSuite<HighTierContext> graphBuilderSuite = createGraphBuilderSuite();
// Failed speculations must be collected before any compilation or
// partial evaluation is performed.
SpeculationLog speculationLog = compilable.getSpeculationLog();
if (speculationLog != null) {
speculationLog.collectFailedSpeculations();
}
try (DebugCloseable a = PartialEvaluationTime.start(debug);
DebugCloseable c = PartialEvaluationMemUse.start(debug)) {
graph = partialEvaluator.createGraph(debug, compilable, inliningPlan, AllowAssumptions.YES, compilationId, speculationLog, cancellable);
}
// Check if the task has been cancelled
if (cancellable != null && cancellable.isCancelled()) {
return;
}
if (listener != null) {
listener.onTruffleTierFinished(compilable, inliningPlan, new GraphInfoImpl(graph));
}
CompilationResult compilationResult = compilePEGraph(graph, compilable.toString(), graphBuilderSuite, compilable, asCompilationRequest(compilationId), listener);
if (listener != null) {
listener.onSuccess(compilable, inliningPlan, new GraphInfoImpl(graph), new CompilationResultInfoImpl(compilationResult));
}
// Partial evaluation and installation are included in
// compilation time and memory usage reported by printer
printer.finish(compilationResult);
} catch (Throwable t) {
// graph is null
if (listener != null) {
BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout);
}
throw t;
}
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class HotSpotTruffleCompilerImpl method installTruffleCallBoundaryMethods.
/**
* @see #compileTruffleCallBoundaryMethod
*/
@Override
@SuppressWarnings("try")
public void installTruffleCallBoundaryMethods() {
HotSpotTruffleCompilerRuntime runtime = (HotSpotTruffleCompilerRuntime) TruffleCompilerRuntime.getRuntime();
for (ResolvedJavaMethod method : runtime.getTruffleCallBoundaryMethods()) {
HotSpotCompilationIdentifier compilationId = (HotSpotCompilationIdentifier) backend.getCompilationIdentifier(method);
OptionValues options = getOptions();
try (DebugContext debug = DebugStubsAndSnippets.getValue(options) ? hotspotGraalRuntime.openDebugContext(options, compilationId, method, getDebugHandlerFactories()) : DebugContext.DISABLED;
Activation a = debug.activate();
DebugContext.Scope d = debug.scope("InstallingTruffleStub")) {
CompilationResult compResult = compileTruffleCallBoundaryMethod(method, compilationId, debug);
CodeCacheProvider codeCache = providers.getCodeCache();
try (DebugContext.Scope s = debug.scope("CodeInstall", codeCache, method, compResult)) {
CompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, method, compilationId.getRequest(), compResult);
codeCache.setDefaultCode(method, compiledCode);
} catch (Throwable e) {
throw debug.handle(e);
}
}
}
}
Aggregations