Language-side Foreign Function Interfaces with NativeBoost IWST - - PowerPoint PPT Presentation

language side foreign function interfaces with nativeboost
SMART_READER_LITE
LIVE PREVIEW

Language-side Foreign Function Interfaces with NativeBoost IWST - - PowerPoint PPT Presentation

Language-side Foreign Function Interfaces with NativeBoost IWST 2013 Camillo Bruni, Luc Fabresse, Stphane Ducasse, Igor Stasenko Outline 1. Context 2. Existing Solutions 3. NativeBoost 4. Speed Comparison of NativeBoost with other FFIs


slide-1
SLIDE 1

Camillo Bruni, Luc Fabresse, Stéphane Ducasse, Igor Stasenko

IWST 2013

Language-side Foreign Function Interfaces with NativeBoost

slide-2
SLIDE 2

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

slide-3
SLIDE 3

IWST ¡2013 ¡@ ¡Annecy

Context

3

Cairo OpenGL

LibC

Language Virtual Machine (VM)

Chipmunk

...

slide-4
SLIDE 4

IWST ¡2013 ¡@ ¡Annecy

Context

4

Language Virtual Machine (VM)

How to interact with external libraries?

Cairo OpenGL

LibC

Chipmunk

...

slide-5
SLIDE 5

IWST ¡2013 ¡@ ¡Annecy

Existing Solutions

Language-side Library VM Extension VM Plugin Foreign Function Interface VM-level Language-level

5

slide-6
SLIDE 6

IWST ¡2013 ¡@ ¡Annecy

Existing Solutions

Language-side Library VM Extension VM Plugin Foreign Function Interface VM-level Language-level

6

costly

slide-7
SLIDE 7

IWST ¡2013 ¡@ ¡Annecy

Existing Solutions

Language-side Library VM Extension VM Plugin Foreign Function Interface VM-level Language-level

7

costly low-level

slide-8
SLIDE 8

IWST ¡2013 ¡@ ¡Annecy

Existing Solutions

Language-side Library VM Extension VM Plugin Foreign Function Interface VM-level Language-level

8

slow fast costly low-level

slide-9
SLIDE 9

IWST ¡2013 ¡@ ¡Annecy

9

NativeBoost

A language-side and fast FFI implementation

slide-10
SLIDE 10

IWST ¡2013 ¡@ ¡Annecy

10

Language-side

  • Extensible
  • Easy to use
  • no

VM code needed

  • no low-level code (C wrapper)

needed

slide-11
SLIDE 11

IWST ¡2013 ¡@ ¡Annecy

11

Fast Transparent

generation of Assembly code from the language-side

slide-12
SLIDE 12

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

12

char* getenv(const char*)

slide-13
SLIDE 13

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

13

char* getenv(const char*)

slide-14
SLIDE 14

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

14

Regular Smalltalk method with one argument

slide-15
SLIDE 15

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

15

A pragma indicating that #primitiveNativeCall of #NativeBoost plugin should be executed when this method is executed

slide-16
SLIDE 16

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

16

slide-17
SLIDE 17

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

17

types annotation used to generate marshalling code

char* getenv(const char*)

slide-18
SLIDE 18

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

18

the value to be passed when calling out

slide-19
SLIDE 19

IWST ¡2013 ¡@ ¡Annecy

NativeBoost Example

19

the external library address in which the function is looked up

slide-20
SLIDE 20

IWST ¡2013 ¡@ ¡Annecy

Speed Comparisons

20

  • NativeBoost
  • Alien FFI
  • C-FFI
  • LuaJIT
  • Callouts
  • Marshalling
  • Callbacks
slide-21
SLIDE 21

IWST ¡2013 ¡@ ¡Annecy

21

Callout Evaluation

uint clock(void)

Average time calling out

0% 50% 100% 150% NativeBoost Alien C-FFI LuaJIT

faster slower

slide-22
SLIDE 22

IWST ¡2013 ¡@ ¡Annecy

22

0% 100% 200% 300% NativeBoost Alien C-FFI LuaJIT

Marshalling int

int abs(int)

slide-23
SLIDE 23

IWST ¡2013 ¡@ ¡Annecy

23

0% 100% 200% 300% 400% NativeBoost Alien C-FFI LuaJIT

Marshalling char*/String

int printf(char*,int,int)

slide-24
SLIDE 24

IWST ¡2013 ¡@ ¡Annecy

24

NativeBoost Alien C-FFI LuaJIT

Marshalling char*/String

char* getenv( char* )

100% 300% 1000%

slide-25
SLIDE 25

IWST ¡2013 ¡@ ¡Annecy

25

NativeBoost Alien C-FFI LuaJIT

Marshalling char*/String

char* getenv( char* )

100% 300% 1000%

slide-26
SLIDE 26

IWST ¡2013 ¡@ ¡Annecy

26

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)

slide-27
SLIDE 27

IWST ¡2013 ¡@ ¡Annecy

27

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*))

n

  • t

s u p p

  • r

t e d

slide-28
SLIDE 28

IWST ¡2013 ¡@ ¡Annecy

Insights into NativeBoost Internals

28

NBExample getenv: ‘PATH’

slide-29
SLIDE 29

IWST ¡2013 ¡@ ¡Annecy

Insights into NativeBoost Internals

29

NBExample getenv: ‘PATH’

slide-30
SLIDE 30

IWST ¡2013 ¡@ ¡Annecy

NBExample getenv: ‘PATH’

Insights into NativeBoost Internals

30

Virtual Machine (VM)

NativeBoost Plugin

slide-31
SLIDE 31

IWST ¡2013 ¡@ ¡Annecy

NBExample getenv: ‘PATH’

Insights into NativeBoost Internals

31

Virtual Machine (VM)

NativeBoost Plugin

Fail if no native code associated with #getenv:

slide-32
SLIDE 32

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
slide-33
SLIDE 33

IWST ¡2013 ¡@ ¡Annecy

Virtual Machine (VM)

NativeBoost Plugin

Insights into NativeBoost Internals

33

activate the native code associated with #getenv:

NBExample getenv: ‘PATH’

slide-34
SLIDE 34

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

slide-35
SLIDE 35

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

slide-36
SLIDE 36

Camillo Bruni, Luc Fabresse, Stéphane Ducasse, Igor Stasenko

IWST 2013

Language-side Foreign Function Interfaces with NativeBoost