$30 off During Our Annual Pro Sale. View Details »

An Efficient and Parallel Abstract Interpreter in Scala — Presentation

An Efficient and Parallel Abstract Interpreter in Scala — Presentation

More Decks by 🌳 Olivier Pirson — OPi 🇧🇪🇫🇷🇬🇧 🐧 👨‍💻 👨‍🔬

Other Decks in Science

Transcript

  1. Universit´
    e Libre de Bruxelles
    Computer Science Department
    MEMO-F524 Masters thesis
    An Efficient and Parallel
    Abstract Interpreter in Scala
    — Presentation —
    Olivier Pirson — [email protected]
    orcid.org/0000-0001-6296-9659
    November 27, 2017
    https://bitbucket.org/OPiMedia/efficient-parallel-abstract-interpreter-in-scala
    Vrije Universiteit Brussel
    Promotors Coen De Roover
    Wolfgang De Meuter
    Advisor Quentin Stievenart

    View Slide

  2. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    1 Abstract interpretation for static analysis
    2 Concrete vs abstract interpretation
    3 Parallelism
    4 Next steps
    5 References
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 2 / 24

    View Slide

  3. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    How do better than testing?
    “The first moral of the story is that program testing can be used very
    effectively to show the presence of bugs but never to show their absence.”
    (Dijkstra, 1971–1973)
    Figure: First “flight” of Ariane 5 in 1996.
    Investigation of Ariane failure:
    first large-scale example of static analysis by abstract interpretation.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 3 / 24

    View Slide

  4. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Static analysis
    Static analysis of program: analysis made without executing program.
    Goal? Prove some properties of program (like correctness, or some
    properties use to transform and optimize program). Or in the opposite, find
    bugs.
    Problem! Undecidable problem (we know that by Rice’s theorem).
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 4 / 24

    View Slide

  5. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Static analysis by abstract interpretation
    Abstract interpretation:
    approximation technique to perform static analysis.
    Based on mathematical notion of partially ordered sets
    (in particular lattice).
    Difficulty! Find good abstractions:
    enough precise to prove desired property,
    and enough approximate to be decidable (and with doable complexity).
    Figure: Ren´
    e Magritte, Le Calcul Mental. 1940.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 5 / 24

    View Slide

  6. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Example of abstraction
    {. . . , −3, −2, −1, 0, 1, 2, 3, . . .} abstracted by sign = {⊥, +, 0, −, ⊤}

    − 0 +

    Figure: Hasse diagram of the complete lattice of signs.
    top ⊤ = {. . . , −3, −2, −1, 0, 1, 2, 3, . . .}
    + = {1, 2, 3, . . .}
    0 = {0}
    − = {−1, −2, −3, . . .}
    bottom ⊥ = ∅
    May be good abstraction for multiplication operations.
    With additions, directly loss of precision.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 6 / 24

    View Slide

  7. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    1 Abstract interpretation for static analysis
    2 Concrete vs abstract interpretation
    3 Parallelism
    4 Next steps
    5 References
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 7 / 24

    View Slide

  8. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Concrete interpretation
    Trace: concrete interpretation with small-step semantics, for one instance.
    e
    s0 s1 s2 s3 s4 · · ·
    injection
    function
    concrete transition function
    Program is executed by interpreter,
    described by an Abstract Machine (AM).
    One execution is for one instance on this program.
    e is for one expression, i.e. a program.
    si
    are states during this execution.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 8 / 24

    View Slide

  9. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Abstract interpretation
    Trace: concrete interpretation with small-step semantics, for one instance.
    e
    s0 s1 s2 s3 s4 · · ·
    s0 s1 s2 s3 s4
    s3′
    injection
    function
    injection
    function
    abstraction
    function α
    abstract transition function
    Abstracting Abstract Machine (AAM).
    2 over-approximations:
    Finite state space.
    Abstract transition function returns all directly reachable states.
    State graph: abstract interpretation, for all instances.
    “The abstract simulates the concrete” (Might)
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 9 / 24

    View Slide

  10. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Concrete interpretation
    Correct program Incorrect program
    Figure: Patrick Cousot. Abstract Interpretation in a Nutshell.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 10 / 24

    View Slide

  11. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Abstract interpretation
    Correct program Incorrect program
    Figure: Patrick Cousot. Abstract Interpretation in a Nutshell.
    Correct abstract interpretation Incorrect abstract interpretation
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 11 / 24

    View Slide

  12. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Abstract interpretation
    Correct abstract interpretation Incorrect abstract interpretation
    Figure: Patrick Cousot. Abstract Interpretation in a Nutshell.
    Summary of difficulties:
    Decidability?
    Soundness vs completeness?
    Good complexity vs precision? =⇒ Parallelism
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 12 / 24

    View Slide

  13. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    1 Abstract interpretation for static analysis
    2 Concrete vs abstract interpretation
    3 Parallelism
    4 Next steps
    5 References
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 13 / 24

    View Slide

  14. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Goal of the thesis: parallelism to improve speed
    Parallelism to keep good precision and improve speed.
    I will parallelize Scala-AM, implemented by Quentin Stievenart.
    Target language: Scheme (“simple” but “general”).
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 14 / 24

    View Slide

  15. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Actor model
    Actor, like an object, isolated entity with its own encapsulated data and
    behaviour. With some fundamental differences.
    Entirely private.
    No shared mutable state (so no data race).
    Communication by immutable asynchronous messages
    (sent and received sequentially).
    Each actor has a mailbox (a queue).
    Capability to create other actors.
    Figure: Richard Doyle. Using Akka and Scala to Render a Mandelbrot Set. 2014.
    http://blog.scottlogic.com/2014/08/15/using-akka-and-scala-to-render-a-mandelbrot-set.html
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 15 / 24

    View Slide

  16. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Akka toolkit
    Akka: toolkit for Scala (and also Java).
    Concurrent and distributed
    (use many cores or several computers without modification).
    Reduced overhead.
    Light implementation of actors
    (in 1 GiB memory, possibility of millions actors,
    instead thousands of threads).
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 16 / 24

    View Slide

  17. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Sequential worklist strategy
    s
    s
    s
    s
    s
    worklist
    Figure: K. Dewey, V. Kashyap, B. Hardekopf. A parallel abstract interpreter for JavaScript. 2015.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 17 / 24

    View Slide

  18. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Naive worklist parallel strategy
    s
    s
    s
    s
    s
    worklist
    merge
    Figure: K. Dewey, V. Kashyap, B. Hardekopf. A parallel abstract interpreter for JavaScript. 2015.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 18 / 24

    View Slide

  19. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Naive worklist parallel strategy
    Redundant computations.
    Synchronization at the merge step.
    Article test on few real JavaScript programs.
    Results show that this adaptation of the sequential algorithm is not optimal.
    Figure: L. Andersen, M. Might. Multi-core Parallelization of Abstracted. 2013.
    I am curious about the results of this algorithm with the lot of little
    Scheme programs with Scala-AM.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 19 / 24

    View Slide

  20. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Better, per-context parallel strategy
    Authors introduce a per-context parallel strategy.
    The main idea is to separate these two parts:
    state exploration
    control of state space by some merging operations.
    The intuitive idea is to parallelize “functions” instead basic “blocks”.
    Figure: K. Dewey, V. Kashyap, B. Hardekopf. A parallel abstract interpreter for JavaScript. 2015.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 20 / 24

    View Slide

  21. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    1 Abstract interpretation for static analysis
    2 Concrete vs abstract interpretation
    3 Parallelism
    4 Next steps
    5 References
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 21 / 24

    View Slide

  22. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    Next steps
    A lot of work!
    Become more comfortable with actors paradigm and Akka.
    Implement the naive parallel algorithm, and experiment.
    Implement better parallel algorithms.
    Evaluate all of them and identify problematic parts.
    Read more.
    . . .
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 22 / 24

    View Slide

  23. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    1 Abstract interpretation for static analysis
    2 Concrete vs abstract interpretation
    3 Parallelism
    4 Next steps
    5 References
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 23 / 24

    View Slide

  24. An Efficient and
    Parallel Abstract
    Interpreter
    in Scala

    Presentation
    Abstract
    interpretation for
    static analysis
    Concrete vs
    abstract
    interpretation
    Parallelism
    Next steps
    References
    References
    Thank you! Questions time. . .
    L. Andersen, M. Might. Multi-core Parallelization of Abstracted
    Abstract Machines. 2013.
    Patrick Cousot. Abstract Interpretation in a Nutshell.
    K. Dewey, V. Kashyap, B. Hardekopf. A parallel abstract
    interpreter for JavaScript. 2015.
    Matthew Might. Tutorial: Small-step CFA. 2011.
    Quentin Sti´
    evenart. Static Analysis of Concurrency Constructs
    in Higher-Order Programs. 2014.
    D. Van Horn, M. Might. Abstracting Abstract Machines. 2010.
    Document, L
    A
    TEX sources, and complete references on Bitbucket:
    https:// Ø Ù ØºÓÖ »ÇÈ Å /efficient-parallel-abstract-interpreter-in-scala
    Olivier Pirson. An Efficient and Parallel Abstract Interpreter in
    Scala — Preparatory Work. 2017.
    An Efficient and Parallel Abstract Interpreter in Scala — Presentation 24 / 24

    View Slide