31
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

Developing and Benchmarking Native Linux Applications on Android

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Developing and Benchmarking Native Linux Applications on Android

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

Page 2: Developing and Benchmarking Native Linux Applications on Android

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

Page 3: Developing and Benchmarking Native Linux Applications on Android

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

Page 4: Developing and Benchmarking Native Linux Applications on Android

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

Page 5: Developing and Benchmarking Native Linux Applications on Android

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)

Page 6: Developing and Benchmarking Native Linux Applications on Android

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.

Page 7: Developing and Benchmarking Native Linux Applications on Android

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

Page 8: Developing and Benchmarking Native Linux Applications on Android

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.

Page 9: Developing and Benchmarking Native Linux Applications on Android

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.

Page 10: Developing and Benchmarking Native Linux Applications on Android

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

Page 11: Developing and Benchmarking Native Linux Applications on Android

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

Page 12: Developing and Benchmarking Native Linux Applications on Android

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

Page 13: Developing and Benchmarking Native Linux Applications on Android

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

Page 14: Developing and Benchmarking Native Linux Applications on Android

Android Overview Native code for Android Benchmarking

Techniques

Techniques

JNIJava Native Interface

PipesTraditional unixoid IPC via FIFOs

Page 15: Developing and Benchmarking Native Linux Applications on Android

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

Page 16: Developing and Benchmarking Native Linux Applications on Android

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

Page 17: Developing and Benchmarking Native Linux Applications on Android

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

Page 18: Developing and Benchmarking Native Linux Applications on Android

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

Page 19: Developing and Benchmarking Native Linux Applications on Android

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

Page 20: Developing and Benchmarking Native Linux Applications on Android

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

Page 21: Developing and Benchmarking Native Linux Applications on Android

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

Page 22: Developing and Benchmarking Native Linux Applications on Android

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

Page 23: Developing and Benchmarking Native Linux Applications on Android

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

Page 24: Developing and Benchmarking Native Linux Applications on Android

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)

Page 25: Developing and Benchmarking Native Linux Applications on Android

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)

Page 26: Developing and Benchmarking Native Linux Applications on Android

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

Page 27: Developing and Benchmarking Native Linux Applications on Android

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

Page 28: Developing and Benchmarking Native Linux Applications on Android

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

Page 29: Developing and Benchmarking Native Linux Applications on Android

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

Page 30: Developing and Benchmarking Native Linux Applications on Android

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

Page 31: Developing and Benchmarking Native Linux Applications on Android

Android Overview Native code for Android Benchmarking

Conclusions

Thank you!