Search in sources :

Example 31 with Receiver

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver 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 32 with Receiver

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver 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 33 with Receiver

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver 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 34 with Receiver

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

the class VMThreadMTFeature method registerAccessors.

private void registerAccessors(Registration r, Class<?> valueClass, boolean isVolatile) {
    String suffix = isVolatile ? "Volatile" : "";
    /* get() method without the VMThread parameter. */
    r.register1("get" + suffix, Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode threadNode = currentThread(b, false);
            return handleGet(b, targetMethod, receiver, threadNode, isVolatile);
        }
    });
    /* get() method with the VMThread parameter. */
    r.register2("get" + suffix, Receiver.class, IsolateThread.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode) {
            return handleGet(b, targetMethod, receiver, threadNode, isVolatile);
        }
    });
    /* set() method without the VMThread parameter. */
    r.register2("set" + suffix, Receiver.class, valueClass, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode valueNode) {
            ValueNode threadNode = currentThread(b, false);
            return handleSet(b, receiver, threadNode, valueNode, isVolatile);
        }
    });
    /* set() method with the VMThread parameter. */
    r.register3("set" + suffix, Receiver.class, IsolateThread.class, valueClass, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode, ValueNode valueNode) {
            return handleSet(b, receiver, threadNode, valueNode, isVolatile);
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 35 with Receiver

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

the class VMThreadSTFeature method registerInvocationPlugins.

/**
 * Intrinsify the {@code get()} and {@code set()} methods during bytecode parsing. We know that
 * every subclass of VMThreadLocal has the same methods. Only the signatures differ based on the
 * type of value.
 * <p>
 * The value is stored in the two arrays that are in the image heap: a Object[] array for thread
 * local object variables, and a byte[] array for all thread local primitive variables.
 * Therefore, we need the proper read/write barriers. The {@link IsolateThread} parameter is
 * ignored.
 */
@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, InvocationPlugins invocationPlugins, boolean hosted) {
    for (Class<? extends FastThreadLocal> threadLocalClass : VMThreadLocalInfo.THREAD_LOCAL_CLASSES) {
        Registration r = new Registration(invocationPlugins, threadLocalClass);
        Class<?> valueClass = VMThreadLocalInfo.getValueClass(threadLocalClass);
        registerAccessors(r, valueClass, false);
        registerAccessors(r, valueClass, true);
        /* compareAndSet() method without the VMThread parameter. */
        r.register3("compareAndSet", Receiver.class, valueClass, valueClass, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode expect, ValueNode update) {
                return handleCompareAndSet(b, targetMethod, receiver, expect, update);
            }
        });
        /* get() method with the VMThread parameter. */
        r.register4("compareAndSet", Receiver.class, IsolateThread.class, valueClass, valueClass, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode, ValueNode expect, ValueNode update) {
                return handleCompareAndSet(b, targetMethod, receiver, expect, update);
            }
        });
    }
    Class<?>[] typesWithGetAddress = new Class<?>[] { FastThreadLocalBytes.class, FastThreadLocalWord.class };
    for (Class<?> type : typesWithGetAddress) {
        Registration r = new Registration(invocationPlugins, type);
        /* getAddress() method without the VMThread parameter. */
        r.register1("getAddress", Receiver.class, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
                return handleGetAddress(b, targetMethod, receiver);
            }
        });
        /* getAddress() method with the VMThread parameter. */
        r.register2("getAddress", Receiver.class, IsolateThread.class, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode) {
                return handleGetAddress(b, targetMethod, receiver);
            }
        });
    }
}
Also used : Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) FastThreadLocalWord(com.oracle.svm.core.threadlocal.FastThreadLocalWord) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) FastThreadLocalBytes(com.oracle.svm.core.threadlocal.FastThreadLocalBytes) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)57 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)57 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)57 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 ValueNode (org.graalvm.compiler.nodes.ValueNode)52 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)52 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)13 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)13 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 LogicNode (org.graalvm.compiler.nodes.LogicNode)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 JavaConstant (jdk.vm.ci.meta.JavaConstant)5 JavaKind (jdk.vm.ci.meta.JavaKind)5 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)3 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)3 BlackholeNode (org.graalvm.compiler.nodes.debug.BlackholeNode)3