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
510
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
240
FloorPlan: Visualize databases' evolution
julioz
0
420
Publishing API & Continuous Deployment on Android
julioz
1
430
Continuous Deploy no Android
julioz
0
3.4k
Other Decks in Programming
See All in Programming
Architecture Decision Record (ADR)
nearme_tech
PRO
1
690
Understand the mechanism! Let's do screenshots tests of Compose Previews with various variations / 仕組みから理解する!Composeプレビューを様々なバリエーションでスクリーンショットテストしよう
sumio
3
790
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
430
状態管理ライブラリZustandの導入から運用まで
k1tikurisu
3
470
今インフラ技術をイチから学び直すなら
yuhta28
1
140
rails_girls_is_my_gate_to_join_the_ruby_commuinty
maimux2x
0
200
Jakarta EE meets AI
ivargrimstad
1
520
はじめてみよう量子プログラミング
itokoichi01
0
210
Go1.23で入った errorsパッケージの小さなアプデ
kuro_kurorrr
2
390
Why Prism?
kddnewton
4
1.7k
React + TextAliveでカッコいいLyric Applicatioinを作ろう!!
tosuri13
0
400
RAGの回答精度評価用のQAデータセットを生成AIに作らせた話
kurahara
0
250
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
359
19k
Design by the Numbers
sachag
277
19k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
25
3.9k
Producing Creativity
orderedlist
PRO
340
39k
The Cost Of JavaScript in 2023
addyosmani
42
5.7k
VelocityConf: Rendering Performance Case Studies
addyosmani
322
23k
Building Your Own Lightsaber
phodgson
101
6k
Visualization
eitanlees
142
15k
Faster Mobile Websites
deanohume
304
30k
The Art of Programming - Codeland 2020
erikaheidi
48
13k
Building an army of robots
kneath
302
42k
Why You Should Never Use an ORM
jnunemaker
PRO
53
8.9k
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