Dalvik (software)

Last updated
Dalvik
Original author(s) Dan Bornstein
Repository
Operating system Linux kernel
Platform Android
Successor Android Runtime
Type Virtual machine
License Apache License 2.0
Website source.android.com/devices/tech/dalvik/index.html

Dalvik 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]

Contents

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

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

A comparison of Dalvik and ART architectures ART view.png
A comparison of Dalvik and ART architectures

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]

According to Google, the design of Dalvik permits a device to run multiple instances of the VM efficiently. [12]

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. [13] [14] [15]

Performance

A Dalvik-powered phone Motorola RAZR XT910.jpg
A Dalvik-powered phone

The relative merits of stack machines versus register-based approaches are a subject of ongoing debate. [16]

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). [17] 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. [18]

Furthermore, as of March 2014, 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. [19] [ 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. [20]

Licensing and patents

Dalvik is published under the terms of the Apache License 2.0. [21] 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. [22] Oracle and some reviewers dispute this. [23]

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. [24] [25] [26] 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. [27] [28] The parties agreed to zero dollars in statutory damages for 9 lines of copied code. [29] [30]

See also

Related Research Articles

<span class="mw-page-title-main">Java (programming language)</span> Object-oriented programming language

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need to recompile. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities that are typically not available in traditional compiled languages.

<span class="mw-page-title-main">Java virtual machine</span> Virtual machine that runs Java programs

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.

<span class="mw-page-title-main">Interpreter (computing)</span> Program that executes source code without a separate compilation step

In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:

  1. Parse the source code and perform its behavior directly;
  2. Translate source code into some efficient intermediate representation or object code and immediately execute that;
  3. Explicitly execute stored precompiled bytecode made by a compiler and matched with the interpreter's virtual machine.

A computing platform, digital platform, or software platform is the infrastructure on which software is executed. While the individual components of a computing platform may be obfuscated under layers of abstraction, the summation of the required components comprise the computing platform.

Bytecode is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references that encode the result of compiler parsing and performing semantic analysis of things like type, scope, and nesting depths of program objects.

In computing, just-in-time (JIT) compilation is compilation during execution of a program rather than before execution. This may consist of source code translation but is more commonly bytecode translation to machine code, which is then executed directly. A system implementing a JIT compiler typically continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation or recompilation would outweigh the overhead of compiling that code.

HotSpot, released as Java HotSpot Performance Engine, is a Java virtual machine for desktop and server computers, developed by Sun Microsystems which was purchased by and became a division of Oracle Corporation in 2010. Its features improved performance via methods such as just-in-time compilation and adaptive optimization. It is the de facto Java Virtual Machine, serving as the reference implementation of the Java programming language.

Java Card is a software technology that allows Java-based applications (applets) to be run securely on smart cards and more generally on similar secure small memory footprint devices which are called "secure elements" (SE). Today, a secure element is not limited to its smart cards and other removable cryptographic tokens form factors; embedded SEs soldered onto a device board and new security designs embedded into general purpose chips are also widely used. Java Card addresses this hardware fragmentation and specificities while retaining code portability brought forward by Java.

Jazelle DBX is an extension that allows some ARM processors to execute Java bytecode in hardware as a third execution state alongside the existing ARM and Thumb modes. Jazelle functionality was specified in the ARMv5TEJ architecture and the first processor with Jazelle technology was the ARM926EJ-S. Jazelle is denoted by a "J" appended to the CPU name, except for post-v5 cores where it is required for architecture conformance.

<span class="mw-page-title-main">Java (software platform)</span> Set of computer software and specifications

Java is a set of computer software and specifications that provides a software platform for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers. Java applets, which are less common than standalone Java applications, were commonly run in secure, sandboxed environments to provide many features of native applications through being embedded in HTML pages.

Dalvik Turbo was created as a proprietary compatibility layer alternative to Google's implementation of the Dalvik virtual machine that runs on the Android operating system and other platforms. It was originally developed by French/Swiss firm Myriad Group. Dalvik Turbo has an alternative version which runs on non-Android platforms, Sailfish OS, which is known as Alien Dalvik.

This article compares the application programming interfaces (APIs) and virtual machines (VMs) of the programming language Java and operating system Android.

<span class="mw-page-title-main">Dalvík</span> Town and Municipality in Northeast Constituency, Iceland

Dalvík is the main village of the Icelandic municipality of Dalvíkurbyggð. Its population is approximately 1,400.

Tracing just-in-time compilation is a technique used by virtual machines to optimize the execution of a program at runtime. This is done by recording a linear sequence of frequently executed operations, compiling them to native machine code and executing them. This is opposed to traditional just-in-time (JIT) compilers that work on a per-method basis.

Java bytecode is the instruction set of the Java virtual machine (JVM), the language to which Java and other JVM-compatible source code is compiled. Each instruction is represented by a single byte, hence the name bytecode, making it a compact form of data.

<span class="mw-page-title-main">GraalVM</span> Virtual machine software

GraalVM is a Java Development Kit (JDK) written in Java. The open-source distribution of GraalVM is based on OpenJDK, and the enterprise distribution is based on Oracle JDK. As well as just-in-time (JIT) compilation, GraalVM can compile a Java application ahead of time. This allows for faster initialization, greater runtime performance, and decreased resource consumption, but the resulting executable can only run on the platform it was compiled for.

Android Runtime (ART) is an application runtime environment used by the Android operating system. Replacing Dalvik, the process virtual machine originally used by Android, ART performs the translation of the application's bytecode into native instructions that are later executed by the device's runtime environment.

<span class="mw-page-title-main">WebAssembly</span> Cross-platform assembly language and bytecode designed for execution in web browsers

WebAssembly (Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating communication between such programs and their host environment.

References

  1. "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.
  2. Journal entry referencing the source of the name
  3. "Google Calling: Inside Android, the gPhone SDK". onlamp.com. Archived from the original on 2017-01-10. Retrieved 2008-02-05.
  4. Sean Buckley (2013-11-06). "'ART' experiment in Android KitKat improves battery life and speeds up apps". Engadget . Retrieved 2014-07-05.
  5. Daniel P. (2013-11-07). "Experimental Google ART runtime in Android KitKat can bring twice faster app executions". phonearena.com. Retrieved 2014-07-05.
  6. 1 2 Live Q&A with Dan Bornstein, Creator of the Dalvik VM. InfoQ. 29 Sep 2015 via YouTube.
  7. Google I/O 2008 - Dalvik Virtual Machine Internals. Google. 4 Jun 2008 via YouTube.
  8. Davis, Brian; Beatty, Andrew; Casey, Kevin; Gregg, David; T Waldron, John (8 Jun 2003). "The case for virtual register machines" (PDF). Association for Computing Machinery : 41–49. doi:10.1145/858570.858575. ISBN   1-58113-655-2. Archived from the original (PDF) on 1 Feb 2024.
  9. Beschizza, Rob (12 Nov 2007). "Android SDK Open For Code". WIRED. Archived from the original on 31 January 2024.
  10. 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.
  11. 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.
  12. Google (2009-04-13). "What is Android?". Archived from the original on 2009-06-27. Retrieved 2009-04-19.
  13. 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.
  14. 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.
  15. "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.
  16. Shi, Yunhe; Gregg, David; Beatty, Andrew; Ertl, M. Anton (2005-06-11). "Virtual Machine Showdown: Stack Versus Registers" (PDF). Retrieved 2009-12-22.
  17. 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.
  18. 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.
  19. "Top AndEBench Scores". www.eembc.org. Retrieved 2014-03-23.
  20. 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.
  21. "Downloading the Source Tree - Android Open Source". Android.git.kernel.org. Archived from the original on 2009-04-17. Retrieved 2012-06-07.
  22. Garling, Caleb. "Google and Oracle 'Experts' Clash over Android's Java Mimic". Wired.
  23. 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.
  24. "Oracle Sues Google Over Java in Android Devices". digitaltrends.com. 2010-08-13. Retrieved 2011-08-08.
  25. James Niccolai (2010-08-12). "Oracle sues Google over Java use in Android". Computerworld . Retrieved 2010-08-13.
  26. Mark Hachman (2010-08-13). "Oracle Sues Google Over Android Java Use". PC Magazine . Ziff Davis.
  27. Josh Lowensohn (May 23, 2012). "Jury clears Google of infringing on Oracle's patents". ZDNet. Retrieved 2012-05-25.
  28. Joe Mullin (May 31, 2012). "Google wins crucial API ruling, Oracle's case decimated". Ars Technica. Retrieved 2012-06-01.
  29. 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.
  30. 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:...