Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Das eierlegende Truffleschwein (DeafIT edition)

Das eierlegende Truffleschwein (DeafIT edition)

Damals, ganz früher, da war Java noch die alleinherschende Sprache auf der JVM und konnte tun und lassen, was sie wollte. Später gesellten sich ein paar Skriptsprachen hinzu, wie zum Beispiel Jython und JRuby. Und die neuen kompilierten Sprachen wie Scala und Kotlin haben das Zeitalter der polyglotten Programmierung endgültig eingeläutet. Das zur GraalVM zugehörige Truffle-Projekt verspricht nun, es noch einfacher zu machen, auch eigentlich JVM-fremde Sprachen mit dem Ökosystem zu verzahnen.

Lars Hupel

March 12, 2021
Tweet

More Decks by Lars Hupel

Other Decks in Programming

Transcript

  1. D a s e i e r l e g e n d e
    T r u f f l e s c h w e i n
    L a r s H u p e l
    D e a f I T
    2 0 2 1 - 0 3 - 1 2

    View full-size slide

  2. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M

    View full-size slide

  3. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y

    View full-size slide

  4. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y

    View full-size slide

  5. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y
    2 0 0 4 e r s t e V e r s i o n v o n S c a l a

    View full-size slide

  6. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y
    2 0 0 4 e r s t e V e r s i o n v o n S c a l a
    2 0 0 6 J a v a 6 m i t J S R 2 2 3 ( s c r i p t i n g )

    View full-size slide

  7. J S R 2 2 3
    P r o b l e m
    S e r v l e t s s i n d c o o l , a b e r w i r w o l l e n u n s e r e W e b s e i t e n i n P H P s c h r e i b e n .

    View full-size slide

  8. J S R 2 2 3
    P r o b l e m
    S e r v l e t s s i n d c o o l , a b e r w i r w o l l e n u n s e r e W e b s e i t e n i n P H P s c h r e i b e n .
    L ö s u n g
    W i r d e f i n i e r e n e i n e S c h n i t t s t e l l e z u m A u s t a u s c h v o n O b j e k t e n z w i s c h e n
    J a v a u n d S k r i p t s p r a c h e n .

    View full-size slide

  9. S k r i p t s p r a c h e n
    • J S R 2 2 3 d e f i n i e r t „ S k r i p t s p r a c h e “ n i c h t
    • F o r m u l i e r u n g s u g g e r i e r t u n g e t y p e
    S p r a c h e n
    • f u n d a m e n t a l e s P r o b l e m : d i e m e i s t e n
    A u f r u f e b e n ö t i g e n R e f l e c t i o n
    ( l a n g s a m )

    View full-size slide

  10. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y
    2 0 0 4 e r s t e V e r s i o n v o n S c a l a
    2 0 0 6 J a v a 6 m i t J S R 2 2 3 ( s c r i p t i n g )

    View full-size slide

  11. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y
    2 0 0 4 e r s t e V e r s i o n v o n S c a l a
    2 0 0 6 J a v a 6 m i t J S R 2 2 3 ( s c r i p t i n g )
    2 0 1 1 J a v a 7 m i t J S R 2 9 2 ( invokedynamic)

    View full-size slide

  12. D a V i n c i M a c h i n e
    • g e s t a r t e t 2 0 0 7 a l s S p i e l w i e s e f ü r V M s
    • T e i l p r o j e k t e : d y n a m i c i n v o c a t i o n ,
    c o n t i n u a t i o n s , t a i l - c a l l s , . . .

    View full-size slide

  13. i n v o k e d y n a m i c
    P r o b l e m
    S k r i p t s p r a c h e n s i n d c o o l , a b e r w i r w i s s e n
    n i c h t w a s z u m G e i e r x + y b e d e u t e t

    View full-size slide

  14. i n v o k e d y n a m i c
    P r o b l e m
    S k r i p t s p r a c h e n s i n d c o o l , a b e r w i r w i s s e n
    n i c h t w a s z u m G e i e r x + y b e d e u t e t
    [object Object]

    View full-size slide

  15. i n v o k e d y n a m i c
    P r o b l e m
    S k r i p t s p r a c h e n s i n d c o o l , a b e r w i r w i s s e n
    n i c h t w a s z u m G e i e r x + y b e d e u t e t
    [object Object]
    L ö s u n g
    D e m C o m p i l e r e r m ö g l i c h e n , e i g e n e L o g i k
    z u m F u n k t i o n s a u f r u f z u i m p l e m e n t i e r e n

    View full-size slide

  16. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y
    2 0 0 4 e r s t e V e r s i o n v o n S c a l a
    2 0 0 6 J a v a 6 m i t J S R 2 2 3 ( s c r i p t i n g )
    2 0 1 1 J a v a 7 m i t J S R 2 9 2 ( invokedynamic)

    View full-size slide

  17. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y
    2 0 0 4 e r s t e V e r s i o n v o n S c a l a
    2 0 0 6 J a v a 6 m i t J S R 2 2 3 ( s c r i p t i n g )
    2 0 1 1 J a v a 7 m i t J S R 2 9 2 ( invokedynamic)
    2 0 1 4 J a v a 8 m i t N a s h o r n

    View full-size slide

  18. J a v a : e i n e k u r z e G e s c h i c h t e
    1 9 9 4 e r s t e V e r s i o n d e r J V M
    2 0 0 1 e r s t e V e r s i o n e n v o n J y t h o n u n d J R u b y
    2 0 0 3 e r s t e V e r s i o n v o n G r o o v y
    2 0 0 4 e r s t e V e r s i o n v o n S c a l a
    2 0 0 6 J a v a 6 m i t J S R 2 2 3 ( s c r i p t i n g )
    2 0 1 1 J a v a 7 m i t J S R 2 9 2 ( invokedynamic)
    2 0 1 4 J a v a 8 m i t N a s h o r n
    2 0 1 9 e r s t e V e r s i o n v o n G r a a l V M

    View full-size slide

  19. G r a a l V M
    • p o l y g l o t t e J V M , e n t w i c k e l t v o n O r a c l e
    • R e i c h t u m a n F e a t u r e s

    View full-size slide

  20. W a s i s t T r u f f l e ?
    “ D a s T r u f f l e - F r a m e w o r k e r m ö g l i c h t d i e e f f i z i e n t e A u s f ü h r u n g v o n P r o -
    g r a m m i e r s p r a c h e n a u f d e r G r a a l V M . E s v e r e i n f a c h t d i e I m p l e m e n -
    t i e r u n g v o n S p r a c h e n , i n d e m e s a u s I n t e r p r e t e r n a u t o m a t i s c h h o c h -
    p e r f o r m a n t e n C o d e e r z e u g t .

    View full-size slide

  21. P a r t i e l l e A p p l i k a t i o n
    A => B => C

    View full-size slide

  22. P a r t i e l l e A p p l i k a t i o n
    A => B => C
    +
    A

    View full-size slide

  23. P a r t i e l l e A p p l i k a t i o n
    A => B => C
    +
    A
    =
    B => C

    View full-size slide

  24. P a r t i e l l e A u s f ü h r u n g
    A => B => C
    +
    A
    =
    B => C

    View full-size slide

  25. C o m p i l e r f ü h r e n C o d e s t ä n d i g p a r t i e l l a u s !
    L o o p u n r o l l i n g
    C o n s t a n t f o l d i n g
    B o u n d s - c h e c k i n g e l i m i n a t i o n
    D e a d c o d e e l i m i n a t i o n
    D e f o r e s t a t i o n
    I n l i n i n g

    View full-size slide

  26. B e i s p i e l
    int f(int x, int y) {
    int res = 0;
    for (int i = 0; i < x; ++i)
    res += y;
    return res;
    }

    View full-size slide

  27. B e i s p i e l
    int f(int x, int y) {
    int res = 0;
    for (int i = 0; i < x; ++i)
    res += y;
    return res;
    }
    stream.map(y => f(3, y));

    View full-size slide

  28. B e i s p i e l
    int f_x3(int y) {
    int res = 0;
    res += y;
    res += y;
    res += y;
    return res;
    }
    stream.map(y => f_x3(y));

    View full-size slide

  29. B e i s p i e l
    int f_x3(int y) {
    return 3 * y;
    }
    stream.map(y => f_x3(y));

    View full-size slide

  30. B e i s p i e l
    stream.map(y => 3 * y);

    View full-size slide

  31. C o m p i l e r
    Q u e l l -
    t e x t
    C o m p i l e r
    K o m -
    p i l a t
    L a u f z e i t
    A u s -
    g a b e
    E i n g a b e

    View full-size slide

  32. I n t e r p r e t e r
    Q u e l l -
    t e x t
    L a u f z e i t
    A u s -
    g a b e
    E i n g a b e

    View full-size slide

  33. F u t a m u r a - P r o j e k t i o n
    Q u e l l -
    t e x t
    L a u f z e i t
    A u s -
    g a b e
    E i n g a b e
    Q u e l l -
    t e x t
    K o m p i l a t

    View full-size slide

  34. F u t a m u r a - P r o j e k t i o n e n
    v o r g e s c h l a g e n v o n Y o s h i h i k o F u t a m u r a
    i n d e n 1 9 8 0 e r - J a h r e n

    View full-size slide

  35. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
    Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
    Applying Futamura projections
    to compose Languages and Tools
    in GraalVM
    PEPM 2019
    Christian Humer
    VM Research Group, Oracle Labs, Zurich

    View full-size slide

  36. public abstract class JSMultiplyNode extends JSBinaryNode {
    public abstract Object execute(Object a, Object b);
    @Specialization(guards = "b > 0", rewriteOn = ArithmeticException.class)
    protected int doIntBLargerZero(int a, int b) { /* ... */ }
    @Specialization(rewriteOn = ArithmeticException.class)
    protected int doInt(int a, int b) { /* ... */ }
    @Specialization
    protected double doDouble(double a, double b) {
    return a * b;
    }
    // ...
    }

    View full-size slide

  37. J V M + P o l y g l o t = P r o f i t
    • S p r a c h e n k ö n n e n s i c h g e g e n s e i t i g a u f r u f e n
    • S p r a c h e n p r o f i t i e r e n v o n d e r J V M :
    N e b e n l ä u f i g k e i t
    T o o l i n g
    B i b l i o t h e k e n
    . . .

    View full-size slide

  38. N a t i v e r C o d e

    View full-size slide

  39. Q & A
    L a r s H u p e l
    � l a r s . h u p e l @ i n n o q . c o m
    � @ l a r s r _ h
    w w w . i n n o q . c o m

    View full-size slide

  40. L A R S H U P E L
    S e n i o r C o n s u l t a n t
    i n n o Q D e u t s c h l a n d G m b H
    L a r s i s k n o w n a s o n e o f t h e f o u n d e r s o f t h e T y p e -
    l e v e l i n i t i a t i v e w h i c h i s d e d i c a t e d t o p r o v i d i n g
    p r i n c i p l e d , t y p e - d r i v e n S c a l a l i b r a r i e s i n a f r i e n d l y ,
    w e l c o m i n g e n v i r o n m e n t . A f r e q u e n t c o n f e r e n c e
    s p e a k e r , t h e y a r e a c t i v e i n t h e o p e n s o u r c e c o m -
    m u n i t y , p a r t i c u l a r l y i n S c a l a .

    View full-size slide

  41. B i l d q u e l l e n

    C o n d e - C l e m e n t e , P a t r i c i a & O r t i n , F r a n c i s c o . ( 2 0 1 4 ) . J I N D Y : A j a v a l i b r a r y t o s u p p o r t i n v o k e d y n a m i c .

    S p i c e s : https://pixabay.com/photos/spices-spice-mix-market-73776/

    D u c k t y p i n g : https://twitter.com/sketchymacro/status/1229046533359689730

    G r a a l V M a r c h i t e c t u r e : https://blogs.oracle.com/graalvm/announcement

    G r a a l V M s l i d e : https://popl19.sigplan.org/details/pepm-2019-papers/2/
    Applying-Futamura-Projections-to-Compose-Languages-and-Tools-in-GraalVM-Invited-Talk

    F u t u r a m a l o g o : https://de.wikipedia.org/w/index.php?title=Datei:Futurama-logo.svg&oldid=88835467

    D a V i n c i V M s l i d e : https://openjdk.java.net/projects/mlvm/pdf/LangNet20080128.pdf

    L L V M l o g o : A p p l e

    D u k e : O r a c l e

    F i e l d : https://unsplash.com/photos/4miBe6zg5r0

    C a t w i t h y a r n : https://www.publicdomainpictures.net/en/view-image.php?image=161669&picture=cat-isolated-on-the-white

    View full-size slide