Dalvik Virtual Machine Vs Java Virtual Machine

26
Dalvik Virtual Machine Vs Java Virtual Machine Arpit Jain Mtech1

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 Presentation

Transcript of Dalvik Virtual Machine Vs Java Virtual Machine

Page 1: Dalvik Virtual Machine  Vs  Java Virtual Machine

Dalvik Virtual Machine Vs

Java Virtual Machine

Arpit JainMtech1

Page 2: Dalvik Virtual Machine  Vs  Java Virtual Machine

OutlineIntroductionDalvik VMJava VMExamplesComparisonsExperimental Evaluation

Page 3: Dalvik Virtual Machine  Vs  Java Virtual Machine

Virtual MachineVirtual machines (VMs) are commonly used

to distribute programs in an architecture-neutral format, which can easily be interpreted or compiled.

Page 4: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 5: Dalvik Virtual Machine  Vs  Java Virtual Machine

Android Framework

Page 6: Dalvik Virtual Machine  Vs  Java Virtual Machine

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

Page 7: Dalvik Virtual Machine  Vs  Java Virtual Machine

Dalvik VMProvides application portability.Runs optimised file format(.dex) and dalvik

byte code.Minimal memory footprint.

Page 8: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 9: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 10: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 11: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.”

Page 12: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 13: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 14: Dalvik Virtual Machine  Vs  Java Virtual Machine
Page 15: Dalvik Virtual Machine  Vs  Java Virtual Machine

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

Page 16: Dalvik Virtual Machine  Vs  Java Virtual Machine

STACK VERSUS REGISTERS

The cost of executing a VM instruction in an interpreter consists of three components:

Dispatching the instructionAccessing the operandsPerforming the computation

Page 17: Dalvik Virtual Machine  Vs  Java Virtual Machine

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)

Page 18: Dalvik Virtual Machine  Vs  Java Virtual 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.

Page 19: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 20: Dalvik Virtual Machine  Vs  Java Virtual Machine

Contd...

Page 21: Dalvik Virtual Machine  Vs  Java Virtual Machine

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:

Page 22: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 23: Dalvik Virtual Machine  Vs  Java Virtual Machine

ExampleInstruction after translation for register based JVM

After forward and backward copy propagation

Page 24: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.

Page 25: Dalvik Virtual Machine  Vs  Java Virtual Machine

Contd...

Page 26: Dalvik Virtual Machine  Vs  Java Virtual Machine

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.