Search in sources :

Example 81 with ResolvedJavaType

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

the class CInterfaceEnumTool method invokeEnumLookup.

private InvokeNode invokeEnumLookup(GraphBuilderTool b, CallTargetFactory callTargetFactory, FrameStateBuilder frameState, int bci, EnumInfo enumInfo, JavaKind parameterKind, ValueNode arg) {
    ValueNode[] args = new ValueNode[2];
    args[0] = ConstantNode.forConstant(snippetReflection.forObject(enumInfo.getRuntimeData()), b.getMetaAccess(), b.getGraph());
    assert !Modifier.isStatic(convertCToJavaMethod.getModifiers()) && convertCToJavaMethod.getSignature().getParameterCount(false) == 1;
    JavaKind expectedKind = convertCToJavaMethod.getSignature().getParameterType(0, null).getJavaKind();
    args[1] = CInterfaceInvocationPlugin.adaptPrimitiveType(b.getGraph(), arg, parameterKind, expectedKind, false);
    ResolvedJavaType convertReturnType = (ResolvedJavaType) convertCToJavaMethod.getSignature().getReturnType(null);
    StampPair returnStamp = StampFactory.forDeclaredType(null, convertReturnType, false);
    MethodCallTargetNode callTargetNode = b.append(callTargetFactory.createMethodCallTarget(InvokeKind.Virtual, convertCToJavaMethod, args, returnStamp, bci));
    Stamp invokeStamp = StampFactory.object(TypeReference.createWithoutAssumptions(convertReturnType));
    InvokeNode invoke = b.append(new InvokeNode(callTargetNode, bci, invokeStamp));
    frameState.push(convertReturnType.getJavaKind(), invoke);
    FrameState stateWithInvoke = frameState.create(bci, invoke);
    frameState.pop(convertReturnType.getJavaKind());
    invoke.setStateAfter(stateWithInvoke);
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 82 with ResolvedJavaType

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

the class CInterfaceInvocationPlugin method replaceFunctionPointerInvoke.

private boolean replaceFunctionPointerInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, CallingConvention.Type callType) {
    if (!functionPointerType.isAssignableFrom(method.getDeclaringClass())) {
        throw UserError.abort(new CInterfaceError("function pointer invocation method " + method.format("%H.%n(%p)") + " must be in a type that extends " + CFunctionPointer.class.getSimpleName(), method).getMessage());
    }
    assert b.getInvokeKind() == InvokeKind.Interface;
    JavaType[] parameterTypes = method.getSignature().toParameterTypes(null);
    if (callType == SubstrateCallingConventionType.NativeCall) {
        Predicate<JavaType> isValid = t -> t.getJavaKind().isPrimitive() || wordTypes.isWord(t);
        UserError.guarantee(Stream.of(parameterTypes).allMatch(isValid) && isValid.test(method.getSignature().getReturnType(null)), "C function pointer invocation method must have only primitive types or word types for its parameters and return value: " + method.format("%H.%n(%p)"));
    /*
             * We currently do not support automatic conversions for @CEnum because it entails
             * introducing additional invokes without real BCIs in a BytecodeParser context, which
             * does not work too well.
             */
    }
    // We "discard" the receiver from the signature by pretending we are a static method
    assert args.length >= 1;
    ValueNode methodAddress = args[0];
    ValueNode[] argsWithoutReceiver = Arrays.copyOfRange(args, 1, args.length);
    assert argsWithoutReceiver.length == parameterTypes.length;
    Stamp returnStamp;
    if (wordTypes.isWord(b.getInvokeReturnType())) {
        returnStamp = wordTypes.getWordStamp((ResolvedJavaType) b.getInvokeReturnType());
    } else {
        returnStamp = b.getInvokeReturnStamp(null).getTrustedStamp();
    }
    CallTargetNode indirectCallTargetNode = b.add(new IndirectCallTargetNode(methodAddress, argsWithoutReceiver, StampPair.createSingle(returnStamp), parameterTypes, method, callType, InvokeKind.Static));
    if (callType == SubstrateCallingConventionType.JavaCall) {
        b.handleReplacedInvoke(indirectCallTargetNode, b.getInvokeReturnType().getJavaKind());
    } else if (callType == SubstrateCallingConventionType.NativeCall) {
        // Native code cannot throw exceptions, omit exception edge
        InvokeNode invokeNode = new InvokeNode(indirectCallTargetNode, b.bci());
        if (pushKind(method) != JavaKind.Void) {
            b.addPush(pushKind(method), invokeNode);
        } else {
            b.add(invokeNode);
        }
    } else {
        throw shouldNotReachHere("Unsupported type of call: " + callType);
    }
    return true;
}
Also used : Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) LocationIdentity(org.graalvm.word.LocationIdentity) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) WordTypes(org.graalvm.compiler.word.WordTypes) AccessorInfo(com.oracle.svm.hosted.c.info.AccessorInfo) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) JavaKind(jdk.vm.ci.meta.JavaKind) AndNode(org.graalvm.compiler.nodes.calc.AndNode) InvokeJavaFunctionPointer(com.oracle.svm.core.annotate.InvokeJavaFunctionPointer) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) UserError(com.oracle.svm.core.util.UserError) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) SizableInfo(com.oracle.svm.hosted.c.info.SizableInfo) ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) Predicate(java.util.function.Predicate) OrNode(org.graalvm.compiler.nodes.calc.OrNode) FrameAccess(com.oracle.svm.core.amd64.FrameAccess) CInterfaceWriteNode(com.oracle.svm.core.graal.nodes.CInterfaceWriteNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) Stream(java.util.stream.Stream) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) StructInfo(com.oracle.svm.hosted.c.info.StructInfo) MulNode(org.graalvm.compiler.nodes.calc.MulNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) BytecodeParser(org.graalvm.compiler.java.BytecodeParser) ConstantInfo(com.oracle.svm.hosted.c.info.ConstantInfo) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) AddNode(org.graalvm.compiler.nodes.calc.AddNode) VMError.shouldNotReachHere(com.oracle.svm.core.util.VMError.shouldNotReachHere) EnumValueInfo(com.oracle.svm.hosted.c.info.EnumValueInfo) CInterfaceLocationIdentity(com.oracle.svm.core.c.struct.CInterfaceLocationIdentity) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) EnumLookupInfo(com.oracle.svm.hosted.c.info.EnumLookupInfo) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) PointerToInfo(com.oracle.svm.hosted.c.info.PointerToInfo) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType) CInterfaceReadNode(com.oracle.svm.core.graal.nodes.CInterfaceReadNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) AccessorKind(com.oracle.svm.hosted.c.info.AccessorInfo.AccessorKind) StampPair(org.graalvm.compiler.core.common.type.StampPair) SubstrateCallingConventionType(com.oracle.svm.core.graal.code.amd64.SubstrateCallingConventionType) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CallingConvention(jdk.vm.ci.code.CallingConvention) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CInterfaceError(com.oracle.svm.hosted.c.CInterfaceError) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode)

Example 83 with ResolvedJavaType

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

the class JNIFunctionTablesFeature method beforeAnalysis.

@Override
public void beforeAnalysis(BeforeAnalysisAccess arg) {
    BeforeAnalysisAccessImpl access = (BeforeAnalysisAccessImpl) arg;
    AnalysisMetaAccess metaAccess = access.getMetaAccess();
    JNIFunctionTables.create();
    NativeLibraries nativeLibraries = access.getNativeLibraries();
    AnalysisType invokeInterface = metaAccess.lookupJavaType(JNIInvokeInterface.class);
    invokeInterfaceMetadata = (StructInfo) nativeLibraries.findElementInfo(invokeInterface);
    AnalysisType functionTable = metaAccess.lookupJavaType(JNINativeInterface.class);
    functionTableMetadata = (StructInfo) nativeLibraries.findElementInfo(functionTable);
    // Manually add functions as entry points so this is only done when JNI features are enabled
    AnalysisType invokes = metaAccess.lookupJavaType(JNIInvocationInterface.class);
    AnalysisType exports = metaAccess.lookupJavaType(JNIInvocationInterface.Exports.class);
    AnalysisType functions = metaAccess.lookupJavaType(JNIFunctions.class);
    Stream<AnalysisMethod> analysisMethods = Stream.of(invokes, functions, exports).flatMap(t -> Stream.of(t.getDeclaredMethods()));
    Stream<AnalysisMethod> unimplementedMethods = Stream.of((AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJNIEnvArgument.class), (AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJavaVMArgument.class));
    Stream.concat(analysisMethods, unimplementedMethods).forEach(method -> {
        CEntryPoint annotation = method.getAnnotation(CEntryPoint.class);
        assert annotation != null : "only entry points allowed in class";
        CEntryPointCallStubSupport.singleton().registerStubForMethod(method, () -> CEntryPointData.create(method));
    });
    ArrayList<ResolvedJavaMethod> generated = new ArrayList<>();
    MetaAccessProvider wrappedMetaAccess = metaAccess.getWrapped();
    ResolvedJavaType generatedMethodClass = wrappedMetaAccess.lookupJavaType(JNIFunctions.class);
    ConstantPool constantPool = generatedMethodClass.getDeclaredMethods()[0].getConstantPool();
    // Generate JNI field accessors
    EnumSet<JavaKind> fldKinds = jniKinds.clone();
    fldKinds.remove(JavaKind.Void);
    for (JavaKind kind : fldKinds) {
        boolean[] trueFalse = { true, false };
        for (boolean isSetter : trueFalse) {
            for (boolean isStatic : trueFalse) {
                JNIFieldAccessorMethod method = new JNIFieldAccessorMethod(kind, isSetter, isStatic, generatedMethodClass, constantPool, wrappedMetaAccess);
                AnalysisMethod analysisMethod = access.getUniverse().lookup(method);
                access.getBigBang().addRootMethod(analysisMethod).registerAsEntryPoint(method.createEntryPointData());
                generated.add(method);
            }
        }
    }
    // Generate JNI primitive array operations
    EnumSet<JavaKind> primitiveArrayKinds = jniKinds.clone();
    primitiveArrayKinds.remove(JavaKind.Void);
    primitiveArrayKinds.remove(JavaKind.Object);
    for (JavaKind kind : primitiveArrayKinds) {
        for (Operation op : Operation.values()) {
            JNIPrimitiveArrayOperationMethod method = new JNIPrimitiveArrayOperationMethod(kind, op, generatedMethodClass, constantPool, wrappedMetaAccess);
            AnalysisMethod analysisMethod = access.getUniverse().lookup(method);
            access.getBigBang().addRootMethod(analysisMethod).registerAsEntryPoint(method.createEntryPointData());
            generated.add(method);
        }
    }
    generatedMethods = generated.toArray(new ResolvedJavaMethod[0]);
}
Also used : BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) ArrayList(java.util.ArrayList) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) Operation(com.oracle.svm.jni.hosted.JNIPrimitiveArrayOperationMethod.Operation) JNIFieldAccessorMethod(com.oracle.svm.jni.hosted.JNIFieldAccessorMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ConstantPool(jdk.vm.ci.meta.ConstantPool) JNIPrimitiveArrayOperationMethod(com.oracle.svm.jni.hosted.JNIPrimitiveArrayOperationMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 84 with ResolvedJavaType

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

the class ClassfileBytecodeProvider method getClassfile.

/**
 * Gets a {@link Classfile} created by parsing the class file bytes for {@code c}.
 *
 * @throws NoClassDefFoundError if the class file cannot be found
 */
private synchronized Classfile getClassfile(Class<?> c) {
    assert !c.isPrimitive() && !c.isArray() : c;
    Classfile classfile = classfiles.get(c);
    if (classfile == null) {
        try {
            ResolvedJavaType type = metaAccess.lookupJavaType(c);
            InputStream in = GraalServices.getClassfileAsStream(c);
            if (in != null) {
                DataInputStream stream = new DataInputStream(in);
                classfile = new Classfile(type, stream, this);
                classfiles.put(c, classfile);
                return classfile;
            }
            throw new NoClassDefFoundError(c.getName());
        } catch (IOException e) {
            throw (NoClassDefFoundError) new NoClassDefFoundError(c.getName()).initCause(e);
        }
    }
    return classfile;
}
Also used : DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 85 with ResolvedJavaType

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

the class BasicArrayCopyNode method isExact.

/*
     * Returns true if this copy doesn't require store checks. Trivially true for primitive arrays.
     */
public boolean isExact() {
    ResolvedJavaType srcType = StampTool.typeOrNull(getSource().stamp(NodeView.DEFAULT));
    ResolvedJavaType destType = StampTool.typeOrNull(getDestination().stamp(NodeView.DEFAULT));
    if (srcType == null || !srcType.isArray() || destType == null || !destType.isArray()) {
        return false;
    }
    if ((srcType.getComponentType().getJavaKind().isPrimitive() && destType.getComponentType().equals(srcType.getComponentType())) || getSource() == getDestination()) {
        return true;
    }
    if (StampTool.isExactType(getDestination().stamp(NodeView.DEFAULT))) {
        if (destType != null && destType.isAssignableFrom(srcType)) {
            return true;
        }
    }
    return false;
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)161 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)63 ValueNode (org.graalvm.compiler.nodes.ValueNode)60 JavaKind (jdk.vm.ci.meta.JavaKind)25 JavaType (jdk.vm.ci.meta.JavaType)25 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)19 Stamp (org.graalvm.compiler.core.common.type.Stamp)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)17 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)16 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)13 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)13 Signature (jdk.vm.ci.meta.Signature)11 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)11 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)11 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)11 ArrayList (java.util.ArrayList)10 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)10 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)9