LCU14 100-dalvik is dead long live dalvik
---------------------------------------------------
Speaker: Stuart Monteith
Date: September 15, 2014
---------------------------------------------------
★ Session Summary ★
The Dalvik virtual machine is the crucial part of Android responsible for executing platform independent code in Android apps.The upcoming L release of Android replaces "Dalvik" with a new implementation of the Dalvik virtual machine called the "Android RunTime" (ART). In this session you can learn about ART, Dalvik compatibility, and our experiences assisting with the 64bit porting efforts on AOSP.
---------------------------------------------------
★ Resources ★
Zerista: http://lcu14.zerista.com/event/member/137702
Google Event: https://plus.google.com/u/0/events/c8qejrla7b95okb56apbn89d770
Video: https://www.youtube.com/watch?v=dR0FbB4uJC0&list=UUIVqQKxCyQLJS6xvSmfndLA
Etherpad: http://pad.linaro.org/p/lcu14-100
---------------------------------------------------
★ Event Details ★
Linaro Connect USA - #LCU14
September 15-19th, 2014
Hyatt Regency San Francisco Airport
---------------------------------------------------
http://www.linaro.org
http://connect.linaro.org
5. What is Dalvik™?
▪ Dalvik is a virtual machine
▪ A managed runtime
▪ Interpreter
▪ Executes Java™ class files translated into
Dalvik “dex” bytecode
▪ Exception handling
▪ Object oriented
▪ References rather than pointers
▪ Garbage collection
▪ Concurrency
▪ Platform independence
5
Native
Code
Interpreter
Heap
OS
Bytecode
6. Compiling for Dalvik
*.java
javac
*.class
Development Installation
/data/dalvik-cache/
*.dex *.apk *.odex
6
dx
dexopt
7. Devices
7
Phone `08 Phone `14 Tablet `10 Tablet `14
Relative to Phone in 2008
30
22.5
15
7.5
0
CPU RAM Pixels
8. Dalvik Evolution
▪ Just-In-Time (JIT) Compiler - Android™ 2.2 “Froyo”, May 2010
▪ Concurrent Garbage collection - Android 2.3 “Gingerbread”, December 2010
▪ SMP1 support - Android 3.0 “Honeycomb”, February 2011
8
1 - Symmetric MultiProcessing
9. Tracing JIT
▪ Just-In-Time Compiler
▪ Compiles code at runtime
▪ Only code that is executed is compiled
▪ Only “Hot code” is compiled
▪ Interpreter executes bytecode instruction by instruction
▪ Profiles code
▪ Sends linear sequences of code to JIT
▪ Native code branched to from interpreter
▪ However…
▪ Code produced is not ideal
▪ Still, 5x faster than interpreter alone
9
21. ARM’s AArch64 Porting effort
▪ Model, kernel, bionic and shell below
▪ LCU14-411 From zero to booting Nano-Android
▪ Not just a recompile!
▪ Dalvik™ VM implementation
▪ Portable C interpreter, garbage collection, class loading, JNI
▪ Compressed references
▪ Java™ core libraries - platform/libcore:
▪ java.* classes
▪ int always 32-bit, long always 64-bit
▪ Java: int pointer; ➤ long pointer;!
▪ C: jint pointer; ➤ jlong pointer;!
▪ pointer = (jlong)(void*) nativeStructure;!
▪ Build system
21
22. ARM’s AArch64 Porting effort (2)
▪ Then:
▪ AArch64 assembler interpreter
▪ Slightly before with VIXL
▪ VIXL - library for simulating, assembling and disassembling ARMv8 A64
instructions.
▪ Just-In-Time compiler
▪ The rest of the Android™libraries
▪ End result - Android with only 64-bit binaries
▪ Initially 64-bit Dalvik™ running on host in November 2012
▪ On ARM’s ARMv8 models on command line in February 2013
▪ Then AOSP on models from July 2013
22
23. Dalvik is Dead, Long Live ART!
▪ After porting AOSP to AArch64 - ART came along in October 2013
▪ Not all was lost:
▪ Able to boot AOSP from July 2013 (4.2/4.3) through to 4.4 on Dalvik™ for
AArch64
▪ Demonstrated AOSP on Juno 2014
23
25. ART
▪ Introduced October 2013 as experimental runtime in Android™ 4.4 “KitKat”
▪ First release in Android “L”
▪ Less lag, more performance
▪ Productised through 2014
▪ ART also introduces 64-bit support into Android
▪ ARM contributed compiler backend components from Dalvik for AArch64
▪ + JNI compiler, glue, fixes, performance features/tweaks
25
26. Unchanged
▪ Dalvik™ Virtual Machine
▪ Java™ applications as before
▪ Garbage collection, class loading, object references, all as before
▪ It is not translating programs into C/C++
▪ Native code works as before (Java Native Interface - JNI)
▪ Eclipse + ADT or Android Studio, NDK are essentially unchanged
▪ Targeting the same platform - Android
▪ Debugging
▪ dalvikvm!
▪ Zygote
▪ app_process - Android’s command for starting VMs.
26
27. Changed
▪ Garbage collection + allocation
▪ Parallel, less pauses
▪ C++ Interpreter
▪ Ahead-of-time compilation (AOT)
▪ Support for 64-bit execution
▪ Diagnostics
▪ Stricter JNI
▪ Stricter bytecode verification
27
28. Initialization
▪ No JITing during startup
▪ Compilation time spent at installation
▪ boot.art:
▪ Part of the heap stored on flash
▪ Built as part of firmware image
▪ Pre-initialized VM heap
▪ ~12 MB on AOSP
▪ Zygote as before
▪ Initialize
▪ Wait for binder request to fork new apps
28
29. Threads
▪ Stacks now unified - each thread has one stack each
▪ Original Dalvik™ implementation had separately allocated VM stack
▪ ART has VM, interpreted, compiler and JNI frames all on same stack
▪ Stack characteristics may be different
▪ Stack overflow + null pointer exceptions detected through fault handlers
▪ Trap and handle
▪ Thread local allocation
▪ Threads can allocate objects without getting global heap lock
29
30. Garbage Collection
▪ More pluggable
▪ Provisions in runtime for different GC schemes
▪ Parallel & Concurrent
▪ More threads doing the work
▪ Background collection
▪ More throughput, less responsive
▪ Mark & Sweep, semi-space, large objects, variations
30
31. 64-bit Support
▪ Two Zygotes, one 32-bit , one 64-bit
▪ 64-bit is the default
▪ Files duplicated on flash - 32/64-bit.
▪ Compressed references
▪ 32-bit object references
▪ Mapped within bottom 4 GB of memory
▪ Heap size: 256 MB
▪ Hard-float ABI
▪ Parameters passed in floating-point registers
▪ JNI 64-bit libraries
▪ Apps with 32-bit JNI run by 32-bit Zygote
31
Zygote32 Zygote64
fork()
32 bit App 64 bit App
32-bit App 64-bit App
32. Compiling for ART
*.java
javac
*.class
Development Installation
/data/dalvik-cache/arm!
*.dex *.apk *.odex
32
dx
dex2oat
or!
/data/dalvik-cache/arm64
33. Compilation
▪ Compiler driver
▪ Portable compiler
▪ Sea of nodes IR
▪ Quick compiler
▪ Optimising compiler
▪ More platform independent code
▪ ARM, MIPS & x86 with 64-bit variants
▪ Performed at install time
▪ Compiler compiles with multiple threads in parallel
▪ Good code quality without onerous compile time
33
35. Working on AOSP
▪ Google working in the open with ART in AOSP
▪ ARM, MIPS, Intel & ARM partners contribute
▪ 64-bit porting work has been a proving ground for this approach
▪ Ideas are nice, but code is better
▪ Understand who is doing what
▪ Check, post to the Google groups (see android-platform, etc.)
▪ Important to test on more than just ARM platforms - check MIPS & x86
▪ Frequently unstable: reversions, build system restructuring
▪ Android is big, and components have interdependencies
35
36. Working on AOSP
▪ AOSP’s gerrit has useful features
▪ Use it to track new changes in projects through email
▪ Volume can be high - can filter on git fields
▪ esp. if you are working on a particular feature
▪ Keep a working branch - pull it forward as quickly as possible though
▪ Use and add to the unit tests
▪ art # mma test-art
36
37. Thank You
The trademarks featured in this presentation are registered and/or unregistered trademarks of ARM Limited (or its
subsidiaries) in the EU and/or elsewhere. All rights reserved. Any other marks featured may be trademarks of their
respective owners
37
38. Sessions
▪ Today:
▪ LCU14-104: Everything’s Done! Android™ for 64-bit ARMv8, What’s next?
◦ Next in this room
▪ LCU14-108: Panel: Faster, Better and more Open AOSP Support
◦ 12:10, this room
▪ Wednesday:
▪ LCU14-309: Introducing Android NDK for 64bit ARMv8 SOCs
◦ 12:10 Grand Peninsula A
▪ Thursday:
▪ LCU14-411: From zero to booting Nano-Android with 64bit support
◦ 12:10 Grand Peninsula C
▪ Friday
▪ LCU14-502: Android User-Space Tests: Multimedia codec tests, Status and Open Discussions
◦ 09:15 Grand Peninsula B
38
39. References
▪ Introducing ART: https://source.android.com/devices/tech/dalvik/art.html
▪ ART compatibility: https://developer.android.com/guide/practices/verifying-apps-art.html
▪ Google I/O 2014, The ART Runtime: https://www.youtube.com/watch?v=EBlTzQsUoOw
▪ VIXL: https://github.com/armvixl/vixl
▪ ARM Juno: http://www.arm.com/products/tools/development-boards/versatile-express/
juno-arm-development-platform.php
▪ AOSP Gerrit: https://android-review.googlesource.com/
▪ Linaro's Android team: https://wiki.linaro.org/Platform/Android
▪ Bug Reports: https://source.android.com/source/report-bugs.html
▪ ARM Connected Community: http://community.arm.com/groups/android-community
▪ ARMv8 Reference Manual: http://infocenter.arm.com/help/index.jsp?topic=/
com.arm.doc.ddi0487a.c/index.html
39
40. Notices
!
▪ The Android™ robot is reproduced or modified from work created and shared by Google and
used according to terms described in the Creative Commons 3.0 Attribution License.
40