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
- static void preload () {
- Preloadclasses ();
- Preloadresources ();
- }
Java code
- Private static void Preloadclasses () {
- final Vmruntime runtime = Vmruntime.getruntime ();
- InputStream is = Zygoteinit. Class.getclassloader (). getResourceAsStream (
- preloaded_classes);
As you can see, the direct call to getClassLoader () is a classloader.
Java code
- Public ClassLoader getClassLoader () {
- if (this.isprimitive ()) {
- return null;
- }
- ClassLoader loader = Getclassloaderimpl ();
- if (loader = = null) {
- Loader = Bootclassloader.getinstance ();
- }
- return loader;
- }
Since this class is not classloader, it is called bootclassloader.getinstance ().
Java code
- /**
- * Provides an explicit representation of the boot class loader. It sits at the
- * Head of the class loader chain and delegates requests to the VM ' s internal
- * Class loading mechanism.
- */
- 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
- Const char* envstr = getenv ("CLASSPATH");
- if (envstr! = NULL) {
- Gdvm.classpathstr = StrDup (ENVSTR);
- } Else {
- Gdvm.classpathstr = StrDup (".");
- }
Java code
- Handlechildproc
Java code
- else {
- Cloader = Classloader.getsystemclassloader ();
- }
- try {
- 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)