From: eLinux.org
Dalvik is the name of the Virtual Machine in which Android applications are run. This VM executes Dalvik bytecode, which is compiled from programs written in the Java language. Note that the Dalvik VM is not a Java VM (JVM).
Every Android application runs in its own process, with its own instance of the Dalvik virtual machine.
At boot time, a single virtual machine, called 'zygote' is created, which preloads a long list of classes. (As of Android version 2.1 (eclair), the list of classes preloaded by zygote had 1,942 entries). All other "java" programs or services are forked from this process, and run as their own process (and threads) in their own address space. Both applications and system services in the Android framework are implemented in "java".
Dalvik was written so that a device can run multiple VMs efficiently. The Dalvik VM executes code 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.
Most Android applications are delivered and stored on the system as packages (.apks), which include both dex bytes code (classes and methods) and resources. During first boot-up the system creates a cache of dex classes in /data/dalvik-cache.
There is some documentation on Dalvik in the source code in the dalvik/docs directory. See the Android dalvik docs git repository-
The source code has some rather large comments, including near the top of Thread.c and Exception.c. The "mterp" directory has some notes describing the structure of the interpreters.
From fadden on the android-platform list:
Who is responsible to read the dex file and call Dalvik ?
Do you have a tutorial launch an app in the terminal adb: bytecode file > dex file > app launch in Dalvik => and see the result in adb ?
Is there a profiler inside Dalvik, which enable us to follow each step in the dalvik execution ?
As of version 2.2 (Froyo), Dalvik includes a Just-In-Time compiler (or JIT).
The Dalvik JIT, as of version 2.2, is a "trace-granularity JIT", which means that it compiles individual code fragments that it discovers at runtime to be "hot spots". (That is, it does not compile whole methods) The Dalvik bytecode interpreter is constantly profiling the code it is executing, and when a piece of code is determined to be running a lot, it is passed to a compiler to turn into native code. Several optimizations may be performed in this process. This code is then executed instead of the bytecode, for future runs through this section of the software.
The memory overhead of the JIT is reported to be between 100K to 200K per application. The ratio of code size between native instructions and DEX byte codes in one example give (see slide 22 of the presentation) was 7.7 to 1. That is, native instructions take approximately 8 times as much space as DEX byte codes do to perform the same operations.
Because Dalvik is not referred to as a Java Virtual Machine it does not utilize the branding of "Java". Also, it does not execute Java bytecodes. Hence, Google can ignore licensing issues with Sun or Oracle, with regards to Java.
However, a Java compiler and set of class libraries are required in order to create a Dalvik program.
As of March 2010, only the Sun JDK, version 1.5 is supported for building the Android system and add-on Android applications.
There are a number of properties you can set, to control operation of the VM and allow for debugging various aspects of the system:
See http://netmite.com/android/mydroid/dalvik/docs/embedded-vm-control.html
(Note that this is in \
this mentions a number of features you can control with properties, including:
You can force the VM to dump a stack trace of all threads by sending a
SIGQUIT signal. This can be done using 'kill -3 \
CheckJNI refers to a special runtime mode of the Dalvik VM, which forces the VM to run certain check and report problems when it sees certain errors occuring from code called via JNI.
See http://android-developers.blogspot.com/2011/07/debugging-android-jni-with-checkjni.html
Dalvik VM Internals - video of presentation by Dan Bornstein at Google IO, 2008
DEX file format, reverse engineered by Michael Pavone