Upload
elvis-jon-freddy-sitinjak
View
444
Download
0
Tags:
Embed Size (px)
Citation preview
Android Overview Native code for Android Benchmarking
Developing and Benchmarking Native LinuxApplications on Android
Leonid Batyuk Aubrey-Derrick SchmidtHans-Gunther Schmidt Ahmet Camtepe Sahin Albayrak
DAI-Labor, Technische Universität Berlin
The Second International ICST Conference on MOBILeWireless MiddleWARE, Operating Systems, and
Applications, 2009
Android Overview Native code for Android Benchmarking
Outline
1 Android OverviewWhat is Android?How does it work?The Dalvik VM
2 Native code for AndroidScopeImportant factsTechniques
3 BenchmarkingPerformance issuesBenchmarking set-upResultsConclusions
Android Overview Native code for Android Benchmarking
Outline
1 Android OverviewWhat is Android?How does it work?The Dalvik VM
2 Native code for AndroidScopeImportant factsTechniques
3 BenchmarkingPerformance issuesBenchmarking set-upResultsConclusions
Android Overview Native code for Android Benchmarking
What is Android?
What is Android?
Android is an open-source OS for mobileinternet devicesAndroid is being driven by the Open HandsetAlliance, including Google, HTC, T-Mobile,Samsung, Sony-Ericsson, Motorola andothersAndroid is tageted at, but not limited tosmartphones. It is supposed for all kinds ofmobile devices, including netbooks
Android Overview Native code for Android Benchmarking
How does it work?
How does it work?
Application
Application Framework
Linux kernel
Libraries Dalvik VM
Android comprises of:Linux kernelModified BSD libc (bionic)Stripped-down unixoid userlandCustom object oriented IPC(OpenBinder)Custom Java VM (Dalvik)
Android Overview Native code for Android Benchmarking
How does it work?
Development of Android applications
Manifest file
Localization
GUI layout
GUI styles
Dalvik bytecode
Resources
APK
Developers are intended to createapplications in JavaAn SDK is provided by Google
EmulatorEclipse pluginDebugging utilities
An application is packaged for distribution inan APK file, which contains:
BytecodeManifest file describing the capabilities etc.Various application resources
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 GoogleUses its own bytecode, not Java bytecodeEach application runs in its own VM instancefor security reasonsRegister-based, optimized for small footprintLacks Just-In-Time compilation and othercommon optimizations, therefore notperformant
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 tobecome part of the SDK by the end of the year.
Google says:
[...] C/C++ code [...] easily runs 10-100x faster than doing thesame 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 tobecome part of the SDK by the end of the year.
Google says:
[...] C/C++ code [...] easily runs 10-100x faster than doing thesame thing in a Java loop.
Android Overview Native code for Android Benchmarking
Outline
1 Android OverviewWhat is Android?How does it work?The Dalvik VM
2 Native code for AndroidScopeImportant factsTechniques
3 BenchmarkingPerformance issuesBenchmarking set-upResultsConclusions
Android Overview Native code for Android Benchmarking
Scope
Scope
What is a good reason to use native code?
Speed up heavy computational tasksTime-critical applicationsRunning a daemon outside of the application lifecycle
Out of scope:100% native applications are impossible since the UI runsin DalvikPorting big and powerful software like Snort or MySQL isunfeasible 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 tasksTime-critical applicationsRunning a daemon outside of the application lifecycle
Out of scope:100% native applications are impossible since the UI runsin DalvikPorting big and powerful software like Snort or MySQL isunfeasible due to linking issues
Android Overview Native code for Android Benchmarking
Important facts
Important facts
Manifest file
Localization
GUI layout
GUI styles
Native library
Native binary
Dalvik bytecode
Resources
APK
ToolchainCode Sourcery G++ (G++-like toolchain)Scratchbox (ARM emulation with a toolchain)
Different page alignmentDynamic linking becomes difficultStatic linking preferred for standaloneexecutables
PackagingIf you want a UI, make your native code apart of an APK
Size limitAny raw resource which is packaged insidean APK may not exceed 1Mb
Android Overview Native code for Android Benchmarking
Techniques
Techniques
JNIJava Native Interface
PipesTraditional unixoid IPC via FIFOs
Android Overview Native code for Android Benchmarking
Techniques
JNI
method
method
native method stub
native function
Java
Native
Java class
C library
JNI - Java Native InterfaceWidely accepted in the Java ecosystem(Eclipse, SWT)Widely used in the Android OSimplementationCurrently not supported in the SDK, butplannedRuns in same thread, no process is beingspawned
Android Overview Native code for Android Benchmarking
Techniques
Pipes
method
native method stub
Java I/O
native function
Java
Native
Java class
C library
Native I/O
FIFOFIFO
FIFO - first in, first outWidely used for simple IPC on unixoidsystemsJava uses a named pipe to communicate to astandalone native executableJava I/O is extremely expensive on Androidand thus a bottleneckRuns in its own thread, can be made adaemonThis allows us to avoid the standardapplication lifecycle
Android Overview Native code for Android Benchmarking
Outline
1 Android OverviewWhat is Android?How does it work?The Dalvik VM
2 Native code for AndroidScopeImportant factsTechniques
3 BenchmarkingPerformance issuesBenchmarking set-upResultsConclusions
Android Overview Native code for Android Benchmarking
Performance issues
Performance of the Sun JVM
0 2,000 4,000
0
0.5
1
1.5
Array size
Tim
eel
apse
d[m
s]
Linux x86 PC (for comparison)
Sun JRE 1.6gcc -O3
Android Overview Native code for Android Benchmarking
Performance issues
Performance issues of the Dalvik VM
0 2,000 4,000
0
50
100
Array size
Tim
eel
apse
d[m
s]
Android emulator
Dalvik VMAndroid C
Android Overview Native code for Android Benchmarking
Performance issues
Performance issues of the Dalvik VM
Dalvik performance problemsNo Just-in-Time compilationOptimized for small footprint, not raw performanceJava 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 anduncomplicated benchmarksMeasuring the performance of the basiccomputing operationsNot intended to rate the overall performanceof the systemNot measuring the responsiveness of the UIor the I/O speed
Android Overview Native code for Android Benchmarking
Benchmarking set-up
Benchmark set-up
Heapsort in JavaHeapsort in a daemon which listenes to a FIFOHeapsort in a JNI libraryBuilt-in Java method for sorting arraysBuilt-in Java method for sorting objects (PriorityQueue)Quicksort in Java
Setup on Android and on a Linux PCAndroid: Code Sourcery gcc -O3 vs. Dalvik VMLinux: 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 JavaHeapsort in a daemon which listenes to a FIFOHeapsort in a JNI libraryBuilt-in Java method for sorting arraysBuilt-in Java method for sorting objects (PriorityQueue)Quicksort in Java
Setup on Android and on a Linux PCAndroid: Code Sourcery gcc -O3 vs. Dalvik VMLinux: GNU Compiler Collection gcc -O3 vs. Sun JDK 1.6
Android Overview Native code for Android Benchmarking
Results
Results on Android
0 1,000 2,000 3,000 4,000 5,000
100
101
102
103
Array size
Tim
eel
apse
d[m
s]
Sorting Integers on Android
pipe (using native Linux)
plain Java heapsort (VM)
PriorityQueue (VM)
Java built-in (VM)
JNI (using native Linux)
Android Overview Native code for Android Benchmarking
Results
Results on a Linux system (for comparison)
0 1,000 2,000 3,000 4,000 5,00010−2
10−1
100
101
Array size
Tim
eel
apse
d[m
s]
Sorting Integers on a Linux PC (for comparison)
pipe (using native Linux)
heapsort (VM)
PriorityQueue (VM)
Java built-in (VM)
JNI (using native Linux)
Android Overview Native code for Android Benchmarking
Conclusions
Conclusions for Android
JNI is the fastest approachJNI is up to 10 times faster than plain JavaPipes are unfeasible for data-intensive tasks because ofthe expensive I/OGoogle should optimize Dalvik:
introduce JITimplement computationally complex classpath methodswith JNI
Android Overview Native code for Android Benchmarking
Conclusions
Conclusions for Android
JNI is the fastest approachJNI is up to 10 times faster than plain JavaPipes are unfeasible for data-intensive tasks because ofthe expensive I/OGoogle should optimize Dalvik:
introduce JITimplement computationally complex classpath methodswith JNI
Android Overview Native code for Android Benchmarking
Conclusions
Conclusions for Android
JNI is the fastest approachJNI is up to 10 times faster than plain JavaPipes are unfeasible for data-intensive tasks because ofthe expensive I/OGoogle should optimize Dalvik:
introduce JITimplement computationally complex classpath methodswith JNI
Android Overview Native code for Android Benchmarking
Conclusions
Conclusions for Android
JNI is the fastest approachJNI is up to 10 times faster than plain JavaPipes are unfeasible for data-intensive tasks because ofthe expensive I/OGoogle should optimize Dalvik:
introduce JITimplement computationally complex classpath methodswith JNI
Android Overview Native code for Android Benchmarking
Conclusions
Future work
Port a more common benchmark to Android (maybeLINPACK)Benchmark various handsets as they emerge during 2009Compare performance of Android to other mobile OSes onthe same hardware
Android Overview Native code for Android Benchmarking
Conclusions
Thank you!