Android虚拟机art流程:JniInvocation 初始化(2)

  • A+
所属分类:art虚拟机
JniInvocation jni_invocation;
jni_invocation.Init(NULL);

 

JniInvocation.cpp \libnativehelper

JniInvocation::JniInvocation() :
    handle_(NULL),
    JNI_GetDefaultJavaVMInitArgs_(NULL),
    JNI_CreateJavaVM_(NULL),
    JNI_GetCreatedJavaVMs_(NULL) {

  LOG_ALWAYS_FATAL_IF(jni_invocation_ != NULL, "JniInvocation instance already initialized");
  jni_invocation_ = this;
}

 

构造函数 没有做太多事情。

bool JniInvocation::Init(const char* library) {

  library = GetLibrary(library, buffer);
  handle_ = dlopen(library, kDlopenFlags);
  const int kDlopenFlags = RTLD_NOW | RTLD_NODELETE;
  if (!FindSymbol(reinterpret_cast<void**>(&JNI_GetDefaultJavaVMInitArgs_),
                  "JNI_GetDefaultJavaVMInitArgs")) {
    return false;
  }
  if (!FindSymbol(reinterpret_cast<void**>(&JNI_CreateJavaVM_),
                  "JNI_CreateJavaVM")) {
    return false;
  }
  if (!FindSymbol(reinterpret_cast<void**>(&JNI_GetCreatedJavaVMs_),
                  "JNI_GetCreatedJavaVMs")) {
    return false;
  }
  return true;
}

 

哦,那其实很简单,就是拿到library 这个就是 “libart.so”。 然后dlopen 打开这个so,从符号表里面找到这三个函数。

  • JNI_GetDefaultJavaVMInitArgs
  • JNI_CreateJavaVM
  • JNI_GetCreatedJavaVMs

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: