rethinking ll: jse & proto

30
17NOV01 Proto @ LL1 Rethinking LL: Rethinking LL: JSE & JSE & Proto Proto Jonathan Bachrach MIT AI Lab

Upload: ovid

Post on 31-Jan-2016

17 views

Category:

Documents


0 download

DESCRIPTION

Rethinking LL: JSE & Proto. Jonathan Bachrach MIT AI Lab. Java Syntactic Extender. Convenient Syntactic Extension for Conventionally Syntaxed Languages Builds on work from Dylan and Lisp Joint work with Keith Playford OOPSLA-01 www.ai.mit.edu/~jrb/jse/. JSE Example. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Rethinking LL:Rethinking LL:

JSE & JSE & ProtoProto

Jonathan Bachrach

MIT AI Lab

Page 2: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Java Syntactic ExtenderJava Syntactic Extender

• Convenient Syntactic Extension for Conventionally Syntaxed Languages

• Builds on work from Dylan and Lisp

• Joint work with Keith Playford

• OOPSLA-01– www.ai.mit.edu/~jrb/jse/

Page 3: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

JSE ExampleJSE Example

forEach(Task elt in tasks) elt.stop();

public syntax forEach { case #{ forEach (?:type ?elt:name in ?:expression) ?:statement }: return #{ Iterator i = ?expression.iterator(); while (i.hasNext()) { ?elt = (?type)i.next(); ?statement

} } };

Page 4: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Scripting Languages Can Be:Scripting Languages Can Be:Fast, Clean, Safe, Powerful, Fast, Clean, Safe, Powerful,

and of course Funand of course Fun

• Don’t have to trade off fun for speed etc.• Don’t need complicated implementation

• Requires forced rethinking and reevaluation of – Technologies - faster, bigger, cheaper

– Architecture - dynamic compilation

– Assumptions - …

Page 5: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

ProtoProtoArt / Science / EducationArt / Science / Education

• Research/Teaching vehicle– For rethinking language design and

implementation

• Reaction to a Reaction …• Targetted for high-performance/interactive

software development for– Embedded systems– Electronic music

Page 6: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Proto PowerProto Power

Features• Pure object-oriented

• Multimethods– Slot accessors as well

• Dynamic types– Ext. param types

• Modules

• Macros

• Restartable exceptions

Builds on• Dylan• Cecil• CLOS• Scheme• Smalltalk

Page 7: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Proto SimplicityProto Simplicity

• PLDI Core Wars– 10K Lines Implementation *– 10 Page Manual **– Hard Limit – “pressure makes pearls”

• Interpreter Semantics• Speed through “partial evaluation”• Implementation Serendipity

Page 8: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Complexity is DangerousComplexity is Dangerousto Your Healthto Your Health

• Complexity will bite you at every turn Minimize number of moving parts

• Complexity can be exponential in part count unless extreme vigilance is applied

• But vigilance is costly especially reactive Apply vigilance towards minimizing part

count instead

Page 9: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Simplified DesignSimplified Design

Simplification• No sealing• Dynamic typing• No databases• Type-based opts only• Prefix syntax• No VM

Recover x with• Global info / d-comp• Type inference• Save-image• C (C--) backend• Short + nesting ops• (Obfuscated) Source

Page 10: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Proto: Speed and InteractivityProto: Speed and Interactivity

• Always optimized

• Always malleable

Page 11: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Incremental Global OptimizationIncremental Global Optimization

• Always compiled

• During compilation dependency tracks assumptions during compilation

• Reoptimize dependents upon change

• Knob for adjusting number of dependents to make recompilation times acceptable

Page 12: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Managing ComplexityManaging Complexity

1. Dynamic compilation

2. Subclass? tests

3. Multimethod dispatch

Page 13: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Complexity Example One:Complexity Example One:Dynamic CompilationDynamic Compilation

• So you want a dynamic compiler?Throw away interpreterAllow for more global optimizations

• But what about the ensuing complexity?Use source instead of VM

• Cut out the middle manUse C back-end and shared libraries (e.g., MathMap)

• More realistically C--Trigger compiler

• By global optimization dependencies• Not profile information

Page 14: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Complexity Example Two:Complexity Example Two:Fast Fast Subclass?Subclass? Tests Tests

• Crucial for the performance of languages– Especially languages with dynamic typing

• Used for – typechecks– downcasts – typecase– method selection

• Used in – Compiler - static analysis– Runtime

Page 15: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Important Subclass? MeasuresImportant Subclass? Measures

• The predicate speed

• The subclass data initialization speed

• The space of subclass data

• The cost of incremental changes– Could be full reinitialization if fast enough

Page 16: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Longstanding ProblemLongstanding Problem

• Choose either– Simple algorithm with O(n^2) space or– Complicated slower to initialize algorithm with

better space properties:• PE – Vitek, Horspool, and Krall OOPSLA-97

• PQE – Zibin and Gil OOPSLA-01

Page 17: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Bit Matrix AlgorithmBit Matrix Algorithm

0A

1B

2C

3D

4E

5F

6G

7H

8I

0

A

1

B

2

C

3

D

4

E

5

F

6

G

7

H

8

I

1 0 1 1 0 1 1 1 0

0 1 1 1 1 1 1 1 1

0 0 1 0 0 1 1 0 0

0 0 0 1 0 0 1 1 0

0 0 0 0 1 0 0 1 1

0 0 0 0 0 1 0 0 0

0 0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 1 0

0 0 0 0 0 0 0 0 1

A 0

F 5 G 6 H 7

C 2 D 3 E 4

B 1

I 8

Page 18: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Clumping OnesClumping Ones

A 0[0,5]

F 2[2,2]

G 3[3,3]

H 5[5,5]

C 1[1,3]

D 4[3,5]

E 6[5,7]

B 8[1,8]

I 7[7,7]

0

A

1

C

2

F

3

G

4

D

5

H

6

B

7

E

8

I

0A

1C

2F

3G

4D

5H

6B

7E

8I

1 1 1 1 1 1 0 0 0

0 1 1 1 0 0 0 0 0

0 0 1 0 0 0 0 0 0

0 0 0 1 0 0 0 0 0

0 0 0 1 1 1 0 0 0

0 0 0 0 1 0 0 0 0

0 1 1 1 1 1 1 1 1

0 0 0 0 0 1 0 1 1

0 0 0 0 0 0 0 0 1

Page 19: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Packing SubClass VectorPacking SubClass Vector

define function isa-0? (x, y)

x.id >= y.min-id & x.id <= y.max-id

& scv[y.base – y.min-id + x.id] = 1

end function

1 1

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 11

A

A C F G D C F G F G G D H H C F G D H B E I D H B E I

C F G D H E IB

27

H

0

A

1

C

2

F

3

G

4

D

5

H

6

B

7

E

8

I

0A

1C

2F

3G

4D

5H

6B

7E

8I

1 1 1 1 1 1 0 0 0

0 1 1 1 0 0 0 0 0

0 0 1 0 0 0 0 0 0

0 0 0 1 0 0 0 0 0

0 0 0 1 1 1 0 0 0

0 0 0 0 1 0 0 0 0

0 1 1 1 1 1 1 1 1

0 0 0 0 0 1 0 1 1

0 0 0 0 0 0 0 0 1

Page 20: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Eliding Range ChecksEliding Range Checks

define function isa-2? (x, y)

scv[y.base – y.min-id + x.id] = y.id

end function;

0

A

1

C

2

F

3

G

4

D

5

H

6

B

7

E

8

I

0A

1C

2F

3G

4D

5H

6B

7E

8I

0 0 0 0 0 0 - - -

- 1 1 1 - - - - -

- - 2 - - - - - -

- - - 3 - - - - -

- - - 4 4 4 - - -

- - - - 5 - - - -

- 6 6 6 6 6 6 6 6

- - - - - 7 - 7 7

- - - - - - - - 8

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

000 0 0 0 1 1 1 2 3 4 4 4 5 6 6 6 6 6 6 6 6 7 - 7 87

27

A

A C F G D C F G F G G D H H C F G D H B E I D H B E I

C F G D H E IB

H

Page 21: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Constant FoldingConstant Folding

define function isa-2? (x, y)

scv[y.base – y.min-id + x.id] = y.id

end function;

==>

define function isa? (x, y)

scv[y.offset + x.id] = y.id

end function;

Page 22: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Multiple InheritanceMultiple Inheritance

• Mixins get assigned randomly in simple preorder walk

• Modified walk to aggressively walk parents

Page 23: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Construction AlgorithmConstruction Algorithm

1. Number classes and calculate min/max’s

2. Assign offsets and calculate PSCV size

3. Populate PSCV with positives

Page 24: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Preliminary ResultsPreliminary Results

• Blindingly fast to construct– Fast enough for incremental changes

• One page of code to implement• Comparable to PE on wide range of real-

world hierarchies– E.g. 95% compression on 5500 class flavors

hierarchy (4MB bit matrix)

• Exhibits approximately n log n space

Page 25: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Subclass? MiscellaneousSubclass? Miscellaneous

• Can use 8 bit keys for even better compression• Talk to be given here in couple weeks• To be submitted to ECOOP-02

– www.ai.mit.edu/~jrb/pscv/

• Thanks – Eric Kidd

• Related range compression in undergrad thesis

– Craig Chambers, James Knight, Greg Sullivan, and Jan Vitek

Page 26: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Complexity Example 3: Complexity Example 3: DispatchDispatch

• For a given generic function and arguments choose the most applicable method

• Example:– Gen: (+ x y)– Mets: num+ int+ flo+– Args: 1 2– Met: int+

Page 27: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Subtype? Based Dispatch Subtype? Based Dispatch MethodologyMethodology

Steps• Dynamic subtype? based

decision tree– Choose more specific

specializers first

– Choose unrelated specializers with stats

• Inline small methods

• Inline decision trees into call-sites

Examples• (fun (x y)

(if (isa? x <int>) ...)))

– Discriminate int+ and flo+ before num+

– Discriminate int+ before flo+

• int+ (and slot accessors)• (+ x 1) (allowing partial

evaluation at call-site)

Page 28: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Subtype? Based Dispatch Subtype? Based Dispatch Happy SynergiesHappy Synergies

• Few moving parts

• “tag-checked” arithmetic for free

• Static dispatch for free

• One arg case comparable to vtable speed– Fewer indirect jumps

• Dynamic type-check insensitive to class numbering

Page 29: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Proto StatusProto Status

Working• Fully bootstrapped• Linux and Win32

Ports• Runtime system tuned• C based dynamic

compiler

In Progress• Fast subclass?• Dependency tracking• Type inference• Decision tree

generation• Parameterized types

Page 30: Rethinking LL: JSE &  Proto

17NOV01 Proto @ LL1

Proto Credits EtcProto Credits Etc

• Thanks to – Craig Chambers– Eric Kidd, James Knight, and Emily Marcus– Greg Sullivan– Howie Shrobe (and DARPA) for funding

• To be open sourced in the coming weeks:– www.ai.mit.edu/~jrb/proto/