The difference between a Java virtual machine and a Dalvik virtual machine

Source: Internet
Author: User
Tags java se

Google launched the Android SDK at the end of 2007 as an important feature of the Android system, and the Dalvik virtual machine was the first to come into view. Its efficient use of memory and its high performance on low-speed CPUs are truly impressive. Relies on the underlying POSIX-compliant operating system, which can simply complete process isolation and thread management. Each Android app will have a standalone Dalvik virtual machine instance on the bottom, and its code can be executed under the virtual machine's interpretation.
Many people think that the Dalvik virtual machine is a Java virtual machine, because the Android programming language is precisely the Java language. This is not true, however, because the Dalvik virtual machine is not implemented according to the specifications of the Java Virtual machine, and is not compatible, and two distinct differences:

    • The Java Virtual machine runs Java bytecode, and the Dalvik virtual machine runs its proprietary file format, Dex (Dalvik executable).
    • Java classes in Java SE programs are compiled into one or more bytecode files (. Class) and then packaged into a jar file, and then the Java Virtual Opportunity obtains the corresponding bytecode from the corresponding class file and Jar file The Android app is also programmed in the Java language, but after compiling it into a class file, a tool (DX) is used to convert all of the class files into a single Dex file, which then dalvik the virtual opportunity to read the instructions and data.

Dalvik and Android Android system as a new generation of Linux-based open-source mobile phone operating system, its system architecture from the bottom can be divided into the following parts:

    • Linux kernel
    • Local library
    • Android Runtime Library
    • Application Framework
    • Application

the difference between a Java virtual machine and a Dalvik virtual machine:

Java Virtual machine Dalvik virtual Machines
Java virtual machines are stack -based. Stack-based machines must use instructions to load and manipulate data on the stack, with more commands required The Dalvik virtual machine is a register -based
The Java virtual machine is running Java bytecode. (Java classes are compiled into one or more bytecode. class files, packaged into a. jar file, the Java virtual machine gets the appropriate bytecode from the corresponding. class file and the. jar file)

Dalvik is running the custom. Dex bytecode format. (After the Java class is compiled into a. class file, all the. class files are converted to a. dex file through a DX tool, and then the Dalvik virtual opportunity reads the instructions and data from them)
Chang has been modified to use only 32-bit indexes to simplify the interpreter. Dalvik heap and stack parameters can be changed by-XMS and-XMX
An application, a virtual machine instance, a process (all Android app threads are corresponding to a Linux thread, all running in their own sandbox, and different apps running in different processes.) Each Android Dalvik application is given a standalone Linux PID (app_*))

One of the first differences between the Dalvik and the standard Java Virtual machine (JVM) is that the Dalvik is based on a register, and the JVM is stack-based. Another big difference between Dalvik and Java is that the operating environment--dalvik optimized, allows instances of multiple virtual machines to run concurrently in limited memory, and each Dalvik application executes as a standalone Linux process. (1) The virtual machine is small, the space used is also small; (2) Dalvik No JITcompiler; (3) The constant pool has been modified to use only 32-bit indexes to simplify the interpreter, and (4) it uses its own bytecode, not Java bytecode.

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, will be compiled into libdvm.so, and "Dalvik/libdex" will be compiled into the LIBDEX.A Static library as the Dex tool; "Dalvik/dexdump" is the Anti-compilation tool for. dex files; The executable program for the virtual machine is in "DALVIK/DALVIKVM" and will be compiled into the DALVIKVM executables.

Dalvik Virtual Machine Architecture:

Android app compile and run process:

Dalvik Process Management:

Dalvik process management is dependent on the process architecture of Linux, such as creating a process for an application that uses the fork mechanism of Linux to replicate a process (the replication process is often more efficient than the creation process).

Zygote is a virtual machine process and also an incubator of virtual machine instances, which is started by the Init process. First, the System_server is hatched (the daemon for most of Android's system services, which listens to the socket Wait request command, and when an application starts, it makes a request, Zygote will fork out a new application process). Whenever a system requires an Android application to execute, Zygote uses the fork of Linux to produce a child process to execute the application.

JVM and Dalvik process management:

There are many ways to communicate between processes in Linux, but Dalvik uses a signaling method to complete interprocess communication.

Android Initialization Process :

The difference between a Java virtual machine and a Dalvik virtual machine

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.