简体   繁体   English

达尔维克如何找到图书馆?

[英]How does dalvik findlibrary?

first, in System.java, it calls Runtime to loadLibrary. 首先,在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());
}

second, it calles VMStack.getCallingClassLoader() to findLibrary. 第二,它将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");
        }
        //....
    }
}

So, i think VMStack.getCallingClassLoader() is the most meaningful. 所以,我认为VMStack.getCallingClassLoader()是最有意义的。 But in its jni file dalvik_system_VMStack.cpp , the Dalvik_dalvik_system_VMStack_getCallingClassLoader function is hard to learn. 但是在其jni文件dalvik_system_VMStack.cpp中Dalvik_dalvik_system_VMStack_getCallingClassLoader函数很难学习。 And at last, how dalvik findLibrary? 最后,dalvik如何找到图书馆?

static void Dalvik_dalvik_system_VMStack_getCallingClassLoader(const u4* args,
    JValue* pResult){
    ClassObject* clazz =
        dvmGetCaller2Class(dvmThreadSelf()->interpSave.curFrame);

    UNUSED_PARAMETER(args);

    if (clazz == NULL)
        RETURN_PTR(NULL);
    RETURN_PTR(clazz->classLoader);
}

VMStack.getCallingClassLoader() returns the class loader of the class that declared the method that called the current method. VMStack.getCallingClassLoader()返回声明调用当前方法的方法的类的类加载器。 In other words, if my function foo() called Runtime.loadLibrary() , it would return foo 's class loader. 换句话说,如果我的函数foo()调用Runtime.loadLibrary() ,它将返回foo的类加载器。

The point of all that is to make sure the library is loaded in the context of whoever called findLibrary , rather than in the context of java.lang.Runtime . 所有这一切都是为了确保库是在调用findLibrary的人的上下文中加载的,而不是在java.lang.Runtime的上下文中。

There's a good chance findLibrary() is implemented by BaseDexClassLoader , which calls into DexPathList.findLibrary() , which does the actual work. findLibrary()很有可能由BaseDexClassLoader实现,它调用DexPathList.findLibrary()来完成实际的工作。 The interesting bit there is the walk through nativeLibraryDirectories , which is initialized from the libraryPath argument to the BaseDexClassLoader constructor (which gets it from PathClassLoader or DexClassLoader ). 有趣的是,遍历nativeLibraryDirectories ,它从libraryPath参数初始化为BaseDexClassLoader构造函数(从PathClassLoaderDexClassLoader )。

For Android apps, take a look at android.app.ApplicationLoaders , which uses a PathClassLoader . 对于Android应用程序,请查看android.app.ApplicationLoaders ,它使用PathClassLoader If you trace that back far enough you'll see the directory being retrieved from ApplicationInfo.nativeLibraryDir . 如果您追溯到足够远,您将看到从ApplicationInfo.nativeLibraryDir中检索的目录。

EDIT: going deeper to address comment... 编辑:更深入地发表评论......

/system/lib comes from the java.library.path property, which the core libraries extract from the LD_LIBRARY_PATH environment variable. /system/lib来自java.library.path属性,核心库从LD_LIBRARY_PATH环境变量中提取该属性。 The app-specific library dir is configured by the framework. 特定于应用程序的库目录由框架配置。

The PackageManagerService constructor sets the lib path in mAppLibInstallDir , and setInternalAppNativeLibraryPath() configures nativeLibraryDir . PackageManagerService构造函数在mAppLibInstallDir设置lib路径, setInternalAppNativeLibraryPath()配置nativeLibraryDir

DexPathList.splitLibraryPath() combines the java.library.path path with the APK-specific path. DexPathList.splitLibraryPath()java.library.path路径与特定于APK的路径组合在一起。 See the comments there for notes on ordering. 有关订购的说明,请参阅那里的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Dalvik VM如何获得对I / O的访问权限? - How does Dalvik VM get access to I/O? Dalvik / JVM如何处理多处理的应用程序 - How does Dalvik/JVM handle multi processed apps JVM与Dalvik和/或ART有何不同? - How exactly does JVM differ from Dalvik and/or ART? 由以下原因引起:java.lang.UnsatisfiedLinkError:无法从加载器dalvik.system.PathClassLoader findLibrary加载gnustl_shared返回null - Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gnustl_shared from loader dalvik.system.PathClassLoader findLibrary returned null java.lang.UnsatisfiedLinkError:无法从加载程序dalvik.system.PathClassLoader加载和enginephysicsbox2dextension…findLibrary返回null - java.lang.UnsatisfiedLinkError: Couldn't load andenginephysicsbox2dextension from loader dalvik.system.PathClassLoader… findLibrary returned null Dalvik lfm是什么意思 - Dalvik what does lfm mean 如何分析Dalvik GC的行为? - How to analyse Dalvik GC behaviour? 如何检查Dalvik Cache是​​否被修改 - How to check if the Dalvik Cache was modified 如何在达尔维克bycode中了解@VIL - How to understand @VIL in dalvik bycode mterp(Dalvik VM)如何组织其字节码解释循环? - How does mterp (Dalvik VM) organize its byte-code interprete loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM