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
550
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
270
FloorPlan: Visualize databases' evolution
julioz
0
450
Publishing API & Continuous Deployment on Android
julioz
1
490
Continuous Deploy no Android
julioz
0
3.5k
Other Decks in Programming
See All in Programming
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Recoilを剥がしている話
kirik
5
6.6k
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
330
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
4
1.1k
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
140
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
120
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
460
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
42 best practices for Symfony, a decade later
tucksaun
1
180
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
33
1.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
How GitHub (no longer) Works
holman
311
140k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Music & Morning Musume
bryan
46
6.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Designing for humans not robots
tammielis
250
25k
Producing Creativity
orderedlist
PRO
341
39k
It's Worth the Effort
3n
183
28k
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