"Analysis" Dalvik virtual machine boot process (iii)

Source: Internet
Author: User

SOURCE version: ANDROID-4.4.4_R2

Tips: Most of the analysis is directly annotated within the code.

Related articles:

"Analysis" Dalvik virtual machine boot process (i)

"Analysis" Dalvik virtual machine boot process (ii)

In the AndroidRuntime::start call AndroidRuntime::startVm function to start the virtual machine, and then call the AndroidRuntime::startReg function to register the Android function:

/* * Register the Android local function with the VM. * Register Android Native functions with the VM.    *//*static*/int Androidruntime::startreg (jnienv* env) {//This function doesn't know what it's for!  /* * This hook is causes all future threads created in this process to being * attached to the JAVAVM.     (This needs to go away in favor of JNI * Attach calls.)    */Androidsetcreatethreadfunc ((ANDROID_CREATE_THREAD_FN) javacreatethreadetc);    ALOGV ("---registering native functions---\ n");  /* * Every "register" function calls one or more things that return * a local reference (e.g. findclass).   Because we haven ' t really * started the VM yet, they ' re all getting stored in the base frame * and never released.     Use Push/pop to manage the storage.    */Env->pushlocalframe (200);    Gregjni is a list of functions that register some local functions.        if (Register_jni_procs (Gregjni, Nelem (GREGJNI), env) < 0) {env->poplocalframe (NULL);    return-1;    } env->poplocalframe (NULL); Createjavathread ("Fubar", quIcktest, (void*) "Hello"); return 0;}

Gregjni:

static const REGJNIREC gregjni[] = {    ...    Reg_jni (Register_android_util_log),    ...};

Take REG_JNI(register_android_util_Log), the function register_jni_procsis called register_android_util_Log:

/* JNI registration. */static Jninativemethod gmethods[] = {/* name, signature, Funcptr */{"isloggable", "(ljava/lang/string;i) Z" , (void*) android_util_log_isloggable}, {"Println_native", "(iiljava/lang/string;    ljava/lang/string;) I ", (void*) android_util_log_println_native},};int register_android_util_log (JNIEnv* env) {    Jclass clazz = Env->findclass ("Android/util/log");        if (clazz = = NULL) {aloge ("Can ' t find Android/util/log");    return-1;    } levels.verbose = Env->getstaticintfield (Clazz, Env->getstaticfieldid (clazz, "verbose", "I"));    Levels.debug = Env->getstaticintfield (Clazz, Env->getstaticfieldid (clazz, "Debug", "I"));    Levels.info = Env->getstaticintfield (Clazz, Env->getstaticfieldid (clazz, "info", "I"));    Levels.warn = Env->getstaticintfield (Clazz, Env->getstaticfieldid (Clazz, "warn", "I"));    Levels.error = Env->getstaticintfield (Clazz, Env->getstaticfieldid (clazz, "error", "I")); Levels.assert = Env->getstaticintfield (Clazz, Env->getstaticfieldid (Clazz, "ASSERT", "I")); Return Androidruntime::registernativemethods (env, "Android/util/log", Gmethods, Nelem (Gmethods));}

the Register_android_util_log function java.util.Logclass is registered in the gMethodsthe two methods in: Isloggable and println_native.
But when I opened Eclipse, looking at the source code in the log class did not have these two classes, I used Jd-jui opened the Android SDK 4.4 of the jar package, found the native method isloggable, but still did not find Println_ Native method, I guess the classes and methods in the Android SDK are after all 不全的!

Conclusion: There are many places that are not analyzed, such as Dalvik virtual machine parameter analysis, Dvmstartup function, the function of a large number of initialization functions.



"Analysis" Dalvik virtual machine boot process (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.