Dalvik Virtual Machine Analysis

Source: Internet
Author: User

Dalvik virtual machine is a Java virtual machine developed by Google for the Android platform, but it does not use JVM specifications. The Dalvik virtual machine provides important functions such as object lifecycle management, thread management, security and exception management, and garbage collection.

Differences between Java Virtual Machine and Dalvik virtual machine:

  Java Virtual Machine Dalvik Virtual Machine
  The Java Virtual Machine is stack-based. Stack-based machines must use commands to load and operate data on stacks. More and more commands are required. The Dalvik virtual machine is register-based.
  The Java virtual machine runs Java bytecode. (The Java class is compiled into one or more bytecode. class file, packaged. in the JAR file, the Java Virtual Machine starts from the corresponding. class file and. obtain the corresponding bytecode in the jar file) Dalvik runs a custom. Dex bytecode format. (After the Java class is compiled into a. Class file, all. class files will be converted into a. Dex file using a DX tool, and Dalvik will then read the commands and data from it)
    The constant pool has been modified to use only 32-bit indexes to simplify the interpreter. The heap and stack parameters of Dalvik can be changed through-XMS and-xmx.
    An application, a virtual machine instance, and a process (all Android Application threads correspond to a Linux thread and run in their sandbox. Different applications run in different processes. Each Android Dalvik application is assigned an independent Linux PID (APP _*))

Dalvik virtual machine architecture:

In the android source code, the implementation of the Dalvik virtual machine is located in the "Dalvik/" directory, where "Dalvik/Vm" is the implementation part of the Virtual Machine and will be compiled into libdvm. and "Dalvik/libdex" will be compiled into libdex. A static library is used as the DEX tool; "Dalvik/dexdump" is. dex file decompilation tool. The executable program of the virtual machine is located in "Dalvik/dalvikvm" and will be compiled into the dalvikvm executable file.

Dalvik virtual machine architecture:


Android app compilation and running process:

Dalvik Process Management:

Dalvik Process Management relies on the Linux Process architecture. To create a process for an application, it uses the Linux fork mechanism to replicate a process (the replication process is often more efficient than the creation process ).

Zygote is a virtual machine process and an incubator for a virtual machine instance. It is started through the INIT process. First, the system_server (daemon of Android's vast majority of multi-system services, which listens to socket waiting for request commands. When an application is started, a request is sent to it, zygote will fork a new application process ). every time the system requires an Android Application to be executed, zygote will use fork in Linux to generate a sub-process to execute the application.

 Differences between JVM and Dalvik Process Management:

........

There are many methods of inter-process communication in Linux, but Dalvik uses the signal method to complete inter-process communication.

Finally, we will introduce the initialization flowchart of Android.

Android initialization process:

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.