Dalvik Virtual machine VS Java Virtual Machine:


Dalvik Virtual machine:


         (DVM) is Register Architecture, designed to run on low memory, uses its own byte code and runs .Dex file (Dalvik Executable File)

Java Virtual Machine:

        (JVM) is Stack Architecture, 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 proprietary file format called DEX that contains Dalvik bytecode.

Difference between .class and .dex file format

         
In DEX all the classes of the application are packed into one file.
         
All the classes in the same DEX file share field, method, etc if they are same.
         
Classes from the same DEX file are loaded by the same class loader instance.

Click on the link below to view in graphic the difference between the two:
 Difference between .class and .dex file:


              1) The dx tool eliminate all the redundant information that is present in the classes. The initial loading and parsing procedures that happens again and again are eliminated.


       2) In general, a Java .class file contains a number of different method signatures used in the code. These signatures are duplicated if referenced in different Java classes.In other words, each of these classes references to the methods that takes the same arguments and the same return type. So, each one of these classes will have to include the same method signatures and hence the efforts of parsing the files are duplicated. In addition to this, there is a large number of strings included that labels the internal bits of the class files.


             3) In the dex conversion all of the separate constant pools are collapsed into a single shared constant pool. This way not only is redundant information eliminated but storage space to store the shared constant pool is also conserved.
  • 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.

    What is DVM(Dalvik Virtual Machine):

1.     All Applications Written in java and are Converted into .dex file
2.     .dex means Dalvik Executable File
3.     Every Application in Android will runs in own Process
4.     Not a Traditional JVM.Its a Customized Virtual Machine which will run multiple VM's in a single Device.
5.     VM uses Linux kernel to handle Low Level Functionality which is threading,memory management ,Security,etc.  
6.     .dex is a binary code 
7.     VM is a Registered based

  Advantage of DVM over JVM

·         JVM requires lot of memory and in mobile resources are very limited. therefore it is not possible to have all classes and methods which are present in core java used in Mobile applications,so that we are moving for DVM. 


Comments

Post a Comment

Popular posts from this blog

How To Run Compatibility Test Suite (CTS) ?

NFC : Reading a MiFare Classic 1K from Android Devices