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

How does TruffleRuby work

How does TruffleRuby work

2019/4/19に行われたRubyKaigi2019でのLT登壇資料です。
Truffleがどのような方針で最適化を行うかという話をしました。

Naoki Kishida

April 19, 2019
Tweet

More Decks by Naoki Kishida

Other Decks in Technology

Transcript

  1. , / 1
    4 2 0 4 4

    View Slide

  2. • )
    • (

    • )

    View Slide




  3. View Slide



  4. View Slide

  5. • ( A 0 D
    • C A
    • H 0 C G

    A C 0
    • 1 G
    D
    )
    (
    1-
    )
    2 D

    View Slide

  6. ! !


    • ..
    • ..

    View Slide

  7. • CA ( 22 2A , 2 ,
    2 2 2 2
    • .C A 2 + A C + 2
    • + 2 2
    • ( - 2A 2 2
    • ( 22 + 2A 2 A C 2 2
    • -C 2 2 A 2AA ) . 2 ( 22
    • -C 2A 2 2 2 ( 22 .C A 2 +

    View Slide

  8. • - A
    • + /
    • A +
    • - - + - -
    • +
    @CoreMethod(names = "^", required = 1)
    public abstract static class BitXOrNode extends
    BignumCoreMethodNode {
    @Specialization
    public int bitXOr(int a, int b) {
    return a ^ b;
    }
    @Specialization
    public long bitXOr(long a, long b) {
    return a ^ b;
    }
    - - . / / - -

    View Slide

  9. • ( ( ( (
    • ( + * ( (
    • ( + ( * ( *
    * (
    ( + ( * + * ()
    • ( (
    def bar(num)
    a = 3
    return num + a
    end
    def foo
    print bar(2)
    end
    def bar(num)
    return num + 3
    end
    def foo
    print bar(2)
    end
    def foo
    print 2 + 3
    end
    def foo
    print 5
    end

    View Slide

  10. . 2
    . 2

    View Slide

  11. ) ( (
    • 1 1 1 1! 1>1 - 1
    1 3- 3 1
    • ( - - 1 3
    • 1 3- 3 1 3 1 1 1 ! 3 1
    • ( - - 1 3
    • 1 3- 3 1 1 3- 3 1 ! 3 1 )1 1 -
    • ( - - 1 3
    • 3 22 1

    View Slide

  12. • - : 2 A 2
    • 1 E 2 I/ A2 I
    • I 2 24:
    • A : : 2 : A
    • :
    : : A
    • 0 : / E A : : ./
    A 2 2 2 : 4 A: : A :
    2 2 : A 2 E
    def jump(self, space, bytecode, frame, cur_pc, target_pc):
    if target_pc < cur_pc:
    self.jitdriver.can_enter_jit(
    self=self, bytecode=bytecode, frame=frame, pc=target_pc,
    block_bytecode=self.get_block_bytecode(frame.block),
    w_trace_proc=space.getexecutioncontext().gettraceproc()
    )
    return target_pc
    A2 : A A

    View Slide



  13. @CoreMethod(names = "^", required = 1)
    public abstract static class BitXOrNode extends
    BignumCoreMethodNode {
    @Specialization
    public int bitXOr(int a, int b) {
    return a ^ b;
    }
    @Specialization
    public long bitXOr(long a, long b) {
    return a ^ b;
    }

    View Slide




  14. • -

    • -
    • -

    View Slide

  15. • (
    • >
    • )>-
    • )>-
    • )>- >
    • - >
    • > -
    • >
    • ->
    • ->

    View Slide







  16. View Slide



  17. • !

    View Slide