Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
42 views7 pages

Android DVM

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

A Brief Overview of Dalvik Virtual Machine - Technical article - OPhone SDN [OPhone ...

Page 1 of 7

Technical article

A Brief Overview of Dalvik Virtual Machine

A Brief Overview of Dalvik Virtual Machine


OPhone platform, 2010-11-17 16:53:27 Tags : Machine Virtual Dalvik

Introduction

As an important feature of the Android system, the Dalvik virtual machine (DVM) came into public view for the first time with the official release of Android SDK by Google at the end of 2007. Its efficient use of memory and high performance with low-speed CPU is indeed impressive. Relying on the underlying Posix-compliant operating system, the DVM is designed for easy process isolation and thread management. Each Android application corresponds to an underlying stand-alone DVM instance, with their codes executed with the interpretation of the VM. Dalvik is often referred to as a Java VM as Android is compiled in Java programming language. However, this is not strictly accurate, as the rules on which DVM operates are different form those of Java VM, and both are incompliant. Also, there are two significant differences between them: The bytecode on which Java VM operates is Java bytecode, but the DVM operates on its own special format .dex (Dalvik Executable). Java classes in Java SE programs are compiled into one or more bytecode files (.class) and zipped into .jar files, and then Java VMs obtain the corresponding bytecodes from the .class files and .jar files. Although Android applications are also compiled in Java programming language, after these applications are compiled into .class files, a tool (dx) transforms all the .class files into a .dex file, from which the DVM reads the instructions and data.

Dalvik OS vs. Android OS

As a new generation Linux-based open-source mobile phone operating system, Android OS can be divided into the following sections from bottom up: Linux Kernel Libraries Android Runtime Application FrameworkApplications

http://en.ophonesdn.com/article/show/353;jsessionid=08324B8FD6460E77446D897CC620... 3/6/2011

el ci t r a l a ci n h c e T

sl o o T

noitatnemucoD

s we N

emoH

A Brief Overview of Dalvik Virtual Machine - Technical article - OPhone SDN [OPhone ... Page 2 of 7

Figure 1

As shown in the above figure, Android Runtime consists of Core Libraries and DVM. Core Libraries include the most basic class libraries, such as data structure, network, Utilities, File system, etc. Many implementation codes are from Apache Harmony, mainly used to ensure maximum compatibility between the class libraries of the VM and Java SE, reduce application developers' difficulty in transferring from Java SE to Android, and increase application availability. DVM is designed to achieve the functions of the object life-cycle management, stack management, thread management, security & abnormity management, garbage collection, etc.

Features

DVM is ideal for use in mobile terminals, with low requirement of CPU and memory space compared to the virtual machines running on the desktop and server systems. According to Google's calculation, 64M RAM has enabled the system to work properly, 24M of which is used to initialize and start the underlying system, and another 20M is used to start high-level services. With the increasing of system services and expanding of application functions, memory consumption is also bound to increase. To sum up, DVM has the following main features: An exclusive file format: .dex The file format .dex is exclusive to DVM. But why to choose this new format rather than sticking to the original bytecode format (.class file)? 1. An application defines many classes. After compilation, a lot of .class files are generated, in which there are a lot of redundant information. However, the file format .dex can integrate all the .class files into a single file, so as to reduce the file size and I/O operations, and accelerate searching speed. The constant pools in each original .class file are managed by one single constant pool in the .dex file, as follows:

http://en.ophonesdn.com/article/show/353;jsessionid=08324B8FD6460E77446D897CC620... 3/6/2011

A Brief Overview of Dalvik Virtual Machine - Technical article - OPhone SDN [OPhone ... Page 3 of 7

Figure 2

Figure 3

2. Support new operation codes. 3. Simplify the file structure and use equal-length instructions, leading to increased parsing speed. 4. The read-only structure is maximized to improve sharing of cross-process data. How to generate .dex files? Android and DVM provide a tool, DX. After Java source codes are compiled into .class files, use the DX tool to convert these .class files into .dex files.

http://en.ophonesdn.com/article/show/353;jsessionid=08324B8FD6460E77446D897CC620... 3/6/2011

A Brief Overview of Dalvik Virtual Machine - Technical article - OPhone SDN [OPhone ... Page 4 of 7

Figure 4 Optimized DEX The structure of .dex files is compact. But, if we want to improve the runtime performance, .dex files can still be further optimized as follows: 1. Adjust the byte order of all fields (LITTLE_ENDIAN) and align each field of the structure; 2. Verify all classes in .dex files; and 3. Optimize some specific classes and operation codes in the method. The size of an optimized file is larger than before, generally 1-4 times as large as the original. There are two timings for optimization. For a pre-built application, a .dex file can be optimized after system compilation. The extension of the optimized file name is changed into .odex. The released application will include such an .odex file apart from an .apk file (no more .dex file). For an application that is not pre-built,
a .dex file included in an .apk file is optimized at run time, and then saved in the cache.

Register-based Compared to the stack-based VM implementation, the register-based VM implementation, despite its poor hardware universality, is superior in code execution efficiency. Generally speaking, the execution time for the instruction interpretation in the VM is mainly spent on the following three parts: 1. Dispatching instructions; 2. Accessing operands; and

3. Implementing operations.

http://en.ophonesdn.com/article/show/353;jsessionid=08324B8FD6460E77446D897CC620... 3/6/2011

A Brief Overview of Dalvik Virtual Machine - Technical article - OPhone SDN [OPhone ... Page 5 of 7

Among them, dispatching instructions plays the most important role in the performance. A register-based VM can reduce dispatch of redundant instructions and access to the memory. For example, although DVM does not use the currently popular virtual machine technology, such as JIT, but according to Google, the absence of this feature does not affect DVM's performance. We also believe that DVM's performance can be further improved. Application/VM Instance/Process Each Android application runs in a DVM instance, and each VM instance is a separate process. VM's thread mechanism, memory allocation & management, Mutex and other functions all rely on the underlying operating system. Each thread in an Android application corresponds to a Linux thread, thus the VM can be more dependent on the thread scheduling and management mechanism of the operating system. Different applications run in different process spaces. Furthermore, different Linux users run the applications of different sources, which can ensure the security and independent operation of the applications at utmost. Zygote is not only a VM process, but also an incubator for VM instances. Whenever the system requests to implement an Android application, Zygote can fork a sub-process to execute applications. The merits of doing so are obvious: Zygote process is generated when the system starts, and it completes the initialization of the VM, library loading, loading and initialization of the pre-built class libraries, etc. While the system needs a new VM instance, Zygote provides it to the system at the fastest speed by copying itself. In addition, for some read-only system libraries, all VM instances share the same memory region with Zygote, considerably saving the memory space.

Figure 5

Android Application Development & DVM

Android applications use Java language as the programming language. Like Java SE, Sun JDK is used to compile Java source programs into a standard Java byte code file (.class file), and then a tool DX can convert all the bytecode files into a .dex file (classes.dex).At last, Android Package Tool (AAPT) is used to zip all .dex

http://en.ophonesdn.com/article/show/353;jsessionid=08324B8FD6460E77446D897CC620... 3/6/2011

A Brief Overview of Dalvik Virtual Machine - Technical article - OPhone SDN [OPhone ... Page 6 of 7

files, resource files, and AndroidManifest.xml files (binary format) into a single application package (.apk file), which can be released on mobile phones for execution.

Figure 6

After the application package (.apk file) is released onto mobile phones, .dex files are optimized before running. The optimized files are saved to the cache region (the optimized format is .dey). The VM can then implement the file directly. If the application package file does not change, .dey files will not be regenerated.

Figure 7

(Copyright Notice: The ophonesdn.com reserves all copyrights on any and/or all articles and press releases with this website. Please contact our Editing Team for reproduction. No reproduction by any media, website or individual, in any form, is permitted without prior written approval from ophonesdn.com. Any authorized

http://en.ophonesdn.com/article/show/353;jsessionid=08324B8FD6460E77446D897CC620... 3/6/2011

ophonesdn.com

.)

reproduction/redistribution of all materials on this website must contain the following attribution:

Source:

A Brief Overview of Dalvik Virtual Machine - Technical article - OPhone SDN [OPhone ... Page 7 of 7

News All News OPhone News Community News & Activities Industrial News

Document What is OPhone? Get Started Developing Apps API docs

Resource OPhone SDK Code Examples

Technical article Structure of apk Overview of Dalvik OMS Logcat manual Music Player sample

ICP

09047398

http://en.ophonesdn.com/article/show/353;jsessionid=08324B8FD6460E77446D897CC620... 3/6/2011

Disclaimer Copyright Terms of Use Privacy Policy

2009 OPhone SDN(OPhone

You might also like