use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.
the class SubstrateGraphKit method mergeUnwinds.
/**
* A graph with multiple unwinds is invalid. Merge the various unwind paths.
*/
public void mergeUnwinds() {
List<UnwindNode> unwinds = new ArrayList<>();
for (Node node : getGraph().getNodes()) {
if (node instanceof UnwindNode) {
unwinds.add((UnwindNode) node);
}
}
if (unwinds.size() > 1) {
MergeNode unwindMergeNode = add(new MergeNode());
ValueNode exceptionValue = InliningUtil.mergeValueProducers(unwindMergeNode, unwinds, null, UnwindNode::exception);
UnwindNode unwindReplacement = add(new UnwindNode(exceptionValue));
unwindMergeNode.setNext(unwindReplacement);
FrameStateBuilder exceptionState = getFrameState().copy();
exceptionState.clearStack();
exceptionState.push(JavaKind.Object, exceptionValue);
exceptionState.setRethrowException(true);
unwindMergeNode.setStateAfter(exceptionState.create(BytecodeFrame.AFTER_EXCEPTION_BCI, unwindMergeNode));
}
}
use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.
the class CFunctionCallStubMethod method buildGraph.
@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
CFunction annotation = method.getAnnotation(CFunction.class);
boolean needsTransition = annotation.transition() != Transition.NO_TRANSITION;
if (purpose == Purpose.PREPARE_RUNTIME_COMPILATION && needsTransition) {
/*
* C function calls that need a transition cannot be runtime compiled (and cannot be
* inlined during runtime compilation). Deoptimization could be required while we are
* blocked in native code, which means the deoptimization stub would need to do the
* native-to-Java transition.
*/
ImageSingletons.lookup(CFunctionFeature.class).warnRuntimeCompilationReachableCFunctionWithTransition(this);
return null;
}
boolean deoptimizationTarget = method instanceof SharedMethod && ((SharedMethod) method).isDeoptTarget();
HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
FrameStateBuilder state = kit.getFrameState();
ValueNode callAddress = kit.unique(new CGlobalDataLoadAddressNode(linkage));
List<ValueNode> arguments = kit.loadArguments(method.toParameterTypes());
Signature signature = adaptSignatureAndConvertArguments(method, providers, nativeLibraries, kit, method.getSignature(), arguments);
state.clearLocals();
ValueNode returnValue = kit.createCFunctionCall(callAddress, method, arguments, signature, needsTransition, deoptimizationTarget);
returnValue = adaptReturnValue(method, providers, nativeLibraries, kit, returnValue);
kit.createReturn(returnValue, signature.getReturnKind());
assert kit.getGraph().verify();
return kit.getGraph();
}
use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.
the class GraphKit method startInvokeWithException.
public InvokeWithExceptionNode startInvokeWithException(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
assert method.isStatic() == (invokeKind == InvokeKind.Static);
Signature signature = method.getSignature();
JavaType returnType = signature.getReturnType(null);
assert checkArgs(method, args);
StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
if (returnStamp == null) {
returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
}
ExceptionObjectNode exceptionObject = add(new ExceptionObjectNode(getMetaAccess()));
if (frameStateBuilder != null) {
FrameStateBuilder exceptionState = frameStateBuilder.copy();
exceptionState.clearStack();
exceptionState.push(JavaKind.Object, exceptionObject);
exceptionState.setRethrowException(false);
exceptionObject.setStateAfter(exceptionState.create(exceptionEdgeBci, exceptionObject));
}
MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, invokeBci));
InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionObject, invokeBci));
AbstractBeginNode noExceptionEdge = graph.add(KillingBeginNode.create(LocationIdentity.any()));
invoke.setNext(noExceptionEdge);
if (frameStateBuilder != null) {
if (invoke.getStackKind() != JavaKind.Void) {
frameStateBuilder.push(invoke.getStackKind(), invoke);
}
invoke.setStateAfter(frameStateBuilder.create(invokeBci, invoke));
if (invoke.getStackKind() != JavaKind.Void) {
frameStateBuilder.pop(invoke.getStackKind());
}
}
lastFixedNode = null;
InvokeWithExceptionStructure s = new InvokeWithExceptionStructure();
s.state = InvokeWithExceptionStructure.State.INVOKE;
s.noExceptionEdge = noExceptionEdge;
s.exceptionEdge = exceptionObject;
s.exceptionObject = exceptionObject;
pushStructure(s);
return invoke;
}
use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.
the class JNIFieldAccessorMethod method buildGraph.
@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
JNIGraphKit kit = new JNIGraphKit(debug, providers, method);
StructuredGraph graph = kit.getGraph();
FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
ValueNode vmThread = kit.loadLocal(0, signature.getParameterKind(0));
kit.append(new CEntryPointEnterNode(EnterAction.Enter, vmThread));
List<ValueNode> arguments = kit.loadArguments(signature.toParameterTypes(null));
ValueNode object;
if (isStatic) {
if (fieldKind.isPrimitive()) {
object = kit.getStaticPrimitiveFieldsArray();
} else {
object = kit.getStaticObjectFieldsArray();
}
} else {
ValueNode handle = arguments.get(1);
object = kit.unboxHandle(handle);
}
ValueNode fieldId = arguments.get(2);
ValueNode offset = kit.getFieldOffsetFromId(fieldId);
ValueNode returnValue;
if (isSetter) {
// void
returnValue = null;
ValueNode newValue = arguments.get(3);
if (fieldKind.isObject()) {
newValue = kit.unboxHandle(newValue);
}
kit.append(new RawStoreNode(object, offset, newValue, fieldKind, LocationIdentity.ANY_LOCATION));
} else {
returnValue = kit.append(new RawLoadNode(object, offset, fieldKind, LocationIdentity.ANY_LOCATION));
if (fieldKind.isObject()) {
returnValue = kit.boxObjectInLocalHandle(returnValue);
}
}
kit.append(new CEntryPointLeaveNode(LeaveAction.Leave));
JavaKind returnKind = isSetter ? JavaKind.Void : fieldKind;
kit.createReturn(returnValue, returnKind);
assert graph.verify();
return graph;
}
use of org.graalvm.compiler.java.FrameStateBuilder in project graal by oracle.
the class DeletedMethod method buildGraph.
public static StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, String message) {
HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
StructuredGraph graph = kit.getGraph();
FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
/*
* A random, but unique and consistent, number for every invoke. This is necessary because
* we, e.g., look up static analysis results by bci.
*/
int bci = 0;
graph.start().setStateAfter(state.create(bci++, graph.start()));
String msg = AnnotationSubstitutionProcessor.deleteErrorMessage(method, message, false);
ValueNode msgNode = ConstantNode.forConstant(SubstrateObjectConstant.forObject(msg), providers.getMetaAccess(), graph);
ValueNode exceptionNode = kit.createInvokeWithExceptionAndUnwind(providers.getMetaAccess().lookupJavaMethod(reportErrorMethod), InvokeKind.Static, state, bci++, bci++, msgNode);
kit.append(new UnwindNode(exceptionNode));
kit.mergeUnwinds();
assert graph.verify();
return graph;
}
Aggregations