Dalvik VM & JITAnkit Somani July 25, 2010
	 	What is VM ?	A virtual machine (VM) is a software implementation of a machine (i.e. a computer) that executes programs like a physical machine.Basic Parts:  A set of registers
  A stack (optional)
  An execution environment
  A garbage-collected heap
  A constant pool
  A method storage area
  An instruction set	 	Types of VM ?	 Based on its Working &Functionality : 1. System Virtual Machine (supports execution of a complete operating system)2. Process Virtual Machine (supports execution of a single process) Based on its architecture :1. Stack based VM (uses instructions to load in a stack for execution)2. Register based VM (uses instructions to be encoded in source and destinationregisters)
	 	Dalvik Virtual MachineDalvik architecture is register based
Can run on slow CPU, with little ram & in OS with lesser or even without swap space
It is optimized to use less space
The interpreter is simplified for faster execution
It executes its own Dalvik byte code rather than Java byte code	 	Why android choose Dalvik?Dalvik (Register based) take average 47 % less executed VM instruction then JVM (Stack based).
Register code is 25% larger than the corresponding stack code.
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.
Some Marketing Reasons too.	 	.Dex file anatomy
Conversion of Java Byte Code to Dalvik Byte Code
	 	Shared Constant Poolpublic interface Zapper {	public String zap(String s, Object o);}public class Blort implements Zapper {	public String zap(String s, Object o) {	      ...;	}}public class ZapUser {	public void useZap(Zapper z) {	     z.zap(...);	}}
	 	Shared Constant Pool (.Class File)
Shared Constant Pool (.Dex File)
Shared Constant Pool (Memory Saved Via) minimal repetition
 per-type pools (implicit typing)
 implicit labeling*After the Obfuscation & compression it will be much lesser.
Example #1: Sourcepublic static long sumArray(int[] arr) {        long sum = 0;        for (inti : arr) {	    sum += i;        }        return sum;}

Dalvik Vm & Jit

  • 1.
    Dalvik VM &JITAnkit Somani July 25, 2010
  • 2.
    What isVM ? A virtual machine (VM) is a software implementation of a machine (i.e. a computer) that executes programs like a physical machine.Basic Parts: A set of registers
  • 3.
    Astack (optional)
  • 4.
    Anexecution environment
  • 5.
    Agarbage-collected heap
  • 6.
    Aconstant pool
  • 7.
    Amethod storage area
  • 8.
    Aninstruction set Types of VM ? Based on its Working &Functionality : 1. System Virtual Machine (supports execution of a complete operating system)2. Process Virtual Machine (supports execution of a single process) Based on its architecture :1. Stack based VM (uses instructions to load in a stack for execution)2. Register based VM (uses instructions to be encoded in source and destinationregisters)
  • 9.
    Dalvik VirtualMachineDalvik architecture is register based
  • 10.
    Can run onslow CPU, with little ram & in OS with lesser or even without swap space
  • 11.
    It is optimizedto use less space
  • 12.
    The interpreter issimplified for faster execution
  • 13.
    It executes itsown Dalvik byte code rather than Java byte code Why android choose Dalvik?Dalvik (Register based) take average 47 % less executed VM instruction then JVM (Stack based).
  • 14.
    Register code is25% larger than the corresponding stack code.
  • 15.
    This increased costof fetching more VM instructions due to larger code size involves only 1.07% extra real machine loads per VM instruction. Which is negligible.
  • 16.
    Some Marketing Reasonstoo. .Dex file anatomy
  • 17.
    Conversion of JavaByte Code to Dalvik Byte Code
  • 18.
    Shared ConstantPoolpublic interface Zapper { public String zap(String s, Object o);}public class Blort implements Zapper { public String zap(String s, Object o) { ...; }}public class ZapUser { public void useZap(Zapper z) { z.zap(...); }}
  • 19.
    Shared ConstantPool (.Class File)
  • 20.
  • 21.
    Shared Constant Pool(Memory Saved Via) minimal repetition
  • 22.
    per-type pools(implicit typing)
  • 23.
    implicit labeling*Afterthe Obfuscation & compression it will be much lesser.
  • 24.
    Example #1: Sourcepublicstatic long sumArray(int[] arr) { long sum = 0; for (inti : arr) { sum += i; } return sum;}