Android internals 05 - Dalvik VM (rev_1.1)

Post on 12-May-2015

2.919 views 5 download

Tags:

description

Course: Android Internals Lecture 5: Dalvik VM

Transcript of Android internals 05 - Dalvik VM (rev_1.1)

Android internalsEgor ElizarovSPbSU 2012

Egor Elizarov SPbSU 20122

Legal info

Android internals by Egor Elizarov is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

You are free to – copy, distribute, display, and perform the work

– make derivative works Under the following conditions

– Attribution. You must give the original author credit

– Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one

All pictures and trademarks are the property of their respective owners. Use of these trademarks and pictures is subject to owners permissions.

Corrections, suggestions, contributions and translations are welcome!

Egor Elizarov SPbSU 20123

Lecture 5

Dalvik VM

yegor.yelizarov(at)gmail.com

http://vk.com/android_internalsRev: 1.1Last update: 05/30/2012

Egor Elizarov SPbSU 20124

Previous time

Vanilla

Kernel types

Android/Kernel interaction

“Androdized” kernel features

Bionic

Log system

Egor Elizarov SPbSU 20125

Virtual Machines

VM concept was introduced in 1960s in Cambridge

Defined by Popek & Goldberg in 1973 as "an efficient, isolated duplicate of a real machine"

System VM (Whole OS emulation)

Process VM (One program emulation)

Egor Elizarov SPbSU 20126

Virtualization approaches

Paravirtualization

Full virtualization

HW assisted virtualization

Egor Elizarov SPbSU 20127

Process VM types

Register VM

Limited number of registers with addresses

State register

List of instructions

Stack VM

Stack

Reverse Polish notation

Load/Store

Egor Elizarov SPbSU 20128

Dalvik VM

Register based

Designed for low memory requirements

Relying on OS– Memory management

– Thread support

– Process isolation

Egor Elizarov SPbSU 20129

Dalvik VM (2)

Allow multiple VM instances to run once

Supports Java Debug Wire Protocol

Based on Apache Harmony (Open Source Java)

Egor Elizarov SPbSU 201210

Dalvik bytecode

Quite similar to common real architectures

Fixed size frames with particular number of registers (one per method)

32-bit registers

Reach meta information for each method

Egor Elizarov SPbSU 201211

Dalvik bytecode example

Egor Elizarov SPbSU 201212

ARM ASM example

Egor Elizarov SPbSU 201213

Interpreter core

Portable (C)

Fast (C + ASM)

JIT (C + ASM + JIT)

Debug (C + ASM + profiling & single stepping)

Egor Elizarov SPbSU 201214

Just-In-Time

Source: http://dl.google.com/googleio/2010/android-jit-compiler-androids-dalvik-vm.pdf

Egor Elizarov SPbSU 201215

Android application

No single entry point

Activities, Services, Broadcast Receivers, Content Providers

Intents

New VM instance (Copy on write)

Egor Elizarov SPbSU 201216

Dalvik EXecutable

Source: http://stid.googlecode.com/files/2008-05-29-Presentation-Of-Dalvik-VM-Internals.pdf

Egor Elizarov SPbSU 201217

Zygote

Nascent VM process

Starts at boot time

Preloads and preinitializes classes

fork()s on command

Egor Elizarov SPbSU 201218

Java application caching

Egor Elizarov SPbSU 201219

Java application launching

Source: http://coltf.blogspot.com/p/android-os-processes-and-zygote.html

Egor Elizarov SPbSU 201220

Dalvik porting

Core libraries should work from scratch

Implement JNI call bridge

Use portable interpreter

Replace opcode stubs

Use debug execution mode for debugging

Egor Elizarov SPbSU 201221

Next Time

Android IPC

Typical Android subsystem

Egor Elizarov SPbSU 201222

Useful links

http://vk.com/android_internals

K.Sutner. Register Machines. Carnegie Mellon University. Fall 2011 URL: http://www.cs.cmu.edu/~cdm/pdf/RegisterMach-6up.pdf

M.Schoeberl. Design and implementation of an Effective Stack Machine. Viena, Austria. URL: http://ti.tuwien.ac.at/rts/people/schoeberl/publications/stack.pdf

Y. Shi, D. Gregg, A. Beatty, M. A. Ertl. Virtual Machine Showdown: Stack Versus Registers. Dublin, Viena. URL: http://static.usenix.org/events/vee05/full_papers/p153-yunhe.pdf

http://www.dalvikvm.com/

Egor Elizarov SPbSU 201223

Useful links (2)

http://pallergabor.uw.hu/common/understandingdalvikbytecode.pdf

$ANDROID_ROOT/dalvik/docs/

http://s.android.com/tech/dalvik/dalvik-bytecode.html

D. Bornstein. Dalvik VM Internals. 2008 URL: http://stid.googlecode.com/files/2008-05-29-Presentation-Of-Dalvik-VM-Internals.pdf

http://coltf.blogspot.com/p/android-os-processes-and-zygote.html

http://www.google.com/events/io/2010/sessions/jit-compiler-androids-dalvik-vm.html

Egor Elizarov SPbSU 201224

Thanks to

Sergey Matyukevich for review and advices (www.linkedin.com/pub/sergey-matyukevich/31/889/769)

Nikolay F. Fominykh for review and advices

Nikita Shulga for advices and notes (http://www.linkedin.com/pub/nikita-shulga/8/582/287)

Grigory Tolstolytkin for advices and notes (http://www.linkedin.com/pub/grigory-tolstolytkin/2a/b41/74)