Dalvik (software)
View on WikipediaDalvik is a discontinued process virtual machine (VM) in the Android operating system that executes applications written for Android.[1] (Dalvik bytecode format is still used as a distribution format, but no longer at runtime in newer Android versions.) Dalvik was an integral part of the Android software stack in the (now unsupported) Android versions 4.4 "KitKat" and earlier, which were commonly used on mobile devices such as mobile phones and tablet computers, and more in some devices such as smart TVs and wearables. Dalvik is open-source software, originally written by Dan Bornstein, who named it after the fishing village of Dalvík in Eyjafjörður, Iceland.[2][3]
Programs for Android are commonly written in Java and compiled to bytecode for the Java Virtual Machine, which is then translated to Dalvik bytecode and stored in .dex (Dalvik EXecutable) and .odex (Optimized Dalvik EXecutable) files; related terms odex and de-odex are associated with respective bytecode conversions. The compact Dalvik Executable format is designed for systems that are constrained in terms of memory and processor speed.
The successor of Dalvik is Android Runtime (ART), which uses the same bytecode and .dex files (but not .odex files), with the succession aiming at performance improvements. The new runtime environment was included for the first time in Android 4.4 "KitKat" as a technology preview,[4][5] and replaced Dalvik entirely in later versions; Android 5.0 "Lollipop" is the first version in which ART is the only included runtime.
History
[edit]Dalvik, named after a town in Iceland by its creator Dan Bornstein,[6] was designed for embedded devices with very low RAM and CPU[7] to run Java code, and eventually support C++ for "heavy-duty apps" and JavaScript for "light-weight widget-like apps" as first-class languages with Java catering to the rest. Android Native Development Kit which eventually paved way for C++ support has existed since Dalvik's first public release. According to Bornstein, Memory-mapping executables and libraries across multiple process and building a faster interpreter with register-based semantics drove much of the early design of the byte-aligned instruction set and the Virtual Machine. Experience working with J2ME on Sidekick at Danger, Bornstein found it was too stripped down and fairly constrained for Android. While improvements such as Isolates as then planned by Sun made process isolation infeasible as it broke Android's intra-Device security model. For Dalvik VM, Bornstein particularly took inspiration from The Case for Register Machines[6] authored by Brian Davis et al of Trinity College, Dublin.[8]
Dalvik was open sourced under Apache License v2 as rest of the Android Open Source Project in 2008.[9]
Architecture
[edit]
Unlike Java Virtual Machines, which are stack machines, the Dalvik VM uses a register-based architecture that requires fewer, typically more complex, virtual machine instructions. Dalvik programs are written in Java using the Android application programming interface (API), compiled to Java bytecode, and converted to Dalvik instructions as necessary.
A tool called dx is used to convert Java .class files into the .dex format. Multiple classes are included in a single .dex file. Duplicate strings and other constants used in multiple class files are included only once in the .dex output to conserve space. Java bytecode is also converted into an alternative instruction set used by the Dalvik VM. An uncompressed .dex file is typically a few percent smaller in size than a compressed Java archive (JAR) derived from the same .class files.[10]
The Dalvik executables may be modified again when installed onto a mobile device. In order to gain further optimizations, byte order may be swapped in certain data, simple data structures and function libraries may be linked inline, and empty class objects may be short-circuited, for example.
Being optimized for low memory requirements, Dalvik has some specific characteristics that differentiate it from other standard VMs:[11]
- The VM was slimmed down to use less space.
- The constant pool has been modified to use only 32-bit indices to simplify the interpreter.
- Standard Java bytecode executes 8-bit stack instructions. Local variables must be copied to or from the operand stack by separate instructions. Dalvik instead uses its own 16-bit instruction set that works directly on local variables. The local variable is commonly picked by a 4-bit "virtual register" field. This lowers Dalvik's instruction count and raises its interpreter speed.
The design of Dalvik permits a device to run multiple instances of the VM efficiently.[12][13]
Android 2.2 "Froyo" brought trace-based just-in-time (JIT) compilation into Dalvik, optimizing the execution of applications by continually profiling applications each time they run and dynamically compiling frequently executed short segments of their bytecode into native machine code. While Dalvik interprets the rest of application's bytecode, native execution of those short bytecode segments, called "traces", provides significant performance improvements.[14][15][16] The potential trace heads are identified in the front-end of the compiler at the parsing stage and after the bytecode conversion. A translation cache is maintained during the runtime. Multiple traces can be chained to reduce synchronisation between the compiler and the interpreter. The trace is optimized by converting it into the Single Static Assignment form, enabling optimizations like dead store elimination, variable folding, and inlining getters and setters.[12]
Performance
[edit]
The relative merits of stack machines versus register-based approaches are a subject of ongoing debate.[17]
Generally, stack-based machines must use instructions to load data on the stack and manipulate that data, and, thus, require more instructions than register machines to implement the same high-level code, but the instructions in a register machine must encode the source and destination registers and, therefore, tend to be larger. This difference is of importance to VM interpreters, for which opcode dispatch tends to be expensive, along with other factors similarly relevant to just-in-time compilation.
Tests performed on ARMv7 devices in 2010 by Oracle (owner of the Java technology) with standard non-graphical Java benchmarks showed the HotSpot VM of Java SE embedded to be 2–3 times faster than the JIT-based Dalvik VM of Android 2.2 (the initial Android release that included a JIT compiler).[18] In 2012, academic benchmarks confirmed the factor of 3 between HotSpot and Dalvik on the same Android board, also noting that Dalvik code was not smaller than Hotspot.[19]
Furthermore, as of March 2014[update], benchmarks performed on an Android device still show up to a factor 100 between native applications and a Dalvik application on the same Android device.[20][original research?][improper synthesis?] Upon running benchmarks using the early interpreter of 2009, both Java Native Interface (JNI) and native code showed an order of magnitude speedup.[21]
Licensing and patents
[edit]Dalvik is published under the terms of the Apache License 2.0.[22] Some [who?] say that Dalvik is a clean-room implementation rather than a development on top of a standard Java runtime, which would mean it does not inherit copyright-based license restrictions from either the standard-edition or open-source-edition Java runtimes.[23] Oracle and some reviewers dispute this.[24]
On August 12, 2010, Oracle, which acquired Sun Microsystems in April 2009 and therefore owns the rights to Java, sued Google over claimed infringement of copyrights and patents. Oracle alleged that Google, in developing Android, knowingly, directly and repeatedly infringed Oracle's Java-related intellectual property.[25][26][27] In May 2012, the jury in this case found that Google did not infringe on Oracle's patents, and the trial judge ruled that the structure of the Java APIs used by Google was not copyrightable.[28][29] The parties agreed to zero dollars in statutory damages for 9 lines of copied code.[30][31]
See also
[edit]- Android Runtime
- Android software development
- Application virtualization
- Comparison of application virtualization software
- Comparison of Java and Android API
- JEB decompiler – a Dalvik (DEX and APK) decompiler
- Dalvik Turbo virtual machine – a proprietary alternative Dalvik implementation
References
[edit]- ^ "Debugging ART Garbage Collection". Retrieved 6 October 2015.
The Dalvik runtime is no longer maintained or available [in current versions of Android] and its byte-code format is now used by ART.
- ^ Journal entry referencing the source of the name
- ^ "Google Calling: Inside Android, the gPhone SDK". onlamp.com. Archived from the original on 2017-01-10. Retrieved 2008-02-05.
- ^ Sean Buckley (2013-11-06). "'ART' experiment in Android KitKat improves battery life and speeds up apps". Engadget. Retrieved 2014-07-05.
- ^ Daniel P. (2013-11-07). "Experimental Google ART runtime in Android KitKat can bring twice faster app executions". phonearena.com. Retrieved 2014-07-05.
- ^ a b Live Q&A with Dan Bornstein, Creator of the Dalvik VM. InfoQ. 29 Sep 2015 – via YouTube.
- ^ Google I/O 2008 - Dalvik Virtual Machine Internals. Google. 4 Jun 2008 – via YouTube.
- ^ Davis, Brian; Beatty, Andrew; Casey, Kevin; Gregg, David; T Waldron, John (8 Jun 2003). "The case for virtual register machines" (PDF). Proceedings of the 2003 workshop on Interpreters, virtual machines and emulators. pp. 41–49. doi:10.1145/858570.858575. ISBN 1-58113-655-2. Archived from the original (PDF) on 1 Feb 2024.
{{cite book}}:|journal=ignored (help) - ^ Beschizza, Rob (12 Nov 2007). "Android SDK Open For Code". WIRED. Archived from the original on 31 January 2024.
- ^ Bornstein, Dan (2008-05-29). "Presentation of Dalvik VM Internals" (PDF). p. 22. Archived from the original (PDF) on 2017-04-16. Retrieved 2010-08-16.
- ^ Rose, John (2008-05-31). "with Android and Dalvik at Google I/O". Archived from the original on 2008-06-04. Retrieved 2008-06-08.
- ^ a b Ramanan, Neeraja (12 Dec 2011). "JIT through the ages" (PDF).
- ^ Google (2009-04-13). "What is Android?". Archived from the original on 2009-06-27. Retrieved 2009-04-19.
- ^ Ben Cheng; Bill Buzbee (May 2010). "A JIT Compiler for Android's Dalvik VM" (PDF). android-app-developer.co.uk. pp. 5–14. Archived from the original (PDF) on 2015-11-06. Retrieved March 18, 2015.
- ^ Phil Nickinson (May 26, 2010). "Google Android developer explains more about Dalvik and the JIT in Froyo". androidcentral.com. Archived from the original on 2014-07-14. Retrieved July 8, 2014.
- ^ "Nexus One Is Running Android 2.2 Froyo. How Fast Is It Compared To 2.1? Oh, Only About 450% Faster". 2010-05-13. Retrieved 2010-05-21.
- ^ Shi, Yunhe; Gregg, David; Beatty, Andrew; Ertl, M. Anton (2005-06-11). "Virtual Machine Showdown: Stack Versus Registers" (PDF). Retrieved 2009-12-22.
- ^ Vandette, Bob (2010-11-22). "Java SE Embedded Performance Versus Android 2.2". Oracle Corporation. Archived from the original on 2011-06-28. Retrieved 2011-09-04.
The results show that although Androids new JIT is an improvement over its interpreter only implementation, Android is still lagging behind the performance of our Hotspot enabled Java SE Embedded. As you can see from the above results, Java SE Embedded can execute Java bytecodes from 2 to 3 times faster than Android 2.2.
- ^ Hyeong-Seok Oh; Beom-Jun Kim; Hyung-Kyu Choi; Soo-Mook Moon (2012). Proceedings of the 10th International Workshop on Java Technologies for Real-time and Embedded Systems - JTRES '12. Association for Computing Machinery. p. 115. doi:10.1145/2388936.2388956. ISBN 9781450316880. S2CID 36316611.
In the JITC mode, however, Dakvik is slower than HotSpot by more than 2.9 times and its generated code size is not smaller than HotSpot's due to its worse code quality and trace-chaining code.
- ^ "Top AndEBench Scores". www.eembc.org. Retrieved 2014-03-23.
- ^ Batyuk, Leonid; Schmidt, Aubrey-Derrick; Schmidt, Hans-Gunther; Camtepe, Ahmet; Albayrak, Sahin (2009-04-29). "Developing and Benchmarking Native Linux Applications on Android". MobileWireless Middleware, Operating Systems, and Applications. Lecture Notes of the Institute for Computer Sciences, Social Informatics and Telecommunications Engineering. Vol. 7. pp. 381–392. Bibcode:2009mmos.book..381B. doi:10.1007/978-3-642-01802-2_28. ISBN 978-3-642-01801-5. S2CID 12131309.
The results show that native C applications can be up to 30 times as fast as an identical algorithm running in Dalvik VM. Java applications can become a speed-up of up to 10 times if utilizing JNI.
- ^ "Downloading the Source Tree - Android Open Source". Android.git.kernel.org. Archived from the original on 2009-04-17. Retrieved 2012-06-07.
- ^ Garling, Caleb. "Google and Oracle 'Experts' Clash over Android's Java Mimic". Wired.
- ^ Ed Bott (September 8, 2011). "The real history of Java and Android, as told by Google". ZDNet. Retrieved 2011-11-27.
The definition of a "clean room" implementation is that the engineers writing the code have no direct exposure to the original, copyrighted material, including code, specifications, and other documentation. That's a problem for Google, as I noted in yesterday's post, because there is substantial evidence that the engineers working on the project had direct access to the copyrighted material.
- ^ "Oracle Sues Google Over Java in Android Devices". digitaltrends.com. 2010-08-13. Retrieved 2011-08-08.
- ^ James Niccolai (2010-08-12). "Oracle sues Google over Java use in Android". Computerworld. Archived from the original on 2023-04-01. Retrieved 2010-08-13.
- ^ Mark Hachman (2010-08-13). "Oracle Sues Google Over Android Java Use". PC Magazine. Ziff Davis.
- ^ Josh Lowensohn (May 23, 2012). "Jury clears Google of infringing on Oracle's patents". ZDNet. Retrieved 2012-05-25.
- ^ Joe Mullin (May 31, 2012). "Google wins crucial API ruling, Oracle's case decimated". Ars Technica. Retrieved 2012-06-01.
- ^ Niccolai, James (June 20, 2012). "Oracle agrees to 'zero' damages in Google lawsuit, eyes appeal". Archived from the original on 2023-04-01. Retrieved 2012-06-23.
- ^
Adam Outler (May 16, 2012). "Update on the Oracle Versus Google Trial". Archived from the original on 2013-05-16. Retrieved 2013-01-18.
A major portion of the Oracle's claims are based on 9 lines of code contained within Java.Util.Arrays.rangeCheck(). Here is the code in question:...
External links
[edit]- Dalvik bytecode – official Android documentation of the instruction set
- Dex Executable format – official Android documentation
- A JIT Compiler for Android's Dalvik VM on YouTube, Google I/O 2010, by Ben Cheng and Bill Buzbee
- Dalvik VM Internals Archived 2010-03-01 at the Wayback Machine, Google I/O 2008, by Dan Bornstein
- The $800 Million Dollar Question: What’s the Difference Between Trademark and Copyright?
Dalvik (software)
View on GrokipediaOverview
Definition and Purpose
Dalvik is a discontinued process virtual machine (VM) designed specifically for executing Android applications, primarily those written in Java and converted from Java bytecode to Dalvik bytecode for optimized runtime performance.[2] This conversion process enables the VM to handle application code in a format tailored to the Android ecosystem, where apps are packaged as Dalvik Executable (DEX) files.[4] The primary purpose of Dalvik was to provide an efficient runtime environment for battery-powered mobile devices constrained by limited memory and CPU resources, facilitating the simultaneous execution of multiple processes from a single operating system instance without excessive overhead.[6] By focusing on low-resource consumption, Dalvik supported the development of resource-efficient applications, allowing multiple VM instances to run concurrently on embedded systems like smartphones.[6] Key features aligned with this purpose include a register-based architecture that minimizes instruction sizes for faster decoding and execution, as well as support for languages like Java—and potentially others such as Scala or Kotlin—through bytecode compilation and interpretation.[6][7] Dalvik was initially created by Dan Bornstein at Google in 2007 and named after the fishing village of Dalvík in Eyjafjörður, Iceland.[7] It has since been replaced by the Android Runtime (ART) as the default VM in modern Android versions.[2]Discontinuation and Legacy
The Android Runtime (ART) was first introduced experimentally in Android 4.4 KitKat in late 2013 as an optional alternative to Dalvik, enabling developers to test ahead-of-time (AOT) compilation for potential performance gains.[8] This preview allowed users to switch between Dalvik and ART, marking the beginning of the transition away from Dalvik's just-in-time (JIT) compilation model. By Android 5.0 Lollipop, released in November 2014, ART became the exclusive runtime, fully replacing Dalvik across the platform.[9] The discontinuation of Dalvik stemmed primarily from ART's advantages in efficiency and resource management. ART's AOT compilation pre-compiles applications into native code at installation time, resulting in faster app startup times, superior overall performance, and reduced battery consumption compared to Dalvik's JIT approach, which compiled bytecode on-the-fly during execution.[2] Additionally, ART incorporated more efficient garbage collection mechanisms, minimizing pauses and lowering memory usage, which addressed key limitations in Dalvik suited for earlier resource-constrained devices.[8] Despite its replacement, Dalvik's legacy endures through the continued use of its bytecode format. Dalvik Executable (.dex) files remain the standard distribution format for Android applications in the Google Play Store and elsewhere, as ART fully supports executing this bytecode via its compatibility mode.[2] This ensures seamless backward compatibility for apps developed under Dalvik without requiring code modifications. As of 2025, Dalvik sees no active deployment on modern Android devices, which exclusively utilize ART for runtime execution. However, it persists in legacy systems running pre-Lollipop Android versions, as well as in emulators simulating older environments and certain embedded or IoT applications based on outdated Android builds.[2]Development History
Origins and Design Goals
Dalvik was developed by Dan Bornstein starting in 2007 as part of the Android project at Google.[10] The virtual machine drew inspiration from research at Trinity College Dublin on register-based architectures for embedded systems, which demonstrated advantages in code density and execution efficiency over traditional stack-based designs.[11] The name Dalvik derives from the fishing village of Dalvík in Eyjafjörður, Iceland, a location tied to one of Bornstein's ancestors.[1] Central design goals centered on minimizing the memory footprint to suit resource-constrained mobile devices, targeting operation with approximately 20 MB of available RAM after accounting for system services.[1] The architecture enabled concurrent application execution through multiple lightweight VM instances per device, allowing resource sharing to avoid the overhead of isolated, full-scale virtual machines for each app.[12] It was also optimized for ARM processors, which were dominant in early mobile hardware due to their power efficiency.[10] Influences included the Java ecosystem for compatibility with familiar development tools, but Dalvik eschewed stack-based virtual machine inefficiencies—such as higher instruction counts—to prioritize a register-based model better suited to low-power, multi-process environments, in contrast to desktop-oriented Java VMs like HotSpot.[1][11] Early prototypes emphasized converting Java bytecode into a compact, device-optimized format to reduce storage needs and improve load times on limited hardware.[4]Key Milestones in Android
Dalvik debuted as the default runtime environment for Android applications with the release of Android 1.0 in September 2008. It served as the process virtual machine optimized for executing bytecode on resource-constrained mobile devices, enabling efficient app execution from the platform's inception.[2] Dalvik was open-sourced under the Apache License 2.0 as part of the Android Open Source Project (AOSP), with initial code contributions dating back to 2005 and full public release in 2008. This licensing facilitated widespread adoption and modification by developers worldwide. A significant enhancement came in Android 2.2 Froyo, released in May 2010, which introduced just-in-time (JIT) compilation to Dalvik, delivering 2-5x performance improvements for CPU-intensive tasks compared to prior versions.[13] Further refinements occurred in Android 4.0 Ice Cream Sandwich, launched in October 2011, where Dalvik adopted indirect JNI references to support advanced garbage collection mechanisms, improving overall system responsiveness and paving the way for future optimizations.[14] Dalvik remained the standard runtime through Android 4.3 Jelly Bean, released in July 2013, powering the platform's core operations without major architectural shifts in that version.[15] By 2014, it supported over a billion Android devices shipped globally, underscoring its scale and reliability during peak usage.[16] Its inclusion in the AOSP enabled extensive community involvement, allowing developers to build custom ROMs and device forks that leveraged Dalvik for tailored Android experiences.[2] The transition to the Android Runtime (ART) began experimentally in Android 4.4 KitKat later in 2013.Technical Architecture
Virtual Machine Design
Dalvik employs a register-based virtual machine architecture, diverging from the stack-based model of traditional Java virtual machines like HotSpot. In this design, each method frame allocates a fixed number of virtual registers—up to 65,536 32-bit registers, though methods typically require no more than 16—to hold operands and intermediate results. This approach enables more compact bytecode, with most instructions encoded in just 16 bits, as register references replace the need to push and pop values from a stack, reducing overhead in interpretation and execution on resource-constrained mobile devices. Registers are untyped and versatile, accommodating integers, floating-point values, object references, or return addresses without explicit type declarations. The process model of Dalvik integrates tightly with the Android operating system's Linux kernel for efficient isolation and startup. Each Android application executes in its own dedicated process, hosting a single instance of the Dalvik VM to ensure sandboxing and prevent interference between apps. Process isolation is enforced by the kernel's standard mechanisms, such as separate address spaces and file descriptor limits, while shared kernel resources like system calls and device drivers are accessed communally. To accelerate app launches, Dalvik leverages the Zygote process, which pre-initializes a base VM instance during system boot, preloading core libraries and runtime components; subsequent app processes are created by forking Zygote, inheriting its warmed-up state via copy-on-write memory sharing, which minimizes initialization time from seconds to milliseconds. Dalvik's instruction set consists of custom opcodes tailored for mobile execution, supporting a range of operations including arithmetic, control flow, and method invocation. For instance, theinvoke-virtual opcode (0x6e) dispatches calls to non-static, non-private virtual methods by resolving the target at runtime based on the object's type. The set handles 32-bit integers natively and extends to 64-bit integers (long) and floating-point types (float and double) using adjacent register pairs for wider values, adhering to IEEE 754 standards for floating-point precision while optimizing for low-power ARM processors common in mobile hardware. These opcodes prioritize efficiency, with type-specific variants (e.g., add-int for integers, add-float for single-precision floats) to avoid unnecessary conversions.
Memory management in Dalvik incorporates optimizations suited to embedded environments, using 32-bit references for classes and objects to align with typical device architectures and limit pointer overhead. Object references occupy a single register, enabling compact data structures without the bloat of 64-bit addressing. Furthermore, Dalvik eschews the full Java standard library in favor of a streamlined Android runtime subset and shared constant pools across classes, which significantly reduce the core library footprint and duplication, easing garbage collection pressures in memory-limited scenarios.
Bytecode Format and Tools
The Dalvik Executable (.dex) format serves as a compact, single-file container for multiple Java classes and their associated data, designed to optimize storage and loading on resource-constrained mobile devices.[4] It employs shared pools for strings, types, and constants to eliminate redundancy across classes, allowing multiple class files to reference the same interned elements efficiently.[4] This structure facilitates optimizations such as method inlining during compilation by providing a unified view of code and metadata.[4] The .dex file begins with a fixed-size header that includes a magic number identifying the file type and version, such asdex\n039\0 for version 039.[4] The header also contains a checksum for integrity verification, a SHA-1 signature, the total file size, and the header size itself (typically 0x70 bytes for standard versions).[4] Following the header are aligned sections for key elements: string_ids for unique UTF-16 strings (sorted and referenced by offset), type_ids for class and type descriptors (limited to 65,535 entries), field_ids for field declarations (sorted by declaring type, name, and field type), method_ids for method prototypes (similarly sorted), and code_item arrays holding the actual bytecode instructions, register counts, and exception handling data.[4] Integers throughout the format use LEB128 variable-length encoding to minimize space for small values.[4]
To generate .dex files, developers use the dx (Dalvik eXchange) tool, which converts one or more Java .class bytecode files—produced by compilers like javac—into the optimized .dex format. The dx tool performs optimizations such as constant propagation, dead code elimination, and register allocation tailored to Dalvik's register-based architecture, merging multiple input files into a single .dex output. Subsequently, the Android Asset Packaging Tool (aapt) incorporates the .dex file along with resources (like layouts, images, and the AndroidManifest.xml) into an APK archive, compressing and aligning contents for distribution.[17]
A key limitation of the .dex format arises from 16-bit indices in certain structures, capping the total number of referenced methods, fields, and types at 65,536 per file, which includes contributions from the app, libraries, and Android framework. To address this for larger applications, multi-dex support was introduced, allowing the dx tool (and later replacements) to split bytecode into multiple .dex files—such as classes.dex, classes2.dex, and so on—packaged within the APK. On Dalvik runtimes (pre-Android 5.0), this requires additional runtime loading via the MultiDex library to extract and register secondary .dex files at startup. Later versions of the format, like the container format in DEX version 41, enable sharing of common data (e.g., strings) across multiple logical .dex files in a single physical container to further reduce redundancy.[4]