use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class TruffleCompilerImpl method compilePEGraph.
/**
* Compiles a graph produced by {@link PartialEvaluator#createGraph partial evaluation}.
*
* @param graph a graph resulting from partial evaluation
* @param name the name to be used for the returned {@link CompilationResult#getName() result}
* @param graphBuilderSuite phase suite to be used for creating new graphs during inlining
* @param compilationRequest
* @param listener
*/
@SuppressWarnings("try")
public CompilationResult compilePEGraph(StructuredGraph graph, String name, PhaseSuite<HighTierContext> graphBuilderSuite, CompilableTruffleAST compilable, CompilationRequest compilationRequest, TruffleCompilerListener listener) {
DebugContext debug = graph.getDebug();
try (DebugContext.Scope s = debug.scope("TruffleFinal")) {
debug.dump(DebugContext.BASIC_LEVEL, graph, "After TruffleTier");
} catch (Throwable e) {
throw debug.handle(e);
}
CompilationResult result = null;
try (DebugCloseable a = CompilationTime.start(debug);
DebugContext.Scope s = debug.scope("TruffleGraal.GraalCompiler", graph, providers.getCodeCache());
DebugCloseable c = CompilationMemUse.start(debug)) {
CompilationResult compilationResult = createCompilationResult(name, graph.compilationId());
result = GraalCompiler.compileGraph(graph, graph.method(), providers, backend, graphBuilderSuite, Optimizations, graph.getProfilingInfo(), suites, lirSuites, compilationResult, CompilationResultBuilderFactory.Default);
} catch (Throwable e) {
throw debug.handle(e);
}
if (listener != null) {
listener.onGraalTierFinished(compilable, new GraphInfoImpl(graph));
}
try (DebugCloseable a = CodeInstallationTime.start(debug);
DebugCloseable c = CodeInstallationMemUse.start(debug)) {
InstalledCode installedCode = createInstalledCode(compilable);
backend.createInstalledCode(debug, graph.method(), compilationRequest, result, graph.getSpeculationLog(), installedCode, false);
} catch (Throwable e) {
throw debug.handle(e);
}
return result;
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class AssemblerTest method runTest.
protected Object runTest(String methodName, CodeGenTest test, Object... args) {
Method method = getMethod(methodName);
InstalledCode code = assembleMethod(method, test);
try {
return code.executeVarargs(args);
} catch (InvalidInstalledCodeException e) {
throw new RuntimeException(e);
}
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class PartialEscapeAnalysisTreesTest method testGraph.
/**
* Prepare a graph that includes some blackholes and then remove the blackholes and compile
* normally to create an unusual situation for PEA.
*/
@SuppressWarnings("try")
public void testGraph(String name) {
ResolvedJavaMethod method = getResolvedJavaMethod(name);
prepareGraph(name, true);
try (DebugContext.Scope s = graph.getDebug().scope(getClass(), method, getCodeCache(), graph)) {
for (BlackholeNode node : graph.getNodes().filter(BlackholeNode.class)) {
graph.removeFixed(node);
}
new DeadCodeEliminationPhase().apply(graph);
new CanonicalizerPhase().apply(graph, context);
InstalledCode code = getCode(method, graph, true);
GraalCompilerTest.Result r = executeExpected(method, null, true);
int expectedInstances = ((TreeNode) r.returnValue).countInstances();
TreeNode r2 = (TreeNode) code.executeVarargs(true);
Assert.assertEquals("Wrong number of nodes in tree", expectedInstances, r2.countInstances());
r = executeExpected(method, null, false);
expectedInstances = ((TreeNode) r.returnValue).countInstances();
r2 = (TreeNode) code.executeVarargs(false);
Assert.assertEquals("Wrong number of nodes in tree", expectedInstances, r2.countInstances());
} catch (Throwable e) {
throw graph.getDebug().handle(e);
}
}
use of jdk.vm.ci.code.InstalledCode 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 jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class SafepointRethrowDeoptTest method test.
@Test
public void test() {
Assume.assumeTrue(GraalOptions.GenLoopSafepoints.getValue(getInitialOptions()));
synchronized (SafepointRethrowDeoptTest.class) {
// needs static fields
terminate = 1;
InstalledCode installed = getCode(getResolvedJavaMethod("execute"));
terminate = 0;
entered = 0;
CountDownLatch cdl = new CountDownLatch(1);
Thread t1 = new Thread(() -> {
try {
cdl.await();
while (entered == 0) {
/* spin */
}
installed.invalidate();
} catch (InterruptedException e) {
Assert.fail("interrupted");
} finally {
terminate = 1;
}
});
Thread t2 = new Thread(() -> {
cdl.countDown();
Object result;
try {
result = installed.executeVarargs();
} catch (Exception e) {
e.printStackTrace();
Assert.fail("exception");
return;
}
Assert.assertEquals(RETURN_VALUE, result);
});
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
Assert.fail("interrupted");
}
}
}
Aggregations