use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class TraceAllocationPhase method apply.
@SuppressWarnings("try")
public final void apply(TargetDescription target, LIRGenerationResult lirGenRes, Trace trace, C context, boolean dumpTrace) {
DebugContext debug = lirGenRes.getLIR().getDebug();
try (DebugContext.Scope s = debug.scope(getName(), this)) {
try (DebugCloseable a = timer.start(debug);
DebugCloseable c = memUseTracker.start(debug)) {
if (dumpTrace) {
if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
debug.dump(DebugContext.DETAILED_LEVEL, trace, "Before %s (Trace%s: %s)", getName(), trace.getId(), trace);
}
}
run(target, lirGenRes, trace, context);
allocatedTraces.increment(debug);
if (dumpTrace) {
if (debug.isDumpEnabled(DebugContext.VERBOSE_LEVEL)) {
debug.dump(DebugContext.VERBOSE_LEVEL, trace, "After %s (Trace%s: %s)", getName(), trace.getId(), trace);
}
}
}
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class BytecodeParser method loadLocalObject.
@SuppressWarnings("try")
public void loadLocalObject(int index) {
ValueNode value = frameState.loadLocal(index, JavaKind.Object);
int nextBCI = stream.nextBCI();
int nextBC = stream.readUByte(nextBCI);
if (nextBCI <= currentBlock.endBci && nextBC == Bytecodes.GETFIELD) {
stream.next();
try (DebugCloseable ignored = openNodeContext()) {
genGetField(stream.readCPI(), Bytecodes.GETFIELD, value);
}
} else {
frameState.push(JavaKind.Object, value);
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class BytecodeParser method tryInvocationPlugin.
@SuppressWarnings("try")
protected boolean tryInvocationPlugin(InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType, JavaType returnType) {
InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod);
if (plugin != null) {
if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
// method should be called.
assert !targetMethod.hasBytecodes() : "TODO: when does this happen?";
return false;
}
InvocationPluginReceiver pluginReceiver = invocationPluginReceiver.init(targetMethod, args);
IntrinsicGuard intrinsicGuard = null;
if (invokeKind.isIndirect()) {
intrinsicGuard = guardIntrinsic(args, targetMethod, pluginReceiver);
if (intrinsicGuard == null) {
return false;
} else if (intrinsicGuard.nonIntrinsicBranch == null) {
assert lastInstr instanceof FixedGuardNode;
}
}
InvocationPluginAssertions assertions = Assertions.assertionsEnabled() ? new InvocationPluginAssertions(plugin, args, targetMethod, resultType) : null;
try (DebugCloseable context = openNodeContext(targetMethod)) {
if (plugin.execute(this, targetMethod, pluginReceiver, args)) {
afterInvocationPluginExecution(true, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
return true;
} else {
afterInvocationPluginExecution(false, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
}
}
}
return false;
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class BytecodeParser method iterateBytecodesForBlock.
@SuppressWarnings("try")
protected void iterateBytecodesForBlock(BciBlock block) {
if (block.isLoopHeader) {
// Create the loop header block, which later will merge the backward branches of
// the loop.
controlFlowSplit = true;
LoopBeginNode loopBegin = appendLoopBegin(this.lastInstr, block.startBci);
lastInstr = loopBegin;
// Create phi functions for all local variables and operand stack slots.
frameState.insertLoopPhis(liveness, block.loopId, loopBegin, forceLoopPhis(), stampFromValueForForcedPhis());
loopBegin.setStateAfter(createFrameState(block.startBci, loopBegin));
/*
* We have seen all forward branches. All subsequent backward branches will merge to the
* loop header. This ensures that the loop header has exactly one non-loop predecessor.
*/
setFirstInstruction(block, loopBegin);
/*
* We need to preserve the frame state builder of the loop header so that we can merge
* values for phi functions, so make a copy of it.
*/
setEntryState(block, frameState.copy());
debug.log(" created loop header %s", loopBegin);
} else if (lastInstr instanceof MergeNode) {
/*
* All inputs of non-loop phi nodes are known by now. We can infer the stamp for the
* phi, so that parsing continues with more precise type information.
*/
frameState.inferPhiStamps((AbstractMergeNode) lastInstr);
}
assert lastInstr.next() == null : "instructions already appended at block " + block;
debug.log(" frameState: %s", frameState);
lastInstr = finishInstruction(lastInstr, frameState);
int endBCI = stream.endBCI();
stream.setBCI(block.startBci);
int bci = block.startBci;
BytecodesParsed.add(debug, block.endBci - bci);
/* Reset line number for new block */
if (graphBuilderConfig.insertFullInfopoints()) {
previousLineNumber = -1;
}
while (bci < endBCI) {
try (DebugCloseable context = openNodeContext()) {
if (graphBuilderConfig.insertFullInfopoints() && !parsingIntrinsic()) {
currentLineNumber = lnt != null ? lnt.getLineNumber(bci) : -1;
if (currentLineNumber != previousLineNumber) {
genInfoPointNode(InfopointReason.BYTECODE_POSITION, null);
previousLineNumber = currentLineNumber;
}
}
// read the opcode
int opcode = stream.currentBC();
assert traceState();
assert traceInstruction(bci, opcode, bci == block.startBci);
if (parent == null && bci == entryBCI) {
if (block.getJsrScope() != JsrScope.EMPTY_SCOPE) {
throw new JsrNotSupportedBailout("OSR into a JSR scope is not supported");
}
EntryMarkerNode x = append(new EntryMarkerNode());
frameState.insertProxies(value -> graph.unique(new EntryProxyNode(value, x)));
x.setStateAfter(createFrameState(bci, x));
}
processBytecode(bci, opcode);
} catch (BailoutException e) {
// Don't wrap bailouts as parser errors
throw e;
} catch (Throwable e) {
throw throwParserError(e);
}
if (lastInstr == null || lastInstr.next() != null) {
break;
}
stream.next();
bci = stream.currentBCI();
assert block == currentBlock;
assert checkLastInstruction();
lastInstr = finishInstruction(lastInstr, frameState);
if (bci < endBCI) {
if (bci > block.endBci) {
assert !block.getSuccessor(0).isExceptionEntry;
assert block.numNormalSuccessors() == 1;
// we fell through to the next block, add a goto and break
appendGoto(block.getSuccessor(0));
break;
}
}
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class BytecodeParser method tryFastInlineAccessor.
/**
* Tries to inline {@code targetMethod} if it is an instance field accessor. This avoids the
* overhead of creating and using a nested {@link BytecodeParser} object.
*/
@SuppressWarnings("try")
private boolean tryFastInlineAccessor(ValueNode[] args, ResolvedJavaMethod targetMethod) {
byte[] bytecode = targetMethod.getCode();
if (bytecode != null && bytecode.length == ACCESSOR_BYTECODE_LENGTH && Bytes.beU1(bytecode, 0) == ALOAD_0 && Bytes.beU1(bytecode, 1) == GETFIELD) {
int b4 = Bytes.beU1(bytecode, 4);
if (b4 >= IRETURN && b4 <= ARETURN) {
int cpi = Bytes.beU2(bytecode, 2);
JavaField field = targetMethod.getConstantPool().lookupField(cpi, targetMethod, GETFIELD);
if (field instanceof ResolvedJavaField) {
ValueNode receiver = invocationPluginReceiver.init(targetMethod, args).get();
ResolvedJavaField resolvedField = (ResolvedJavaField) field;
try (DebugCloseable context = openNodeContext(targetMethod, 1)) {
genGetField(resolvedField, receiver);
notifyBeforeInline(targetMethod);
printInlining(targetMethod, targetMethod, true, "inline accessor method (bytecode parsing)");
notifyAfterInline(targetMethod);
}
return true;
}
}
}
return false;
}
Aggregations