Search in sources :

Example 86 with InvocationPlugin

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

the class PEGraphDecoderTest method registerPlugins.

private static void registerPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, PEGraphDecoderTest.class);
    r.register2("readInt", Object.class, long.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode obj, ValueNode offset) {
            AddressNode address = b.add(new OffsetAddressNode(obj, offset));
            ReadNode read = b.addPush(JavaKind.Int, new ReadNode(address, LocationIdentity.any(), StampFactory.forKind(JavaKind.Int), BarrierType.NONE));
            read.setGuard(AbstractBeginNode.prevBegin(read));
            return true;
        }
    });
}
Also used : OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) 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) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 87 with InvocationPlugin

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

the class PointerTrackingTest method register.

private void register(Registration r, String fnName) {
    ResolvedJavaMethod intrinsic = getResolvedJavaMethod(fnName + "Intrinsic");
    BytecodeProvider bytecodeProvider = getSystemClassLoaderBytecodeProvider();
    r.register1(fnName, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) {
            return b.intrinsify(bytecodeProvider, targetMethod, intrinsic, receiver, new ValueNode[] { arg });
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) BytecodeProvider(org.graalvm.compiler.bytecode.BytecodeProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 88 with InvocationPlugin

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

the class AMD64GraphBuilderPlugins method registerUnsafePlugins.

private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider) {
    Registration r;
    if (Java8OrEarlier) {
        r = new Registration(plugins, Unsafe.class);
    } else {
        r = new Registration(plugins, "jdk.internal.misc.Unsafe", replacementsBytecodeProvider);
    }
    for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long, JavaKind.Object }) {
        Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
        r.register4("getAndSet" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) {
                // Emits a null-check for the otherwise unused receiver
                unsafe.get();
                b.addPush(kind, new AtomicReadAndWriteNode(object, offset, value, kind, LocationIdentity.any()));
                b.getGraph().markUnsafeAccess();
                return true;
            }
        });
        if (kind != JavaKind.Object) {
            r.register4("getAndAdd" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode delta) {
                    // Emits a null-check for the otherwise unused receiver
                    unsafe.get();
                    AddressNode address = b.add(new OffsetAddressNode(object, offset));
                    b.addPush(kind, new AtomicReadAndAddNode(address, delta, LocationIdentity.any()));
                    b.getGraph().markUnsafeAccess();
                    return true;
                }
            });
        }
    }
    for (JavaKind kind : new JavaKind[] { JavaKind.Char, JavaKind.Short, JavaKind.Int, JavaKind.Long }) {
        Class<?> javaClass = kind.toJavaClass();
        r.registerOptional3("get" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, false));
        r.registerOptional4("put" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, false));
    }
}
Also used : Unsafe(sun.misc.Unsafe) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) UnsafePutPlugin(org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.UnsafePutPlugin) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) 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) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind) AtomicReadAndAddNode(org.graalvm.compiler.nodes.java.AtomicReadAndAddNode) UnsafeGetPlugin(org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.UnsafeGetPlugin)

Example 89 with InvocationPlugin

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

the class ClassCastBytecodeExceptionTest method registerInvocationPlugins.

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
    invocationPlugins.register(new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode obj, ValueNode classNode) {
            ResolvedJavaType type = b.getConstantReflection().asJavaType(classNode.asConstant());
            Constant hub = b.getConstantReflection().asObjectHub(type);
            Stamp hubStamp = b.getStampProvider().createHubStamp(StampFactory.object(TypeReference.createExactTrusted(type)));
            ConstantNode hubConst = b.add(ConstantNode.forConstant(hubStamp, hub, b.getMetaAccess()));
            return throwBytecodeException(b, ClassCastException.class, obj, hubConst);
        }
    }, Exceptions.class, "throwClassCast", Object.class, Class.class);
    super.registerInvocationPlugins(invocationPlugins);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Constant(jdk.vm.ci.meta.Constant) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 90 with InvocationPlugin

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

the class AArch64GraphBuilderPlugins method registerMathPlugins.

private static void registerMathPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Math.class);
    registerUnaryMath(r, "sin", SIN);
    registerUnaryMath(r, "cos", COS);
    registerUnaryMath(r, "tan", TAN);
    registerUnaryMath(r, "exp", EXP);
    registerUnaryMath(r, "log", LOG);
    registerUnaryMath(r, "log10", LOG10);
    r.register2("pow", Double.TYPE, Double.TYPE, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
            b.push(JavaKind.Double, b.append(BinaryMathIntrinsicNode.create(x, y, BinaryMathIntrinsicNode.BinaryOperation.POW)));
            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) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)89 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)83 ValueNode (org.graalvm.compiler.nodes.ValueNode)74 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)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 JavaKind (jdk.vm.ci.meta.JavaKind)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)5 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)3