How applications are run on Android ? Jean-Loup Bogalho & Jrmy - - PowerPoint PPT Presentation

how applications are run on android
SMART_READER_LITE
LIVE PREVIEW

How applications are run on Android ? Jean-Loup Bogalho & Jrmy - - PowerPoint PPT Presentation

How applications are run on Android ? Jean-Loup Bogalho & Jrmy Lefaure clippix@lse.epita.fr blatinox@lse.epita.fr Table of contents 1. Dalvik and ART 2. Executable files 3. Memory management 4. Compilation What is Dalvik ?


slide-1
SLIDE 1

How applications are run

  • n Android ?

Jean-Loup Bogalho & Jérémy Lefaure clippix@lse.epita.fr blatinox@lse.epita.fr

slide-2
SLIDE 2

Table of contents

  • 1. Dalvik and ART
  • 2. Executable files
  • 3. Memory management
  • 4. Compilation
slide-3
SLIDE 3

What is Dalvik ?

  • Android’s Virtual Machine
  • Designed to run on embedded systems
  • Register-based (lower memory consumption)
  • Run Dalvik Executable (.dex) files
slide-4
SLIDE 4

What is ART ?

  • Android RunTime
  • Dalvik’s successor
  • ART Is Not a JVM
  • Huge performance gain thanks to ahead-of-time

(AOT) compilation

  • Available in Android 4.4
slide-5
SLIDE 5

What is ART ?

slide-6
SLIDE 6

Executable files

slide-7
SLIDE 7

Dalvik: .dex files

  • Not the same bytecode as classical Java

bytecode

  • .class files are converted in .dex files at build

time

  • Optimized for minimal memory footprint
slide-8
SLIDE 8

Dalvik: .dex files

slide-9
SLIDE 9

Dalvik: application installation

  • Verification:

○ bytecode check (illegal instructions, valid indices,...) ○ checksum on files

  • Optimization:

○ method inlining ○ byte swapping and padding ○ static linking

slide-10
SLIDE 10

ART: OAT file

  • Generated during installation (dex2oat)
  • ELF format
  • Classes metadata
slide-11
SLIDE 11
slide-12
SLIDE 12

Memory management

slide-13
SLIDE 13

Zygote

  • Daemon started at boot time
  • Loads and initializes core libraries
  • Forks to create new Dalvik instance
  • Startup time of new VM is reduced
  • Memory layouts are shared across processes
slide-14
SLIDE 14

Dalvik: memory management

  • Memory is garbage collected
  • Automatic management avoids programming

errors

  • Objects are not freed as soon as they become

unused

slide-15
SLIDE 15

Dalvik: memory allocation

  • Allocation profiling:

○ allocation count (succeeded or failed) ○ total allocated size (succeeded or failed)

  • malloc function is more complex since memory

is garbage collected

slide-16
SLIDE 16

Dalvik: memory allocation

slide-17
SLIDE 17

Dalvik: memory allocation

slide-18
SLIDE 18

Dalvik: memory allocation

slide-19
SLIDE 19

Dalvik: memory allocation

slide-20
SLIDE 20

Dalvik: memory allocation

slide-21
SLIDE 21

Dalvik: garbage collection

  • Mark and Sweep algorithm

○ depends on the size of the heap ○ collects all garbage

  • Stop the world before Android 2.3
  • Mostly concurrent (2 pauses)
slide-22
SLIDE 22

Mark and Sweep

slide-23
SLIDE 23

Mark and Sweep

Step 1: Mark the roots

slide-24
SLIDE 24

Mark and Sweep

Step 2: Recursively mark reachable objects

slide-25
SLIDE 25

Mark and Sweep

Step 3: Sweep unmarked objects

slide-26
SLIDE 26

ART: garbage collectors

  • GC faster
  • Less fragmentation: moving collectors
  • Concurrent, only one pause
slide-27
SLIDE 27

ART: Rosalloc

  • new allocator()
  • Scales better for multithreaded applications
slide-28
SLIDE 28

ART: Rosalloc

slide-29
SLIDE 29

JIT and AOT compilation

slide-30
SLIDE 30

JIT and AOT compilation

  • Vocabulary:

○ Just In Time compilation ○ Ahead Of Time compilation ○ Hot code / Cold code ○ Granularity

  • Purpose

○ Better performance

slide-31
SLIDE 31

JIT and AOT compilation

  • Granularity

○ Bigger: ■ Performance (optimizations) ■ Less context switches, synchronizations ■ Less re-usability ○ Smaller: ■ The opposite

slide-32
SLIDE 32

JIT and AOT compilation

  • When should we compile?

○ When you can accept latencies ○ Later compilation allows more optimizations ○ Coarse grained: ■ Installation ■ Launching ■ Execution (1 more thread to run)

slide-33
SLIDE 33

JIT and AOT compilation

  • Drawbacks:

○ CPU time (compilation) ○ Memory (results of compilation, tables) ○ Mostly: time

slide-34
SLIDE 34

Dalvik: JIT compilation

  • Operate on traces (~100 instructions)
  • During program’s execution
  • Why:

○ Hottest portions are compiled ○ Small translation cache ○ Performance boost is early perceived ○ Ignore jumps and method calls ○ Good trade-off between speed and memory

slide-35
SLIDE 35

Dalvik: JIT compilation

  • One thread by Java application

○ Shared between every threads ○ Not shared between processes ○ Use private pages

  • Re-done at every run of the application
  • Several target architectures

○ ARM, MIPS, x86 ○ Values and code generation that differs (performance,

instructions set)

slide-36
SLIDE 36

Dalvik: JIT compilation

  • Stages:

○ Profile traces ○ Trace is considered hot: ■ Compiled version ?

  • Yes: use it
  • No: ask for a compilation

○ Repeat

  • Compilation:

○ Task queue full => flush or block every other threads

slide-37
SLIDE 37
slide-38
SLIDE 38

Dalvik: Tuning and debugging

  • Debug options enables:

○ Statistics ○ Debug information

  • Types of profiling:

○ Continuous polling ○ periodic polling (user defined)

slide-39
SLIDE 39

Dalvik: Tuning and debugging

  • Statistics:

○ Traces ○ Compiled traces ○ Calls to compiler ○ Number of traces profiled ○ Number of chained translated blocks ○ Time spent in compilation ○ Time during which the GC was blocked

slide-40
SLIDE 40

Dalvik: Tuning and debugging

  • Tunning:

○ Size of translation cache ○ Threshold to compile a trace ○ Maximal length of a trace ○ Layers and filters for hotness

  • Debugging:

○ Comparison of the results of interpreted and compiled

versions

slide-41
SLIDE 41

ART: AOT compilation

  • Compile at install-time
  • Use llvm
slide-42
SLIDE 42

ART: AOT compilation

  • Stages (dex2oat):

○ Resolution ○ Verification ○ Initialisation ○ Compilation

slide-43
SLIDE 43

Conclusion

  • http://blog.lse.epita.fr
  • #lse on rezosup
  • blatinox@lse.epita.fr
  • clippix@lse.epita.fr
slide-44
SLIDE 44

QUESTIONS?