The ClassLoader of the Master of Android (iii)

Source: Internet
Author: User

Because see C + + and C code look very tired, very hard. The previous chapter was finally freed up in Java code. The first getclassloader occurs in the preload method of Main,

public static void Main (String argv[]) {

Preload ();

}

Java code
    1. static void preload () {
    2. Preloadclasses ();
    3. Preloadresources ();
    4. }

Java code
    1. Private static void Preloadclasses () {
    2. final Vmruntime runtime = Vmruntime.getruntime ();
    3. InputStream is = Zygoteinit. Class.getclassloader (). getResourceAsStream (
    4. preloaded_classes);

As you can see, the direct call to getClassLoader () is a classloader.

Java code
  1. Public ClassLoader getClassLoader () {
  2. if (this.isprimitive ()) {
  3. return null;
  4. }
  5. ClassLoader loader = Getclassloaderimpl ();
  6. if (loader = = null) {
  7. Loader = Bootclassloader.getinstance ();
  8. }
  9. return loader;
  10. }

Since this class is not classloader, it is called bootclassloader.getinstance ().

Java code
    1. /**
    2. * Provides an explicit representation of the boot class loader. It sits at the
    3. * Head of the class loader chain and delegates requests to the VM ' s internal
    4. * Class loading mechanism.
    5. */
    6. Class Bootclassloader extends ClassLoader {

Now you get it. Bootclassloader turned out to be the first class ClassLoader. For Zygote is Com.android.internal.os.ZygoteInit, for others, that is Com.android.internal.os.RuntimeInit ClassLoader. This is the classloader specified in Init.rc bootclasspath.

Now look at another method, that is, runtimeinit loading.

Java code
    1. Const char* envstr = getenv ("CLASSPATH");
    2. if (envstr! = NULL) {
    3. Gdvm.classpathstr = StrDup (ENVSTR);
    4. } Else {
    5. Gdvm.classpathstr = StrDup (".");
    6. }

Java code
    1. Handlechildproc

Java code
    1. else {
    2. Cloader = Classloader.getsystemclassloader ();
    3. }
    4. try {
    5. Zygoteinit.invokestaticmain (Cloader, ClassName, Mainargs);

Classloader.getsystemclassloader (); This ClassLoader is different from the ordinary ClassLoader. This is a pathclassloader this with Bootclassloader as the Father loader. This is obviously a decorator pattern.

The ClassLoader of the Android Master (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.