Search in sources :

Example 6 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class SnippetTemplate method bind.

/**
 * Gets the instantiation-time bindings to this template's parameters.
 *
 * @return the map that will be used to bind arguments to parameters when inlining this template
 */
private EconomicMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider metaAccess, Arguments args) {
    EconomicMap<Node, Node> replacements = EconomicMap.create(Equivalence.IDENTITY);
    assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")";
    for (int i = 0; i < parameters.length; i++) {
        Object parameter = parameters[i];
        assert parameter != null : this + " has no parameter named " + args.info.getParameterName(i);
        Object argument = args.values[i];
        if (parameter instanceof ParameterNode) {
            if (argument instanceof ValueNode) {
                replacements.put((ParameterNode) parameter, (ValueNode) argument);
            } else {
                JavaKind kind = ((ParameterNode) parameter).getStackKind();
                assert argument != null || kind == JavaKind.Object : this + " cannot accept null for non-object parameter named " + args.info.getParameterName(i);
                JavaConstant constant = forBoxed(argument, kind);
                replacements.put((ParameterNode) parameter, ConstantNode.forConstant(constant, metaAccess, replaceeGraph));
            }
        } else if (parameter instanceof ParameterNode[]) {
            ParameterNode[] params = (ParameterNode[]) parameter;
            Varargs varargs = (Varargs) argument;
            int length = params.length;
            List<?> list = null;
            Object array = null;
            if (varargs.value instanceof List) {
                list = (List<?>) varargs.value;
                assert list.size() == length : length + " != " + list.size();
            } else {
                array = varargs.value;
                assert array != null && array.getClass().isArray();
                assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
            }
            for (int j = 0; j < length; j++) {
                ParameterNode param = params[j];
                assert param != null;
                Object value = list != null ? list.get(j) : Array.get(array, j);
                if (value instanceof ValueNode) {
                    replacements.put(param, (ValueNode) value);
                } else {
                    JavaConstant constant = forBoxed(value, param.getStackKind());
                    ConstantNode element = ConstantNode.forConstant(constant, metaAccess, replaceeGraph);
                    replacements.put(param, element);
                }
            }
        } else {
            assert parameter.equals(CONSTANT_PARAMETER) || parameter.equals(UNUSED_PARAMETER) : "unexpected entry for parameter: " + args.info.getParameterName(i) + " -> " + parameter;
        }
    }
    return replacements;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ArrayList(java.util.ArrayList) List(java.util.List) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 7 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class StandardGraphBuilderPlugins method registerStringPlugins.

private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) {
    final Registration r = new Registration(plugins, String.class, bytecodeProvider);
    r.register1("hashCode", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant()) {
                String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
                b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
                return true;
            }
            return false;
        }
    });
    if (Java8OrEarlier) {
        r.registerMethodSubstitution(StringSubstitutions.class, "equals", Receiver.class, Object.class);
        r.register7("indexOf", char[].class, int.class, int.class, char[].class, int.class, int.class, int.class, new StringIndexOfConstantPlugin());
        Registration sr = new Registration(plugins, StringSubstitutions.class);
        sr.register1("getValue", String.class, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                ResolvedJavaField field = b.getMetaAccess().lookupJavaField(STRING_VALUE_FIELD);
                b.addPush(JavaKind.Object, LoadFieldNode.create(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), b.getAssumptions(), value, field, false, false));
                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) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 8 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant 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 9 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class PartialEvaluator method getDecision.

private static TruffleInliningPlan.Decision getDecision(TruffleInliningPlan inlining, JavaConstant callNode) {
    TruffleInliningPlan.Decision decision = inlining.findDecision(callNode);
    if (decision == null) {
        JavaConstant target = getRuntime().getCallTargetForCallNode(callNode);
        PerformanceInformationHandler.reportDecisionIsNull(target, callNode);
    } else if (!decision.isTargetStable()) {
        JavaConstant target = getRuntime().getCallTargetForCallNode(callNode);
        PerformanceInformationHandler.reportCallTargetChanged(target, callNode, decision);
        return null;
    }
    return decision;
}
Also used : TruffleInliningPlan(org.graalvm.compiler.truffle.common.TruffleInliningPlan) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 10 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class ArrayEqualsNode method arrayEquals.

private static boolean arrayEquals(ConstantReflectionProvider constantReflection, JavaConstant a, JavaConstant b, int len) {
    for (int i = 0; i < len; i++) {
        JavaConstant aElem = constantReflection.readArrayElement(a, i);
        JavaConstant bElem = constantReflection.readArrayElement(b, i);
        if (!constantReflection.constantEquals(aElem, bElem) && !(isNaNFloat(aElem) && isNaNFloat(bElem))) {
            return false;
        }
    }
    return true;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5