use of org.graalvm.compiler.nodes.InvokeWithExceptionNode in project graal by oracle.
the class AssertValueNode method insert.
protected static void insert(ValueNode input, AssertValueNode assertionNode) {
StructuredGraph graph = input.graph();
/* Find the insertion point where we want to add the assertion node. */
FixedWithNextNode insertionPoint;
if (input instanceof ParameterNode) {
insertionPoint = graph.start();
} else if (input instanceof InvokeWithExceptionNode) {
insertionPoint = ((InvokeWithExceptionNode) input).next();
} else if (input instanceof FixedWithNextNode) {
insertionPoint = (FixedWithNextNode) input;
} else {
throw shouldNotReachHere("Node is not fixed: " + input);
}
/*
* When inserting after an invoke that is also a loop exit, a proxy node is inserted between
* the invoke and every usage. We need to be after this proxy node to avoid unschedulable
* graphs.
*/
ProxyNode proxyUsage = null;
boolean otherUsages = false;
for (Node usage : input.usages()) {
if (usage instanceof ProxyNode && ((ProxyNode) usage).proxyPoint() == insertionPoint) {
assert proxyUsage == null : "can have only one proxy";
proxyUsage = (ProxyNode) usage;
} else if (!(usage instanceof FrameState)) {
otherUsages = true;
}
}
assert proxyUsage == null || otherUsages == false : "cannot have other usages when having a proxy usage";
ValueNode assertInput = proxyUsage != null ? proxyUsage : input;
/*
* Replace the object at usages. We do not process usages at the frame state because it
* could be the stateAfter() of the insertion point. Since frame states are not doing
* anything in code, this is not a loss of assertion precision.
*/
for (Node usage : assertInput.usages().snapshot()) {
if (!(usage instanceof FrameState)) {
usage.replaceFirstInput(assertInput, assertionNode);
}
}
/*
* Set the input object of the assertion node, now that all other usages have been replaced.
*/
assertionNode.updateUsages(assertionNode.input, assertInput);
assertionNode.input = assertInput;
/* Insert assertion node in graph. */
graph.addAfterFixed(insertionPoint, assertionNode);
}
use of org.graalvm.compiler.nodes.InvokeWithExceptionNode in project graal by oracle.
the class JNIGraphKit method createStaticInvokeRetainException.
private InvokeWithExceptionNode createStaticInvokeRetainException(String name, ValueNode... args) {
ResolvedJavaMethod method = findMethod(JNIGeneratedMethodSupport.class, name, true);
int invokeBci = bci();
int exceptionEdgeBci = bci();
InvokeWithExceptionNode invoke = startInvokeWithException(method, InvokeKind.Static, getFrameState(), invokeBci, exceptionEdgeBci, args);
exceptionPart();
ExceptionObjectNode exception = exceptionObject();
retainPendingException(exception);
endInvokeWithException();
return invoke;
}
use of org.graalvm.compiler.nodes.InvokeWithExceptionNode in project graal by oracle.
the class JNIJavaCallWrapperMethod method createInvoke.
private static ValueNode createInvoke(JNIGraphKit kit, ResolvedJavaMethod invokeMethod, InvokeKind kind, FrameStateBuilder state, int bci, ValueNode... args) {
int exceptionEdgeBci = kit.bci();
InvokeWithExceptionNode invoke = kit.startInvokeWithException(invokeMethod, kind, state, bci, exceptionEdgeBci, args);
kit.exceptionPart();
ExceptionObjectNode exceptionObject = kit.exceptionObject();
kit.retainPendingException(exceptionObject);
ValueNode exceptionValue = null;
if (invoke.getStackKind() != JavaKind.Void) {
exceptionValue = kit.unique(ConstantNode.defaultForKind(invoke.getStackKind()));
}
AbstractMergeNode merge = kit.endInvokeWithException();
ValueNode returnValue = null;
JavaKind returnKind = invokeMethod.getSignature().getReturnKind();
if (invoke.getStackKind() != JavaKind.Void) {
ValueNode[] inputs = { invoke, exceptionValue };
returnValue = kit.getGraph().addWithoutUnique(new ValuePhiNode(invoke.stamp(NodeView.DEFAULT), merge, inputs));
state.push(returnKind, returnValue);
}
merge.setStateAfter(state.create(bci, merge));
if (invoke.getStackKind() != JavaKind.Void) {
state.pop(returnKind);
}
return returnValue;
}
use of org.graalvm.compiler.nodes.InvokeWithExceptionNode in project graal by oracle.
the class JNINativeCallWrapperMethod 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();
InvokeWithExceptionNode handleFrame = kit.nativeCallPrologue();
ValueNode callAddress = kit.nativeCallAddress(kit.createObject(linkage));
ValueNode environment = kit.environment();
JavaType javaReturnType = method.getSignature().getReturnType(null);
JavaType[] javaArgumentTypes = method.toParameterTypes();
List<ValueNode> javaArguments = kit.loadArguments(javaArgumentTypes);
List<ValueNode> jniArguments = new ArrayList<>(2 + javaArguments.size());
List<JavaType> jniArgumentTypes = new ArrayList<>(jniArguments.size());
JavaType environmentType = providers.getMetaAccess().lookupJavaType(JNIEnvironment.class);
JavaType objectHandleType = providers.getMetaAccess().lookupJavaType(JNIObjectHandle.class);
jniArguments.add(environment);
jniArgumentTypes.add(environmentType);
if (method.isStatic()) {
JavaConstant clazz = providers.getConstantReflection().asJavaClass(method.getDeclaringClass());
ConstantNode clazzNode = ConstantNode.forConstant(clazz, providers.getMetaAccess(), graph);
ValueNode box = kit.boxObjectInLocalHandle(clazzNode);
jniArguments.add(box);
jniArgumentTypes.add(objectHandleType);
}
for (int i = 0; i < javaArguments.size(); i++) {
ValueNode arg = javaArguments.get(i);
JavaType argType = javaArgumentTypes[i];
if (javaArgumentTypes[i].getJavaKind().isObject()) {
ValueNode obj = javaArguments.get(i);
arg = kit.boxObjectInLocalHandle(obj);
argType = objectHandleType;
}
jniArguments.add(arg);
jniArgumentTypes.add(argType);
}
assert jniArguments.size() == jniArgumentTypes.size();
JavaType jniReturnType = javaReturnType;
if (jniReturnType.getJavaKind().isObject()) {
jniReturnType = objectHandleType;
}
if (getOriginal().isSynchronized()) {
ValueNode monitorObject;
if (method.isStatic()) {
Constant hubConstant = providers.getConstantReflection().asObjectHub(method.getDeclaringClass());
DynamicHub hub = (DynamicHub) SubstrateObjectConstant.asObject(hubConstant);
monitorObject = ConstantNode.forConstant(SubstrateObjectConstant.forObject(hub), providers.getMetaAccess(), graph);
} else {
monitorObject = javaArguments.get(0);
}
MonitorIdNode monitorId = graph.add(new MonitorIdNode(kit.getFrameState().lockDepth(false)));
MonitorEnterNode monitorEnter = kit.append(new MonitorEnterNode(monitorObject, monitorId));
kit.getFrameState().pushLock(monitorEnter.object(), monitorEnter.getMonitorId());
monitorEnter.setStateAfter(kit.getFrameState().create(kit.bci(), monitorEnter));
}
kit.getFrameState().clearLocals();
Signature jniSignature = new JNISignature(jniArgumentTypes, jniReturnType);
ValueNode returnValue = kit.createCFunctionCall(callAddress, method, jniArguments, jniSignature, true, false);
if (getOriginal().isSynchronized()) {
MonitorIdNode monitorId = kit.getFrameState().peekMonitorId();
ValueNode monitorObject = kit.getFrameState().popLock();
MonitorExitNode monitorExit = kit.append(new MonitorExitNode(monitorObject, monitorId, null));
monitorExit.setStateAfter(kit.getFrameState().create(kit.bci(), monitorExit));
}
if (javaReturnType.getJavaKind().isObject()) {
// before destroying handles in epilogue
returnValue = kit.unboxHandle(returnValue);
}
kit.nativeCallEpilogue(handleFrame);
kit.rethrowPendingException();
if (javaReturnType.getJavaKind().isObject()) {
// Just before return to always run the epilogue and never suppress a pending exception
returnValue = castObject(kit, returnValue, (ResolvedJavaType) javaReturnType);
}
kit.createReturn(returnValue, javaReturnType.getJavaKind());
kit.mergeUnwinds();
assert graph.verify();
return graph;
}
use of org.graalvm.compiler.nodes.InvokeWithExceptionNode 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;
}
}
Aggregations