use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class MonitorDeoptTest method run0.
@Test
public void run0() throws Throwable {
ResolvedJavaMethod javaMethod = getResolvedJavaMethod("test");
StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
removeLoopSafepoint(graph);
CompilationResult compilationResult = compile(javaMethod, graph);
final InstalledCode installedCode = getBackend().createDefaultInstalledCode(graph.getDebug(), javaMethod, compilationResult);
final Monitor monitor = new Monitor();
Thread controlThread = new Thread(new Runnable() {
@Override
public void run() {
try {
// Wait for thread to reach RUNNING_GRAAL and then invalidate the code
monitor.invalidate(installedCode);
// wait for the main thread to continue running in the interpreter
monitor.waitState(State.RUNNING_INTERPRETER);
// terminate the main thread
monitor.setState(State.TERMINATED);
} catch (InterruptedException e) {
}
}
});
controlThread.start();
boolean result = test(monitor);
Assert.assertTrue(result);
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class InfopointReasonTest method lineInfopoints.
@Test
public void lineInfopoints() {
final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
final StructuredGraph graph = parse(builder(method, AllowAssumptions.ifTrue(OptAssumptions.getValue(getInitialOptions()))), getDebugGraphBuilderSuite());
int graphLineSPs = 0;
for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
++graphLineSPs;
}
}
assertTrue(graphLineSPs > 0);
PhaseSuite<HighTierContext> graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()), createLIRSuites(graph.getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
int lineSPs = 0;
for (Infopoint sp : cr.getInfopoints()) {
assertNotNull(sp.reason);
if (sp.reason == InfopointReason.BYTECODE_POSITION) {
++lineSPs;
}
}
assertTrue(lineSPs > 0);
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class Stub method buildCompilationResult.
@SuppressWarnings("try")
private CompilationResult buildCompilationResult(DebugContext debug, final Backend backend) {
CompilationIdentifier compilationId = getStubCompilationId();
final StructuredGraph graph = getGraph(debug, compilationId);
CompilationResult compResult = new CompilationResult(compilationId, toString(), GeneratePIC.getValue(options));
// Stubs cannot be recompiled so they cannot be compiled with assumptions
assert graph.getAssumptions() == null;
if (!(graph.start() instanceof StubStartNode)) {
StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
newStart.setStateAfter(graph.start().stateAfter());
graph.replaceFixed(graph.start(), newStart);
}
try (DebugContext.Scope s0 = debug.scope("StubCompilation", graph, providers.getCodeCache())) {
Suites suites = createSuites();
emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites);
LIRSuites lirSuites = createLIRSuites();
emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites);
assert checkStubInvariants(compResult);
} catch (Throwable e) {
throw debug.handle(e);
}
return compResult;
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class Stub method getCode.
/**
* Gets the code for this stub, compiling it first if necessary.
*/
@SuppressWarnings("try")
public synchronized InstalledCode getCode(final Backend backend) {
if (code == null) {
try (DebugContext debug = openDebugContext(DebugContext.forCurrentThread())) {
try (DebugContext.Scope d = debug.scope("CompilingStub", providers.getCodeCache(), debugScopeContext())) {
CodeCacheProvider codeCache = providers.getCodeCache();
CompilationResult compResult = buildCompilationResult(debug, backend);
try (DebugContext.Scope s = debug.scope("CodeInstall", compResult);
DebugContext.Activation a = debug.activate()) {
assert destroyedCallerRegisters != null;
// Add a GeneratePIC check here later, we don't want to install
// code if we don't have a corresponding VM global symbol.
HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, null, null, compResult);
code = codeCache.installCode(null, compiledCode, null, null, false);
} catch (Throwable e) {
throw debug.handle(e);
}
} catch (Throwable e) {
throw debug.handle(e);
}
assert code != null : "error installing stub " + this;
}
}
return code;
}
use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.
the class SubstrateCodeCacheProvider method installCode.
@Override
@SuppressFBWarnings(value = { "BC_UNCONFIRMED_CAST" }, justification = "We know what we are doing.")
public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compiledCode, InstalledCode predefinedInstalledCode, SpeculationLog log, boolean isDefault) {
VMError.guarantee(!isDefault);
SubstrateInstalledCode substrateInstalledCode;
if (predefinedInstalledCode instanceof SubstrateInstalledCode.Access) {
substrateInstalledCode = ((SubstrateInstalledCode.Access) predefinedInstalledCode).getSubstrateInstalledCode();
} else {
substrateInstalledCode = (SubstrateInstalledCode) predefinedInstalledCode;
}
CompilationResult compResult = ((SubstrateCompiledCode) compiledCode).getCompilationResult();
InstalledCodeBuilder builder = new InstalledCodeBuilder((SharedRuntimeMethod) method, compResult, substrateInstalledCode, null);
builder.install();
return predefinedInstalledCode;
}
Aggregations