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
890
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
460
FloorPlan: Visualize databases' evolution
julioz
0
790
Publishing API & Continuous Deployment on Android
julioz
1
870
Continuous Deploy no Android
julioz
0
3.7k
Other Decks in Programming
See All in Programming
The free-lunch guide to idea circularity
hollycummins
0
330
20260228_JAWS_Beginner_Kansai
takuyay0ne
5
610
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
420
メタプログラミングで実現する「コードを仕様にする」仕組み/nikkei-tech-talk43
nikkei_engineer_recruiting
0
210
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
1
150
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
140
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
270
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.4k
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
8.3k
実践ハーネスエンジニアリング #MOSHTech
kajitack
4
1.5k
PHP 7.4でもOpenTelemetryゼロコード計装がしたい! / PHPerKaigi 2026
arthur1
1
390
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
150
Featured
See All Featured
Designing for Performance
lara
611
70k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
240
YesSQL, Process and Tooling at Scale
rocio
174
15k
RailsConf 2023
tenderlove
30
1.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
AI: The stuff that nobody shows you
jnunemaker
PRO
3
470
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
160
Building an army of robots
kneath
306
46k
Code Reviewing Like a Champion
maltzj
528
40k
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