Search in sources :

Example 1 with WrappedJavaMethod

use of com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod in project graal by oracle.

the class NativeImageGenerator method checkInvocationPluginMethods.

private static boolean checkInvocationPluginMethods(SubstrateReplacements replacements) {
    for (ResolvedJavaMethod method : replacements.getDelayedInvocationPluginMethods()) {
        ResolvedJavaMethod unwrapped = method;
        while (unwrapped instanceof WrappedJavaMethod) {
            unwrapped = ((WrappedJavaMethod) unwrapped).getWrapped();
        }
        if (method != unwrapped) {
            String runtimeDescriptor = method.getSignature().toMethodDescriptor();
            String hostedDescriptor = unwrapped.getSignature().toMethodDescriptor();
            if (!runtimeDescriptor.equals(hostedDescriptor)) {
                String name = method.format("%H.%n");
                throw new AssertionError(String.format("Cannot have invocation plugin for a method whose runtime signature is different from its hosted signature:%n" + "            method: %s%n" + "  hosted signature: %s%n" + " runtime signature: %s", name, runtimeDescriptor, hostedDescriptor));
            }
        }
        assert method == unwrapped || method.getSignature().toMethodDescriptor().equals(unwrapped.getSignature().toMethodDescriptor());
    }
    return true;
}
Also used : WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with WrappedJavaMethod

use of com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod in project graal by oracle.

the class CEntryPointCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    UniverseMetaAccess metaAccess = (UniverseMetaAccess) providers.getMetaAccess();
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    JavaType[] parameterTypes = method.toParameterTypes();
    JavaType[] parameterLoadTypes = Arrays.copyOf(parameterTypes, parameterTypes.length);
    EnumInfo[] parameterEnumInfos;
    parameterEnumInfos = adaptParameterTypes(providers, nativeLibraries, kit, parameterTypes, parameterLoadTypes, purpose);
    ValueNode[] args = kit.loadArguments(parameterLoadTypes).toArray(new ValueNode[0]);
    InvokeNode prologueInvoke = generatePrologue(providers, kit, parameterLoadTypes, args);
    adaptArgumentValues(providers, kit, parameterTypes, parameterEnumInfos, args);
    ResolvedJavaMethod unwrappedTargetMethod = targetMethod;
    while (unwrappedTargetMethod instanceof WrappedJavaMethod) {
        unwrappedTargetMethod = ((WrappedJavaMethod) unwrappedTargetMethod).getWrapped();
    }
    ResolvedJavaMethod universeTargetMethod = lookupMethodInUniverse(metaAccess, unwrappedTargetMethod);
    int invokeBci = kit.bci();
    int exceptionEdgeBci = kit.bci();
    // Also support non-static test methods (they are not allowed to use the receiver)
    InvokeKind invokeKind = universeTargetMethod.isStatic() ? InvokeKind.Static : InvokeKind.Special;
    ValueNode[] invokeArgs = args;
    if (invokeKind != InvokeKind.Static) {
        invokeArgs = new ValueNode[args.length + 1];
        invokeArgs[0] = kit.createObject(null);
        System.arraycopy(args, 0, invokeArgs, 1, args.length);
    }
    InvokeWithExceptionNode invoke = kit.startInvokeWithException(universeTargetMethod, invokeKind, kit.getFrameState(), invokeBci, exceptionEdgeBci, invokeArgs);
    kit.exceptionPart();
    ExceptionObjectNode exception = kit.exceptionObject();
    generateExceptionHandler(providers, kit, exception, invoke.getStackKind());
    kit.endInvokeWithException();
    ValueNode returnValue = adaptReturnValue(method, providers, purpose, metaAccess, nativeLibraries, kit, invoke);
    InvokeNode epilogueInvoke = generateEpilogue(providers, kit);
    kit.createReturn(returnValue, returnValue.getStackKind());
    inlinePrologueAndEpilogue(kit, prologueInvoke, epilogueInvoke, invoke.getStackKind());
    assert graph.verify();
    return graph;
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with WrappedJavaMethod

use of com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod in project graal by oracle.

the class JNINativeCallWrapperMethod method createLinkage.

private static JNINativeLinkage createLinkage(ResolvedJavaMethod method) {
    ResolvedJavaMethod unwrapped = method;
    while (unwrapped instanceof WrappedJavaMethod) {
        unwrapped = ((WrappedJavaMethod) unwrapped).getWrapped();
    }
    String className = unwrapped.getDeclaringClass().getName();
    String descriptor = unwrapped.getSignature().toMethodDescriptor();
    return JNIAccessFeature.singleton().makeLinkage(className, unwrapped.getName(), descriptor);
}
Also used : WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

WrappedJavaMethod (com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 UniverseMetaAccess (com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess)1 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)1 EnumInfo (com.oracle.svm.hosted.c.info.EnumInfo)1 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)1 JavaType (jdk.vm.ci.meta.JavaType)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)1 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)1 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 ExceptionObjectNode (org.graalvm.compiler.nodes.java.ExceptionObjectNode)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1