Print logs in the Java core library

Source: Internet
Author: User

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.

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.