Search in sources :

Example 41 with GraphBuilderContext

use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerJFREventTokenPlugins.

private static void registerJFREventTokenPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, "com.oracle.jrockit.jfr.EventToken", bytecodeProvider);
    r.register1("isEnabled", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            receiver.get();
            b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 42 with GraphBuilderContext

use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerArraysPlugins.

private static void registerArraysPlugins(InvocationPlugins plugins, boolean analysis) {
    Registration r = new Registration(plugins, Arrays.class).setAllowOverwrite(true);
    r.register2("copyOf", Object[].class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength) {
            if (analysis) {
                b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength));
            } else {
                /* Get the class from the original node. */
                GetClassNode originalArrayType = b.add(new GetClassNode(original.stamp(NodeView.DEFAULT), b.nullCheckedValue(original)));
                ValueNode originalLength = b.add(ArrayLengthNode.create(original, b.getConstantReflection()));
                Stamp stamp = b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp().join(original.stamp(NodeView.DEFAULT));
                b.addPush(JavaKind.Object, new SubstrateArraysCopyOfNode(stamp, original, originalLength, newLength, originalArrayType));
            }
            return true;
        }
    });
    r.register3("copyOf", Object[].class, int.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode original, ValueNode newLength, ValueNode newArrayType) {
            if (analysis) {
                /*
                     * If the new array type comes from a GetClassNode or is a constant we can infer
                     * the concrete type of the new array, otherwise we conservatively assume that
                     * the new array can have any of the instantiated array types.
                     */
                b.addPush(JavaKind.Object, new AnalysisArraysCopyOfNode(b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp(), original, newLength, newArrayType));
            } else {
                Stamp stamp;
                if (newArrayType.isConstant()) {
                    ResolvedJavaType newType = b.getConstantReflection().asJavaType(newArrayType.asConstant());
                    stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(newType));
                } else {
                    stamp = b.getInvokeReturnStamp(b.getAssumptions()).getTrustedStamp();
                }
                ValueNode originalLength = b.add(ArrayLengthNode.create(original, b.getConstantReflection()));
                b.addPush(JavaKind.Object, new SubstrateArraysCopyOfNode(stamp, original, originalLength, newLength, newArrayType));
            }
            return true;
        }
    });
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) SubstrateArraysCopyOfNode(com.oracle.svm.core.graal.jdk.SubstrateArraysCopyOfNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) AnalysisArraysCopyOfNode(com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Arrays(java.util.Arrays) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 43 with GraphBuilderContext

use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerPinnedAllocatorPlugins.

private static void registerPinnedAllocatorPlugins(ConstantReflectionProvider constantReflection, InvocationPlugins plugins) {
    Registration r = new Registration(plugins, PinnedAllocator.class);
    r.register2("newInstance", Receiver.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver pinnedAllocator, ValueNode instanceClassNode) {
            ResolvedJavaType instanceClass = typeValue(constantReflection, b, targetMethod, instanceClassNode, "instanceClass");
            ValueNode pinnedAllocatorNode = pinnedAllocator.get();
            b.addPush(JavaKind.Object, new NewPinnedInstanceNode(instanceClass, pinnedAllocatorNode));
            return true;
        }
    });
    r.register3("newArray", Receiver.class, Class.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver pinnedAllocator, ValueNode componentTypeNode, ValueNode length) {
            ResolvedJavaType componentType = typeValue(constantReflection, b, targetMethod, componentTypeNode, "componentType");
            ValueNode pinnedAllocatorNode = pinnedAllocator.get();
            b.addPush(JavaKind.Object, new NewPinnedArrayNode(componentType, length, pinnedAllocatorNode));
            return true;
        }
    });
}
Also used : NewPinnedInstanceNode(com.oracle.svm.core.graal.nodes.NewPinnedInstanceNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) NewPinnedArrayNode(com.oracle.svm.core.graal.nodes.NewPinnedArrayNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 44 with GraphBuilderContext

use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerSizeOfPlugins.

private static void registerSizeOfPlugins(SnippetReflectionProvider snippetReflection, InvocationPlugins plugins) {
    Registration r = new Registration(plugins, SizeOf.class);
    r.register1("get", Class.class, new InvocationPlugin() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
            Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
            int result = SizeOf.get(clazz);
            b.notifyReplacedCall(targetMethod, b.addPush(JavaKind.Int, ConstantNode.forInt(result)));
            return true;
        }
    });
    r.register1("unsigned", Class.class, new InvocationPlugin() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
            Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
            UnsignedWord result = SizeOf.unsigned(clazz);
            b.notifyReplacedCall(targetMethod, b.addPush(JavaKind.Object, ConstantNode.forConstant(snippetReflection.forObject(result), b.getMetaAccess())));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) UnsignedWord(org.graalvm.word.UnsignedWord) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) PointerBase(org.graalvm.word.PointerBase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 45 with GraphBuilderContext

use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext in project graal by oracle.

the class CInterfaceInvocationPlugin method replaceFunctionPointerInvoke.

private boolean replaceFunctionPointerInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, CallingConvention.Type callType) {
    if (!functionPointerType.isAssignableFrom(method.getDeclaringClass())) {
        throw UserError.abort(new CInterfaceError("function pointer invocation method " + method.format("%H.%n(%p)") + " must be in a type that extends " + CFunctionPointer.class.getSimpleName(), method).getMessage());
    }
    assert b.getInvokeKind() == InvokeKind.Interface;
    JavaType[] parameterTypes = method.getSignature().toParameterTypes(null);
    if (callType == SubstrateCallingConventionType.NativeCall) {
        Predicate<JavaType> isValid = t -> t.getJavaKind().isPrimitive() || wordTypes.isWord(t);
        UserError.guarantee(Stream.of(parameterTypes).allMatch(isValid) && isValid.test(method.getSignature().getReturnType(null)), "C function pointer invocation method must have only primitive types or word types for its parameters and return value: " + method.format("%H.%n(%p)"));
    /*
             * We currently do not support automatic conversions for @CEnum because it entails
             * introducing additional invokes without real BCIs in a BytecodeParser context, which
             * does not work too well.
             */
    }
    // We "discard" the receiver from the signature by pretending we are a static method
    assert args.length >= 1;
    ValueNode methodAddress = args[0];
    ValueNode[] argsWithoutReceiver = Arrays.copyOfRange(args, 1, args.length);
    assert argsWithoutReceiver.length == parameterTypes.length;
    Stamp returnStamp;
    if (wordTypes.isWord(b.getInvokeReturnType())) {
        returnStamp = wordTypes.getWordStamp((ResolvedJavaType) b.getInvokeReturnType());
    } else {
        returnStamp = b.getInvokeReturnStamp(null).getTrustedStamp();
    }
    CallTargetNode indirectCallTargetNode = b.add(new IndirectCallTargetNode(methodAddress, argsWithoutReceiver, StampPair.createSingle(returnStamp), parameterTypes, method, callType, InvokeKind.Static));
    if (callType == SubstrateCallingConventionType.JavaCall) {
        b.handleReplacedInvoke(indirectCallTargetNode, b.getInvokeReturnType().getJavaKind());
    } else if (callType == SubstrateCallingConventionType.NativeCall) {
        // Native code cannot throw exceptions, omit exception edge
        InvokeNode invokeNode = new InvokeNode(indirectCallTargetNode, b.bci());
        if (pushKind(method) != JavaKind.Void) {
            b.addPush(pushKind(method), invokeNode);
        } else {
            b.add(invokeNode);
        }
    } else {
        throw shouldNotReachHere("Unsupported type of call: " + callType);
    }
    return true;
}
Also used : Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) LocationIdentity(org.graalvm.word.LocationIdentity) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) WordTypes(org.graalvm.compiler.word.WordTypes) AccessorInfo(com.oracle.svm.hosted.c.info.AccessorInfo) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) JavaKind(jdk.vm.ci.meta.JavaKind) AndNode(org.graalvm.compiler.nodes.calc.AndNode) InvokeJavaFunctionPointer(com.oracle.svm.core.annotate.InvokeJavaFunctionPointer) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) UserError(com.oracle.svm.core.util.UserError) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) SizableInfo(com.oracle.svm.hosted.c.info.SizableInfo) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) Predicate(java.util.function.Predicate) OrNode(org.graalvm.compiler.nodes.calc.OrNode) FrameAccess(com.oracle.svm.core.amd64.FrameAccess) CInterfaceWriteNode(com.oracle.svm.core.graal.nodes.CInterfaceWriteNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) Stream(java.util.stream.Stream) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) StructInfo(com.oracle.svm.hosted.c.info.StructInfo) MulNode(org.graalvm.compiler.nodes.calc.MulNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) BytecodeParser(org.graalvm.compiler.java.BytecodeParser) ConstantInfo(com.oracle.svm.hosted.c.info.ConstantInfo) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) AddNode(org.graalvm.compiler.nodes.calc.AddNode) VMError.shouldNotReachHere(com.oracle.svm.core.util.VMError.shouldNotReachHere) EnumValueInfo(com.oracle.svm.hosted.c.info.EnumValueInfo) CInterfaceLocationIdentity(com.oracle.svm.core.c.struct.CInterfaceLocationIdentity) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) EnumLookupInfo(com.oracle.svm.hosted.c.info.EnumLookupInfo) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) PointerToInfo(com.oracle.svm.hosted.c.info.PointerToInfo) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType) CInterfaceReadNode(com.oracle.svm.core.graal.nodes.CInterfaceReadNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) AccessorKind(com.oracle.svm.hosted.c.info.AccessorInfo.AccessorKind) StampPair(org.graalvm.compiler.core.common.type.StampPair) SubstrateCallingConventionType(com.oracle.svm.core.graal.code.amd64.SubstrateCallingConventionType) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CallingConvention(jdk.vm.ci.code.CallingConvention) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode)

Aggregations

GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)88 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)86 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)83 ValueNode (org.graalvm.compiler.nodes.ValueNode)76 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)13 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)13 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)10 LogicNode (org.graalvm.compiler.nodes.LogicNode)10 JavaKind (jdk.vm.ci.meta.JavaKind)9 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)8 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)6 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 Stamp (org.graalvm.compiler.core.common.type.Stamp)4 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)4