dalvik virtual machine vs java virtual machine
DESCRIPTION
Dalvik Virtual Machine Vs Java Virtual Machine. Arpit Jain Mtech1. Outline. Introduction Dalvik VM Java VM Examples Comparisons Experimental Evaluation. Virtual Machine. - PowerPoint PPT PresentationTRANSCRIPT
Dalvik Virtual Machine Vs
Java Virtual Machine
Arpit JainMtech1
OutlineIntroductionDalvik VMJava VMExamplesComparisonsExperimental Evaluation
Virtual MachineVirtual machines (VMs) are commonly used
to distribute programs in an architecture-neutral format, which can easily be interpreted or compiled.
Android OSAndroid OS is a software stack consisting of java app running on a java app framework on top of java core library running on dalvik VM.Android uses dalvik virtual machine. Compile java code to dalvik executables and that is run on dalvik VM.
Android Framework
Dalvik VMDalvik is the virtual machine (VM) in Google's
Android operating system. It is the software that runs the apps on Android devices.
Programs are commonly written in Java and compiled to byte code. They are then converted from Java Virtual Machine-compatible .class files to Dalvik-compatible .dex (Dalvik Executable) files before installation on a device
Dalvik VMProvides application portability.Runs optimised file format(.dex) and dalvik
byte code.Minimal memory footprint.
DEX formatA tool called dx is used to convert some (but
not all) Java .class files into the .dex format. Multiple classes are included in a single .dex file. Duplicate strings and other constants used in multiple class files are included only once in the .dex output to conserve space.
An uncompressed .dex file is typically a few percent smaller in size than a compressed .jar (Java Archive) derived from the same .class files.
Dex fileOn the Android platform, Java source code is
still compiled into .class files. But after .class files are generated, the “dx” tool is used to convert the .class files into a .dex, or Dalvik Executable, file.
Whereas a .class file contains only one class, a .dex file contains multiple classes.
It is the .dex file that is executed on the Dalvik VM. The .dex file has been optimized for memory usage.
ZygoteSince every application runs in its own
instance of the VM, VM instances must be able to start quickly when a new application is launched and the memory footprint of the VM must be minimal.
Android uses a concept called the Zygote to enable both sharing of code across VM instances and to provide fast start up time of new VM instances.
Java VMA Java virtual machine (JVM) is a virtual machine
that can execute Java bytecode. It is the code execution component of the Java software platform.
A JVM is distributed along with a set of standard class libraries that implement the Java application programming interface (API). Appropriate APIs bundled together with JVM form the Java Runtime Environment.
Java has always been marketed as “write once, run anywhere.”
Java VMIn standard Java environments, Java source
code is compiled into Java bytecode, which is stored within .class files. The .class files are read by the JVM at runtime.
Each class in your Java code will result in one .class file. This means that if you have, say, one .java source file that contains one public class, one static inner class, and three anonymous classes, the compilation process (javac) will output 5 .class files.
ComparisonsDalvik VM Java VMRegister Based Stack BasedExecutes .dex file Executes .class fileIt uses shared, type-specific constant pools as it’s primary mechanism for conserving memory. Rather than store these values throughout the class, they are always referred to by their index in the constant pool.
In the case of the .class file, each class has its own private, heterogeneous constantpool.
Disadvantages of DexBy allowing for classes to share constants
pools, repetition of constant values is kept to a minimum. The consequence of the minimal repetition is that there are significantly more logical pointers or references within a .dex file compared to a .class file.
Simplicity of JVM implementation, ease of writing a compiler back-end
STACK VERSUS REGISTERS
The cost of executing a VM instruction in an interpreter consists of three components:
Dispatching the instructionAccessing the operandsPerforming the computation
Dispatching instructionIt involves fetching next VM instruction and
jump to the corresponding segment of interpreter code.
Example: A=B+C can be ILOAD c, ILOAD b, IADD, ISTORE a(stack
JVM)IADD a, b, c (virtual register Machine)
Operands AccessingLocation of operands appears explicit in
register code, while in stack based operands are found relative to stack pointer.
So, average register instruction is longer than the corresponding stack instruction.
This is the reason why stack architecture is popular.
Translating Stack to RegisterIn stack based JVM, local variable is accessed
using an index, and the operands stack is accessed using stack pointer. So all variables are short lived.
While Register based JVM considers both local variables and operand stack as virtual register.
Contd...
Translating Stack to RegisterSo, most of the stack-based JVM instructions
are translated to corresponding register based virtual machine instruction with implicit operands translated to explicit operand registers.
Example:
Copy propagationIn stack based JVM, operands are pushed
from local variables to operand stack before they can be used and result again back to local variable.
This causes redundancy in our register based JVM as instructions can directly use local variables without going through the stack. So we use forward and backward copy propagation to eliminate redundancy.
ExampleInstruction after translation for register based JVM
After forward and backward copy propagation
Experimental EvaluationStudies shows that a register-based
architecture requires and average of 47% less executed VM instructions than the stack based.
On the other hand the register code is 25% larger than the corresponding stack code but this increased cost of fetching more VM instructions due to larger code size involves only 1.07% extra real machine loads per VM instruction which is negligible.
Contd...
References[1] Virtual Machine Showdown: Stack Versus
Registers by Yunhe Shi, David Gregg, Andrew Beatty Department of Computer Science University of Dublin, Trinity College Dublin 2, Ireland
[2] J. Park and S. mook Moon. Optimistic register coalescing, Mar. 30 1999.
[3] The dalvik virtual machine architecture by David Ehringer.