Integrate ART with NativeBridge interfaces
Native-bridge will provide the following interfaces to ART:
struct NativeBridgeCallbacks {
bool (*initialize )(NativeBridgeArtCallbacks* vm_itf);
void* (*loadLibrary )(const char* libpath, int flag);
void* (*getTrampoline)(void* handle, const char* name, const char* shorty,
uint32_t len);
bool (*isSupported )(const char* libpath);
};
Native-bridge will expose a symbol NativeBridgeItf with the
type of NativeBridgeCallbacks to ART.
And ART will provide the interfaces below to native-bridge:
struct NativeBridgeArtCallbacks {
int (*logger )(int prio, const char* tag, const char* fmt, ...);
const char* (*getMethodShorty)(JNIEnv* env, jmethodID mid);
int (*getNativeMethodCount )(JNIEnv* env, jclass clazz);
int (*getNativeMethods )(JNIEnv* env, jclass clazz, JNINativeMethod* methods,
uint32_t method_count);
};
Based on the interfaces, if an ART call to dlopen fails to open a native library,
it queries the native bridge by using NativeBridgeCallbacks::isSupported(). If the
native library is supported by native-bridge, ART can load the native library
using NativeBridgeCallbacks::loadLibrary() and get a trampoline for a specific
native method using NativeBridgeCallbacks::getTrampoline(). ART can then call
the native method using the normal signature and the address of the trampoline.
On the other side, in the case of a native method calling JNI native function
CallXXXXMethodY(), native-bridge calls back to Art for the shorty of the method
using NativeBridgeArtCallbacks::getMethodShorty() so that it can prepare based
on host calling convention.
In case of JNI function RegisterNatives()/UnregisterNatives(), native bridge can
call back to NativeBridgeArtCallbacks::getNativeMethodCount() and NativeBridgeArtCallbacks
::getNativeMethods() to get all native methods of specified class so that all
corresponding trampolines can be prepared/destroyed.
Class NativeBridge is created to encapsulate the function pointers of
NativeBridgeCallbacks and provides better abstraction to ART.
Note: functionality is turned off in native_bridge.cc at the moment.
Change-Id: I652755044957a7960254648652b538cce70dd011
4 files changed