What is the difference between DVM and JVM?

JavaAndroidJvmDvm

Java Problem Overview


What is difference between Java Virtual Machine and Dalvik Virtual Machine?

Java Solutions


Solution 1 - Java

DVM is Register based which is designed to run on low memory, uses its own byte code and runs .Dex file

JVM is Stack based which uses java byte code and runs .class file having JIT.

Java source code is compiled by the Java compiler into .class files. Then the dx (dexer) tool, part of the Android SDK processes the .class files into a file format called DEX that contains Dalvik bytecode. The dx tool eliminate all the redundant information that is present in the classes. In DEX all the classes of the application are packed into one file. DVM has been designed so that a device can run multiple instances of the VM efficiently.

stack-based machines must use instructions to load data on the stack and manipulate that data, and, thus, require more instructions than register machines to implement the same high level code, but the instructions in a register machine must encode the source and destination registers and, therefore, tend to be larger.

Solution 2 - Java

> Conceptually, there is little > difference from an application level > between a DVM and a JVM. > Architecturally, there is a major > difference between the registerbased > DVM and the stack-based JVM. > > Both use a VM code model. However, the > DVM uses registerbased opcodes that > are comparable to the register-based > bytecode instructions that most of the > target platforms already execute. This > includes architectures such as those > available from ARM and MIPS and the > x86-compatible architectures from > Intel, AMD, and VIA Technologies. > > Google developed Android and chose DVM > for several reasons. First, there were > licensing issues with most JVMs. Next, > the DVM should be more efficient in > terms of memory usage and performance > on a register-based machine. DVM is > also supposed to be more efficient > when running multiple instances of the > DVM. Applications are given their own > instance. Hence, multiple active > applications require multiple DVM > instances. Like most Java > implementations, the DVM has an > automatic garbage collector.

More about it

Solution 3 - Java

The jvm architecture is stack-based whereas the dvm architecture is register-based. Stack-based machines require more instructions(i.e. larger instruction set) than register-based machines for the same task. On the other side, each instruction in the register-based machines are larger.

Solution 4 - Java

When a Java virtual machine start running a program, it needs memory to store many things, including bytecodes and other information it extracts from loaded class files, objects the program instantiates, parameters to methods, return values, local variables, and intermediate results of computations.

The Java virtual machine organizes the memory it requires to execute a program into several runtime data areas.

Generally, stack-based machines must use instructions to load data on the stack and manipulate that data, and, thus, require more instructions than register machines to implement the same high level code, but the instructions in a register machine must encode the source and destination registers and, therefore, tend to be larger.

This difference is primarily of importance to VM interpreters for whom opcode dispatch tends to be expensive and other factors are relevant for JIT Compilation.

Being optimized for low memory requirements, Dalvik has some specific characteristics that differentiate it from other standard VMs>>>>>

The VM was just slimmed down to use less space--->> Dalvik currently has no just-in-time-compiler (JIT), but Android 2.0 includes experimental source for one (disabled by default). The constant pool has been modified to use only32-bit indexes to simplify the interpreter. It uses its own bytecode, not Java bytecode*****

Solution 5 - Java

Dalvik VM can't execute Java bytecode(.class) It has to be(.dex)

Oracle JVM has stack based architecture & Dalvik has register based architecture.

JVM suppost to multiple operating system. (it is open source) but DVM supported for Android Operating system (before comming android 5.o android used the DVM)

Solution 6 - Java

Here is a tabular comparison(Source: Mr. Atul):

enter image description here

Solution 7 - Java

Jvm will work based on byte code and the dvm will works based on optimized bytecode it is optimised for mobile platforms because mobile devices have low memory and low process that's why it is using the linux kernal.

Solution 8 - Java

enter image description here

Here, We can get the basic difference among the JVM (Java Virtual Machine) and DVM (Dalvik Virtual Machine). From figure it is obvious that DVM can run only .dex files. Dex compiler takes all .class (can be executed by JVM) files for all the classes belongs to application and convert all of them into a single .dex file. Later .dex file is executed by DVM. Additionally, .class files resulted by Javac (java compiler) from .java->.class.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionanishView Question on Stackoverflow
Solution 1 - JavaMayuriView Answer on Stackoverflow
Solution 2 - JavaDixonDView Answer on Stackoverflow
Solution 3 - JavaskyView Answer on Stackoverflow
Solution 4 - JavaSheelView Answer on Stackoverflow
Solution 5 - JavaKaumadie KariyawasamView Answer on Stackoverflow
Solution 6 - JavaManish Kumar SharmaView Answer on Stackoverflow
Solution 7 - JavarameshView Answer on Stackoverflow
Solution 8 - JavaParveen KumarView Answer on Stackoverflow