Android Internals and the Dalvik VM!

Similar documents
Dalvik VM Internals. Dan Bornstein Google

Another difference is that the kernel includes only the suspend to memory mechanism, and not the suspend to hard disk, which is used on PCs.

Improving Java Code Performance. Make your Java/Dalvik VM happier

Lecture 1 - Introduction to Android

Android Overview. Most of the material in this section comes from

Android App Development. Muhammad Sharjeel COMSATS Institute of Information Technology, Lahore

Introduction. Lecture 1. Operating Systems Practical. 5 October 2016

An Introduction to Android. Jason Chen Developer Advocate Google I/O 2008

Lecture 1 Introduction to Android. App Development for Mobile Devices. App Development for Mobile Devices. Announcement.

Improving Java Performance

SHWETANK KUMAR GUPTA Only For Education Purpose

IJRDTM Kailash ISBN No Vol.17 Issue

Mobile and Ubiquitous Computing: Android Programming (part 1)

Android App Development

Android. (XKE Mars 2009) Erwan Alliaume.

Introduction to Android

CS260 Intro to Java & Android 04.Android Intro

Operating System Services. User Services. System Operation Services. User Operating System Interface - CLI. A View of Operating System Services

Introduction To Android

Introduction to Android

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

Android: Under the Hood. GDG-SG DevFest 5th Nov 2016 Jason Zaman

Android Fundamentals - Part 1

Infrastructure Middleware (Part 3): Android Runtime Core & Native Libraries

Android Ecosystem and. Revised v4presenter. What s New

H.-S. Oh, B.-J. Kim, H.-K. Choi, S.-M. Moon. School of Electrical Engineering and Computer Science Seoul National University, Korea

Programming with Android: System Architecture. Luca Bedogni. Dipartimento di Scienze dell Informazione Università di Bologna

Security Philosophy. Humans have difficulty understanding risk

ATC Android Application Development

Lecture 3 Android Internals

Introduction to Android Android Smartphone Programming. Outline University of Freiburg. What is Android? Background University of Freiburg.

Android Development Tutorial. Yi Huang

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Applications Mobiles et Internet des Objets Introduction a l architecture d Android

DROID. By S.Gokulakrishnan AP/CSE SCSVMV

Lecture 08. Android Permissions Demystified. Adrienne Porter Felt, Erika Chin, Steve Hanna, Dawn Song, David Wagner. Operating Systems Practical

Mobile Computing. Introduction to Android

PAPER ON ANDROID ESWAR COLLEGE OF ENGINEERING SUBMITTED BY:

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Just In Time Compilation

ios vs Android By: Group 2

ANDROID NATIVE APP: INTRODUCTION TO ANDROID. Roberto Beraldi

Chapter 1 Hello, Android

Android Internals. Lecture 1. Android and Low-level Optimizations Summer School. 13 July 2015

Japan Linux Symposium Daisuke Numaguchi Tetsuo Handa Giuseppe La Tona NTT DATA CORPORATION

Android Software Development Kit (Part I)

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

Android Overview. Francesco Mercaldo, PhD

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015


A Framework for Evaluating Mobile App Repackaging Detection Algorithms

UNIT:2 Introduction to Android

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

Chapter 2. Operating-System Structures

Android System Development Training 4-day session

Android App Development. Ahmad Tayeb

Developer s overview of the Android platform

Android on Tizen. Moscow State University

Chapter 2: Operating-System Structures

Course Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion

Android framework. How to use it and extend it

Mobile and Wireless Systems Programming

Four Components of a Computer System

CSCE 314 Programming Languages

COLLEGE OF ENGINEERING, NASHIK-4

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Kernel hacking su Android. Better Embedded Andrea Righi

Android Application Development Course Code: AND-401 Version 7 Duration: 05 days

Mobile OS. Symbian. BlackBerry. ios. Window mobile. Android

Introduction to Android

Mobile Application Development - Android

Android - open source mobile platform

2 Lecture Embedded System Security A.-R. Darmstadt, Android Security Extensions

Libraries are wri4en in C/C++ and compiled for the par>cular hardware.

SD Module- Android Programming

ID: Sample Name: YNtbLvNHuo Cookbook: defaultandroidfilecookbook.jbs Time: 14:44:34 Date: 12/01/2018 Version:

EMBEDDED SYSTEMS PROGRAMMING Application Basics

High-Level Language VMs

Android Internals. Lecture 3. Operating Systems Practical. 19 October 2016

Introduction to Dalvik VM. Kim Seongjin Sangji Univ.

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler

JVML Instruction Set. How to get more than 256 local variables! Method Calls. Example. Method Calls

Android Programming in Bluetooth Cochlea Group

Oak Intermediate Bytecodes

Minds-on: Android. Session 1

Architectural Support for Operating Systems. Jinkyu Jeong ( Computer Systems Laboratory Sungkyunkwan University

Lecture Embedded System Security

Abstract. 1. Introduction

Android OS and Power Architecture

Renderscript. Lecture May Android Native Development Kit. NDK Renderscript, Lecture 10 1/41

Portable Resource Control in Java The J-SEAL2 Approach

Compiler construction 2009

ITG Software Engineering

Introduction to Android Application Development. Mike Kvintus Principal Engineer JDSU

Developing Mobile Applications

Structure of OS. After knowing a bit of OS Review of different computing environment

BCA 6. Question Bank

android application development CONTENTS 1.1 INTRODUCTION TO O ANDROID OPERATING SYSTEM... TURES Understanding the Android Software Stack...

Transcription:

Android Internals and the Dalvik VM! Adam Champion, Andy Pyles, Boxuan Gu! Derived in part from presentations by Patrick Brady, Dan Bornstein, and Dan Morrill from Google (http://source.android.com/documentation)!

Introduction! Android internals (e.g., Linux kernel, libraries, etc.)! Dalvik Virtual Machine! Android application framework!

How everything fits together!

Android Internals - Linux Kernel! Android runs on the Linux 2.6.27 kernel -- but Android is not Linux!! o No GNU libc (discussed on next slide)! o No windowing system! Android extends Linux with custom IPC framework (Binder) and aggressive power management! o Binder is Google's lightweight IPC driver that uses shared memory for high performance, synch. process calls to maintain single-process programming model! o (Linux) Power management: shuts down CPU/screen to save battery power unless app requests that either CPU or both CPU and display stay on (wake locks)!

Android Internals - Native Libraries! Android uses these C/C++ libraries (among others):! o Bionic, Google's libc implementation optimized for embedded software platforms (BSD license)! o WebKit open-source browser engine (powers Safari)! o SQLite relational data store (stores all persistent data)! o Media framework (supports many A/V codecs)! o SurfaceFlinger graphics compositor to framebuffer! o AudioFlinger audio "compositor" to earpiece/headset/...! All these libraries sit atop the Hardware Abstraction Layer (HAL), where handset manufacturers provide native code for graphics, audio, GPS, etc.! o The HAL runs in user space, not kernel space! o Copes with non-standard interface specs, IP issues!

Android Internals - Runtime! Android's runtime runs atop these libraries. Comprises Dalvik VM and core libraries exposed via Java (JNI)! o Dalvik VM designed for!! App portability on different hardware implementations!! CPU/memory efficiency! o All Android apps run atop Dalvik! o Core libraries provide standard Java API for app developers, e.g.,!! Data structure!! File & network access!! Graphics! o They "plug in" to Dalvik!

Application Framework Terminology (1)! Android PacKage (APK) is a collection of components! o The APK file is a Zip file that contains source code files, resources (e.g., images, GUI layouts), etc.! o Components share databases, file space, prefs, etc.! o Each APK has an associated Linux process with a unique UID! o There's usually 1 thread per process! Terminology: Apps are characterized by Activities, Tasks, and Processes! o An Activity is a discrete chunk of functionality (concrete class that encapsulates some operation)! o A Task contains one or more Activities (a.k.a. an app)! o A Process is a Linux process!

Application Framework Terminology (2)! A process for a UID is launched "as needed"! o Binding to a Service or ContentProvider! o Launching an Activity! o Firing an IntentReceiver! Process runs until Android kills it to save memory! Each Activity has a managed lifecycle! o Started when requested! o Can lose focus or visibility if, e.g., a dialog box pops up, user launches another app! o Android nondeterministically kills Activity to free up memory!

Activity life cycle!

Android Application Security! As previously mentioned, each application has its own UID.! By default, an application has zero permissions. Must explicitly declare permissions in AndroidManifest.xml file! For instance, an app that monitors incoming SMS messages must put the following in that file:!! <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.app..." > <uses-permission android:name="android.permission.receive_sms" /> </manifest> #! Each app must also be signed with a certificate for which the developer has the private key.!

Dalvik VM Overview! Motivation: VM must run with low memory, limited CPU power, no swap space, and while powered by a battery! While the Android SDK uses Java code, Java bytecode (.class files) and JAR archives are slightly bloated! Dalvik uses Dalvik EXecutable (.dex) custom bytecode to compress bytecode constants & data efficiently! Strategy: "Zygote" process launches at boot, maximizes shared memory! o Minimizes use of "dirty" heap memory by creating heap at boot, using shared memory as much as possible! o Zygote preloads common Android classes, libraries! o It listens for new processes and fork()s on demand! Garbage Collection - mark bits separated from object data!

Overview of Dalvik VM Compilation and Interpretation!

Dex overview! public static long sumarray(int[] arr) # { long sum = 0; # for (int i : arr) # { sum += i; }# return sum; }# #

.class bytecode output!! 25 bytes, 45 reads, 16 writes!! 0000: lconst_0# 0001: lstore_1 0002: aload_0 0003: astore_3 0004: aload_3 0005: arraylength# 0006: istore 04 0008: iconst_0# 0009: istore 05 000b: iload 05 // rl ws 000d: iload 04 // rl ws 000f: if_icmpge 0024 // rs rs 0012: aload_3 // rl ws 0013: iload 05 // rl ws 0015: iaload // rs rs ws 0016: istore 06 // rs wl 0018: lload_1 // rl rl ws 0019: iload 06 // rl ws# 001b: i2l // rs ws ws 001c: ladd // rs rs rs rs ws ws 001d: lstore_1 // rs rs wl wl // ws = write stack 001e: iinc 05, #+01 // rl wl 0021: goto 000b // rl = read local // wl = write local 0024: lload_1 0025: lreturn#

.dex bytecode output!! 18 bytes, 19 reads, 6 writes!! 0000: const-wide/16 v0, #long 0 0002: array-length v2, v8 0003: const/4 v3, #int 0 # 0004: move v7, v3 0005: move-wide v3, v0 0006: move v0, v7 0007: if-ge v0, v2, 0010 0009: aget v1, v8, v0 000b: int-to-long v5, v1 000c: add-long/2addr v3, v5 000d: add-int/lit8 v0, v0, #int 1 000f: goto 0007 0010: return-wide v3# #

Questions & Comments?!!! Thank you!!