Search in sources :

Example 6 with FixedGuardNode

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

the class HotSpotGraphBuilderPlugins method registerClassPlugins.

private static void registerClassPlugins(Plugins plugins, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins.getInvocationPlugins(), Class.class, bytecodeProvider);
    r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getModifiers", Receiver.class);
    r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isInterface", Receiver.class);
    r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isArray", Receiver.class);
    r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isPrimitive", Receiver.class);
    r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getSuperclass", Receiver.class);
    if (config.getFieldOffset("ArrayKlass::_component_mirror", Integer.class, "oop", Integer.MAX_VALUE) != Integer.MAX_VALUE) {
        r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getComponentType", Receiver.class);
    }
    r.register2("cast", Receiver.class, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode javaClass = receiver.get();
            LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), javaClass, object, true));
            if (condition.isTautology()) {
                b.addPush(JavaKind.Object, object);
            } else {
                FixedGuardNode fixedGuard = b.add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
                b.addPush(JavaKind.Object, DynamicPiNode.create(b.getAssumptions(), b.getConstantReflection(), object, fixedGuard, javaClass));
            }
            return true;
        }

        @Override
        public boolean inlineOnly() {
            return true;
        }
    });
}
Also used : BigInteger(java.math.BigInteger) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) 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) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 7 with FixedGuardNode

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

the class MethodHandleNode method maybeCastArgument.

/**
 * Inserts a node to cast the argument at index to the given type if the given type is more
 * concrete than the argument type.
 *
 * @param adder
 * @param index of the argument to be cast
 * @param type the type the argument should be cast to
 */
private static void maybeCastArgument(GraphAdder adder, ValueNode[] arguments, int index, JavaType type) {
    ValueNode argument = arguments[index];
    if (type instanceof ResolvedJavaType && !((ResolvedJavaType) type).isJavaLangObject()) {
        Assumptions assumptions = adder.getAssumptions();
        TypeReference targetType = TypeReference.create(assumptions, (ResolvedJavaType) type);
        /*
             * When an argument is a Word type, we can have a mismatch of primitive/object types
             * here. Not inserting a PiNode is a safe fallback, and Word types need no additional
             * type information anyway.
             */
        if (targetType != null && !targetType.getType().isPrimitive() && !argument.getStackKind().isPrimitive()) {
            ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp(NodeView.DEFAULT));
            if (argumentType == null || (argumentType.isAssignableFrom(targetType.getType()) && !argumentType.equals(targetType.getType()))) {
                LogicNode inst = InstanceOfNode.createAllowNull(targetType, argument, null, null);
                assert !inst.isAlive();
                if (!inst.isTautology()) {
                    inst = adder.add(inst);
                    AnchoringNode guardAnchor = adder.getGuardAnchor();
                    DeoptimizationReason reason = DeoptimizationReason.ClassCastException;
                    DeoptimizationAction action = DeoptimizationAction.InvalidateRecompile;
                    JavaConstant speculation = JavaConstant.NULL_POINTER;
                    GuardingNode guard;
                    if (guardAnchor == null) {
                        FixedGuardNode fixedGuard = adder.add(new FixedGuardNode(inst, reason, action, speculation, false));
                        guard = fixedGuard;
                    } else {
                        GuardNode newGuard = adder.add(new GuardNode(inst, guardAnchor, reason, action, false, speculation));
                        adder.add(new ValueAnchorNode(newGuard));
                        guard = newGuard;
                    }
                    ValueNode valueNode = adder.add(PiNode.create(argument, StampFactory.object(targetType), guard.asNode()));
                    arguments[index] = valueNode;
                }
            }
        }
    }
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) AnchoringNode(org.graalvm.compiler.nodes.extended.AnchoringNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Assumptions(jdk.vm.ci.meta.Assumptions) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 8 with FixedGuardNode

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

the class BytecodeParser method handleUnresolvedCheckCast.

/**
 * @param type the unresolved type of the type check
 * @param object the object value whose type is being checked against {@code type}
 */
protected void handleUnresolvedCheckCast(JavaType type, ValueNode object) {
    assert !graphBuilderConfig.unresolvedIsError();
    append(new FixedGuardNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), Unresolved, InvalidateRecompile));
    frameState.push(JavaKind.Object, appendConstant(JavaConstant.NULL_POINTER));
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode)

Example 9 with FixedGuardNode

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

the class BytecodeParser method tryInvocationPlugin.

@SuppressWarnings("try")
protected boolean tryInvocationPlugin(InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType, JavaType returnType) {
    InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod);
    if (plugin != null) {
        if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
            // method should be called.
            assert !targetMethod.hasBytecodes() : "TODO: when does this happen?";
            return false;
        }
        InvocationPluginReceiver pluginReceiver = invocationPluginReceiver.init(targetMethod, args);
        IntrinsicGuard intrinsicGuard = null;
        if (invokeKind.isIndirect()) {
            intrinsicGuard = guardIntrinsic(args, targetMethod, pluginReceiver);
            if (intrinsicGuard == null) {
                return false;
            } else if (intrinsicGuard.nonIntrinsicBranch == null) {
                assert lastInstr instanceof FixedGuardNode;
            }
        }
        InvocationPluginAssertions assertions = Assertions.assertionsEnabled() ? new InvocationPluginAssertions(plugin, args, targetMethod, resultType) : null;
        try (DebugCloseable context = openNodeContext(targetMethod)) {
            if (plugin.execute(this, targetMethod, pluginReceiver, args)) {
                afterInvocationPluginExecution(true, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
                return true;
            } else {
                afterInvocationPluginExecution(false, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
            }
        }
    }
    return false;
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 10 with FixedGuardNode

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

the class BytecodeParser method emitCheckForInvokeSuperSpecial.

/**
 * Checks that the class of the receiver of an {@link Bytecodes#INVOKESPECIAL} in a method
 * declared in an interface (i.e., a default method) is assignable to the interface. If not,
 * then deoptimize so that the interpreter can throw an {@link IllegalAccessError}.
 *
 * This is a check not performed by the verifier and so must be performed at runtime.
 *
 * @param args arguments to an {@link Bytecodes#INVOKESPECIAL} implementing a direct call to a
 *            method in a super class
 */
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) {
    ResolvedJavaType callingClass = method.getDeclaringClass();
    if (callingClass.getHostClass() != null) {
        callingClass = callingClass.getHostClass();
    }
    if (callingClass.isInterface()) {
        ValueNode receiver = args[0];
        TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), callingClass);
        LogicNode condition = genUnique(createInstanceOf(checkedType, receiver, null));
        FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, ClassCastException, None, false));
        args[0] = append(PiNode.create(receiver, StampFactory.object(checkedType, true), fixedGuard));
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)31 LogicNode (org.graalvm.compiler.nodes.LogicNode)25 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)10 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)8 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)8 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)8 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)7 Stamp (org.graalvm.compiler.core.common.type.Stamp)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)5 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)4 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)4 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)4 FixedNode (org.graalvm.compiler.nodes.FixedNode)4 IfNode (org.graalvm.compiler.nodes.IfNode)4 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)4 PiNode (org.graalvm.compiler.nodes.PiNode)4 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)4