Android implementation-System Basics

Source: Internet
Author: User

I have been studying the implementation of Dalvik. Today I suddenly think of one thing. We can use java by default. lang. when is the system class such as Object loaded? Can our own class be loaded in advance like this?

 

Following this idea, let's review the previous process of starting Zygote and explore it!

 

Zygote Startup Process (many analyses on the Internet are not detailed ):

>>> Start Kernel

>>> Start the init program, which parses init. rc for execution.

>>> Start zygote code in init. rc

>>> After zygote is started, fork will output system_server for system service.

>>> Zygote waits for the socket event to prepare to hatch the user process

 

The following key calls are available at Zygote startup:

AppRuntime. start com. android. internal. OS. ZygoteInit class Processing

 

Now that the java class can be called for processing, which system basic class must be ready before this? Let's look at it.

AppRuntime inherits AndroidRuntime

The start function of AndroidRuntime calls the JNI_CreateJavaVM function to generate a virtual machine.

JNI_CreateJavaVM is a function in jni. c, that is, libdvm. so.

In JNI_CreateJavaVM, The dvmStartup function is called to start a virtual machine.

DvmStartup calls setCommandLineDefaults to implement the default value of the parameter. The BOOTCLASSPATH method is the most important method to get the environment change.

Looking back at init. rc

 

export BOOTCLASSPATH /system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar

It turns out that some basic class jar packages are specified here

 

Continue viewing code

In dvmStartup, setCommandLineDefaults is called to set the default BOOTCLASSPATH.

DvmStartup calls dvmClassStartup to load the default startup class.

DvmClassStartup calls the processClassPath processing class path, which is actually the value in BOOTCLASSPATH.

ClassPathEntry is created in processClassPath to store a path.

PrepareCpe is called in processClassPath to prepare the class path node.

In prepareCpe, dvmJarFileOpen is called to open a jar package.

All loaded Jar packages are stored in gDvm. bootClassPath.

GDvm. bootClassPath is represented by a special struct at the end of the object. kind = kCpeLastEntry indicates the last class path node, because some variables do not need to represent the size.

 

Probably clear!

 

-------------------------------------- Boring split line --------------------------------------

 

Which of the following methods can we add a basic package for the system:

  1. Change the initial value of the BOOTCLASSPATH environment variable of init. rc.
  2. Change the BOOTCLASSPATH environment variable before zygote starts.
  3. After zygote is started, try to load a jar package.

 

At this point, we found that the system starts and starts, and all the implementation is scalable, so it is easy to code without hard coding.

 

We will continue to study loading of other things in the future. For example, an interesting apk (ramework-res.apk) is a pack implemented by the system skin.

 

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.