Android Overview Native code for Android Benchmarking
Developing and Benchmarking Native Linux Applications on Android
Leonid Batyuk Aubrey-Derrick Schmidt Hans-Gunther Schmidt Ahmet Camtepe Sahin Albayrak
DAI-Labor, Technische Universität Berlin
The Second International ICST Conference on MOBILe Wireless MiddleWARE, Operating Systems, and Applications, 2009 Android Overview Native code for Android Benchmarking
Outline
1 Android Overview What is Android? How does it work? The Dalvik VM
2 Native code for Android Scope Important facts Techniques
3 Benchmarking Performance issues Benchmarking set-up Results Conclusions Android Overview Native code for Android Benchmarking
Outline
1 Android Overview What is Android? How does it work? The Dalvik VM
2 Native code for Android Scope Important facts Techniques
3 Benchmarking Performance issues Benchmarking set-up Results Conclusions Android Overview Native code for Android Benchmarking
What is Android? What is Android?
Android is an open-source OS for mobile internet devices Android is being driven by the Open Handset Alliance, including Google, HTC, T-Mobile, Samsung, Sony-Ericsson, Motorola and others Android is tageted at, but not limited to smartphones. It is supposed for all kinds of mobile devices, including netbooks Android Overview Native code for Android Benchmarking
How does it work? How does it work?
Android comprises of:
Application Linux kernel
Application Framework Modified BSD libc (bionic) Stripped-down unixoid userland Libraries Dalvik VM Custom object oriented IPC Linux kernel (OpenBinder) Custom Java VM (Dalvik) Android Overview Native code for Android Benchmarking
How does it work? Development of Android applications
Developers are intended to create Manifest file applications in Java
Dalvik bytecode An SDK is provided by Google Emulator Eclipse plugin GUI styles Debugging utilities GUI layout An application is packaged for distribution in an APK file, which contains: Localization Bytecode Manifest file describing the capabilities etc. Resources Various application resources APK Distribution is possible, but not restricted to, the Android Market. Android Overview Native code for Android Benchmarking
The Dalvik VM The Dalvik VM
Custom Java VM developed by Google Uses its own bytecode, not Java bytecode Each application runs in its own VM instance for security reasons Register-based, optimized for small footprint Lacks Just-In-Time compilation and other common optimizations, therefore not performant Android Overview Native code for Android Benchmarking
The Dalvik VM
Why not speed-up using native code? Using native code is still not supported, but is expected to become part of the SDK by the end of the year.
Google says: [...] C/C++ code [...] easily runs 10-100x faster than doing the same thing in a Java loop. Android Overview Native code for Android Benchmarking
The Dalvik VM
Why not speed-up using native code? Using native code is still not supported, but is expected to become part of the SDK by the end of the year.
Google says: [...] C/C++ code [...] easily runs 10-100x faster than doing the same thing in a Java loop. Android Overview Native code for Android Benchmarking
Outline
1 Android Overview What is Android? How does it work? The Dalvik VM
2 Native code for Android Scope Important facts Techniques
3 Benchmarking Performance issues Benchmarking set-up Results Conclusions Android Overview Native code for Android Benchmarking
Scope Scope
What is a good reason to use native code? Speed up heavy computational tasks Time-critical applications Running a daemon outside of the application lifecycle
Out of scope: 100% native applications are impossible since the UI runs in Dalvik Porting big and powerful software like Snort or MySQL is unfeasible due to linking issues Android Overview Native code for Android Benchmarking
Scope Scope
What is a good reason to use native code? Speed up heavy computational tasks Time-critical applications Running a daemon outside of the application lifecycle
Out of scope: 100% native applications are impossible since the UI runs in Dalvik Porting big and powerful software like Snort or MySQL is unfeasible due to linking issues Android Overview Native code for Android Benchmarking
Important facts Important facts
Manifest file Toolchain Dalvik bytecode Code Sourcery G++ (G++-like toolchain) Scratchbox (ARM emulation with a toolchain) Native binary Different page alignment Dynamic linking becomes difficult Native library Static linking preferred for standalone GUI styles executables Packaging GUI layout If you want a UI, make your native code a part of an APK Localization Size limit Resources Any raw resource which is packaged inside an APK may not exceed 1Mb APK Android Overview Native code for Android Benchmarking
Techniques Techniques
JNI Java Native Interface
Pipes Traditional unixoid IPC via FIFOs Android Overview Native code for Android Benchmarking
Techniques JNI
Java class JNI - Java Native Interface method Widely accepted in the Java ecosystem method (Eclipse, SWT) native method stub Widely used in the Android OS
Java implementation Native Currently not supported in the SDK, but planned native function Runs in same thread, no process is being C library spawned Android Overview Native code for Android Benchmarking
Techniques Pipes
Java class FIFO - first in, first out method Widely used for simple IPC on unixoid native method stub systems Java uses a named pipe to communicate to a Java I/O Java standalone native executable FIFO FIFO Java I/O is extremely expensive on Android Native and thus a bottleneck Native I/O Runs in its own thread, can be made a daemon native function This allows us to avoid the standard C library application lifecycle Android Overview Native code for Android Benchmarking
Outline
1 Android Overview What is Android? How does it work? The Dalvik VM
2 Native code for Android Scope Important facts Techniques
3 Benchmarking Performance issues Benchmarking set-up Results Conclusions Android Overview Native code for Android Benchmarking
Performance issues Performance of the Sun JVM
Linux x86 PC (for comparison)
1.5
1
0.5 Time elapsed [ms]
Sun JRE 1.6 0 gcc -O3 0 2,000 4,000 Array size Android Overview Native code for Android Benchmarking
Performance issues Performance issues of the Dalvik VM
Android emulator
Dalvik VM Android C
100
50 Time elapsed [ms]
0
0 2,000 4,000 Array size Android Overview Native code for Android Benchmarking
Performance issues Performance issues of the Dalvik VM
Dalvik performance problems No Just-in-Time compilation Optimized for small footprint, not raw performance Java I/O (java.io) and built-in functions relatively slow Android Overview Native code for Android Benchmarking
Benchmarking set-up Microbenchmarking approach
Microbenchmarking focuses on small and uncomplicated benchmarks Measuring the performance of the basic computing operations Not intended to rate the overall performance of the system Not measuring the responsiveness of the UI or the I/O speed Android Overview Native code for Android Benchmarking
Benchmarking set-up Benchmark set-up
Heapsort in Java Heapsort in a daemon which listenes to a FIFO Heapsort in a JNI library Built-in Java method for sorting arrays Built-in Java method for sorting objects (PriorityQueue) Quicksort in Java
Setup on Android and on a Linux PC Android: Code Sourcery gcc -O3 vs. Dalvik VM Linux: GNU Compiler Collection gcc -O3 vs. Sun JDK 1.6 Android Overview Native code for Android Benchmarking
Benchmarking set-up Benchmark set-up
Heapsort in Java Heapsort in a daemon which listenes to a FIFO Heapsort in a JNI library Built-in Java method for sorting arrays Built-in Java method for sorting objects (PriorityQueue) Quicksort in Java
Setup on Android and on a Linux PC Android: Code Sourcery gcc -O3 vs. Dalvik VM Linux: GNU Compiler Collection gcc -O3 vs. Sun JDK 1.6 Android Overview Native code for Android Benchmarking
Results Results on Android
Sorting Integers on Android
103
102
pipe (using native Linux) 101 Time elapsed [ms] plain Java heapsort (VM) PriorityQueue (VM) Java built-in (VM) 0 10 JNI (using native Linux) 0 1,000 2,000 3,000 4,000 5,000 Array size Android Overview Native code for Android Benchmarking
Results Results on a Linux system (for comparison)
Sorting Integers on a Linux PC (for comparison)
101
100
pipe (using native Linux) −1
Time elapsed [ms] 10 heapsort (VM) PriorityQueue (VM) Java built-in (VM) JNI (using native Linux) 10−2 0 1,000 2,000 3,000 4,000 5,000 Array size Android Overview Native code for Android Benchmarking
Conclusions Conclusions for Android
JNI is the fastest approach JNI is up to 10 times faster than plain Java Pipes are unfeasible for data-intensive tasks because of the expensive I/O Google should optimize Dalvik: introduce JIT implement computationally complex classpath methods with JNI Android Overview Native code for Android Benchmarking
Conclusions Conclusions for Android
JNI is the fastest approach JNI is up to 10 times faster than plain Java Pipes are unfeasible for data-intensive tasks because of the expensive I/O Google should optimize Dalvik: introduce JIT implement computationally complex classpath methods with JNI Android Overview Native code for Android Benchmarking
Conclusions Conclusions for Android
JNI is the fastest approach JNI is up to 10 times faster than plain Java Pipes are unfeasible for data-intensive tasks because of the expensive I/O Google should optimize Dalvik: introduce JIT implement computationally complex classpath methods with JNI Android Overview Native code for Android Benchmarking
Conclusions Conclusions for Android
JNI is the fastest approach JNI is up to 10 times faster than plain Java Pipes are unfeasible for data-intensive tasks because of the expensive I/O Google should optimize Dalvik: introduce JIT implement computationally complex classpath methods with JNI Android Overview Native code for Android Benchmarking
Conclusions Future work
Port a more common benchmark to Android (maybe LINPACK) Benchmark various handsets as they emerge during 2009 Compare performance of Android to other mobile OSes on the same hardware Android Overview Native code for Android Benchmarking
Conclusions
Thank you!