2010年8月18日 星期三

Dalvik Interpreting Workflow (1)

How Dalvik VM execute the .dex file

dalvikvm/Main.c

1. Jni fuction: JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args)

JNI_CreateJavaVM will be called to construct a Dalvik virtual machine. JNI_CreateJavaVM is a function defined in Jni.h. The spec of Jni.h can be found on java site [1]. The JNI_CreateJavaVM will create everything needed to execute the .dex file, such as dynamic memory management, thread, bytecode verifier, etc. Then JavaVM and JNIEnv arguments will become the function interfaces to provide supported functions.

2. Jni function: FindClass(JNIEnv* env, const char* name)

This function will be called to find the class by name. Before executing a main method in java program, its class is needed to be found by a specified name. 

3. Jni function: GetStaticMethodID(JNIEnv* env, jclass jclazz,
    const char* name, const char* sig)

Because the java main function must be a static method, this jni function will be called to get the main method ID.

4. Jni function: CallStaticVoidMethod(JNIEnv* env, jclass jclazz, jmethodID methodID, ...)

This function will start to interprete the .dex file. This function will call the Dalvik interpreter to interprete the .dex file. However, we can't find a direct definition of the function in the directory because the developer of Dalvik VM used a trick to define this function. Things will be explained in the next.

References:

沒有留言:

張貼留言