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();
}
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;
}
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;
}
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;
}
Aggregations