Dalvik is the process virtual machine (VM) in Google's Android operating system. It is the software that runs the apps on Android devices. Dalvik is thus an integral part of Android, which is typically used on mobile devices such as mobile phones and tablet computers as well as more recently on embedded devices such as smart TVs and media streamers.
“Dalvik virtual machine”, the open-source software originally created by one Dan Bornstein.
Java has always been marketed as “write once, run anywhere.” The capability has largely been
made possible by the Java Platform, the foundation of which is the Java Virtual Machine (JVM).
Although this goal has largely been met for the Java platform on desktop (JSE) and server (JEE)
environments, the mobile Java ecosystem (JME) is a bit more fragmented with various configurations, profiles, and packages causing significant modifications to applications in order to
support different devices.
Android uses the Dalvik virtual machine with just-in-time compilation to run Dalvik bytecode, which is usually translated from Java bytecode.
Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimised 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.
Dalvik Virtual Machine Architecture:
• Unlike Java VMs, which are stack machines, the Dalvik VM uses a register-based architecture.
• Dalvik virtual machine is intended to run multiple VMs at a time .
• So every app runs in its own process, with its own instance of the Dalvik virtual machine.
Dex File Format:
• In standard Java environments, Java source code is compiled into Java bytecode, which is stored within .class files.
• Each class in your Java code will result in one .class file read by JVM at runtime.
• On 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 and the design is primarily driven by sharing of data.
• A constant pool stores all literal constant values used within the class.
• This includes values such as string constants used in your code as well as field, variable, class, interface, and method names.
• 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 constant pool. It is heterogeneous in that all types of constants.
• Contrast this to the .dex file that contains many classes, all of which share the same type-specific constants pools. Duplication of constants across .class files is eliminated in the .dex format.