Just-In-Time compilation Study setup Abstract interpretation Correctness proof Tracing Compilation by Abstract Interpretation S. Dissegna, F. Logozzo, F. Ranzato Théophile Bastian March 7, 2018 Slides: https://tiny.tobast.fr/m2-absint-slides Article: https://tiny.tobast.fr/m2-absint-article Théophile Bastian Tracing Compilation by Abstract Interpretation 0 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Just-In-Time compilation 1 Study setup 2 Abstract interpretation 3 Correctness proof 4 Théophile Bastian Tracing Compilation by Abstract Interpretation 0 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Just-In-Time (JIT) compilation Dynamic languages: hard to compile (rely on runtime) Yet ubiquitous: javascript, python, . . . Idea: compile at runtime the most used program parts Used in browsers (JS), PyPy (Python), most JVMs (Java), . . . r e Runtime l i Offline p m r o e c l i p e m d o o c c e t T y I B J Byte/machine Byte code Source code code Théophile Bastian Tracing Compilation by Abstract Interpretation 1 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof How is it done? (In most cases) strong interaction interpreter ↔ JIT compiler Article claim : mostly done using hot paths within loops (in a single function); most speedup is type specialization. Hot path: path used ≥ N times at runtime in a given (abstract) store state Théophile Bastian Tracing Compilation by Abstract Interpretation 2 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof How is it done? (In most cases) strong interaction interpreter ↔ JIT compiler Article claim : mostly done using hot paths within loops (in a single function); most speedup is type specialization. Hot path: path used ≥ N times at runtime in a given (abstract) store state Wrong. But, heh, we’ll deal with it nevertheless. (Inlining, translation to machine code, global optimizations, lock elimination, non-volatile-write elimination/propagation, . . . ) Théophile Bastian Tracing Compilation by Abstract Interpretation 2 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Study objectives Formalism to interpret JIT with AbsInt ( source transformation ) Hot path extraction Type specialization Formalism to extract observables from code � compare observables with/without JIT � prove correctness Can be extended with virtually any feature Théophile Bastian Tracing Compilation by Abstract Interpretation 3 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Studied language L : program labels K : literal values Conditional: V : variables ( P := C list ) : programs l 0 : b 0 → l t l 0 : ¬ b 0 → l f C ::= L : A → L ′ C Turing-complete A ::= ( x := E ) | B | skip A E , E ′ ::= v | x | E + E ′ Supposed to model some Expr bytecode B , B ′ ::= ⊤ | ⊥ | E ≤ E ′ BExpr | ¬ B | B ∧ B ′ Théophile Bastian Tracing Compilation by Abstract Interpretation 4 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Types, rough semantics Types & values Ω K := Z ∪ { a , . . . , z } ∗ Types: Int, String, Undef, ∅ , Ω String Int Undef Undef: error type ∅ Semantics Type-dependant + : Store := V → K ρ + String : concatenation State := C × Store � C , ρ � + Int : usual + Trace := State ∗ + Str , Int : yields Undef Théophile Bastian Tracing Compilation by Abstract Interpretation 5 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof AbsInt hot path extraction Assertion: a hot path is necessarily a (whole) loop body Introduce a function hot N selecting N -hot paths from a trace α N hot : P (Trace) → P (Trace # ) is an abstraction, a corresponding γ can be derived Note: a Trace # includes (abstract) stores, allowing optimisations on the hot path Théophile Bastian Tracing Compilation by Abstract Interpretation 6 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Hot path stitching For a ∈ Store # , introduce guard E a ∈ BExpr, true iff. ρ ∈ γ ( a ) Optimized path: duplicate hot path, guard each operation, fallback to original path Formally define an operator extr hp ( P ) extracting the hot path hp from the program P Once the hot path is extracted, it can be optimized wrt. known store restrictions. Théophile Bastian Tracing Compilation by Abstract Interpretation 7 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Hot path stitching sketch B 0 A 1 A n ⇓ G E a 0 G E a 1 G E a n B 0 A 1 A n B 0 A 1 A n Théophile Bastian Tracing Compilation by Abstract Interpretation 8 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Value type specialization Seen again as abstract interpretation: define α, γ . First, consider abstract type stores Store t := V → Type Clearly a valid abstract domain for Store Then, an operator E t ( E ) ρ : Expr → Store t → Type typing an expression (possibly to Undef or Ω ) Finally, define type specialization TS hp as the substitution in hp of + by its typed alternative, if possible ( ie. E t ( E + E ′ ) ρ ∈ { Int , String } ) Théophile Bastian Tracing Compilation by Abstract Interpretation 9 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Correctness proof sketch Idea: define (cf. Cousot) correctness of transformation as observational equivalence of source and transformed programs wrt. some abstraction α : P (Trace) → P (Store ∗ ) . That is, if α derives the abstraction, T extracts the program traces and Tr transforms it, we want α ( T ( P )) = α ( T ( Tr ( P ))) Heavy but safe: α = α sc , store changes � St ( s 1 ) · sc ( s 2 σ ) , St ( s 1 ) � = St ( s 2 ) sc ( s 1 s 2 σ ) := sc ( s 2 σ ) , St ( s 1 ) = St ( s 2 ) Lighter: same, but only at loop entry/exit points Théophile Bastian Tracing Compilation by Abstract Interpretation 10 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Correctness proof sketch, trace extraction Theorem Trace extraction is correct wrt. α sc , that is, ∀ P , ∀ hp , α sc ( T ( P )) = α sc ( T (extr hp ( P ))) Proved by mapping σ ∈ Trace to its correct trace through tr hp ( σ ) in extr hp ( P ) =: P hp Then show that tr hp ( T ( P )) ⊆ T ( P hp ) i α sc ( T ( P hp )) ⊆ α sc ( T ( P )) ii α sc ◦ tr hp = α sc iii Théophile Bastian Tracing Compilation by Abstract Interpretation 11 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Correctness proof sketch, type specialization Theorem Type specialization is correct (at traces level) Define tt ( σ ) erasing type specialization ( eg. + Int �→ + ). Then, tt ( T ( TS hp ( stitch P ( hp )))) = T ( stitch P ( hp )) Theorem Stitching type specialization to a hot path is correct wrt. α sc . (directly follows) Théophile Bastian Tracing Compilation by Abstract Interpretation 12 / 13
Just-In-Time compilation Study setup Abstract interpretation Correctness proof Conclusion Pros Opens the way for AbsInt formalism in JIT Provides an (implemented?) framework for JIT study Cons Overly restrictive in JIT features, pretends otherwise Unusably small toy language Absurdly hard to read toy language Proof wrt. some α which does not handle effects Please, stop claiming every line or two that your paper is better than Guo and Palsberg’s Théophile Bastian Tracing Compilation by Abstract Interpretation 13 / 13
Recommend
More recommend