What is the difference between a Java virtual machine and a Dalvik Virtual Machine? Why is DVM designed to be register-based!

Source: Internet
Author: User

Some people think that the Dalvik virtual machine is a Java virtual machine, because the Android programming language is exactly the Java language. However, this statement is not accurate, because the Dalvik virtual machine is not implemented in accordance with the Java Virtual Machine specifications, the two are not compatible; there are also two obvious differences:

Java virtual machine runs Java bytecode, while Dalvik virtual machine runs its proprietary file format DEX (Dalvik Executable ).

The Java class in the Java SE program will be compiled into one or more bytecode files (. class) and then package it into the JAR file. Then, the Java Virtual Machine obtains the corresponding bytecode from the corresponding CLASS file and JAR file. Although Android applications are programming in Java, however, after being compiled into a CLASS file, a tool (dx) will be used to convert all the CLASS files to a DEX file, and then Dalvik will have a virtual opportunity to read commands and data from it.

Differences between Java Virtual Machine and Dalvik virtual machine:

Java Virtual Machine Dalvik Virtual Machine

Java Virtual Machine is based onStack. Stack-based machines must use commands to load and operate data on stacks. More and more commands are required. The dalvik virtual machine is based onRegisterOf

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 _*))

One of the primary differences between Dalvik and the standard Java Virtual Machine (JVM) Is that Dalvik is based on registers while JVM is based on stacks. Why is Dalvik based on registers?
(1) the virtual machine is small and the space used is small; (2) the Dalvik does not JITCompiler; (3) the constant pool has been changed to a 32-bit index to simplify the interpreter; (4) it uses its own bytecode instead of the Java bytecode.

What is the difference between stack-based and register-based?

Register Concept

Registers are components of a central processor. Registers are high-speed storage components with limited storage capacity. They can be used to store commands, data, and addresses. The control components of the central processor include the instruction registers (IR) and program counters (PC). In the arithmetic and logic components of the central processor, the included registers are accumulators (ACC ).

Stack Concept

The stack is unique to the thread and stores its running status and Local Automatic variables (so local variables in multithreading are independent of each other, different from class variables ). The stack is initialized at the beginning of the thread (the thread's Start method, initialization and allocation stack). The stacks of each thread are independent of each other. Each function has its own stack, which is used to pass parameters between functions. The operating system automatically switches the stack when switching the thread, that is, switches the SS/ESP register. Stack space does not need to be explicitly allocated or released in advanced languages.

Register concept:

Registers are components of a central processor. Registers are high-speed storage components with limited storage capacity. They can be used to store commands, data, and addresses. The control components of the central processor include the instruction registers (IR) and program counters (PC). In the arithmetic and logic components of the central processor, the included registers are accumulators (ACC ).

Registers are part of the central processor. Registers are high-speed storage components with limited storage capacity. They can be used to store commands, data, and locations. The register commands contained in the central processor's control components include instruction registers and program counters, registers included in the arithmetic and logical components of the central processor include accumulators;

Stack concept;

Stack stores the running status and Local Automatic variables of a thread (all local variables in multiple threads are in the same team, different from class variables ). The stack is initialized at the beginning of the thread. the stacks of each thread are independent of each other. Each function has its own stack, which is used to pass parameters between functions. The operating system automatically switches stacks when switching threads. Stack space does not need to be allocated or released in advanced languages.











Related Article

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.