New Android Runtime, ART란 무엇인가?
Download
Report
Transcript New Android Runtime, ART란 무엇인가?
제14회 칸드로이드 기술 세미나 (2014.10.24.금)
New Android Runtime, ART
•
Android Developer Backstage Podcast
Episode 10, 11에 대한 분석이 갖는 의미(1시간)
•
New Android Runtime, ART란 무엇인가? (2시간)
•
ART Memory Management 상세(2시간)
•
함께 논의하기(1시간)
양정수(kandroid 운영자) & 이경민(LG전자)
www.kandroid.org
Android Developer Backstage Podcast
Episode 10, 11에 대한 분석이 갖는 의미 (1시간)
-
등장인물 3+1, 이들은 누구인가?
우리는 이들의 이야기를 어떻게 분석했는가?
이들은 어떤 이야기를 나누었는가?
이들이 나눈 이야기의 핵심 키워드 또는 주제는 무엇인가?
• "Reusing the feature, the language“
• "GC Ergonomics“
등장인물 3+1, 이들은 누구인가?
Tor Norbye
Xavier
Ducrohet
Episode 10-11 : ART, Part 1-2
Android Developer Backstage Ep 10 ART, pART 1.mp3
Android Developer Backstage Ep 11 ART, pART 2 (Trash Talk).mp3
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
39:00
46:51
3
Andrew Jeon
Austin Robison
Brahim Elbouchikhi
Chris Nesladek
Daniel Lehmann
Eddy Talvala
Gabriel Peal
Ian Lewis
Jason Bayer
Joe Onorato
Kirill Grouchnikov
Magnus Hyttsten
Michael Mahemoff
Nathan Streu
Patrick Brady
Raph Levien
Robert Kroeger
Taddeo Zacchini
Tony Chan
Wayne Pan
Andrew Stadler
Dave Sparks
Justin Mattson
Nick Pelly
Dan Morrill
Rachel Garb
Tor Norbye
Romain Guy
Google I/O 발표횟수
12
10
8
6
4
Google I/O 발표횟수
2
0
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
4
Google I/O 발표횟수 (상위 8명)
12
10
8
6
Google I/O 발표횟수
4
2
0
Romain
Xavier
Chet
Guy
Ducrohet
Haase
Reto Meier Dan Galpin
Adam
Tor
Powell
Norbye
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
5
Romain
Romain
Romain
Romain
Romain
Romain
Romain
Romain
Romain
Romain
Romain
Chet
Chet
Chet
Chet
Chet
Chet
Chet
Chet
Chet
Chet
Guy
Guy
Guy
Guy
Guy
Guy
Guy
Guy
Guy
Guy
Guy
Haase
Haase
Haase
Haase
Haase
Haase
Haase
Haase
Haase
Haase
2009 Turbo-charge your UI: How to Make your Android UI Fast and Efficient
2010 The world of ListView
2011 Accelerated Android Rendering
2011 Honeycomb Highlights
2012 What's New in Android?
2012 For Butter or Worse: Smoothing Out Performance in Android UIs
2013 Writing Custom Views for Android
2013 Android Graphics Performance
2013 A Moving Experience
2013 Fireside Chat with the Android Team
2014 Material witness: How Android material applications work
2011 Accelerated Android Rendering
2011 Honeycomb Highlights
2012 What's New in Android?
2012 For Butter or Worse: Smoothing Out Performance in Android UIs
2013 Android Graphics Performance
2013 A Moving Experience
2014 What's new in Android
2014 Android fireside chat
2014 Material science: Developing Android applications with material design
2014 Material witness: How Android material applications work
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
6
Xavier
Xavier
Xavier
Xavier
Xavier
Xavier
Xavier
Xavier
Xavier
Xavier
Tor
Tor
Tor
Tor
Tor
Ducrohet
Ducrohet
Ducrohet
Ducrohet
Ducrohet
Ducrohet
Ducrohet
Ducrohet
Ducrohet
Ducrohet
Norbye
Norbye
Norbye
Norbye
Norbye
2011 Android + App Engine: A Developer's Dream Combination
2011 Android Development Tools
2011 Fireside Chat with the Android Team
2012 Android Fireside Chat
2012 What's New in Android Developers’ Tools
2013 What's New in Android Developer Tools
2013 Fireside Chat with the Android Team
2013 The New Android SDK Build System
2014 Android fireside chat
2014 What’s new in Android development tools
2011 Android Development Tools
2012 What's New in Android Developers’ Tools
2012 So You've Read the Design Guide; Now What?
2013 What's New in Android Developer Tools
2014 What’s new in Android development tools
Xavier
Ducrohet
Tor Norbye
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
7
Anwar Ghuloum
2014 The ART runtime
Brian Carlstrom
2014 The ART runtime
Ian Rogers
2014 The ART runtime
Bill Buzbee
2010 A JIT Compiler for Android's Dalvik VM
Ben Cheng
2010 A JIT Compiler for Android's Dalvik VM
Dan Bornstein
Dan Bornstein
2008 Dalvik VM Internals
2011 Fireside Chat with the Android Team
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
8
우리는 이들의 이야기를 어떻게 분석했는
가?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
9
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
10
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
11
이들은 어떤 이야기를 나누었는가?
ART 1
들어가며 : 패널소개/ 주제소개
ART 관련 이슈 및 해결방안
ART 도입 이유
ART의 장점
Dalvikism vs. ARTism
1. Micro Optimization
2. Language Features
6. AOT 성능
1.
2.
3.
4.
5.
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
12
이들은 어떤 이야기를 나누었는가?
ART 2
1.
2.
3.
4.
소개
GC
Tools
Wrap up
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
13
이들이 나눈 이야기의 핵심 키워드 또는 주제는 무엇인가?
•
“Reusing the feature, the language”
•
“GC Ergonomics”
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
14
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
15
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
16
Android New Runtime, ART란 무엇인가? (2시간)
-
Dalvik VM 관련 기술 History : Dalvik Interpreter, JIT an AOT
• Dalvik Interpreter, JIT, AOT 101
• Why a new runtime (ART), not evolving the old one (Dalvik)?
-
ART Workflow
• ART AOT 구현 : Compiler, OAT 포맷, Loader 및 Execution
• 기타 도구 및 디버깅 환경 연동 구조
-
ART
•
•
•
•
-
Dalvik과 ART의 핵심적인 구조의 차이는?
Runtime
아키텍처 지원
메모리 관리(allocator and collector)
인터프리터(Interpreter)
외부 도구와의 인터페이스
안드로이드 런타임 초기 모습 : Fast Interpreter – Register 기반 VM
public static long sumArray(int[] arr) {
long sum = 0;
For (int i : arr) {
sum += i;
}
return sum;
}
※ Stack, Accumulator, Register machine
Stack machine : 0-operand instruction set
Accumulator machine : 1-operand …
Register machine : 2 or 3-operand …
Java VM(JVM) bytecode
000b:
000d:
000f:
0012:
0013:
0015:
0016:
0018:
0019:
001b:
001c:
001d:
001e:
0021:
iload 05
iload 04
if_icmpge 0024
aload_3
iload 05
iaload
istore 06
lload_1
iload 06
i2l
ladd
lstore_1
iinc 05, #+01
goto 000b
Items
JVM
DVM
bytes
25
18
dispatches
14
6
reads
45
19
writes
16
6
Dalvik VM(DVM) bytecode
0007:
0009:
000b:
000c:
000d:
000f:
if-ge v0, v2, 0010
aget v1, v8, v0
int-to-long v5, v1
add-long/2addr v3, v5
add-int/lit8 v0, v0, #int 1
goto 0007
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
18
Android Start-up : fork & exec vs. fork & additional class loading
3
5
daemons
Phone & Nfc(JB) App
DRMServer (JB)
6
Launcher
(User App)
MediaServer
• usbd
• adbd
• debuggerd
• installd
• rild
SurfaceFlinger
SystemServer
Java Service
• core + h/w Service
Dalvik VM
2
Native Service
• Sensor Service
Service
Manager
4
Zygote
1
Init
/dev/binder
Kernel
Binder Driver
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
19
안드로이드 런타임 성능 개선 방안 : JIT 및 AOT 기술 도입 검토
소프트웨어 가속
AOT
하드웨어 가속
JIT
Jazelle®
• Ahead of Time Compilation
• WIPI의 COD (Compile-ondemand) 방식
• Just-in-Time Compilation
•
Java bytecode를 CPU가 바
로 실행 함. (arm/thumb/java
mode)
• 10x ~ 15x
• 6x ~ 10x
•
6x ~ 10x
• 어플리케이션 크기가 커짐.
• 프로파일링 및 컴파일 시간이
있어 실행 초기 느려질 수 있
음.
►
►
모바일 단말에서는 JIT와 Jazelle® 사용이 일반화 되어 있음.
어플리케이션 크기가 커지는 것을 제외하면, AOT 방식이 최대 성능을 보일 수 있음.
2008.3. 제1회 kandroid 세미나 세션 4. “Dalvik VM vs. Java VM” – 류혁곤 님 발표 中에서
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
20
안드로이드 런타임 성능 개선 방안 : Froyo에서 JIT 도입
There are a wide variety of JIT styles.
“When to compile?” and “What to compile?".
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
21
안드로이드 런타임 성능 개선 방안 : KitKat에서 AOT 실험적 도입
What Is ART?
• Dalvik : JIT(Just-In-Time) vs. ART : AOT (Ahead-Of-Time)
How Much Better Is It?
• ART seems to be more faster, less power consumption than Dalvik,
but not yet. (Due to the optimization capability of AOT compiler)
What Are The Compromises?
• Application Size
• Install Time
The Benchmark Results
• Floating-point calculations and basic responsiveness are obviously reaping the
benefits of the new runtime, but that's about it.
• There's little or no overall improvement for integer calculations, most regular code
execution, or much of anything else.
• In fact, it looks like gamers would be better served by sticking to Dalvik, for now.
Source :
• http://www.androidpolice.com/2013/11/06/meet-art-part-1-the-new-super-fast-android-runtime-google-has-been-working-on-in-secret-for-over-2years-debuts-in-kitkat/
• http://www.androidpolice.com/2013/11/12/meet-art-part-2-benchmarks-performance-wont-blow-away-today-will-get-better/
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
22
L-Developer Preview : 아키텍처 변화
Why ART? The ART manifesto
Performance
Garbage collection
Better living through compilation
Fast allocation, less jank, smaller footprint
HALP, “Performance boosting thing” needed
When, what, how :
- When to compile?
- What to target?
- How much to optimize?
Foundation for code generators present and future
Benefits of the ART compiler
The life of an APK
Ahead of time(AOT) compilation
Art file, Oat file
Compiler driver
Performance Boosting Thing, realized
Managing memory, in a nutshell
No memory management approach is free
Things that happen in GC
Pauses in Dalvik’s GC
Pauses can hurt
GC_FOR_ALLOC
When GC goes really bad
ART: Everything is awesome
- Faster overall GC
- Single, short pause
- Less fragmentation
- Less memory usage
Pauses in ART’s GC : Everything is faster
You shouldn’t notice GC
Large object space: where ‘all’ the bitmaps go
Less jank
Fast allocation : rosalloc
ART’s moving collector
Moving collector
- Less fragmentation
- Saves heap
- Long pause, so only boot and for background apps
64-bit support
Supporting the future
64-bit performance gains: RS, native, and crypto
64-bit performance gains: ART
ART compiler for 64-bit architectures
Dual zygote support for 32- and 64-bit apps
Reference compression for efficient memory usage in
64-bit apps
New NDK and RS support for 64-bit shipping with L
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
23
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
24
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
25
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
26
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
27
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
28
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
29
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
30
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
31
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
32
Why a new runtime (ART),
not evolving the old one (Dalvik)?
GMS (Apps)
A PPLICATIONS
Alarm
Dialer
SMS/MMS
IM
Browser
Contacts
Voice Dial
Email
Calendar
…
Gmail
Market
Talk
…
GoogleServiceFramework
A PPLICATION F RAMEWORK
Activity
Manager
Window
Manager
Content
Provider
View
System
Notification
Manager
Package
Manager
Telephony
Manager
Resource
Manager
Location
Manager
…
L IBRARIES
Surface Manager
Media Framework
SQLite
OpenGL|ES
FreeType
WebKit
SGL
Libc
…
A NDROID RUNTIME
Core Libraries
Map lib
Dalvik Virtual Machine
voice
HAL(HARDWARE ABSTRACTION LAYER)
Graphics
Audio
Camera
Bluetooth
GPS
Radio(RIL)
WiFi
…
L INUX K ERNEL
Display Driver
Camera Driver
Bluetooth Driver
USB Driver
Keypad Driver
WiFi Driver
Shared Memory
Driver
Audio
Driver
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
Binder (IPC)
Driver
Power
Management
33
Dalvikism vs. ARTism
ARTism
Dalvikism
2008
AOSP
Branch
SDK
(API Level)
NDK
(Revision)
1
2009
2010
M
C
D E F
23
45 6 7 8
1 2
2011
34
GH
2012
I
2015
K
L
1819
20
J
9 10 13 1415
5
2014
2013
6 7
16
17
8
9 9c
RenderScript
android.support.v8.renderscript
Extras
Support Lib.
android-support-v13.jar
r1
r2 r3 r4 r6
android-support-v7.jar
r8r9 r10 r11 r13 r18
android-support-v4.jar
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
34
초기 안드로이드 플랫폼 및 개발환경에서,
안드로이드만이 갖는 고유한 특징은 무엇이라고 생각하세요?
1. Dalvik, Dex Executable
2. Zygote
3. Prelink (Redhat)
4. ….
그렇다면, 이것들이 정확히 의미하는 것과 그런 특징을 가진 이유는?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
35
Dalvikism : Stage #1 - Java를 선택하다.
Source : http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/images/gcslides/Slide1.png
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
36
Dalvikism : Stage #1 - Java를 선택하다. (제한된 h/w 자원 이슈 봉착)
Class Loader Subsystem
Class
Files
Method
Area
Load
Link
1. Verify
2. Prepare
3. Resolve
Heap
Java
Threads
Program
Counter
Registers
Initialize
Native
Internal
Threads
Runtime Data Areas
Execution
Engine
JIT
Compiler
Garbage
Collector
Native
Method
Interface
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
Native
Method
Libraries
37
Dalvikism : Stage #1 - Java를 선택하다. (제한된 h/w 자원 이슈 봉착)
이슈에 대한 해법은?
•
•
•
•
Class Loader Subsystem
Build time
install time
pre initialization
run time
Class
Files
Method
Area
Load
Link
1. Verify
2. Prepare
3. Resolve
Heap
Java
Threads
Program
Counter
Registers
Initialize
Native
Internal
Threads
Runtime Data Areas
Execution
Engine
JIT
Compiler
Garbage
Collector
Native
Method
Interface
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
Native
Method
Libraries
38
2008 Google I/O - Dalvik VM Internals, Dan Bornstein
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
39
2008 Google I/O - Dalvik VM Internals, Dan Bornstein
library “live”
dex structures 란?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
40
Dalvikism : Stage #1 - Java를 선택하다. (제한된 h/w 자원 이슈 봉착)
이슈에 대한 해법은?
•
•
•
•
Class Loader Subsystem
Build time
install time
pre initialization
run time
Class
Files
Method Area
1. Verify
2. Prepare
3. Resolve
Heap
initialization
Link
Load
live dex
structures
Java
Threads
Program
Counter
Registers
Initialize
Native
Internal
Threads
Runtime Data Areas
Execution
Engine
JIT
Compiler
Garbage
Collector
Native
Method
Interface
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
Native
Method
Libraries
41
2008 Google I/O - Dalvik VM Internals, Dan Bornstein
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
42
초기 안드로이드 플랫폼 및 개발환경에서,
성능개선을 위해 도입된 주요 기법들은 무엇이라고 생각하세요?
1. NDK
2. JIT
3. SMP
4. GPUI
5. GC 개선
6. LLVM & Renderscript
7. 다양한 측정 프레임워크
8. …
그렇다면, 이것들이 정확히 의미하는 것과 그런 특징을 가진 이유는?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
43
Dalvikism : Stage #2 – Native 성능과의 비교
•
•
•
•
•
Class Loader Subsystem
NDK 도입 이후 이슈는?
왜 JIT를 도입했는가?
안드로이드 JIT 기술의
장단점은?
JIT 구현의 성과는?
Class
Files
Method Area
initialization
Link
Load
1. Verify
2. Prepare
3. Resolve
Heap
live dex
structures
Initialize
Program
Counter
Registers
Java
Threads
Native
Internal
Threads
Runtime Data Areas
Execution
Engine
JIT
Compiler
Garbage
Collector
Native
Method
Interface
Custom
Native
Method
Libraries
Code Cache
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
44
Google IO 2010 - A JIT Compiler for Android’s Dalvik VM,
Ben Cheng, Bill Buzbee
Code Cache
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
45
Google IO 2010 - A JIT Compiler for Android’s Dalvik VM,
Ben Cheng, Bill Buzbee
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
46
NDK 및 JIT 도입 이후의 안드로이드 플랫폼 및 개발환경에서,
성능개선을 위해 필요한 것은 무엇이라고 생각하세요?
1. JIT Code Cache의 한계를 극복한 Aggressive Optimization
1. 어떻게 가능한가?
그렇다면, 이것들이 정확히 의미하는 것과 그런 특징을 가진 이유는?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
47
ARTism : Stage #3 – Aggressive 최적화 어떻게 가능한가?
Class Loader Subsystem
Class
Files
Method Area
initialization
Link
Load
1. Verify
2. Prepare
3. Resolve
Heap
live dex
structures
Initialize
Program
Counter
Registers
Java
Threads
Native
Internal
Threads
Runtime Data Areas
Execution
Engine
JIT
Compiler
Garbage
Collector
Native
Method
Interface
Custom
Native
Method
Libraries
Code Cache
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
48
ARTism : Stage #3 – Aggressive 최적화 어떻게 가능한가?
JIT Code
Cache
JIT Code
Cache
JIT Code
Cache
Aggressive
Optimization Area
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
49
ARTism : Stage #3 – Aggressive 최적화 어떻게 가능한가?
ART Compiler는 왜 ART runtime을 사용하여 컴파일하는가?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
50
ARTism : Stage #3 – Aggressive 최적화 어떻게 가능한가?
boot.art와 boot.oat는 무엇인가?
b4856000-b4857000
7418a000-7418b000
7285d000-7418a000
70dd0000-7285d000
b4858000-b4885000
702b3000-70dd0000
r--p
rw-p
r-xp
r--p
r--p
rw-p
00000000
033ba000
01a8d000
00000000
00b1d000
00000000
1f:01
1f:01
1f:01
1f:01
1f:01
1f:01
7054
7054
7054
7054
7053
7053
/data/dalvik-cache/x86/system@[email protected]
/data/dalvik-cache/x86/system@[email protected]
/data/dalvik-cache/x86/system@[email protected]
/data/dalvik-cache/x86/system@[email protected]
/data/dalvik-cache/x86/system@[email protected]
/data/dalvik-cache/x86/system@[email protected]
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
51
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
52
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
53
Google IO 2014 - The ART runtime,
Brian Carlstrom, Anwar Ghuloum, Ian Rogers
We want to do potentially different
optimization levels for different use
cases.
So rather than just trying to build
“one performance thing”,
we want to build a
“framework of
performance boosting things”.
- Brian Carlstrom
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
54
2012, 제10회 Kandroid 기술세미나 – LLVM, Clang and GDK
What is LLVM?
•
LLVM Project History : This project started in 2000 at the University of Illinois at
Urbana-Champaign, under the direction of Vikram Adve and Chris Lattner.
•
LLVM Compiler Infrastructure
“a design and implementation of a compiler infrastructure which supports a
unique multi-stage optimization system. This system is designed to support
extensive interprocedural and profile-driven optimizations, while being efficient
enough for use in commercial compiler systems”
- In 2002, Chris Lattner stated a definition of the LLVM in his master’s thesis
“a compiler framework that aims to make lifelong program analysis
and transformation available for arbitrary software and in a manner that is
transparent to programmers”
- In 2004, Vikram Adve and Chris Lattner provided a further description of the LLVM
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
55
2012, 제10회 Kandroid 기술세미나 – LLVM, Clang and GDK
LLVM enables life long time optimization
Source Code
Compile-time Optimization
Object Code
Link-time Optimization
Off-line
Optimization
Executable Code
Profile
AOT vs. JIT
Install-time
Optimization
Run-time
Optimization
Running Code
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
56
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
57
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
• ART에 Interpreter는 왜 존재하는가?
• 그리고 기존 Dalvik Interpreter와 동일한 것인가?
참조 - 2008년. Interpreter 구현의 3가지 방법
1. The portable way
2. The gcc way
3. ARM assembly
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
58
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
• AOT로 컴파일된 oat 파일의 실행되는 방식은?
참조 : 뒤 페이지의 startActivity Process를 기준으로 검토
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
59
intent.addCategory(Intent.CATEGORY_HOME);
LAUNCH
ACTIVITY
8
IApplicationThread
TLS
Activity
Manager
Service
Application
Thread
(#BT)
7
1
Activity
Thread
11
10
IApplicationThread.scheduleLaunchActivity()
Launcher
Activity
dispatch
Message()
Looper
send
Message()
6
H
IApplicationThread.bindApplication()
9
Message
Queue
sytemReady()
handle
5
&addr
IActivityManager.attachApplication( )
4
2
system_server
IActivityManager
User application
Process
fork request
3
Select
LoopMode
fork
Zygote
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
60
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
• AOT로 컴파일된 oat 파일을 JDWP로 디버깅하는 것은 가능한가?
• 가능하다면 어떻게 가능한가?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
61
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
TraceView with Sampling Profiler
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
62
ART : Flexible Compiler Infrastructure and Ergonomic Runtime
Flexible
Compiler
Infrastructure
Ergonomic
Runtime
ART
&
OAT
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
63
Android Lollipop (5.0)
Performance focus
Android now runs exclusively on the new ART runtime, built from the ground
up to support a mix of ahead-of-time (AOT), just-in-time (JIT),
and interpreted code. It’s supported on ARM, x86, and MIPS
architectures and is fully 64-bit compatible.
Source : http://developer.android.com/about/versions/lollipop.html
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
64
ART Memory Management 상세 (2시간)
-
-
-
Memory Management in General
• Terminology & Design Choices
• Tuning & Ergonomics
Collection: GC & GC Ergonomics
• Change History of GC in Android
• GC in ART
• Ergonomics in ART GC
Allocation: Cross-Layer (Java and Native) Optimization
• Allocators (dlmalloc, ptmalloc, tcmalloc, jemalloc, rosalloc)
• Spaces and Memory Layout
Dalvik과 ART의 핵심적인 메모리 관리의 차이는?
Memory Management 101
Memory management is the act of managing computer memory.
The essential requirement of memory management is to provide ways
to dynamically allocate portions of memory to programs at their
request, and free it for reuse when no longer needed.
(Source: http://en.wikipedia.org/wiki/Memory_management)
1. Manual (Explicit)
Memory Leak & Dangling Pointer
2. Automatic (Implicit) == Garbage Collection
GC Overhead, GC Pause, Nondeterministic
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
66
Garbage Collection 101
The process of finding and freeing (also known as reclaiming) the
space used by the dead objects termed garbage
(Source: Memory Management in the Java HotSpot™ Virtual Machine)
1. Identify live objects
2. Remove dead objects
3. Coalesce free space (optionally)
Unreachable (Dead)
Objects = Garbage
Reachable (Live)
Objects
GC Roots
- Local variables
- Static variables
- JNI references
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
67
GC Performance Metrics & Tradeoff
•
•
•
•
•
•
Throughput
Garbage collection overhead = 1 / Throughput
Pause time
Frequency of collection
Footprint
Promptness
(Source: Memory Management in the Java HotSpot™ Virtual Machine)
time
space
freq.
Heap Size
GC Time
GC Freq.
↓
↓
↑
↑
↑
↓
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
68
GC Design Choices
• Serial vs. Parallel
• Concurrent vs. Stop-the-world
• Non-Compacting vs. Compacting vs. Copying
(Source: Memory Management in the Java HotSpot™ Virtual Machine)
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
69
GC Tuning
Users, developers, and administrators with strict performance goals or
other requirements may need to explicitly select the garbage
collector and tune certain parameters to achieve the desired level of
performance.
(Source: Java SE 6 HotSpot™ Virtual Machine Garbage Collection Tuning)
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
70
1|root@generic_x86:/ # dalvikvm -help
dalvikvm -help
dalvikvm: [options] class [argument ...]
The following standard options are supported:
-classpath classpath (-cp classpath)
-Dproperty=value
-verbose:tag ('gc', 'jni', or 'class')
-showversion
-help
-agentlib:jdwp=options
The following extended options are supported:
-Xrunjdwp:<options>
-Xbootclasspath:bootclasspath
-Xcheck:tag (e.g. 'jni')
-XmsN (min heap, must be multiple of 1K, >= 1MB)
-XmxN (max heap, must be multiple of 1K, >= 2MB)
-XssN (stack size)
-Xint
The following Dalvik options are supported:
-Xzygote
-Xjnitrace:substring (eg NativeClass or nativeMethod)
-Xstacktracefile:<filename>
-Xgc:[no]preverify
-Xgc:[no]postverify
-XX:+DisableExplicitGC
-XX:HeapGrowthLimit=N
-XX:HeapMinFree=N
-XX:HeapMaxFree=N
-XX:NonMovingSpaceCapacity=N
-XX:HeapTargetUtilization=doublevalue
-XX:ForegroundHeapGrowthMultiplier=doublevalue
-XX:LowMemoryMode
-Xprofile:{threadcpuclock,wallclock,dualclock}
The following unique to ART options are supported:
-Xgc:[no]preverify_rosalloc
-Xgc:[no]postsweepingverify_rosalloc
-Xgc:[no]postverify_rosalloc
-Xgc:[no]presweepingverify
-Ximage:filename
-XX:ParallelGCThreads=integervalue
-XX:ConcGCThreads=integervalue
-XX:MaxSpinsBeforeThinLockInflation=integervalue
-XX:LongPauseLogThreshold=integervalue
-XX:LongGCLogThreshold=integervalue
-XX:DumpGCPerformanceOnShutdown
-XX:IgnoreMaxFootprint
-XX:UseTLAB
-XX:BackgroundGC=none
-Xmethod-trace
-Xmethod-trace-file:filename -Xmethod-trace-file-size:integervalue
-Xenable-profiler
-Xprofile-filename:filename
-Xprofile-period:integervalue
-Xprofile-duration:integervalue
-Xprofile-interval:integervalue
-Xprofile-backoff:doublevalue
-Xprofile-start-immediately
-Xprofile-top-k-threshold:doublevalue
-Xprofile-top-k-change-threshold:doublevalue
-Xprofile-type:{method,stack}
-Xprofile-max-stack-depth:integervalue
-Xcompiler:filename
-Xcompiler-option dex2oat-option
-Ximage-compiler-option dex2oat-option
-Xpatchoat:filename
-X[no]relocate
-X[no]dex2oat (Whether to invoke dex2oat on the application)
-X[no]image-dex2oat (Whether to create and use a boot image)
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
71
GC Ergonomics (Java SE 5~) & Self-Tuning JVM (Java SE 9)
1. Automatic Selection of Collector, Heap Sizes, and Virtual Machine
Based on Platform and OS
2. Behavior-based Tuning of Parallel Collector
Based on the goals for maximum pause time and application
throughput
-XX:+UseAdaptiveSizePolicy
-XX:MaxGCPauseMillis=nnn
References:
-XX:GCTimeRatio=nnn
•
•
Java SE 6 HotSpot™ Virtual Machine
Garbage Collection Tuning
Garbage Collector Ergonomics (Java SE 7)
http://docs.oracle.com/javase/7/docs/tech
notes/guides/vm/gc-ergonomics.html
Attempt to eliminate the need for
command-line parameters altogether,
regardless of the application.
Source: http://qconlondon.com/dl/qcon-london-2012/slides/SimonRitter_TheFutureOfTheJavaPlatformJavaSE8Beyond.pdf
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
72
GC in Android
WHY
~ Froyo
Gingerbread ~ Kikkat
Lollipop ~
GC_FOR_MALLOC
GC_FOR_ALLOC
GC_CONCURRENT
GC_EXPLICIT
GC_EXTERNAL_ALLOC
Alloc
Background
Explicit
NativeAlloc
GC_EXPLICIT
GC_EXTERNAL_ALLOC
GC_HPROF_DUMP_HEAP
GC_BEFORE_OOM
CollectorTransition
DisableMovingGc, HeapTrim
HomogeneousSpaceCompact
WHERE
Full
Full, Partial
Full, Partial, Sticky
HOW
Stop-the-world
Serial
Non-moving
Stop-the-world, Concurrent
Serial
Non-moving
Stop-the-world, Concurrent
Serial, Parallel
Non-moving, Moving
Mark-Sweep
(Concurrent-)Mark-Sweep
(Concurrent-)Mark-Sweep
(Generational) Semi-Space
Mark-Compact
Concurrent Copying
Homogeneous Space Compaction
Trim heap if necessary
Trim heap if necessary
Concurrent GC timing based on
Trim heap if necessary
Concurrent GC timing based
on Estimated Remaining Bytes
Sticky / non-sticky GC chosen based
on each Estimated Throughputs
Ergono
mics
Allocation Threshold
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
73
1
2
Thread
Object to allocate
Reachable object
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
Free object
74
Initial
Mark
Concurrent
Mark
Remark
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
Concurrent
Sweep
75
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
76
Initial
Mark
Concurrent
Mark
No pause for initial mark
by doing it concurrently
Remark
Concurrent
Sweep
Shorter pause for remark
by pre-cleaning
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
77
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
78
Due to fragmented heap
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
79
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
80
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
81
Primitive arrays that have
no out-bound references
Help reduce heap fragmentation
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
82
• Less fragmentation
• Saves heap
• Long pauses, so only boot and for background apps
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
83
Full vs Partial vs Sticky
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
84
Interpreting GC Logs
GC Cause
GC_HPROF_DUMP_HEAP freed 47K, 50% free 2730K/5379K, external 8825K/9762K, paused 2262ms
GC_EXPLICIT
39K, 49% free 3434K/6727K, external 1625K/2137K, paused 61ms
• freed
Alloc
GC_EXTERNAL_ALLOC freed 113K, 48% free 2849K/5447K, external 2069K/2137K, paused 29ms
• freed
Background
GC_FOR_MALLOC
672K, 46% free 4505K/8263K, external 1625K/2137K, paused 36ms
• Explicit
GC_EXPLICIT
freed 298K, 5% free 9395K/9820K,
paused 5ms+4ms, total 46ms
•
NativeAlloc
GC_FOR_ALLOC
freed 62K, 4% free 9981K/10356K,
paused 14ms, total 14ms
GC_CONCURRENT •
freed
452K, 5% free 11442K/11924K,
paused 2ms+3ms, total 32ms
CollectorTransition
GC_BEFORE_OOM
freed <1K, 25% free 48653K/64327K,
paused 20ms
• DisableMovingGc
L Preview
• sweep
HomogeneousSpaceCompact
Explicit concurrent mark
GC
freed •65595(3MB)
AllocSpace objects, 9(4MB) LOS objects, 810% free, 38MB/58MB,
HeapTrim
Gingerbread
paused 1.195ms total 87.219ms
Background partial concurrent mark sweep GC
freed 74626(3MB) AllocSpace objects, 39(4MB) LOS objects, 1496% free, 25MB/32MB,
paused 4.422ms total 1.371747s
Background sticky concurrent mark sweep GC
freed 70319(3MB) AllocSpace objects, 59(5MB) LOS objects, 825% free, 49MB/56MB,
paused 6.139ms total 52.868ms
Source : http://www.anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l/2
// What caused the GC?
enum GcCause {
// GC triggered by a failed allocation. Thread doing allocation is blocked waiting for GC before retrying
allocation.
kGcCauseForAlloc,
// A background GC trying to ensure there is free memory ahead of allocations.
kGcCauseBackground,
// An explicit System.gc() call.
kGcCauseExplicit,
// GC triggered for a native allocation.
kGcCauseForNativeAlloc,
// GC triggered for a collector transition.
kGcCauseCollectorTransition,
// Not a real GC cause, used when we disable moving GC (currently for GetPrimitiveArrayCritical).
kGcCauseDisableMovingGc,
// Not a real GC cause, used when we trim the heap.
kGcCauseTrim,
// GC triggered for background transition when both foreground and background collector are CMS.
kGcCauseHomogeneousSpaceCompact,
};
Source: https://android.googlesource.com/platform/art/+/master/runtime/gc/gc_cause.h
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
86
Interpreting GC Logs
GC GC_HPROF_DUMP_HEAP
Cause
freed 47K,
•
•
•
•
•
•
•
•
GC Type
50% free 2730K/5379K, external 8825K/9762K, paused 2262ms
Alloc
GC_EXPLICIT
freed 39K, 49%
3434K/6727K, external 1625K/2137K, paused 61ms
• freeSticky
Background
GC_EXTERNAL_ALLOC freed 113K, 48% free 2849K/5447K, external 2069K/2137K, paused 29ms
• freePartial
GC_FOR_MALLOC
freed 672K, 46%
4505K/8263K, external 1625K/2137K, paused 36ms
Explicit
Gingerbread
NativeAlloc
• Full
GC_EXPLICIT
freed 298K, 5% free 9395K/9820K,
paused 5ms+4ms, total 46ms
CollectorTransition
GC_FOR_ALLOC
freed 62K, 4% free 9981K/10356K,
paused 14ms, total 14ms
DisableMovingGc
GC_CONCURRENT
freed 452K, 5% free 11442K/11924K,
paused 2ms+3ms, total 32ms
HomogeneousSpaceCompact
GC_BEFORE_OOM
freed <1K, 25% free 48653K/64327K,
paused 20ms
HeapTrim
L Preview
Explicit concurrent mark sweep GC
freed 65595(3MB) AllocSpace objects, 9(4MB) LOS objects, 810% free, 38MB/58MB,
paused 1.195ms total 87.219ms
Background partial concurrent mark sweep GC
freed 74626(3MB) AllocSpace objects, 39(4MB) LOS objects, 1496% free, 25MB/32MB,
paused 4.422ms total 1.371747s
Background sticky concurrent mark sweep GC
freed 70319(3MB) AllocSpace objects, 59(5MB) LOS objects, 825% free, 49MB/56MB,
paused 6.139ms total 52.868ms
Source : http://www.anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l/2
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
87
// The type of collection to be performed. The ordering of the enum matters, it is used to
// determine which GCs are run first.
enum GcType {
// Placeholder for when no GC has been performed.
kGcTypeNone,
// Sticky mark bits GC that attempts to only free objects allocated since the last GC.
kGcTypeSticky,
// Partial GC that marks the application heap but not the Zygote.
kGcTypePartial,
// Full GC that marks and frees in both the application and Zygote heap.
kGcTypeFull,
};
// Number of different GC types.
kGcTypeMax,
Source: https://android.googlesource.com/platform/art/+/master/runtime/gc/collector/gc_type.h
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
88
Interpreting GC Logs
GC GC_HPROF_DUMP_HEAP
Cause
freed 47K,
•
•
•
•
•
•
•
•
GC Type
Collector Type
50% free 2730K/5379K, external 8825K/9762K, paused 2262ms
• free
sticky
freed 39K, 49%
3434K/6727K,
1625K/2137K,
• external
mark
sweep paused 61ms
•
partial
freed 113K, 48% free 2849K/5447K, external 2069K/2137K, paused 29ms
• external
concurrent
mark
freed 672K, 46%
4505K/8263K,
1625K/2137K,
pausedsweep
36ms
• free
(full)
Alloc
GC_EXPLICIT
Background
GC_EXTERNAL_ALLOC
GC_FOR_MALLOC
Explicit
NativeAlloc
•
GC_EXPLICIT
freed 298K, 5% free 9395K/9820K,
CollectorTransition
•
GC_FOR_ALLOC
freed 62K, 4% free 9981K/10356K,
DisableMovingGc
GC_CONCURRENT
freed 452K, 5% free 11442K/11924K,
•
HomogeneousSpaceCompact
GC_BEFORE_OOM
freed <1K, 25% free 48653K/64327K,
HeapTrim
mark compact
paused 5ms+4ms, total 46ms
marksweep +paused
semispace
14ms, total 14ms
paused 2ms+3ms,
total 32ms
concurrent copying
+ mark
sweep
Gingerbread
paused 20ms
L Preview
Explicit concurrent mark sweep GC
freed 65595(3MB) AllocSpace objects, 9(4MB) LOS objects, 810% free, 38MB/58MB,
paused 1.195ms total 87.219ms
Background partial concurrent mark sweep GC
freed 74626(3MB) AllocSpace objects, 39(4MB) LOS objects, 1496% free, 25MB/32MB,
paused 4.422ms total 1.371747s
Background sticky concurrent mark sweep GC
freed 70319(3MB) AllocSpace objects, 59(5MB) LOS objects, 825% free, 49MB/56MB,
paused 6.139ms total 52.868ms
Source : http://www.anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l/2
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
89
// Which types of collections are able to be performed.
enum CollectorType {
// No collector selected.
kCollectorTypeNone,
// Non concurrent mark-sweep.
kCollectorTypeMS,
// Concurrent mark-sweep.
kCollectorTypeCMS,
// Semi-space / mark-sweep hybrid, enables compaction.
kCollectorTypeSS,
// A generational variant of kCollectorTypeSS.
kCollectorTypeGSS,
// Mark compact colector.
kCollectorTypeMC,
// Heap trimming collector, doesn't do any actual collecting.
kCollectorTypeHeapTrim,
// A (mostly) concurrent copying collector.
kCollectorTypeCC,
// A homogeneous space compaction collector used in background transition
// when both foreground and background collector are CMS.
kCollectorTypeHomogeneousSpaceCompact,
};
Source: https://android.googlesource.com/platform/art/+/master/runtime/gc/collector_type.h
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
90
Interpreting GC Logs
GC Cause
GC Type
Collector Type
GC_HPROF_DUMP_HEAP freed 47K, 50% free 2730K/5379K, external 8825K/9762K, paused 2262ms
•
Alloc
•
sticky external
• 1625K/2137K,
mark sweeppaused 61ms
GC_EXPLICIT
freed 39K, 49% free 3434K/6727K,
•
Background
•
partial external
• 2069K/2137K,
concurrent paused
mark sweep
GC_EXTERNAL_ALLOC
freed 113K, 48% free 2849K/5447K,
29ms
GC_FOR_MALLOC
freed 672K, 46% free 4505K/8263K,
paused 36ms
•
Explicit
•
(full) external
• 1625K/2137K,
mark compact
•
NativeAlloc
•
GC_EXPLICIT
freed 298K, 5% free 9395K/9820K,
•
CollectorTransition
•
GC_FOR_ALLOC
freed 62K, 4% free 9981K/10356K,
•
DisableMovingGcfreed 452K, 5% free 11442K/11924K,
GC_CONCURRENT
•
HomogeneousSpaceCompact
GC_BEFORE_OOM
freed <1K, 25% free 48653K/64327K,
•
HeapTrim
marksweep + semispace
5ms+4ms, total 46ms
concurrent paused
copying
+ mark sweep
Gingerbread
paused 14ms, total 14ms
paused 2ms+3ms, total 32ms
paused 20ms
L Preview
Explicit concurrent mark sweep GC
freed 65595(3MB) AllocSpace objects, 9(4MB) LOS objects, 810% free, 38MB/58MB,
paused 1.195ms total 87.219ms
Background partial concurrent mark sweep GC
freed 74626(3MB) AllocSpace objects, 39(4MB) LOS objects, 1496% free, 25MB/32MB,
paused 4.422ms total 1.371747s
Background sticky concurrent mark sweep GC
freed 70319(3MB) AllocSpace objects, 59(5MB) LOS objects, 825% free, 49MB/56MB,
paused 6.139ms total 52.868ms
Source : http://www.anandtech.com/show/8231/a-closer-look-at-android-runtime-art-in-android-l/2
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
91
Garbage Collectors in ART
Class
IsConcurrent
GcType
IsMoving
Yes/No
Full
No
Yes/No
Partial
No
Yes/No
Sticky
No
|─ MarkCompact
No
Partial/Full
Yes
|─ SemiSpace
No
Partial/Full
Yes
No
Partial/Full
Yes
Yes
Partial/Full
Yes
GarbageCollector
|─ MarkSweep
|─ PartialMarkSweep
|─ StickyMarkSweep
|─ZygoteCompactingCollector
|─ ConcurrentCopying
Source: https://android.googlesource.com/platform/art/+/master/runtime/gc/collector/
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
92
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
93
Memory Allocators
dlmalloc
ptmalloc
tcmalloc
jemalloc
Boundary Tags
Binning
Thread-local arena
Thread-local cache
Central heap
Arena
Thread-local cache
- Single lock
- Fragmentation
Doug Lea
Android
- Fragmentation
Wolfram Gloger
Sanjay Ghemawat
Jason Evans
Glibc
GFS
BigTable
MapReduce
FreeBSD
Facebook
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
94
dlmalloc vs. rosalloc
128
Source: http://gee.cs.oswego.edu/dl/html/malloc.html
run
32
run
48
run
34
…
Trie
16
512
run
1k
run
2k
run
Runs of Slots
Source: https://android.googlesource.com/platform/
art/+/master/runtime/gc/allocator/rosalloc.[h|cc]
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
+-------------------+
| magic_num
|
+-------------------+
| size_bracket_idx |
+-------------------+
| is_thread_local
|
+-------------------+
| to_be_bulk_freed |
+-------------------+
| top_bitmap_idx
|
+-------------------+
|
|
| alloc bit map
|
|
|
+-------------------+
|
|
| bulk free bit map |
|
|
+-------------------+
|
|
| thread-local free |
| bit map
|
|
|
+-------------------+
| padding due to
|
| alignment
|
+-------------------+
| slot 0
|
+-------------------+
| slot 1
|
+-------------------+
| slot 2
|
+-------------------+
...
+-------------------+
| last slot
|
+-------------------+
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
95
Why not tcmalloc or jemalloc?
• Small: [8], [16, 32, 48, ..., 128], [192, 256, 320, ..., 512],
[768, 1024, 1280, ..., 3840]
• Large: [4 KiB, 8 KiB, 12 KiB, ..., 4072 KiB]
• Huge: [4 MiB, 8 MiB, 12 MiB, ...]
Small Object Allocation
~ 170 allocatable
size-classes
Large Object (<= 32K) Allocation
http://goog-perftools.sourceforge.net/doc/tcmalloc.html
Source: https://www.facebook.com/notes/facebook-engineering/scalablememory-allocation-using-jemalloc/480222803919
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
96
// Different types of allocators.
enum AllocatorType {
kAllocatorTypeBumpPointer, // Use BumpPointer allocator, has entrypoints.
kAllocatorTypeTLAB, // Use TLAB allocator, has entrypoints.
kAllocatorTypeRosAlloc, // Use RosAlloc allocator, has entrypoints.
kAllocatorTypeDlMalloc, // Use dlmalloc allocator, has entrypoints.
kAllocatorTypeNonMoving, // Special allocator for non moving objects, doesn't have
entrypoints.
};
kAllocatorTypeLOS, // Large object space, also doesn't have entrypoints.
Source: https://android.googlesource.com/platform/art/+/master/runtime/gc/allocator_type.h
void Heap::ChangeCollector(CollectorType collector_type) {
// if collector_type is one of moving collectors
if (use_tlab_) {
ChangeAllocator(kAllocatorTypeTLAB);
} else {
ChangeAllocator(kAllocatorTypeBumpPointer);
}
…
// if collector_type is one of non-moving collectors
ChangeAllocator(kUseRosAlloc ? kAllocatorTypeRosAlloc : kAllocatorTypeDlMalloc);
Source: https://android.googlesource.com/platform/art/+/master/runtime/gc/heap.cc
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
97
Dalvik과 ART의 핵심적인 메모리 관리의 차이는?
accounting
allocator
collector
space
Framework
Ergonomics
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
98
함께 논의하기 (1시간)
-
논의1 : 왜 Dalvik을 개선하지 않고,
ART라는 새로운 New Runtime을 도입했는가?
-
논의2 : 왜 Eclipse & Ant 에서 IntelliJ & Gradle로 전환하는가?
-
논의3 : Android 기술의 미래는 어디로 가고 있는가?
-
기타 Q&A
GDK : What is GDK?
Hooray! We done the GDK building system.
This building system is independent on NDK.
It builds what is should (bitcodes), and then transfer the control
to NDK building system, doing the remaining building.
This code is still ugly. Need cleanup.
gdk git commit id : edde771d8940a6f1b00fd68bcca1486b575e6d9e
Author : Nowar Gu <[email protected]>
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
100
GDK : What is GDK? : hello-llvm Sample (1)
Android-portable.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello_llvm
LOCAL_CFLAGS := -D NUM=7788
LOCAL_SRC_FILES := hello_llvm.c test.cpp
LOCAL_C_INCLUDES := jni/test-include
include $(BUILD_BITCODE)
include $(CLEAR_VARS)
LOCAL_MODULE := test2
LOCAL_SRC_FILES := test2.c
include $(BUILD_BITCODE)
$ cd ~/android-4.1.1_r1/gdk/samples/hello-llvm/jni
$ export OUT=~/android-4.1.1_r1/out/target/product/generic
$ ../../../gdk-build --ndk-root=~/android-ndk-r8b
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
101
GDK : What is GDK? : hello-llvm Sample (2)
$ ../../../gdk-build --ndk-root=/home/jsyang/android-ndk-r8b
Compile Bitcode : hello_llvm <= hello_llvm.c
Compile++ Bitcode: hello_llvm <= test.cpp
BitcodeLibrary : libhello_llvm.bc
Install BCLib : libhello_llvm.bc => res/raw/libhello_llvm.bc
clang
clang++
llvm-link
Compile Bitcode : test2 <= test2.c
BitcodeLibrary : libtest2.bc
Install BCLib : libtest2.bc => res/raw/libtest2.bc
Gdbserver
Gdbsetup
Gdbserver
Gdbsetup
: [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
: libs/armeabi/gdb.setup
: [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver
: libs/armeabi-v7a/gdb.setup
Compile thumb : hello_llvm <= hello_llvm.c
Compile++ thumb : hello_llvm <= test.cpp
StaticLibrary : libstdc++.a
SharedLibrary : libhello_llvm.so
Install
: libhello_llvm.so => libs/armeabi/libhello_llvm.so
Compile thumb : hello_llvm <= hello_llvm.c
Compile++ thumb : hello_llvm <= test.cpp
StaticLibrary : libstdc++.a
SharedLibrary : libhello_llvm.so
Install
: libhello_llvm.so => libs/armeabi-v7a/libhello_llvm.so
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
102
GDK : What is GDK? : bitmap-plasma-llvm Sample (1)
plasmaLLVM.cpp
bccReadBC(script_ref, "libplasma_portable.bc",
(const char*)script_ptr, length, 0);
bccLinkFile(script_ref, "/system/lib/libclcore.bc", 0);
bccPrepareExecutable(script_ref,
"/data/data/com.example.plasma.llvm/",
"plasmaLLVM", 0);
crash
native_function
= (pPlasmaType)bccGetFuncAddr(script_ref, "root");
native_function(info.width, info.height,
info.stride, time_ms,
palette, pixels, angle_sin_tab);
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
103
GDK : What is GDK? : bitmap-plasma-llvm Sample (2)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/yakju/maguro:4.1.1/JRO03C/398337:user/release-keys'
pid: 16063, tid: 16063, name: ple.plasma.llvm >>> com.example.plasma.llvm <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
r0 00000027 r1 deadbaad r2 4010baec r3 00000000
…..
backtrace:
#00 pc 000180ae /system/lib/libc.so
#01 pc 0000dbd4 /system/lib/libc.so (abort+4)
#02 pc 0037fed7 /system/lib/libbcc.so
#03 pc 00379f79 /system/lib/libbcc.so
#04 pc 00379ffb /system/lib/libbcc.so (llvm::FPPassManager::runOnModule(llvm::Module&)+62)
#05 pc 00379ccb /system/lib/libbcc.so (llvm::MPPassManager::runOnModule(llvm::Module&)+394)
#06 pc 00379da3 /system/lib/libbcc.so (llvm::PassManagerImpl::run(llvm::Module&)+82)
#07 pc 00054891 /system/lib/libbcc.so (bcc::Compiler::runMCCodeGen(llvm::TargetData*, llvm::TargetMachine*)+80)
#08 pc 00055ab7 /system/lib/libbcc.so (bcc::Compiler::compile(bcc::CompilerOption const&)+1638)
#09 pc 000584db /system/lib/libbcc.so (bcc::Script::internalCompile(bcc::CompilerOption const&)+154)
#10 pc 000596dd /system/lib/libbcc.so (bcc::Script::prepareExecutable(char const*, char const*, unsigned long)+160)
#11 pc 00054053 /system/lib/libbcc.so (bccPrepareExecutable+38)
#12 pc 0000136f /data/data/com.example.plasma.llvm/lib/libplasma.so
(Java_com_example_plasma_llvm_PlasmaView_nativeRenderPlasma+510)
$ addr2line -e ./out/target/product/generic/symbols/system/lib/libc.so 000180ae
~/android-4.1.1_r1/bionic/libc/bionic/pthread-timers.c:478
$ addr2line -e ./out/target/product/generic/symbols/system/lib/libc.so 0000dbd4
~/android-4.1.1_r1/bionic/libc/arch-arm/bionic/abort_arm.S:41
$ addr2line -e ./out/target/product/generic/symbols/system/lib/libbcc.so 0037fed7
~/android-4.1.1_r1/external/llvm/lib/VMCore/Instructions.cpp:2749
$ addr2line -e ./out/target/product/generic/symbols/system/lib/libbcc.so 00379f79
~/android-4.1.1_r1/external/llvm/include/llvm/ADT/ilist.h:559
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
104
GDK : What is GDK? : bitmap-plasma-llvm Sample (3)
crash
LLVM Frame : ??
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
105
GDK : Why GDK uses Clang/LLVM?
Frame Rate Drawing Performance Comparison - LLVM vs. GCC
Enable the use of cache.
With this check-in, end-to-end LLVM milestone achieved.
For NDK samples, Plasma, running on Nexus-S, 800x480 screen:
• LLVM Time Run: 12.60ms per frame, Avg: 12.57
• GCC Time Run: 50.89ms per frame, Avg: 52.34
LLVM can achieve 80 fps,
while GCC yields 19 fps.
GCC is visibly much slower on my Nexus-S.
gdk git commit ID :
4a395f0e19b3e3f5790ef95fd7b72694cd4296b6
Shihwei Liao <[email protected]>
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
106
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
107
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
108
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
109
Google IO 2012 : Project Butter & Incognito Mode
Galaxy Nexus, Nexus 7, Nexus Q
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
110
Google IO 2013 : ?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
111
Google I/O 2014 : Keynote
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
112
Google I/O 2014 : Keynote
Mobile
MOMEMTUM
Platform
EVOLUTION
• 1 Billion 30-Day Active Users
• Android Tablet Global Market Share : 62%
• Android One for emerging markets
• L Developer Preview
• For form factors beyond mobile
Developer
SUCCESS
• Google Cloud Platform
• Compute
• Storage
• App Service
• Google Play
• Developer Tools
• AndroidWear
• User Experience
• AndroidAuto
• Material Design
• AndroidTV
• Enhanced Notifications
• ChromeCast
• Authentication
• ChromeBook
• Mobile Web Experience
• Performance
• Runtime
• Graphics
• Battery Life
• Android Security Innovation
• Android Work for Enterprise
• Productivity : Native Office Editing, Google Drive
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
113
만약, 안드로이드 기술이 성공적으로 Chrome OS를 통합해 낸다면,
Google IO 2012
Project Butter
Google IO 2014
Android Developer Podcast
Episode 10, 11
New Business Model
Traditional Service/Game Company
Traditional Manufacturer
kandroid s/w membership (2012)
kandroid s/w fundamentals study group (2013)
1.
2.
3.
4.
5.
How SoC Works?
How Linux Works?
How Toolchain Works?
How Programming Language Works?
How Chrome Browser Works?
Kandroid 기술세미나 : MinMax (2014)
Deview 2013, 2014
2009
2012
2014
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
114
Beyond Android
With the current market saturation, is it possible to create a new
platform?
• B2G, Tizen, LG Web OS, Ubuntu Mobile
The successful development of a new platform could lead to advances.
Nevertheless, it would be just one more in an already saturated
market. So, we must streamline the market and focus on crossplatform compatibility with the status quo.
•
•
•
•
•
Web-based (e.g. PhoneGap)
Native-based (e.g. Cocos2d-x)
VM-based (e.g. Mono)
UX-based (e.g. Material Design, Polymer…)
?
2014.10.24.금. 14th kandroid MinMax(칸드로이드 기술세미나) : New Android Runtime, ART - www.kandroid.org
115