Search in sources :

Example 1 with CEntryPointEnterNode

use of com.oracle.svm.core.graal.nodes.CEntryPointEnterNode 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;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CEntryPointEnterNode(com.oracle.svm.core.graal.nodes.CEntryPointEnterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 2 with CEntryPointEnterNode

use of com.oracle.svm.core.graal.nodes.CEntryPointEnterNode in project graal by oracle.

the class JNIJavaCallWrapperMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    UniverseMetaAccess metaAccess = (UniverseMetaAccess) providers.getMetaAccess();
    JNIGraphKit kit = new JNIGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
    state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
    JavaKind vmThreadKind = metaAccess.lookupJavaType(JNIEnvironment.class).getJavaKind();
    ValueNode vmThread = kit.loadLocal(0, vmThreadKind);
    kit.append(new CEntryPointEnterNode(EnterAction.Enter, vmThread));
    ResolvedJavaMethod invokeMethod = providers.getMetaAccess().lookupJavaMethod(reflectMethod);
    Signature invokeSignature = invokeMethod.getSignature();
    List<Pair<ValueNode, ResolvedJavaType>> argsWithTypes = loadAndUnboxArguments(kit, providers, invokeMethod, invokeSignature);
    JavaKind returnKind = invokeSignature.getReturnKind();
    if (invokeMethod.isConstructor()) {
        // return `this` to implement NewObject
        assert returnKind == JavaKind.Void;
        returnKind = JavaKind.Object;
    }
    IfNode ifNode = kit.startIf(null, BranchProbabilityNode.FAST_PATH_PROBABILITY);
    kit.thenPart();
    LogicNode typeChecks = LogicConstantNode.tautology(kit.getGraph());
    ValueNode[] args = new ValueNode[argsWithTypes.size()];
    for (int i = 0; i < argsWithTypes.size(); i++) {
        ValueNode value = argsWithTypes.get(i).getLeft();
        ResolvedJavaType type = argsWithTypes.get(i).getRight();
        if (!type.isPrimitive() && !type.isJavaLangObject()) {
            TypeReference typeRef = TypeReference.createTrusted(kit.getAssumptions(), type);
            LogicNode instanceOf = kit.unique(InstanceOfNode.createAllowNull(typeRef, value, null, null));
            typeChecks = LogicNode.and(typeChecks, instanceOf, BranchProbabilityNode.FAST_PATH_PROBABILITY);
            FixedGuardNode guard = kit.append(new FixedGuardNode(instanceOf, DeoptimizationReason.ClassCastException, DeoptimizationAction.None, false));
            value = kit.append(PiNode.create(value, StampFactory.object(typeRef), guard));
        }
        args[i] = value;
    }
    // safe because logic nodes are floating
    ifNode.setCondition(typeChecks);
    InvokeKind kind = // 
    invokeMethod.isStatic() ? // 
    InvokeKind.Static : ((nonVirtual || invokeMethod.isConstructor()) ? InvokeKind.Special : InvokeKind.Virtual);
    ValueNode invokeResult = createInvoke(kit, invokeMethod, kind, state, kit.bci(), args);
    if (invokeMethod.isConstructor()) {
        // return `this` to implement NewObject
        invokeResult = args[0];
    }
    // illegal parameter types
    kit.elsePart();
    ConstantNode exceptionObject = kit.createObject(cachedArgumentClassCastException);
    kit.retainPendingException(exceptionObject);
    ValueNode typeMismatchValue = null;
    if (returnKind != JavaKind.Void) {
        typeMismatchValue = kit.unique(ConstantNode.defaultForKind(returnKind.getStackKind()));
    }
    AbstractMergeNode merge = kit.endIf();
    ValueNode returnValue = null;
    if (returnKind != JavaKind.Void) {
        ValueNode[] inputs = { invokeResult, typeMismatchValue };
        returnValue = kit.getGraph().addWithoutUnique(new ValuePhiNode(invokeResult.stamp(NodeView.DEFAULT), merge, inputs));
        state.push(returnKind, returnValue);
    }
    merge.setStateAfter(state.create(kit.bci(), merge));
    if (returnKind != JavaKind.Void) {
        state.pop(returnKind);
        if (returnKind.isObject()) {
            returnValue = kit.boxObjectInLocalHandle(returnValue);
        }
    }
    kit.append(new CEntryPointLeaveNode(LeaveAction.Leave));
    kit.createReturn(returnValue, returnKind);
    assert graph.verify();
    return graph;
}
Also used : UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JNIEnvironment(com.oracle.svm.jni.nativeapi.JNIEnvironment) CEntryPointEnterNode(com.oracle.svm.core.graal.nodes.CEntryPointEnterNode) Signature(jdk.vm.ci.meta.Signature) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind) Pair(org.graalvm.collections.Pair)

Example 3 with CEntryPointEnterNode

use of com.oracle.svm.core.graal.nodes.CEntryPointEnterNode in project graal by oracle.

the class JNIPrimitiveArrayOperationMethod 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 result = null;
    switch(operation) {
        case NEW:
            result = newArray(providers, kit, arguments);
            break;
        case GET_ELEMENTS:
            {
                ValueNode arrayHandle = arguments.get(1);
                ValueNode array = kit.unboxHandle(arrayHandle);
                ValueNode isCopy = arguments.get(2);
                result = kit.pinArrayAndGetAddress(array, isCopy);
                break;
            }
        case RELEASE_ELEMENTS:
            {
                ValueNode address = arguments.get(2);
                kit.unpinArrayByAddress(address);
                break;
            }
        case GET_REGION:
        case SET_REGION:
            {
                ValueNode arrayHandle = arguments.get(1);
                ValueNode array = kit.unboxHandle(arrayHandle);
                ValueNode start = arguments.get(2);
                ValueNode count = arguments.get(3);
                ValueNode buffer = arguments.get(4);
                if (operation == Operation.GET_REGION) {
                    kit.getPrimitiveArrayRegionRetainException(elementKind, array, start, count, buffer);
                } else {
                    kit.setPrimitiveArrayRegionRetainException(elementKind, array, start, count, buffer);
                }
                break;
            }
        default:
            throw VMError.shouldNotReachHere();
    }
    kit.append(new CEntryPointLeaveNode(LeaveAction.Leave));
    kit.createReturn(result, (result != null) ? result.getStackKind() : JavaKind.Void);
    assert graph.verify();
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CEntryPointEnterNode(com.oracle.svm.core.graal.nodes.CEntryPointEnterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode)

Example 4 with CEntryPointEnterNode

use of com.oracle.svm.core.graal.nodes.CEntryPointEnterNode in project graal by oracle.

the class CEntryPointSupport method registerEntryPointActionsPlugins.

private static void registerEntryPointActionsPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, CEntryPointActions.class);
    r.register1("enterCreateIsolate", CEntryPointCreateIsolateParameters.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode parameters) {
            b.addPush(JavaKind.Int, new CEntryPointEnterNode(EnterAction.CreateIsolate, parameters));
            return true;
        }
    });
    r.register1("enterAttachThread", Isolate.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
            b.addPush(JavaKind.Int, new CEntryPointEnterNode(EnterAction.AttachThread, isolate));
            return true;
        }
    });
    r.register1("enter", IsolateThread.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode thread) {
            b.addPush(JavaKind.Int, new CEntryPointEnterNode(EnterAction.Enter, thread));
            return true;
        }
    });
    r.register1("enterIsolate", Isolate.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
            b.addPush(JavaKind.Int, new CEntryPointEnterNode(EnterAction.EnterIsolate, isolate));
            return true;
        }
    });
    InvocationPlugin bailoutPlugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new CEntryPointPrologueBailoutNode(value));
            return true;
        }
    };
    r.register1("bailoutInPrologue", WordBase.class, bailoutPlugin);
    r.register1("bailoutInPrologue", long.class, bailoutPlugin);
    r.register1("bailoutInPrologue", double.class, bailoutPlugin);
    r.register1("bailoutInPrologue", boolean.class, bailoutPlugin);
    r.register0("bailoutInPrologue", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new CEntryPointPrologueBailoutNode(null));
            return true;
        }
    });
    r.register0("leave", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.Leave));
            return true;
        }
    });
    r.register0("leaveDetachThread", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.DetachThread));
            return true;
        }
    });
    r.register0("leaveTearDownIsolate", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.TearDownIsolate));
            return true;
        }
    });
    r.register2("failFatally", int.class, CCharPointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
            b.add(new CEntryPointUtilityNode(UtilityAction.FailFatally, arg1, arg2));
            return true;
        }
    });
}
Also used : CEntryPointPrologueBailoutNode(com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) CEntryPointEnterNode(com.oracle.svm.core.graal.nodes.CEntryPointEnterNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) CEntryPointUtilityNode(com.oracle.svm.core.graal.nodes.CEntryPointUtilityNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

CEntryPointEnterNode (com.oracle.svm.core.graal.nodes.CEntryPointEnterNode)4 CEntryPointLeaveNode (com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 FrameStateBuilder (org.graalvm.compiler.java.FrameStateBuilder)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 JavaKind (jdk.vm.ci.meta.JavaKind)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 UniverseMetaAccess (com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess)1 CEntryPointPrologueBailoutNode (com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode)1 CEntryPointUtilityNode (com.oracle.svm.core.graal.nodes.CEntryPointUtilityNode)1 JNIEnvironment (com.oracle.svm.jni.nativeapi.JNIEnvironment)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Signature (jdk.vm.ci.meta.Signature)1 Pair (org.graalvm.collections.Pair)1 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)1 IfNode (org.graalvm.compiler.nodes.IfNode)1