use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class InvokeGraal method compileAndInstallMethod.
/**
* The simplest way to compile a method, using the default behavior for everything.
*/
@SuppressWarnings("try")
protected InstalledCode compileAndInstallMethod(ResolvedJavaMethod method) {
/* Create a unique compilation identifier, visible in IGV. */
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
try (DebugContext.Scope s = debug.scope("compileAndInstallMethod", new DebugDumpScope(String.valueOf(compilationId), true))) {
/*
* The graph that is compiled. We leave it empty (no nodes added yet). This means that
* it will be filled according to the graphBuilderSuite defined below. We also specify
* that we want the compilation to make optimistic assumptions about runtime state such
* as the loaded class hierarchy.
*/
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).compilationId(compilationId).build();
/*
* The phases used to build the graph. Usually this is just the GraphBuilderPhase. If
* the graph already contains nodes, it is ignored.
*/
PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite();
/*
* The optimization phases that are applied to the graph. This is the main configuration
* point for Graal. Add or remove phases to customize your compilation.
*/
Suites suites = backend.getSuites().getDefaultSuites(options);
/*
* The low-level phases that are applied to the low-level representation.
*/
LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites(options);
/*
* We want Graal to perform all speculative optimistic optimizations, using the
* profiling information that comes with the method (collected by the interpreter) for
* speculation.
*/
OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL;
ProfilingInfo profilingInfo = graph.getProfilingInfo(method);
/* The default class and configuration for compilation results. */
CompilationResult compilationResult = new CompilationResult(graph.compilationId());
CompilationResultBuilderFactory factory = CompilationResultBuilderFactory.Default;
/* Invoke the whole Graal compilation pipeline. */
GraalCompiler.compileGraph(graph, method, providers, backend, graphBuilderSuite, optimisticOpts, profilingInfo, suites, lirSuites, compilationResult, factory);
/*
* Install the compilation result into the VM, i.e., copy the byte[] array that contains
* the machine code into an actual executable memory location.
*/
return backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compilationResult);
} catch (Throwable ex) {
throw debug.handle(ex);
}
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class FloatArraysEqualsTest method testStableArray.
public void testStableArray(String methodName) {
ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
Result expected = executeExpected(method, null);
StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
ConstantNode newConstantNode = ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess());
newConstantNode = graph.unique(newConstantNode);
constantNode.replaceAndDelete(newConstantNode);
}
}
CompilationResult result = compile(method, graph);
InstalledCode code = addMethod(graph.getDebug(), method, result);
Result actual;
try {
actual = new Result(code.executeVarargs(), null);
} catch (Exception e) {
actual = new Result(null, e);
}
assertEquals(expected, actual);
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class GraalCompilerTest method compile.
/**
* Compiles a given method.
*
* @param installedCodeOwner the method the compiled code will be associated with when installed
* @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
* be obtained from {@code installedCodeOwner} via
* {@link #parseForCompile(ResolvedJavaMethod)}.
*/
protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class NativeImageCodeCache method layoutMethods.
@SuppressWarnings("try")
public void layoutMethods(DebugContext debug) {
try (Indent indent = debug.logAndIndent("layout methods")) {
// Assign a location to all methods.
assert codeCacheSize == 0;
HostedMethod firstMethod = null;
for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
HostedMethod method = entry.getKey();
if (firstMethod == null) {
firstMethod = method;
}
CompilationResult compilation = entry.getValue();
compilationsByStart.put(codeCacheSize, compilation);
method.setCodeAddressOffset(codeCacheSize);
codeCacheSize = ObjectLayout.roundUp(codeCacheSize + compilation.getTargetCodeSize(), CODE_ALIGNMENT);
}
// Build run-time metadata.
FrameInfoCustomization frameInfoCustomization = new FrameInfoCustomization();
CodeInfoEncoder codeInfoEncoder = new CodeInfoEncoder(frameInfoCustomization, null);
for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
final HostedMethod method = entry.getKey();
final CompilationResult compilation = entry.getValue();
codeInfoEncoder.addMethod(method, compilation, method.getCodeAddressOffset());
}
if (NativeImageOptions.PrintMethodHistogram.getValue()) {
System.out.println("encoded deopt entry points ; " + frameInfoCustomization.numDeoptEntryPoints);
System.out.println("encoded during call entry points ; " + frameInfoCustomization.numDuringCallEntryPoints);
}
ImageCodeInfo imageCodeInfo = CodeInfoTable.getImageCodeCache();
codeInfoEncoder.encodeAll();
codeInfoEncoder.install(imageCodeInfo);
imageCodeInfo.setData(MethodPointer.factory(firstMethod), WordFactory.unsigned(codeCacheSize));
if (CodeInfoEncoder.Options.CodeInfoEncoderCounters.getValue()) {
for (Counter counter : ImageSingletons.lookup(CodeInfoEncoder.Counters.class).group.getCounters()) {
System.out.println(counter.getName() + " ; " + counter.getValue());
}
}
if (Options.VerifyDeoptimizationEntryPoints.getValue()) {
/*
* Missing deoptimization entry points lead to hard-to-debug transient failures, so
* we want the verification on all the time and not just when assertions are on.
*/
verifyDeoptEntries(imageCodeInfo);
}
assert verifyMethods(codeInfoEncoder);
}
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class NativeImageCodeCache method layoutConstants.
public void layoutConstants() {
for (CompilationResult compilation : compilations.values()) {
for (DataSection.Data data : compilation.getDataSection()) {
if (data instanceof SubstrateDataBuilder.ObjectData) {
JavaConstant constant = ((SubstrateDataBuilder.ObjectData) data).getConstant();
constantReasons.put(constant, compilation.getName());
}
}
dataSection.addAll(compilation.getDataSection());
}
dataSection.close();
}
Aggregations