SlideShare uma empresa Scribd logo
1 de 24
Dalvik VM & JIT Ankit 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: ,[object Object]
  A stack (optional)
  An execution environment
  A garbage-collected heap
  A constant pool
  A method storage area
  An instruction set,[object Object]
	 	Dalvik Virtual Machine ,[object Object]
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,[object Object]
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.,[object Object]
Conversion of Java Byte Code to Dalvik Byte Code
	 	Shared Constant Pool public 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) ,[object Object]
 per-type pools (implicit typing)
 implicit labeling*After the Obfuscation & compression it will be much lesser.
Example #1: Source public static long sumArray(int[] arr) {         long sum = 0;         for (inti : arr) { 	    sum += i;         }         return sum; }

Mais conteúdo relacionado

Mais procurados

Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
Utkarsh Mankad
 
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Cyber Security Alliance
 

Mais procurados (20)

KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Android Data Binding in action using MVVM pattern - droidconUK
Android Data Binding in action using MVVM pattern - droidconUKAndroid Data Binding in action using MVVM pattern - droidconUK
Android Data Binding in action using MVVM pattern - droidconUK
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
 
Kotlin Coroutines - the new async
Kotlin Coroutines - the new asyncKotlin Coroutines - the new async
Kotlin Coroutines - the new async
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
Binder: Android IPC
Binder: Android IPCBinder: Android IPC
Binder: Android IPC
 
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
Asfws 2014 slides why .net needs ma-cs and other serial(-ization) tales_v2.0
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Async History - javascript
Async History - javascriptAsync History - javascript
Async History - javascript
 
Clean code
Clean codeClean code
Clean code
 
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL Triggers
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
AIDL - Android Interface Definition Language
AIDL  - Android Interface Definition LanguageAIDL  - Android Interface Definition Language
AIDL - Android Interface Definition Language
 
Android AIDL Concept
Android AIDL ConceptAndroid AIDL Concept
Android AIDL Concept
 

Destaque

"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
Vladimir Ivanov
 

Destaque (8)

Introduction To Android
Introduction To AndroidIntroduction To Android
Introduction To Android
 
Dalvik jit
Dalvik jitDalvik jit
Dalvik jit
 
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
 
Inside Android's Dalvik VM - NEJUG Nov 2011
Inside Android's Dalvik VM - NEJUG Nov 2011Inside Android's Dalvik VM - NEJUG Nov 2011
Inside Android's Dalvik VM - NEJUG Nov 2011
 
just in time JIT compiler
just in time JIT compilerjust in time JIT compiler
just in time JIT compiler
 
Java-java virtual machine
Java-java virtual machineJava-java virtual machine
Java-java virtual machine
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 

Semelhante a Dalvik Vm & Jit

Sybsc cs sem 3 core java
Sybsc cs sem 3 core javaSybsc cs sem 3 core java
Sybsc cs sem 3 core java
WE-IT TUTORIALS
 
QTP Interview Questions and answers
QTP Interview Questions and answersQTP Interview Questions and answers
QTP Interview Questions and answers
Rita Singh
 

Semelhante a Dalvik Vm & Jit (20)

Dvm
DvmDvm
Dvm
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Ijaprr vol1-2-13-60-64tejinder
Ijaprr vol1-2-13-60-64tejinderIjaprr vol1-2-13-60-64tejinder
Ijaprr vol1-2-13-60-64tejinder
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Java basic
Java basicJava basic
Java basic
 
Copper: A high performance workflow engine
Copper: A high performance workflow engineCopper: A high performance workflow engine
Copper: A high performance workflow engine
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Sybsc cs sem 3 core java
Sybsc cs sem 3 core javaSybsc cs sem 3 core java
Sybsc cs sem 3 core java
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Java unit 1
Java unit 1Java unit 1
Java unit 1
 
Synopsis on online shopping by sudeep singh
Synopsis on online shopping by  sudeep singhSynopsis on online shopping by  sudeep singh
Synopsis on online shopping by sudeep singh
 
QTP Interview Questions and answers
QTP Interview Questions and answersQTP Interview Questions and answers
QTP Interview Questions and answers
 
Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1
 
Basic Java I
Basic Java IBasic Java I
Basic Java I
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark faster
 
Terracotta DSO
Terracotta DSOTerracotta DSO
Terracotta DSO
 

Dalvik Vm & Jit

Notas do Editor

  1. Android platform has its own virtual machine dalvik. Every Android application runs in its own process, with its own instance of the Dalvik virtualmachine. Dalvik has been written so that a device can run multiple instances of the VM eciently. The Dalvik VM executes les in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included dx tool. The Dalvik VM relies on the Linux kernelfor underlying functionalities such as threading and low-level memory management. In this presentation we have discussed virtual machines, specially Dalvik virtual machine in detail and their runtime libraries in comparison with JVM's libraries. The report answers questions, such as why Dalvik was needed and how it overcomes the deficiencies of its counterpart Java virtual machine
  2. Virtual Machine (VM) is a software environment that can be an emulator, anoperating system or a complete hardware virtualization, that has an implementationof resources without the actual hardware being present.Thus the main idea of virtual machine is to provide an environment that can execute instructions other than those associated with the host environment regardless of the hardware and software
  3. System VM (also known as hardware virtual machine) and Process VM (also known as application virtual machine) [23]. The categorization is based on their usage and level of correspondence to the associated physical machine. The system VM simulates the complete system hardware stack and supports the execution of complete operating system. On the other hand, Process VM adds up layer over an operating systemwhich is use to simulate the programming environment for the execution of individual process. Virtual Machines are use to share & specify appropriate system resources to the software (could be multiple operating systems or an application); and these softwares are limited to their given resources provided by VM.For many years, in virtual machine architecture, the stack based VMs [23] was the architectural choice due to simplicity of the VM implementation and the size of executables for stack architectures. Registered-based VM [23] can be an attractive alternative to stack-based VM due to the reason that it allows a number of executed VM instructions to be substantially reduced. A study on analysis of dierent VM shows that register-based architecture requires an average of 47% less executed VM instructions than the stack based. On the other hand the register code is 25% largerthan 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. The overall performance of the register-based VM is that it take, on average, a 32.3% less time to execute standard benchmarks.
  4. Dalvik Executable are complied by Dalvik VM, and are zipped into a single .apk (Android Package) le on the device. The .dex les can be created automatically by translating compiled applications written in the Java programming language.The .dex le is divided into dierent constant pool sections. Each constant pool section is of a particular type. The string_ids section identies all strings included in the .dex le. For example, an explicit coded string in the source code or the name of the method or function. At the bottom it contains a series of class denitions as a single .dex le may contain multiple classes.
  5. Every Java program (as usual in Java) is compiled to byte code. The Java byte-code is then transformed into Dalvik byte-code with the help of dx tool and stored in .dex le, and that's on what Dalvik performs operations such as verication and optimization.Developers write their own applications in Java and at build time the Java code is converted to a format compatible with Dalvik VM. The Android SDK has a specialized tool called dx tool which converts the .class les of Java to the Dalvik executable les. The dx tool arranges all the Java class les and eliminate all the redundant information that is present in the class les. The initial le loading and parsing procedures that happens again and again are eliminated. Finally, the byte code from the original class les is written into the new form which is executed by the Dalvik VM.In general, a Java .class le contains a number of dierent method signatures used in the code. These signatures are duplicated if referenced in dierent 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 eorts of parsing the les are duplicated. In addition to this, there is a large number of strings included that labels the internal bits of the class les. On the other hand, when the Java class les are converted to the Dalvik dex les, only a single dex le is created and all of the class les are included in this le. 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 storagespace to store the shared constant pool is also conserved.
  6. Developers write their own applications in Java and at build time the Java code is converted to a format compatible with Dalvik VM. The Android SDK has a specialized tool called dx tool which converts the .class les of Java to the Dalvik executable les. The dx tool arranges all the Java class les and eliminate all the redundant information that is present in the class les. The initial le loading and parsing procedures that happens again and again are eliminated. Finally, the byte code from the original class les is written into the new form which is executed by the Dalvik VM.In general, a Java .class le contains a number of dierent method signatures used in the code. These signatures are duplicated if referenced in dierent 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 eorts of parsing the les are duplicated. In addition to this, there is a large number of strings included that labels the internal bits of the class les. On the other hand, when the Java class les are converted to the Dalvik dex les, only a single dex le is created and all of the class les are included in this le. 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 storagespace to store the shared constant pool is also conserved
  7. At the center of every VM is an interpreter. It fetches dalvik instructions and then interprets and executes it on the host processor. This is an extra stage of interpretation between the CPU. This can be slow. Truth is, the Dalvik interpreter is very fast, and much faster than a traditional Java interpreter. But not everything is in interpretation the whole time. The system has already optimized some processes. In typical use, about a third of operations are being done in the interpreter. This is good enough for most apps, but not perfect. A partial solution is the Native Development Kit, which allows apps to call statically-compiled methods. The other solution is JIT, which avoids runtime interpretation and instead translates byte-code to native code at run time. 
  8. There are a wide variety of JIT styles. The questions to ask are "when should it compile?" and "what stuff should it compile?". What we need is something that uses a very small amount of memory.It also needs to co-exist with dalvik's container based security model.It must also be quick to deliver a performance boost, rather than require the app to run for a while before performance increases.The transition to compiled code and interpretation should also be very smooth. 
  9. There are a wide variety of JIT styles. The questions to ask are "when should it compile?" and "what stuff should it compile?". What we need is something that uses a very small amount of memory.It also needs to co-exist with dalvik's container based security model.It must also be quick to deliver a performance boost, rather than require the app to run for a while before performance increases.The transition to compiled code and interpretation should also be very smooth. 
  10. Techniques:Method vs. Trace Granularity....Method granularity JIT is the most common model. it detects the "hot methods" by profiling the app. Once you identify them, the methods probably have some cold code. You end up compiling code that's not used often.Trace granularity JIT starts interpreting to discover the hot chunks, but not entire methods, but rather chunks of instructions. It creates a straight line trace of code and store them in a cache that can chain multiple chunks. You don't have to respect method call boundaries. You only optimize the hottest of the hot code. It has tight integration with the interpreter. It has a rapid return rate on performance boost once hot chunks are detected; only compiling small chunks that are stitched into the application. Weaknesses are that you don't know what's happening outside the hot chunk, so peaks might be brief; more synchronization with the interpreter is required; and it's more difficult to share translations across processes We found that method JIT provides best optimization possibilities, but trace has best return rate on speed and space. So we chose a trace JIT. The trace provides almost immediate speed returns. In the future, we might use both trace and method jit. For example, when charging and plugged in, the method JIT could take control and perform more profiling in the background. 
  11. We have a curved translation cache for each process. Sharing only within the sandboxes.Local optimizations include load and store elimination if we can, perform redundant null-checking, and some heuristic scheduling. Loop optimizations include simple loop detection and invartiand code motion, plus variable optimzations