Search in sources :

Example 21 with JavaKind

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

the class JNIFunctionTablesFeature method buildFunctionsInitializer.

private JNIStructFunctionsInitializer<JNINativeInterface> buildFunctionsInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
    Class<JNIFunctions> clazz = JNIFunctions.class;
    HostedType functions = access.getMetaAccess().lookupJavaType(clazz);
    HostedMethod[] methods = functions.getDeclaredMethods();
    int index = 0;
    int count = methods.length + generatedMethods.length;
    // Call, CallStatic, CallNonvirtual: for each return value kind: array, va_list, varargs
    // NewObject: array, va_list, varargs
    count += (jniKinds.size() * 3 + 1) * 3;
    int[] offsets = new int[count];
    CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
    for (HostedMethod method : methods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, method.getName());
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = getStubFunctionPointer(access, method);
        index++;
    }
    for (ResolvedJavaMethod accessor : generatedMethods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, accessor.getName());
        AnalysisUniverse analysisUniverse = access.getUniverse().getBigBang().getUniverse();
        AnalysisMethod analysisMethod = analysisUniverse.lookup(accessor);
        HostedMethod hostedMethod = access.getUniverse().lookup(analysisMethod);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = MethodPointer.factory(hostedMethod);
        index++;
    }
    for (CallVariant variant : CallVariant.values()) {
        CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false);
        String suffix = (variant == CallVariant.ARRAY) ? "A" : ((variant == CallVariant.VA_LIST) ? "V" : "");
        CFunctionPointer nonvirtualTrampoline = prepareCallTrampoline(access, variant, true);
        for (JavaKind kind : jniKinds) {
            String[] prefixes = { "Call", "CallStatic" };
            for (String prefix : prefixes) {
                StructFieldInfo field = findFieldFor(functionTableMetadata, prefix + kind.name() + "Method" + suffix);
                offsets[index] = field.getOffsetInfo().getProperty();
                pointers[index] = trampoline;
                index++;
            }
            StructFieldInfo field = findFieldFor(functionTableMetadata, "CallNonvirtual" + kind.name() + "Method" + suffix);
            offsets[index] = field.getOffsetInfo().getProperty();
            pointers[index] = nonvirtualTrampoline;
            index++;
        }
        StructFieldInfo field = findFieldFor(functionTableMetadata, "NewObject" + suffix);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = trampoline;
        index++;
    }
    VMError.guarantee(index == offsets.length && index == pointers.length);
    return new JNIStructFunctionsInitializer<>(JNINativeInterface.class, offsets, pointers, unimplemented);
}
Also used : CallVariant(com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) HostedType(com.oracle.svm.hosted.meta.HostedType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 22 with JavaKind

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

the class ReflectionSubstitutionType method fillArgsArray.

private static void fillArgsArray(HostedGraphKit graphKit, ValueNode argumentArray, int receiverOffset, ValueNode[] args, Class<?>[] argTypes) {
    for (int i = 0; i < argTypes.length; i++) {
        JavaKind argKind = JavaKind.fromJavaClass(argTypes[i]);
        ValueNode arg = graphKit.createLoadIndexed(argumentArray, i, JavaKind.Object);
        if (argKind.isPrimitive()) {
            arg = createCheckcast(graphKit, arg, graphKit.getMetaAccess().lookupJavaType(argKind.toBoxedJavaClass()), true);
            arg = graphKit.createUnboxing(arg, argKind);
        } else {
            arg = createCheckcast(graphKit, arg, graphKit.getMetaAccess().lookupJavaType(argTypes[i]), false);
        }
        args[i + receiverOffset] = arg;
    }
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 23 with JavaKind

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

the class JNIFieldAccessorMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    JNIGraphKit kit = new JNIGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
    state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
    ValueNode vmThread = kit.loadLocal(0, signature.getParameterKind(0));
    kit.append(new CEntryPointEnterNode(EnterAction.Enter, vmThread));
    List<ValueNode> arguments = kit.loadArguments(signature.toParameterTypes(null));
    ValueNode object;
    if (isStatic) {
        if (fieldKind.isPrimitive()) {
            object = kit.getStaticPrimitiveFieldsArray();
        } else {
            object = kit.getStaticObjectFieldsArray();
        }
    } else {
        ValueNode handle = arguments.get(1);
        object = kit.unboxHandle(handle);
    }
    ValueNode fieldId = arguments.get(2);
    ValueNode offset = kit.getFieldOffsetFromId(fieldId);
    ValueNode returnValue;
    if (isSetter) {
        // void
        returnValue = null;
        ValueNode newValue = arguments.get(3);
        if (fieldKind.isObject()) {
            newValue = kit.unboxHandle(newValue);
        }
        kit.append(new RawStoreNode(object, offset, newValue, fieldKind, LocationIdentity.ANY_LOCATION));
    } else {
        returnValue = kit.append(new RawLoadNode(object, offset, fieldKind, LocationIdentity.ANY_LOCATION));
        if (fieldKind.isObject()) {
            returnValue = kit.boxObjectInLocalHandle(returnValue);
        }
    }
    kit.append(new CEntryPointLeaveNode(LeaveAction.Leave));
    JavaKind returnKind = isSetter ? JavaKind.Void : fieldKind;
    kit.createReturn(returnValue, returnKind);
    assert graph.verify();
    return graph;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CEntryPointEnterNode(com.oracle.svm.core.graal.nodes.CEntryPointEnterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 24 with JavaKind

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

the class AArch64FloatArithmeticSnippets method lower.

public void lower(RemNode node, LoweringTool tool) {
    JavaKind kind = node.stamp(NodeView.DEFAULT).getStackKind();
    assert kind == JavaKind.Float || kind == JavaKind.Double;
    if (node instanceof SafeNode) {
        // We already introduced the necessary checks, nothing to do.
        return;
    }
    SnippetTemplate.SnippetInfo snippet = kind == JavaKind.Float ? frem : drem;
    StructuredGraph graph = node.graph();
    Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage());
    args.add("x", node.getX());
    args.add("y", node.getY());
    template(node, args).instantiate(providers.getMetaAccess(), node, SnippetTemplate.DEFAULT_REPLACER, tool, args);
}
Also used : SnippetTemplate(org.graalvm.compiler.replacements.SnippetTemplate) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Arguments(org.graalvm.compiler.replacements.SnippetTemplate.Arguments) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 25 with JavaKind

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

the class AArch64IntegerArithmeticSnippets method lower.

public void lower(FixedBinaryNode node, LoweringTool tool) {
    JavaKind kind = node.stamp(NodeView.DEFAULT).getStackKind();
    assert kind == JavaKind.Int || kind == JavaKind.Long;
    SnippetTemplate.SnippetInfo snippet;
    if (node instanceof SafeNode) {
        // We already introduced the zero division check, nothing to do.
        return;
    } else if (node instanceof SignedDivNode) {
        snippet = kind == JavaKind.Int ? idiv : ldiv;
    } else if (node instanceof SignedRemNode) {
        snippet = kind == JavaKind.Int ? irem : lrem;
    } else if (node instanceof UnsignedDivNode) {
        snippet = kind == JavaKind.Int ? uidiv : uldiv;
    } else if (node instanceof UnsignedRemNode) {
        snippet = kind == JavaKind.Int ? uirem : ulrem;
    } else {
        throw GraalError.shouldNotReachHere();
    }
    StructuredGraph graph = node.graph();
    Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage());
    args.add("x", node.getX());
    args.add("y", node.getY());
    template(node, args).instantiate(providers.getMetaAccess(), node, SnippetTemplate.DEFAULT_REPLACER, args);
}
Also used : SnippetTemplate(org.graalvm.compiler.replacements.SnippetTemplate) UnsignedRemNode(org.graalvm.compiler.nodes.calc.UnsignedRemNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Arguments(org.graalvm.compiler.replacements.SnippetTemplate.Arguments) SignedRemNode(org.graalvm.compiler.nodes.calc.SignedRemNode) UnsignedDivNode(org.graalvm.compiler.nodes.calc.UnsignedDivNode) JavaKind(jdk.vm.ci.meta.JavaKind) SignedDivNode(org.graalvm.compiler.nodes.calc.SignedDivNode)

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