android -------- java virtual machine and Dalvik virtual machine

java virtual machine

A virtual machine is an abstract computer that is implemented by simulating various computer functions on an actual computer. The Java virtual machine has its own complete hardware architecture, such as processor, stack, registers, etc., and also has a corresponding instruction system. The Java virtual machine shields the information related to the specific operating system platform, so that the Java program only needs to generate the object code (bytecode) running on the Java virtual machine, and it can run on various platforms without modification.

 

The Java Virtual Machine (Java Virtual Machine for short JVM) is an abstract computer that runs all Java programs and is the runtime environment of the Java language. It is one of the most attractive features of Java.

 

Dalvik virtual machine

Dalvik is Google's own virtual machine designed for the Android platform. The Dalvik virtual machine is one of the core components of the Android mobile device platform jointly developed by manufacturers such as Google. It can support the running of Java applications that have been converted to .dex (ie Dalvik Executable) format, which is a compression format specially designed for Dalvik and is suitable for systems with limited memory and processor speed. Dalvik is optimized to allow multiple instances of virtual machines to run concurrently in limited memory, and each Dalvik application executes as a separate Linux process. A separate process prevents all programs from being shut down in the event of a virtual machine crash.

 

DVM virtual machine Dalvik Virtual Machine, is a virtual machine used in Android. All Android programs run in the Android system process. Each process corresponds to a Dalvik virtual machine instance.

 

The difference between Dalvik and the standard Java Virtual Machine (JVM)

The java virtual machine is stack based.

The java virtual machine runs java bytecode.

The java class will be compiled into one or more bytecode .class files, packaged into .jar files, and the java virtual machine will obtain the corresponding bytecodes from the corresponding .class files and .jar files

 

The dalvik virtual machine is register-based

Dalvik virtual machine runs Dalvik bytecode

After the java class is compiled into a .class file, all the .class files will be converted into a .dex file by a dx tool, and then the dalvik virtual machine will read instructions and data from it
 

 

Another big difference between Dalvik and Java is the runtime environment - Dalvik is optimized to allow multiple instances of a virtual machine to run simultaneously in limited memory, and each Dalvik application executes as a separate Linux process.

 

Dalvik virtual machine architecture:

  

 

Android application compilation and running process:

 

 

The java virtual machine is different from the Dalvik virtual machine architecture. The Java virtual machine is based on a stack architecture. When the program is running, the virtual machine needs to frequently read or write data from the stack. This process requires more instruction dispatch and memory access times, which consumes a lot of CPU time. For devices with limited resources such as mobile devices, this is a considerable overhead. The Dalvik virtual machine is based on a register architecture, and data access is directly transferred between registers, which is much faster than the stack-based method.

 

The difference between Dalvik and Java runtime environment

 

1: Dalvik mainly completes important functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

 

2: Dalvik is responsible for process isolation and thread management. Each Android application corresponds to an independent Dalvik virtual machine instance at the bottom layer, and its code is executed under the interpretation of the virtual machine.

 

3: Unlike the Java virtual machine that runs java bytecode, the Dalvik virtual machine runs its proprietary file format Dex

 

4: The dex file format can reduce the overall file size and improve the class search speed of I/O operations.

 

5: odex is to further improve the performance during operation and further optimize the dex file.

 

6: All Android application threads correspond to a Linux thread, so the virtual machine can rely more on the thread scheduling and management mechanism of the operating system

 

7: There is a special virtual machine process Zygote, which is an incubator of virtual machine instances. It will be generated when the system starts, and it will complete the initialization of the virtual machine, the loading of the library, the prefabricated class library and the initialization. If the system needs a new virtual machine instance, it quickly replicates itself to provide the fastest data to the system. For some read-only system libraries, all virtual machine instances share a memory area with Zygote.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325120282&siteId=291194637