A great WordPress.com site

Notes from OnAndroid 2013 Oct conf: Dalvik VM

This talk was all about Dalvik under the hood. The full slides are available in this SpeakerDeck page. The most useful slides in this talk are towards the end – they contain interesting optimization tips while developing code for Android.

Unlike JVM, all classes in Dalvik are compiled into .dex files and packaged into an apk along with res and manifest files. The dex file itself is not compressed though.

Java’s JVM is stack-based whereas Dalvik is register-based. The main upside of being a register-based system is lesser instructions and lesser dispatches to accomplish the same task – no push-pop involved and memory footprint is lesser. See slides for an example of instruction optimization. The downside is that complexity of each instruction increases. Java’s JVM is very efficient for desktop machines.

Dalvik unifies the constants pool (i.e.) lots of symbols (~estimated at ~60%) are duplicated across classes – only 1 copy is stored across these instances.

Dalviks JIT is trace based as opposed to JVM’s method based. Once it figures out a hotspot, it converts it to native and runs the native version from then on.

Zygote is the father of all VM’s. When an app is started, the Zygote is forked, to minimize initial load time. The app’s VM contains a reference to Zygote (with its core libraries) plus the app’s heap + dex files.

Development tip #1: Prefer signalling (Notifications) vs Polling.

Dev tip #2: Minimize work when there is no user, network or sensor input.

Dev tip #3: Monitor the state of the battery. The Android dev site has good tips.