https://www.zhihu.com/column/c_1507847302362742784
https://www.kancloud.cn/alex_wsc/androids/472173
https://www.kancloud.cn/alex_wsc/androids/473624 (老罗)

虚拟机的创建与启动

见源码 art/runtime/jni/java_vm_ext.cc

1186 // JNI Invocation interface.
1187 
1188 extern "C" jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args) {
1189   ScopedTrace trace(__FUNCTION__);
1190   const JavaVMInitArgs* args = static_cast<JavaVMInitArgs*>(vm_args);
1191   if (JavaVMExt::IsBadJniVersion(args->version)) {
1192     LOG(ERROR) << "Bad JNI version passed to CreateJavaVM: " << args->version;
1193     return JNI_EVERSION;
1194   }
1195   RuntimeOptions options;
1196   for (int i = 0; i < args->nOptions; ++i) {
1197     JavaVMOption* option = &args->options[i];
1198     options.push_back(std::make_pair(std::string(option->optionString), option->extraInfo));
1199   }
1200   bool ignore_unrecognized = args->ignoreUnrecognized;
1201   if (!Runtime::Create(options, ignore_unrecognized)) {
1202     return JNI_ERR;
1203   }
1204 
1205   // Initialize native loader. This step makes sure we have
1206   // everything set up before we start using JNI.
1207   android::InitializeNativeLoader();
1208 
1209   Runtime* runtime = Runtime::Current();
1210   bool started = runtime->Start();
1211   if (!started) {
1212     delete Thread::Current()->GetJniEnv();
1213     delete runtime->GetJavaVM();
1214     LOG(WARNING) << "CreateJavaVM failed";
1215     return JNI_ERR;
1216   }
1217 
1218   *p_env = Thread::Current()->GetJniEnv();
1219   *p_vm = runtime->GetJavaVM();
1220   return JNI_OK;
1221 }

→Runtime::Create

http://xinyiworld.top/wordpress_it/?p=14578
创建Runtime单例,调用Runtime实例的Init方法

→Runtime::Start


0 条评论

发表回复

您的电子邮箱地址不会被公开。