Dalvik (software) explained

Dalvik
Author:Dan Bornstein
Operating System:Linux kernel
Platform:Android
Genre:Virtual machine
License:Apache License 2.0
Replaced By:Android Runtime

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]

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

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

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

See main article: Oracle v. Google. Dalvik is published under the terms of the Apache License 2.0.[21] Some 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

External links

Notes and References

  1. Web site: Debugging ART Garbage Collection . The Dalvik runtime is no longer maintained or available [in current versions of Android] and its byte-code format is now used by ART. . 6 October 2015.
  2. http://uke.livejournal.com/25660.html Journal entry
  3. Web site: Google Calling: Inside Android, the gPhone SDK . onlamp.com . 2008-02-05 . 2017-01-10 . https://web.archive.org/web/20170110110729/http://www.onlamp.com/pub/a/onlamp/2007/11/12/google-calling-inside-the-gphone-sdk.html . dead .
  4. Web site: 'ART' experiment in Android KitKat improves battery life and speeds up apps . 2013-11-06 . 2014-07-05 . Sean Buckley . Engadget.
  5. Web site: Experimental Google ART runtime in Android KitKat can bring twice faster app executions . 2013-11-07 . 2014-07-05 . Daniel P. . phonearena.com.
  6. Live Q&A with Dan Bornstein, Creator of the Dalvik VM . YouTube . InfoQ . 29 Sep 2015 .
  7. Google I/O 2008 - Dalvik Virtual Machine Internals . YouTube . Google . 4 Jun 2008 .
  8. 10.1145/858570.858575 . The case for virtual register machines . https://web.archive.org/web/20240201175416/https://www.scss.tcd.ie/David.Gregg/papers/Gregg-SoCP-2005.pdf . 1 Feb 2024 . 8 Jun 2003 . . Davis . Brian . Beatty . Andrew . Casey . Kevin . Gregg . David . T Waldron . John .
  9. Web site: Android SDK Open For Code . https://archive.today/20240131161213/https://www.wired.com/2007/11/android-sdk-ope/ . 31 January 2024 . 12 Nov 2007 . WIRED . Beschizza . Rob.
  10. Web site: Presentation of Dalvik VM Internals. Dan. Bornstein. 2008-05-29. 2010-08-16. PDF. 22. 2017-04-16. https://web.archive.org/web/20170416064828/https://sites.google.com/site/io/dalvik-vm-internals/2008-05-29-Presentation-Of-Dalvik-VM-Internals.pdf?attredirects=0. dead.
  11. Web site: with Android and Dalvik at Google I/O. Rose. John. 2008-05-31. 2008-06-08. https://web.archive.org/web/20080604070631/http://blogs.sun.com/jrose/entry/with_android_and_dalvik_at. 2008-06-04. dead.
  12. Web site: What is Android?. ((Google)). 2009-04-13. 2009-04-19. https://web.archive.org/web/20090627025128/https://developer.android.com/guide/basics/what-is-android.html. 2009-06-27.
  13. Web site: A JIT Compiler for Android's Dalvik VM . May 2010 . March 18, 2015 . Ben Cheng . Bill Buzbee . android-app-developer.co.uk . 5 - 14 . https://web.archive.org/web/20151106221110/http://www.android-app-developer.co.uk/android-app-development-docs/android-jit-compiler-androids-dalvik-vm.pdf . 2015-11-06 . dead .
  14. Web site: Google Android developer explains more about Dalvik and the JIT in Froyo . May 26, 2010 . July 8, 2014 . Phil Nickinson . androidcentral.com . https://web.archive.org/web/20140714171809/http://www.androidcentral.com/google-android-developer-explains-more-about-dalvik-and-jit-froyo . 2014-07-14.
  15. Web site: Nexus One Is Running Android 2.2 Froyo. How Fast Is It Compared To 2.1? Oh, Only About 450% Faster . 2010-05-13 . 2010-05-21.
  16. Web site: Virtual Machine Showdown: Stack Versus Registers. M. Anton . Ertl. Yunhe . Shi. David . Gregg. Andrew . Beatty. 2005-06-11. 2009-12-22.
  17. Web site: Java SE Embedded Performance Versus Android 2.2 . . Bob . Vandette . 2010-11-22 . 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. . 2011-09-04 . https://web.archive.org/web/20110628210207/http://blogs.oracle.com/javaseembedded/entry/how_does_android_22s_performance_stack_up_against_java_se_embedded . 2011-06-28 . dead.
  18. Book: Association for Computing Machinery. Hyeong-Seok Oh . Proceedings of the 10th International Workshop on Java Technologies for Real-time and Embedded Systems - JTRES '12. 115. Beom-Jun Kim . Hyung-Kyu Choi . Soo-Mook Moon . 2012. 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.. 10.1145/2388936.2388956. 9781450316880. 36316611 .
  19. Web site: Top AndEBench Scores . www.eembc.org. 2014-03-23.
  20. Book: 7. 381–392. 2009-04-29. 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.. 10.1007/978-3-642-01802-2_28. Batyuk. Leonid. Schmidt. Aubrey-Derrick. Schmidt. Hans-Gunther. Camtepe. Ahmet. Albayrak. Sahin. MobileWireless Middleware, Operating Systems, and Applications. Developing and Benchmarking Native Linux Applications on Android. Lecture Notes of the Institute for Computer Sciences, Social Informatics and Telecommunications Engineering. 2009mmos.book..381B. 12131309. 978-3-642-01801-5.
  21. Web site: Downloading the Source Tree - Android Open Source . Android.git.kernel.org . 2012-06-07 . dead . https://web.archive.org/web/20090417091524/http://android.git.kernel.org/?p=platform%2Fdalvik.git . 2009-04-17 .
  22. Google and Oracle 'Experts' Clash over Android's Java Mimic. Wired. Garling. Caleb.
  23. Web site: The real history of Java and Android, as told by Google. Ed Bott. ZDNet. 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. . September 8, 2011. 2011-11-27.
  24. Web site: Oracle Sues Google Over Java in Android Devices. digitaltrends.com. 2010-08-13. 2011-08-08.
  25. Web site: Oracle sues Google over Java use in Android. James Niccolai. 2010-08-12. Computerworld. 2010-08-13.
  26. Web site: Oracle Sues Google Over Android Java Use. Mark Hachman. 2010-08-13. PC Magazine. Ziff Davis.
  27. Web site: Jury clears Google of infringing on Oracle's patents . Josh Lowensohn . ZDNet . May 23, 2012 . 2012-05-25.
  28. Web site: Google wins crucial API ruling, Oracle's case decimated. Joe Mullin. Ars Technica. May 31, 2012. 2012-06-01.
  29. Web site: Oracle agrees to 'zero' damages in Google lawsuit, eyes appeal. 2012-06-23. James. Niccolai. June 20, 2012. 2023-04-01. https://web.archive.org/web/20230401114703/https://www.computerworld.com/article/2722368/oracle-agrees-to--zero--damages-in-google-lawsuit--eyes-appeal.html. dead.
  30. Web site: Update on the Oracle Versus Google Trial. 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:.... 2013-01-18. Adam Outler. May 16, 2012. https://web.archive.org/web/20130516201945/http://www.xda-developers.com/android/update-on-the-oracle-versus-google-trial/. 2013-05-16.