Search in sources :

Example 6 with JavaKind

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

the class SubstrateGraphKit method returnStamp.

private Stamp returnStamp(Signature signature) {
    JavaType returnType = signature.getReturnType(null);
    JavaKind returnKind = signature.getReturnKind();
    if (returnKind == JavaKind.Object && returnType instanceof ResolvedJavaType) {
        return StampFactory.object(TypeReference.createTrustedWithoutAssumptions((ResolvedJavaType) returnType));
    } else {
        return getLoweringProvider().loadStamp(StampFactory.forKind(returnKind), signature.getReturnKind());
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 7 with JavaKind

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

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

the class UnsafeEATest method testEscapeAnalysis.

@Override
protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
    // Exercise both a graph containing UnsafeAccessNodes and one which has been possibly been
    // canonicalized into AccessFieldNodes.
    testingUnsafe = true;
    super.testEscapeAnalysis(snippet, expectedConstantResult, iterativeEscapeAnalysis);
    testingUnsafe = false;
    super.testEscapeAnalysis(snippet, expectedConstantResult, iterativeEscapeAnalysis);
    if (expectedConstantResult != null) {
        // Check that a compiled version of this method returns the same value if we expect a
        // constant result.
        ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
        JavaKind[] javaKinds = method.getSignature().toParameterKinds(false);
        Object[] args = new Object[javaKinds.length];
        int i = 0;
        for (JavaKind k : javaKinds) {
            args[i++] = JavaConstant.defaultForKind(k).asBoxedPrimitive();
        }
        Result result = executeExpected(method, null, args);
        assertTrue(result.returnValue.equals(expectedConstantResult.asBoxedPrimitive()));
    }
}
Also used : ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 9 with JavaKind

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

the class QueryResultParser method visitConstantInfo.

@Override
protected void visitConstantInfo(ConstantInfo constantInfo) {
    TargetDescription target = nativeLibs.getTarget();
    switch(constantInfo.getKind()) {
        case INTEGER:
            parseIntegerProperty(constantInfo.getSizeInfo());
            parseSignedness(constantInfo.getSignednessInfo());
            parseIntegerConstantValue(constantInfo.getValueInfo());
            /*
                 * From the point of view of the C compiler, plain #define constants have the type
                 * int and therefore size 4. But sometimes we want to access such values as short or
                 * byte to avoid casts. Check the actual value of the constant, and if it fits the
                 * declared type of the constant, then change the actual size to the declared size.
                 */
            ResolvedJavaMethod method = (ResolvedJavaMethod) constantInfo.getAnnotatedElement();
            ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
            JavaKind returnKind = returnType.getJavaKind();
            if (returnKind == JavaKind.Object) {
                returnKind = target.wordJavaKind;
            }
            int declaredSize = target.arch.getPlatformKind(returnKind).getSizeInBytes();
            int actualSize = constantInfo.getSizeInfo().getProperty();
            if (declaredSize != actualSize) {
                long value = (long) constantInfo.getValueInfo().getProperty();
                if (value >= returnKind.getMinValue() && value <= returnKind.getMaxValue()) {
                    constantInfo.getSizeInfo().setProperty(declaredSize);
                }
            }
            break;
        case POINTER:
            parseIntegerProperty(constantInfo.getSizeInfo());
            parseIntegerConstantValue(constantInfo.getValueInfo());
            break;
        case FLOAT:
            parseIntegerProperty(constantInfo.getSizeInfo());
            parseFloatValue(constantInfo.getValueInfo());
            break;
        case STRING:
            parseStringValue(constantInfo.getValueInfo());
            break;
        case BYTEARRAY:
            parseByteArrayValue(constantInfo.getValueInfo());
            break;
        default:
            throw shouldNotReachHere();
    }
}
Also used : TargetDescription(jdk.vm.ci.code.TargetDescription) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 10 with JavaKind

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

the class BytecodeParser method genGetField.

private void genGetField(ResolvedJavaField resolvedField, ValueNode receiver) {
    if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
        graph.recordField(resolvedField);
    }
    for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
        if (plugin.handleLoadField(this, receiver, resolvedField)) {
            return;
        }
    }
    ValueNode fieldRead = append(genLoadField(receiver, resolvedField));
    if (resolvedField.getDeclaringClass().getName().equals("Ljava/lang/ref/Reference;") && resolvedField.getName().equals("referent")) {
        LocationIdentity referentIdentity = new FieldLocationIdentity(resolvedField);
        append(new MembarNode(0, referentIdentity));
    }
    JavaKind fieldKind = resolvedField.getJavaKind();
    if (resolvedField.isVolatile() && fieldRead instanceof LoadFieldNode) {
        StateSplitProxyNode readProxy = append(genVolatileFieldReadProxy(fieldRead));
        frameState.push(fieldKind, readProxy);
        readProxy.setStateAfter(frameState.create(stream.nextBCI(), readProxy));
    } else {
        frameState.push(fieldKind, fieldRead);
    }
}
Also used : FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) StateSplitProxyNode(org.graalvm.compiler.nodes.extended.StateSplitProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) LocationIdentity(org.graalvm.word.LocationIdentity) MembarNode(org.graalvm.compiler.nodes.extended.MembarNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaKind (jdk.vm.ci.meta.JavaKind)90 ValueNode (org.graalvm.compiler.nodes.ValueNode)44 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)24 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)16 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)13 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)12 JavaType (jdk.vm.ci.meta.JavaType)11 Stamp (org.graalvm.compiler.core.common.type.Stamp)10 LocationIdentity (org.graalvm.word.LocationIdentity)10 ArrayList (java.util.ArrayList)9 JavaConstant (jdk.vm.ci.meta.JavaConstant)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FrameState (org.graalvm.compiler.nodes.FrameState)8 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)8 Signature (jdk.vm.ci.meta.Signature)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6