Search in sources :

Example 1 with NativeMethodNode

use of com.oracle.truffle.espresso.nodes.NativeMethodNode in project graal by oracle.

the class Method method lookupJniCallTarget.

private CallTarget lookupJniCallTarget(Method findNative, boolean fullSignature) {
    String mangledName = Mangle.mangleMethod(this, fullSignature);
    long handle = (long) findNative.invokeWithConversions(null, getDeclaringKlass().getDefiningClassLoader(), mangledName);
    if (handle == 0) {
        // not found
        return null;
    }
    TruffleObject symbol = getVM().getFunction(handle);
    TruffleObject nativeMethod = bind(symbol);
    return EspressoRootNode.create(null, new NativeMethodNode(nativeMethod, this.getMethodVersion())).getCallTarget();
}
Also used : NativeMethodNode(com.oracle.truffle.espresso.nodes.NativeMethodNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 2 with NativeMethodNode

use of com.oracle.truffle.espresso.nodes.NativeMethodNode in project graal by oracle.

the class JniEnv method RegisterNative.

// endregion DirectBuffers
// region Register/Unregister natives
@JniImpl
@TruffleBoundary
public int RegisterNative(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject methodNamePtr, @Pointer TruffleObject methodSignaturePtr, @Pointer TruffleObject closure) {
    String methodName = NativeUtils.interopPointerToString(methodNamePtr);
    String methodSignature = NativeUtils.interopPointerToString(methodSignaturePtr);
    assert methodName != null && methodSignature != null;
    Symbol<Name> name = getNames().lookup(methodName);
    Symbol<Signature> signature = getSignatures().lookupValidSignature(methodSignature);
    Meta meta = getMeta();
    if (name == null || signature == null) {
        setPendingException(Meta.initException(meta.java_lang_NoSuchMethodError));
        return JNI_ERR;
    }
    Method targetMethod = clazz.getMirrorKlass().lookupDeclaredMethod(name, signature);
    if (targetMethod != null && targetMethod.isNative()) {
        targetMethod.unregisterNative();
        getSubstitutions().removeRuntimeSubstitution(targetMethod);
    } else {
        setPendingException(Meta.initException(meta.java_lang_NoSuchMethodError));
        return JNI_ERR;
    }
    Substitutions.EspressoRootNodeFactory factory = null;
    // Lookup known VM methods to shortcut native boudaries.
    factory = lookupKnownVmMethods(closure, targetMethod);
    if (factory == null) {
        NativeSignature ns = Method.buildJniNativeSignature(targetMethod.getParsedSignature());
        final TruffleObject boundNative = getNativeAccess().bindSymbol(closure, ns);
        factory = createJniRootNodeFactory(() -> new NativeMethodNode(boundNative, targetMethod.getMethodVersion()), targetMethod);
    }
    Symbol<Type> classType = clazz.getMirrorKlass().getType();
    getSubstitutions().registerRuntimeSubstitution(classType, name, signature, factory, true);
    return JNI_OK;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) Substitutions(com.oracle.truffle.espresso.substitutions.Substitutions) NativeMethodNode(com.oracle.truffle.espresso.nodes.NativeMethodNode) IntrinsifiedNativeMethodNode(com.oracle.truffle.espresso.nodes.IntrinsifiedNativeMethodNode) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with NativeMethodNode

use of com.oracle.truffle.espresso.nodes.NativeMethodNode in project graal by oracle.

the class Method method lookupLibJavaCallTarget.

private CallTarget lookupLibJavaCallTarget() {
    // in the native Java library.
    if (StaticObject.isNull(getDeclaringKlass().getDefiningClassLoader())) {
        for (boolean withSignature : new boolean[] { false, true }) {
            String mangledName = Mangle.mangleMethod(this, withSignature);
            // Look in libjava
            TruffleObject nativeMethod = lookupAndBind(getVM().getJavaLibrary(), mangledName);
            if (nativeMethod != null) {
                return EspressoRootNode.create(null, new NativeMethodNode(nativeMethod, getMethodVersion())).getCallTarget();
            }
        }
    }
    return null;
}
Also used : NativeMethodNode(com.oracle.truffle.espresso.nodes.NativeMethodNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 4 with NativeMethodNode

use of com.oracle.truffle.espresso.nodes.NativeMethodNode in project graal by oracle.

the class Method method lookupAgents.

private CallTarget lookupAgents() {
    // Look in agents
    for (boolean withSignature : new boolean[] { false, true }) {
        String mangledName = Mangle.mangleMethod(this, withSignature);
        TruffleObject nativeMethod = getContext().bindToAgent(this, mangledName);
        if (nativeMethod != null) {
            return EspressoRootNode.create(null, new NativeMethodNode(nativeMethod, getMethodVersion())).getCallTarget();
        }
    }
    return null;
}
Also used : NativeMethodNode(com.oracle.truffle.espresso.nodes.NativeMethodNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 NativeMethodNode (com.oracle.truffle.espresso.nodes.NativeMethodNode)4 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)1 Signature (com.oracle.truffle.espresso.descriptors.Symbol.Signature)1 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)1 NativeSignature (com.oracle.truffle.espresso.ffi.NativeSignature)1 NativeType (com.oracle.truffle.espresso.ffi.NativeType)1 Method (com.oracle.truffle.espresso.impl.Method)1 Meta (com.oracle.truffle.espresso.meta.Meta)1 IntrinsifiedNativeMethodNode (com.oracle.truffle.espresso.nodes.IntrinsifiedNativeMethodNode)1 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)1 Substitutions (com.oracle.truffle.espresso.substitutions.Substitutions)1