Search in sources :

Example 1 with CFunction

use of org.graalvm.nativeimage.c.function.CFunction in project graal by oracle.

the class CFunctionCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    CFunction annotation = method.getAnnotation(CFunction.class);
    boolean needsTransition = annotation.transition() != Transition.NO_TRANSITION;
    if (purpose == Purpose.PREPARE_RUNTIME_COMPILATION && needsTransition) {
        /*
             * C function calls that need a transition cannot be runtime compiled (and cannot be
             * inlined during runtime compilation). Deoptimization could be required while we are
             * blocked in native code, which means the deoptimization stub would need to do the
             * native-to-Java transition.
             */
        ImageSingletons.lookup(CFunctionFeature.class).warnRuntimeCompilationReachableCFunctionWithTransition(this);
        return null;
    }
    boolean deoptimizationTarget = method instanceof SharedMethod && ((SharedMethod) method).isDeoptTarget();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    FrameStateBuilder state = kit.getFrameState();
    ValueNode callAddress = kit.unique(new CGlobalDataLoadAddressNode(linkage));
    List<ValueNode> arguments = kit.loadArguments(method.toParameterTypes());
    Signature signature = adaptSignatureAndConvertArguments(method, providers, nativeLibraries, kit, method.getSignature(), arguments);
    state.clearLocals();
    ValueNode returnValue = kit.createCFunctionCall(callAddress, method, arguments, signature, needsTransition, deoptimizationTarget);
    returnValue = adaptReturnValue(method, providers, nativeLibraries, kit, returnValue);
    kit.createReturn(returnValue, signature.getReturnKind());
    assert kit.getGraph().verify();
    return kit.getGraph();
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) Signature(jdk.vm.ci.meta.Signature) ValueNode(org.graalvm.compiler.nodes.ValueNode) CFunction(org.graalvm.nativeimage.c.function.CFunction) SharedMethod(com.oracle.svm.core.meta.SharedMethod) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)

Aggregations

CGlobalDataLoadAddressNode (com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)1 SharedMethod (com.oracle.svm.core.meta.SharedMethod)1 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)1 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)1 Signature (jdk.vm.ci.meta.Signature)1 FrameStateBuilder (org.graalvm.compiler.java.FrameStateBuilder)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 CFunction (org.graalvm.nativeimage.c.function.CFunction)1