use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class BytecodeParser method genReturn.
protected void genReturn(ValueNode returnVal, JavaKind returnKind) {
if (parsingIntrinsic() && returnVal != null) {
if (returnVal instanceof StateSplit) {
StateSplit stateSplit = (StateSplit) returnVal;
FrameState stateAfter = stateSplit.stateAfter();
if (stateSplit.hasSideEffect()) {
assert stateSplit != null;
if (stateAfter.bci == BytecodeFrame.AFTER_BCI) {
assert stateAfter.usages().count() == 1;
assert stateAfter.usages().first() == stateSplit;
stateAfter.replaceAtUsages(graph.add(new FrameState(BytecodeFrame.AFTER_BCI, returnVal)));
GraphUtil.killWithUnusedFloatingInputs(stateAfter);
} else {
/*
* This must be the return value from within a partial intrinsification.
*/
assert !BytecodeFrame.isPlaceholderBci(stateAfter.bci);
}
} else {
assert stateAfter == null;
}
}
}
ValueNode realReturnVal = processReturnValue(returnVal, returnKind);
frameState.setRethrowException(false);
frameState.clearStack();
beforeReturn(realReturnVal, returnKind);
if (parent == null) {
append(new ReturnNode(realReturnVal));
} else {
if (returnDataList == null) {
returnDataList = new ArrayList<>();
}
returnDataList.add(new ReturnToCallerData(realReturnVal, lastInstr));
lastInstr = null;
}
}
use of org.graalvm.compiler.nodes.FrameState 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);
}
}
}
use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class BytecodeParser method genGetStatic.
private void genGetStatic(JavaField field) {
ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, null);
if (resolvedField == null) {
return;
}
if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
graph.recordField(resolvedField);
}
/*
* Javac does not allow use of "$assertionsDisabled" for a field name but Eclipse does, in
* which case a suffix is added to the generated field.
*/
if ((parsingIntrinsic() || graphBuilderConfig.omitAssertions()) && resolvedField.isSynthetic() && resolvedField.getName().startsWith("$assertionsDisabled")) {
frameState.push(field.getJavaKind(), ConstantNode.forBoolean(true, graph));
return;
}
ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();
if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedField.getDeclaringClass())) {
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
classInitializationPlugin.apply(this, resolvedField.getDeclaringClass(), stateBefore);
}
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
if (plugin.handleLoadStaticField(this, resolvedField)) {
return;
}
}
frameState.push(field.getJavaKind(), append(genLoadField(null, resolvedField)));
}
use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class BytecodeParser method genConstantTargetIf.
private void genConstantTargetIf(BciBlock trueBlock, BciBlock falseBlock, LogicNode condition) {
LogicConstantNode constantLogicNode = (LogicConstantNode) condition;
boolean value = constantLogicNode.getValue();
BciBlock nextBlock = falseBlock;
if (value) {
nextBlock = trueBlock;
}
int startBci = nextBlock.startBci;
int targetAtStart = stream.readUByte(startBci);
if (targetAtStart == Bytecodes.GOTO && nextBlock.getPredecessorCount() == 1) {
// This is an empty block. Skip it.
BciBlock successorBlock = nextBlock.successors.get(0);
ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
profilingPlugin.profileGoto(this, method, bci(), successorBlock.startBci, stateBefore);
}
appendGoto(successorBlock);
assert nextBlock.numNormalSuccessors() == 1;
} else {
ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
profilingPlugin.profileGoto(this, method, bci(), nextBlock.startBci, stateBefore);
}
appendGoto(nextBlock);
}
}
use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.
the class BytecodeParser method genInvokeStatic.
void genInvokeStatic(JavaMethod target) {
if (callTargetIsResolved(target)) {
ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
ResolvedJavaType holder = resolvedTarget.getDeclaringClass();
if (!holder.isInitialized() && ResolveClassBeforeStaticInvoke.getValue(options)) {
handleUnresolvedInvoke(target, InvokeKind.Static);
} else {
ValueNode classInit = null;
ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin();
if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedTarget.getDeclaringClass())) {
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
classInit = classInitializationPlugin.apply(this, resolvedTarget.getDeclaringClass(), stateBefore);
}
ValueNode[] args = frameState.popArguments(resolvedTarget.getSignature().getParameterCount(false));
Invoke invoke = appendInvoke(InvokeKind.Static, resolvedTarget, args);
if (invoke != null) {
invoke.setClassInit(classInit);
}
}
} else {
handleUnresolvedInvoke(target, InvokeKind.Static);
}
}
Aggregations