use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class GraphKit method createInvokeWithExceptionAndUnwind.
@SuppressWarnings("try")
public InvokeWithExceptionNode createInvokeWithExceptionAndUnwind(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
try (DebugCloseable context = graph.withNodeSourcePosition(NodeSourcePosition.substitution(graph.currentNodeSourcePosition(), method))) {
InvokeWithExceptionNode result = startInvokeWithException(method, invokeKind, frameStateBuilder, invokeBci, exceptionEdgeBci, args);
exceptionPart();
ExceptionObjectNode exception = exceptionObject();
append(new UnwindNode(exception));
endInvokeWithException();
return result;
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class ReplacementsImpl method getSnippet.
@Override
@SuppressWarnings("try")
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
assert method.hasBytecodes() : "Snippet must not be abstract or native";
StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null;
if (graph == null || (trackNodeSourcePosition && !graph.trackNodeSourcePosition())) {
try (DebugContext debug = openDebugContext("Snippet_", method);
DebugCloseable a = SnippetPreparationTime.start(debug)) {
StructuredGraph newGraph = makeGraph(debug, defaultBytecodeProvider, method, args, recursiveEntry, trackNodeSourcePosition, replaceePosition);
DebugContext.counter("SnippetNodeCount[%#s]", method).add(newGraph.getDebug(), newGraph.getNodeCount());
if (!UseSnippetGraphCache.getValue(options) || args != null) {
return newGraph;
}
newGraph.freeze();
if (graph != null) {
graphs.replace(method, graph, newGraph);
} else {
graphs.putIfAbsent(method, newGraph);
}
graph = graphs.get(method);
}
}
assert !trackNodeSourcePosition || graph.trackNodeSourcePosition();
return graph;
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class MacroNode method replaceWithInvoke.
@SuppressWarnings("try")
public InvokeNode replaceWithInvoke() {
try (DebugCloseable context = withNodeSourcePosition()) {
InvokeNode invoke = createInvoke();
graph().replaceFixedWithFixed(this, invoke);
return invoke;
}
}
use of org.graalvm.compiler.debug.DebugCloseable 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.debug.DebugCloseable in project graal by oracle.
the class BytecodeParser method build.
@SuppressWarnings("try")
protected void build(FixedWithNextNode startInstruction, FrameStateBuilder startFrameState) {
if (PrintProfilingInformation.getValue(options) && profilingInfo != null) {
TTY.println("Profiling info for " + method.format("%H.%n(%p)"));
TTY.println(Util.indent(profilingInfo.toString(method, CodeUtil.NEW_LINE), " "));
}
try (Indent indent = debug.logAndIndent("build graph for %s", method)) {
if (bytecodeProvider.shouldRecordMethodDependencies()) {
assert getParent() != null || method.equals(graph.method());
// Record method dependency in the graph
graph.recordMethod(method);
}
// compute the block map, setup exception handlers and get the entrypoint(s)
BciBlockMapping newMapping = BciBlockMapping.create(stream, code, options, graph.getDebug());
this.blockMap = newMapping;
this.firstInstructionArray = new FixedWithNextNode[blockMap.getBlockCount()];
this.entryStateArray = new FrameStateBuilder[blockMap.getBlockCount()];
if (!method.isStatic()) {
originalReceiver = startFrameState.loadLocal(0, JavaKind.Object);
}
/*
* Configure the assertion checking behavior of the FrameStateBuilder. This needs to be
* done only when assertions are enabled, so it is wrapped in an assertion itself.
*/
assert computeKindVerification(startFrameState);
try (DebugContext.Scope s = debug.scope("LivenessAnalysis")) {
int maxLocals = method.getMaxLocals();
liveness = LocalLiveness.compute(debug, stream, blockMap.getBlocks(), maxLocals, blockMap.getLoopCount());
} catch (Throwable e) {
throw debug.handle(e);
}
lastInstr = startInstruction;
this.setCurrentFrameState(startFrameState);
stream.setBCI(0);
BciBlock startBlock = blockMap.getStartBlock();
if (this.parent == null) {
StartNode startNode = graph.start();
if (method.isSynchronized()) {
assert !parsingIntrinsic();
startNode.setStateAfter(createFrameState(BytecodeFrame.BEFORE_BCI, startNode));
} else {
if (!parsingIntrinsic()) {
if (graph.method() != null && graph.method().isJavaLangObjectInit()) {
/*
* Don't clear the receiver when Object.<init> is the compilation root.
* The receiver is needed as input to RegisterFinalizerNode.
*/
} else {
frameState.clearNonLiveLocals(startBlock, liveness, true);
}
assert bci() == 0;
startNode.setStateAfter(createFrameState(bci(), startNode));
} else {
if (startNode.stateAfter() == null) {
FrameState stateAfterStart = createStateAfterStartOfReplacementGraph();
startNode.setStateAfter(stateAfterStart);
}
}
}
}
try (DebugCloseable context = openNodeContext()) {
if (method.isSynchronized()) {
finishPrepare(lastInstr, BytecodeFrame.BEFORE_BCI);
// add a monitor enter to the start block
methodSynchronizedObject = synchronizedObject(frameState, method);
frameState.clearNonLiveLocals(startBlock, liveness, true);
assert bci() == 0;
genMonitorEnter(methodSynchronizedObject, bci());
}
ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin();
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
profilingPlugin.profileInvoke(this, method, stateBefore);
}
finishPrepare(lastInstr, 0);
genInfoPointNode(InfopointReason.METHOD_START, null);
}
currentBlock = blockMap.getStartBlock();
setEntryState(startBlock, frameState);
if (startBlock.isLoopHeader) {
appendGoto(startBlock);
} else {
setFirstInstruction(startBlock, lastInstr);
}
BciBlock[] blocks = blockMap.getBlocks();
for (BciBlock block : blocks) {
processBlock(block);
}
}
}
Aggregations