Search in sources :

Example 31 with GraphBuilderContext

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

the class VMThreadMTFeature 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>
 * When the {@link IsolateThread} is not passed in as a parameter, we use the
 * {@link LoadVMThreadLocalNode current thread}. We do not need read/write barriers since we
 * access memory that we manage ourselfs.
 */
@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) {
                ValueNode threadNode = currentThread(b, false);
                return handleCompareAndSet(b, targetMethod, receiver, threadNode, 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, threadNode, 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) {
                ValueNode threadNode = currentThread(b, true);
                return handleGetAddress(b, targetMethod, receiver, threadNode);
            }
        });
        /* 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, threadNode);
            }
        });
    }
}
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)

Example 32 with GraphBuilderContext

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

the class IntrinsifyMethodHandlesInvocationPlugin method registerInvocationPlugins.

private static void registerInvocationPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, "java.lang.invoke.DirectMethodHandle", bytecodeProvider);
    r.register1("ensureInitialized", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            /*
                 * Method handles for static methods have a guard that initializes the class (if the
                 * class was not yet initialized when the method handle was created). We initialize
                 * the class during static analysis anyway, so we can just do nothing.
                 */
            return true;
        }
    });
    r = new Registration(plugins, "java.lang.invoke.Invokers", bytecodeProvider);
    r.registerOptional1("maybeCustomize", MethodHandle.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode mh) {
            /*
                 * JDK 8 update 60 added an additional customization possibility for method handles.
                 * For all use cases that we care about, that seems to be unnecessary, so we can
                 * just do nothing.
                 */
            return true;
        }
    });
}
Also used : 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) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 33 with GraphBuilderContext

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

the class VMThreadSTFeature method registerAccessors.

private void registerAccessors(Registration r, Class<?> valueClass, boolean isVolatile) {
    /*
         * Volatile accesses do not need memory barriers in single-threaded mode, i.e., we register
         * the same plugin for normal and volatile accesses.
         */
    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) {
            return handleGet(b, targetMethod, receiver);
        }
    });
    /* 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);
        }
    });
    /* 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) {
            return handleSet(b, receiver, valueNode);
        }
    });
    /* 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, valueNode);
        }
    });
}
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 34 with GraphBuilderContext

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

the class DataPatchTest method registerInvocationPlugins.

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
    Registration r = new Registration(invocationPlugins, DataPatchTest.class);
    r.register1("compressUncompress", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) {
            CompressEncoding encoding = runtime().getVMConfig().getOopEncoding();
            ValueNode compressed = b.add(HotSpotCompressionNode.compress(arg, encoding));
            ValueNode proxy = b.add(new OpaqueNode(compressed));
            b.addPush(JavaKind.Object, HotSpotCompressionNode.uncompress(proxy, encoding));
            return true;
        }
    });
    super.registerInvocationPlugins(invocationPlugins);
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) CompressEncoding(org.graalvm.compiler.core.common.CompressEncoding) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 35 with GraphBuilderContext

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

the class ForeignCallDeoptimizeTest method registerInvocationPlugins.

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
    ForeignCallsProvider foreignCalls = ((HotSpotProviders) getProviders()).getForeignCalls();
    invocationPlugins.register(new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) {
            ForeignCallNode node = new ForeignCallNode(foreignCalls, HotSpotForeignCallsProviderImpl.TEST_DEOPTIMIZE_CALL_INT, arg);
            b.addPush(JavaKind.Int, node);
            return true;
        }
    }, ForeignCallDeoptimizeTest.class, "testCallInt", int.class);
    super.registerInvocationPlugins(invocationPlugins);
}
Also used : ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) HotSpotProviders(org.graalvm.compiler.hotspot.meta.HotSpotProviders) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

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