首先,在System.java中,它将Runtime调用为loadLibrary.
public static void loadLibrary(String libName) {
SecurityManager smngr = System.getSecurityManager();
if (smngr != null) {
smngr.checkLink(libName);
}
Runtime.getRuntime().loadLibrary(libName, VMStack.getCallingClassLoader());
}
Run Code Online (Sandbox Code Playgroud)
第二,它将VMStack.getCallingClassLoader()调用到findLibrary.
void loadLibrary(String libraryName, ClassLoader loader) {
if (loader != null) {
String filename = loader.findLibrary(libraryName);
if (filename == null) {
throw new UnsatisfiedLinkError("Couldn't load " + libraryName + ": " +
"findLibrary returned null");
}
//....
}
}
Run Code Online (Sandbox Code Playgroud)
所以,我认为VMStack.getCallingClassLoader()是最有意义的.但是在其jni文件dalvik_system_VMStack.cpp中,该Dalvik_dalvik_system_VMStack_getCallingClassLoader功能很难学习.最后,dalvik如何找到图书馆?
static void Dalvik_dalvik_system_VMStack_getCallingClassLoader(const u4* args,
JValue* pResult){
ClassObject* clazz =
dvmGetCaller2Class(dvmThreadSelf()->interpSave.curFrame);
UNUSED_PARAMETER(args);
if …Run Code Online (Sandbox Code Playgroud)