language-side foreign function interfaces with nativeboost
DESCRIPTION
Language-side Foreign Function Interfaces with NativeBoost Camillo Bruni, Luc Fabresse, Stéphane Ducasse, Igor StasenkoTRANSCRIPT
![Page 1: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/1.jpg)
Camillo Bruni, Luc Fabresse, Stéphane Ducasse, Igor Stasenko
IWST 2013
Language-side Foreign Function Interfaces
with NativeBoost
![Page 2: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/2.jpg)
IWST 2013 @ Annecy
Outline
1. Context
2. Existing Solutions
3. NativeBoost
4. Speed Comparison of NativeBoost with other FFIs
5. NativeBoost Internals
6. Conclusion & Future Work
2
![Page 3: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/3.jpg)
IWST 2013 @ Annecy
Context
3
CairoOpenGL
LibC
Language
Virtual Machine (VM)
Chipmunk
...
![Page 4: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/4.jpg)
IWST 2013 @ Annecy
Context
4
Language
Virtual Machine (VM)
How to interact with external libraries?
CairoOpenGL
LibC
Chipmunk
...
![Page 5: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/5.jpg)
IWST 2013 @ Annecy
Existing Solutions
Language-side Library
VM Extension
VM Plugin
Foreign Function Interface
VM-level
Language-level
5
![Page 6: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/6.jpg)
IWST 2013 @ Annecy
Existing Solutions
Language-side Library
VM Extension
VM Plugin
Foreign Function Interface
VM-level
Language-level
6
costly
![Page 7: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/7.jpg)
IWST 2013 @ Annecy
Existing Solutions
Language-side Library
VM Extension
VM Plugin
Foreign Function Interface
VM-level
Language-level
7
costly
low-level
![Page 8: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/8.jpg)
IWST 2013 @ Annecy
Existing Solutions
Language-side Library
VM Extension
VM Plugin
Foreign Function Interface
VM-level
Language-level
8
slowfast
costly
low-level
![Page 9: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/9.jpg)
IWST 2013 @ Annecy9
NativeBoost
A language-side and fast
FFI implementation
![Page 10: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/10.jpg)
IWST 2013 @ Annecy10
Language-side
• Extensible
• Easy to use
• no VM code needed
• no low-level code (C wrapper) needed
![Page 11: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/11.jpg)
IWST 2013 @ Annecy11
Fast
Transparent generation of Assembly code
from the language-side
![Page 12: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/12.jpg)
IWST 2013 @ Annecy
NativeBoost Example
12
char* getenv(const char*)
![Page 13: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/13.jpg)
IWST 2013 @ Annecy
NativeBoost Example
13
char* getenv(const char*)
![Page 14: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/14.jpg)
IWST 2013 @ Annecy
NativeBoost Example
14
Regular Smalltalk methodwith one argument
![Page 15: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/15.jpg)
IWST 2013 @ Annecy
NativeBoost Example
15
A pragma indicating that #primitiveNativeCall of #NativeBoost pluginshould be executed when this method is executed
![Page 16: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/16.jpg)
IWST 2013 @ Annecy
NativeBoost Example
16
![Page 17: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/17.jpg)
IWST 2013 @ Annecy
NativeBoost Example
17
types annotation used to generate marshalling code
char* getenv(const char*)
![Page 18: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/18.jpg)
IWST 2013 @ Annecy
NativeBoost Example
18
the value to be passed when calling out
![Page 19: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/19.jpg)
IWST 2013 @ Annecy
NativeBoost Example
19
the external library address in which the function is looked up
![Page 20: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/20.jpg)
IWST 2013 @ Annecy
Speed Comparisons
20
• NativeBoost
• Alien FFI
• C-FFI
• LuaJIT
• Callouts
• Marshalling
• Callbacks
![Page 21: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/21.jpg)
IWST 2013 @ Annecy21
Callout Evaluation
uint clock(void)
Average time calling out
0%
50%
100%
150%
NativeBoost Alien C-FFI LuaJIT
faster
slower
![Page 22: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/22.jpg)
IWST 2013 @ Annecy22
0%
100%
200%
300%
NativeBoost Alien C-FFI LuaJIT
Marshalling int
int abs(int)
![Page 23: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/23.jpg)
IWST 2013 @ Annecy23
0%
100%
200%
300%
400%
NativeBoost Alien C-FFI LuaJIT
Marshalling char*/String
int printf(char*,int,int)
![Page 24: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/24.jpg)
IWST 2013 @ Annecy24
NativeBoost Alien C-FFI LuaJIT
Marshalling char*/String
char* getenv( char* )
100%
300%
1000%
![Page 25: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/25.jpg)
IWST 2013 @ Annecy25
NativeBoost Alien C-FFI LuaJIT
Marshalling char*/String
char* getenv( char* )
100%
300%
1000%
![Page 26: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/26.jpg)
IWST 2013 @ Annecy26
NativeBoost Alien C-FFI LuaJIT
Marshalling structs
100%
400%
1000%
void cairo_matrix_multiply ( cairo_matrix_t *result, cairo_matrix_t *a, cairo_matrix_t *b)
![Page 27: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/27.jpg)
IWST 2013 @ Annecy27
NativeBoost Alien C-FFI LuaJIT
Callbacks Evaluation
30%
100%
void qsort ( void *base, size_t nel, size_t width, int (*compare)(const void*, const void*))
not
su
ppor
ted
![Page 28: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/28.jpg)
IWST 2013 @ Annecy
Insights into NativeBoost Internals
28
NBExample getenv: ‘PATH’
![Page 29: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/29.jpg)
IWST 2013 @ Annecy
Insights into NativeBoost Internals
29
NBExample getenv: ‘PATH’
![Page 30: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/30.jpg)
IWST 2013 @ Annecy
NBExample getenv: ‘PATH’
Insights into NativeBoost Internals
30
Virtual Machine (VM)
NativeBoost Plugin
![Page 31: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/31.jpg)
IWST 2013 @ Annecy
NBExample getenv: ‘PATH’
Insights into NativeBoost Internals
31
Virtual Machine (VM)
NativeBoost Plugin
Fail if no native codeassociated with #getenv:
![Page 32: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/32.jpg)
IWST 2013 @ Annecy
NBExample getenv: ‘PATH’
Insights into NativeBoost Internals
32
Virtual Machine (VM)
NativeBoost Plugin
1. generate native code for marshalling, ...2. associate it with #getenv:3. restart the method execution
![Page 33: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/33.jpg)
IWST 2013 @ Annecy
Virtual Machine (VM)
NativeBoost Plugin
Insights into NativeBoost Internals
33
activate the native code associated with #getenv:
NBExample getenv: ‘PATH’
![Page 34: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/34.jpg)
IWST 2013 @ Annecy
Conclusion
34
• NativeBoost-FFI is:
• Language-side: extensible, high-level code only
• Fast compared to other Smalltalk FFI
• Needs optimizations on Callbacks but that would require strong VM support
![Page 35: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/35.jpg)
IWST 2013 @ Annecy
Future Work
• Improve NativeBoost Callback performance
• Reuse Alien’s VM Callback support?
• Better integration of NativeBoost with the JIT
• Do not leave JIT-mode when activating a NB method
35
![Page 36: Language-side Foreign Function Interfaces with NativeBoost](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555bdea9d8b42a38078b4862/html5/thumbnails/36.jpg)
Camillo Bruni, Luc Fabresse, Stéphane Ducasse, Igor Stasenko
IWST 2013
Language-side Foreign Function Interfaces
with NativeBoost