Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
System.loadLibrary("Unix, Native Code and why b...
Search
Júlio Zynger
March 16, 2018
Programming
0
540
System.loadLibrary("Unix, Native Code and why bother")
Presented at AppDevCon (Amsterdam) 2018
Júlio Zynger
March 16, 2018
Tweet
Share
More Decks by Júlio Zynger
See All by Júlio Zynger
Improving developer productivity with Gradle Enterprise in 2023
julioz
1
260
FloorPlan: Visualize databases' evolution
julioz
0
450
Publishing API & Continuous Deployment on Android
julioz
1
460
Continuous Deploy no Android
julioz
0
3.5k
Other Decks in Programming
See All in Programming
役立つログに取り組もう
irof
28
9.6k
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
930
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
CSC509 Lecture 12
javiergs
PRO
0
160
Contemporary Test Cases
maaretp
0
140
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
初めてDefinitelyTypedにPRを出した話
syumai
0
420
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Featured
See All Featured
KATA
mclloyd
29
14k
A Tale of Four Properties
chriscoyier
156
23k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Site-Speed That Sticks
csswizardry
0
26
Transcript
System.loadLibrary( “Unix, Native Code and why bother”)
Library static shared static dynamic loading (.o, .a, ...) (.so,
.dll, .dylib, ...)
Program A Program B static libs (.a) static libs (.a)
static linking compile-time
Program A Program B Program A Program B static libs
(.a) static libs (.a) shared libs (.so) static linking dynamic linking compile-time run-time
Library static shared bookstore library Paul Richter
source code compiler
source code compiler objects (.o) .o .o .o .a archive
.o
source code compiler linker objects (.o) .o .o .o .a
archive .o executable .so .so .so .so
source code compiler linker loader objects (.o) .o .o .o
.a archive .o executable in-memory image .so .so .so .so
Building the objects
lib1.c
main.c
Static Libraries
Static Libraries
Shared Libraries: Static Loading
Shared Libraries: Static Loading LD_LIBRARY_PATH
Shared Libraries: Dynamic Loading
main.c
main.c
Android
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Application Framework Apps Home Contacts Dialer Clock Your app 3rd party app ... Activity Manager Window Manager Package Manager Location Manager View System Content Providers ... Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ...
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Libraries Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Android Bionic
Bionic libc libm libdl Linker libstdc++
Bionic libc libm libdl Linker libstdc++ License Size Speed
Bionic libc libm libdl Linker libstdc++ BSD + Rewritten code
+ Android specific services
Bionic libc libm libdl Linker libstdc++
Bionic libc libm libdl Linker libstdc++ Completely from scratch! dlopen()
dlsym() dlerror() dlclose() {
Bionic libc libm libdl Linker libstdc++
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Application Framework Apps Home Contacts Dialer Clock Your app 3rd party app ... Activity Manager Window Manager Package Manager Location Manager View System Content Providers ... Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Kernel Audio driver Application Framework Apps Your app Media Player
Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Media Framework Media Player Audio Flinger libaudio.so JNI dlopen()
System.loadLibrary
System.loadLibrary Runtime.loadLibrary
Runtime.java
Runtime.java
None
None
Win: main.dll Linux: libmain.so Mac: libmain.dylib
None
LD_LIBRARY_PATH
Runtime.java
//TODO Runtime::doLoad Runtime.java
//TODO Runtime::doLoad
//TODO Runtime::doLoad LD_LIBRARY_PATH
ClassLoader search (for application libraries) VM search (for system libraries)
Runtime.java
Workaround for zygote’s LD_LIBRARY_PATH Runtime.java
Runtime.cpp
Native.cpp
Native.cpp
Native.cpp
Kernel Application Framework Apps Your app Runtime.java Libraries Android Runtime
Dalvik Virtual Machine (DVM) Native.cpp Runtime.cpp yourlib.so JNI dlopen()
We learned... • Static vs Shared Libraries • Dynamic Loading
• Library paths (+ difference on android) • Android’s internals ◦ Bionic ◦ Dynamic Loading with Dalvik ◦ System.loadLibrary
Thanks! @juliozynger soundcloud.com/jobs