Mint: A Multi-stage Augmentation of Java.


68 views
Uploaded on:
Category: Product / Service
Description
Mint: A Multi-stage Augmentation of Java COMP 600 Mathias Ricken Rice College February 8, 2010 Multi-stage Programming Multi-stage programming (MSP) dialects Give builds to program era Statically wrote: don't delay blunder checking until runtime
Transcripts
Slide 1

Mint: A Multi-stage Extension of Java COMP 600 Mathias Ricken Rice University February 8, 2010

Slide 2

Multi-stage Programming Multi-stage programming (MSP) dialects Provide builds for system era Statically wrote: don\'t postpone slip checking until runtime Useful for project specialization Optimizing a project for specific qualities Abstractions without the expense

Slide 3

MSP in Java Brackets delay calculation, yield an estimation of sort Code< ? > <| e |> or <| { s; s; } |> Escapes line together bits of code ` c Run executes a bit of code, returning result c .run() Ex: Code< Integer > x = <| 2 + 3 |> ; Code< Integer > y = <| 1 + ` x |> ; int z = y .run() ;/== 6

Slide 4

Unstaged force Function twofold power(double x, int n) { twofold acc = 1; for(int i=0; i<n; ++i) acc = acc * x; return acc; } twofold d = power(2, 4); Overhead because of circle Faster approach to figure x 4 : x*x*x*x Don’t need to compose x 2 , x 3 , x 4 … by hand Result: 16

Slide 5

Unstaged/Staged Comparison twofold power(double x, int n) { twofold acc = 1; for(int i=0; i<n; ++i) acc = acc * x; return acc; } Code< Double > spower( Code< Double > x,int n) { Code< Double > acc = <| 1 |> ; for(int i=0; i<n; ++i) acc = <| ` acc * ` x |> ; return acc; }

Slide 6

Staged force Function Code< Double > spower( Code< Double > x,int n) { Code< Double > acc = <| 1 |> ; for(int i=0; i<n; ++i) acc = <| ` acc * ` x |> ; return acc; } Code<Double> c = spower( <| 2 |> , 4); Double d = c .run() ; Result: <| (((1 * 2) * 2) * 2) * 2 |> Result: 16

Slide 7

Staged force Function Code< ? augments Lambda > codePower4 = <| new Lambda() { open Double apply(final Double x) { return ` (spower( <| x |> , 4));/return ` ( <| (((1*x)*x)*x)*x |> );/return (((1*x)*x)*x)*x; } |> ; Lambda power4 = codePower4 .run() ; Double d = power4.apply(2); Result: 16

Slide 8

Effects: Assignment Imperative dialects permit symptoms Example: Assignment Code< Integer > x; <| { Integer y = foo(); ‘ (x = <| y |> ); } |>.run() ; Integer i = x .run() ; <| y |> y utilized out of degree!

Slide 9

Effects: Exceptions Code< Integer > foo( Code< Integer > c) { toss new CodeContainerException(c); } attempt { <| { Integer y; ‘ (foo( <| y |> )); } |>.run(); } catch(CodeContainerException e) { Code< Integer > c = e.getCode(); Integer i = c .run() ; } <| y |> y utilized out of extension!

Slide 10

Scope Extrusion Side impacts including code Can move a variable access outside the extension where it is characterized Executing that code would bring about a lapse Causes Assignment of code qualities Exceptions containing code Cross-stage steadiness (CSP) of code 1

Slide 11

Weak Separability Prohibits symptoms including code in a break to be obvious from the outside Restricts code generators, not created code Escapes must be feebly distinguishable Generated code can openly utilize reactions.:

Slide 12

Weak versus Solid Separability (Strong) distinguishableness condition in Kameyama’08,’09 Did not permit any symptoms in a break to be unmistakable outside Weak detachability is more expressive Allow without code reactions obvious outside Useful in basic dialects like Java

Slide 13

Weakly Separable Terms A term is pitifully distinct if… Assignment just to sans code variables 2 Exceptions tossed don\'t have constructors taking code 3 CSP just for sans code sorts Only feebly divisible techniques and constructors called ( detachable modifier) Only pitifully distinguishable code is sewed in ( SafeCode rather than Code )

Slide 14

Evaluation Formalism Prove security Implementation Evaluate expressivity Benchmarks to contrast organizing advantages with known results from useful dialects

Slide 15

Lightweight Mint Developed a formalism in view of Lightweight Java (Strni š a’07) Proves that powerless distinctness counteracts scope expulsion Fairly substantial to model wellbeing issues Models task, arranging builds, unknown internal classes Many other basic MSP frameworks don\'t have formalisms

Slide 16

Implementation Based on the OpenJDK compiler Java 6 perfect Cross-stage (needs SoyLatte on Mac) Modified compiler to bolster arranging annotations Invoke compiler at runtime

Slide 17

Compiler Stages Compile time Generate bytecode to make ASTs for sections Safety checks authorizing frail detachability Runtime Create AST objects where sections are discovered Compile AST to class records when code is run Serialize AST into a string in memory Pass to javac compiler Load classes utilizing reflection

Slide 18

Expressivity Staged translator build up interpeter (Taha’04) Throws special case if environment lookup fizzles Staged exhibit sees

Slide 19

Unstaged Interpreter interface Exp { open int eval(Env e, FEnv f); } class Int actualizes Exp { private int _v; open Int(int esteem ) { _v = v; } open int eval(Env e, FEnv f) { return _v; } class App executes Exp { private String _s; private Exp _a;/contention open App(String s, Exp a) { _s = s; _a = a; } open int eval(Env e, FEnv f) { return f.get(_s).apply(_a.eval(e,f)); }

Slide 20

Staged Interpreter interface Exp { open detachable SafeCode< Integer > eval(Env e, FEnv f); } class Int actualizes Exp {/* ... */open detachable SafeCode< Integer > eval(Env e, FEnv f) { last int v = _v; return <| v |> ; } class App actualizes Exp {/* ... */open divisible SafeCode< Integer > eval(Env e, FEnv f) { return <| ` (f.get(_s)).apply( ` (_a.eval(e,f))) |> ; }

Slide 21

Staged Environment static distinguishable Env ext(final env, last String x, last SafeCode< Integer > v) { return new Env() { open distinct SafeCode< Integer > get(String y) { if (x==y) return v; else return env.get(y); }; } static Env env0 = new Env() { open detachable SafeCode< Integer > get(String y) { toss Yikes(y); } Throw a special case. Can’t be done securely in other MSP frameworks.

Slide 22

Expressivity Staged mediator Throws special case if environment lookup falls flat Staged exhibit sees HJ’s method for mapping numerous measurements into a 1-dimensional cluster (Shirako’07) Removal of file math Loop unrolling Side impacts in clusters

Slide 23

Unstaged Array Views class DoubleArrayView { double[] base;/... open twofold get(int i, int j) { return base[offset + (j-j0) + jSize*(i-i0)]; } open void set(double v, int i, int j) { base[offset + (j-j0) + jSize*(i-i0 )] = v; }

Slide 24

Staged Array Views class SDoubleArrayView { Code< double[] > base;/... open detachable Code< Double > get(final int i, last int j) { return <| ` (base)[ ` balance + (j-` j0) + ` jSize*(i-` i0)] |> ; } open divisible Code< Void > set(final Code< Double > v, last int i, last int j) { return <| { ` (base)[ ` counterbalance + (j-` j0) + ` jSize*(i-` i0)] = ` v; } |> ; }

Slide 25

Using Staged Array Views Much more helpful in Java than past MSP frameworks. open Code< Void > stranspose(int m, int n, last SDoubleArrayView information, last SDoubleArrayView yield) { Code< Void > details = <| { } |> ; for (int i = 0; i < m; i ++) for (int j = 0; j < m; j ++) details = <| { ` details; ` (output.set(input.get(i,j),j,i)); } |> ; return details; } Code< Void > c = stranspose(4, 4, a, b);/Generates code like this b [0+(0-0)+4*(0-0)] = a [0+(0-0)+4*(0-0)]; b [0+(0-0)+4*(1-0)] = a [0+(1-0)+4*(0-0)];//... Circle unrolling utilizing for-circle. Symptoms in clusters. Can’t be done in other MSP frameworks.

Slide 26

Benchmarks Apple MacBook 2.0 GHz Intel Core Duo 2 MB L2 store, 2 GB RAM, Mac OS 10.4

Slide 27

Future Work Speed up runtime gathering Use NextGen layout class innovation (Sasitorn’06) Compile bits statically, interface together at runtime Avoid 64 kB technique size JVM limit Cooperation with Habanero Group Integrate organized cluster perspectives into HJ http://habanero.rice.edu/Integrate with Closures for Java? http://javac.info/

Slide 28

Conclusion Statically-wrote safe MSP for basic dialects More expressive than past frameworks Implementation in light of OpenJDK Java profits by organizing not surprisingly

Slide 29

Thank You Weak detachability: safe, expressive multi-stage programming in basic dialects Download http://mint.concutest.org/Thanks to my co-creators Edwin Westbrook, Jun Inoue, Tamer Abdelatif, and Walid Taha, and to my consultant Corky Cartwright

Slide 30

Footnotes

Slide 31

Footnotes Scope expulsion by CSP of code, see additional slide . Task just to sans code variables, unless the variables are bound in the term. Special cases tossed might not have constructors taking code, unless the exemption is gotten in the term.

Slide 32

Extra Slides

Slide 33

Unstaged force in MetaOCaml let rec power(x, n) = if n=0 then 1 else x*power(x, n-1);; power(2, 4);; Overhead because of recursion Faster approach to ascertain x 4 : x*x*x*x Don’t need to compose x 2 , x 3 , x 4 … by hand Result: 16

Slide 34

Staged force in MetaOCaml let rec spower(x, n) = if n=0 then .< 1 >. else .< .~ (x) * .~ (power(x, n-1)) >. ;; let c = spower( .< 2 >. , 4);; let d = .! c;; Result: .< 2 * (2 * (2 * (2 * 1))) >. Result: 16

Slide 35

Staged forc

Recommended
View more...