After Android starts the zygote process, it initializes the Fork sub-process before receiving the command. loading the Java core library is an important step. The source code of these core libraries is located in the/libcore/luni directory.
Now we have encountered a problem, because when zygote loads the Java core library, it calls timezones. in Java, the createzonestringsfor static method applies to the static field timezones. cachedtimezones. A problem occurs during names initialization, causing VM crash. During debugging, You need to print some logs in the createzonestringsfor method to verify the values of some fields. I tried several methods. Like system. Out, because in this stage of Zygote, out indicates that filedescriptor is empty, so it is invalid. Android. util. log is built on the Java core library and cannot be used at this time. Finally, I looked at Android. util. log and found that the final call was <cutils/log. h>. I moved these things to the Java core library.
1. Move the local method in Android. util. log to/framework/base/CORE/Java/Android/util/log. java.
Public static native int println_native (INT bufid, int priority, string tag, string MSG );
2. Move the local method corresponding to/framework/base/CORE/JNI/android_util_log.cpp to/libcore/luni/src/main/native/timezones. cpp.
Static jint android_util_log_println_native (jnienv * ENV, jobject clazz,
Jint bufid, jint priority, jstring tagobj, jstring msgobj)
{
......
}
3. register the local method in the/libcore/luni/src/main/native/timezones. cpp file.
Static jninativemethod gmethods [] = {
Native_method (timezones, getdisplaynameimpl, "(ljava/lang/string; ziljava/lang/string;) ljava/lang/string ;"),
Native_method (timezones, forcountrycode, "(ljava/lang/string;) [ljava/lang/string ;"),
Native_method (timezones, getzonestringsimpl, "([ljava/lang/string;) V "),
Native_method (timezones, log, "(iiljava/lang/string; ljava/lang/string;) I "),
};
In this way, you can use the local method named log to print logs in timezones. java.