Environment Analysis of Higher-Order Languages Matthew Might - - PowerPoint PPT Presentation

environment analysis of higher order languages
SMART_READER_LITE
LIVE PREVIEW

Environment Analysis of Higher-Order Languages Matthew Might - - PowerPoint PPT Presentation

Environment Analysis of Higher-Order Languages Matthew Might Georgia Institute of Technology 7 June 2007 1 Thesis Environment analysis is feasible and useful for higher-order languages. 2 Points Environment analysis is feasible :


slide-1
SLIDE 1

Environment Analysis of Higher-Order Languages

Matthew Might

Georgia Institute of Technology

7 June 2007

1

slide-2
SLIDE 2

Thesis

Environment analysis is feasible and useful for higher-order languages.

2

slide-3
SLIDE 3

Points

Environment analysis is feasible:

◮ Abstract counting. (ICFP 2006, VMCAI 2007, JFP 2007) ◮ Abstract frame strings. (POPL 2006, TCS 2007) ◮ Abstract garbage collection. (ICFP 2006, VMCAI 2007, JFP 2007) ◮ Configuration-widening, etc.

Environment analysis is useful:

◮ Super-β optimizations. (PLDI 2006) ◮ Logic-flow analysis. (POPL 2007)

These techniques are novel:

◮ Related work.

3

slide-4
SLIDE 4

Why perform environment analysis?

◮ Globalization. ◮ Register-allocated environments. ◮ Lightweight closure conversion. ◮ Super-β inlining. ◮ Super-β copy propagation. ◮ Static closure allocation. ◮ Super-β rematerialization. ◮ Super-β teleportation. ◮ Escape analysis. ◮ Lightweight continuation conversion. ◮ Transducer fusion. ◮ Must-alias analysis. ◮ Logic-flow analysis & program verification.

4

slide-5
SLIDE 5

Environments

An environment is a dictionary of names to values.

5

slide-6
SLIDE 6

Environments

An environment is a dictionary of names to values.

Example

◮ x → 3, y → 4 ◮ x → "foo"

Environment facts

◮ May be created, extended, mutated, contracted and destroyed. ◮ Arbitrary number can arise during execution.

6

slide-7
SLIDE 7

Environment problem (Take 1)

Given two environments, on which names do they agree in value?

7

slide-8
SLIDE 8

Higher-order languages

A higher-order language allows computation/behavior as value.

8

slide-9
SLIDE 9

Higher-order languages

A higher-order language allows computation/behavior as value.

Example

◮ Scheme/Lisp ◮ Standard ML

9

slide-10
SLIDE 10

Higher-order languages

A higher-order language allows computation/behavior as value.

Example

◮ Scheme/Lisp ◮ Standard ML ◮ Java ◮ C++ ◮ · · ·

All face the same challenges in analysis.

10

slide-11
SLIDE 11

The challenge: tri-facetted nature of λ

In one construct, λ is:

◮ control, ◮ environment, ◮ and data.

11

slide-12
SLIDE 12

Outline

◮ Develop k-CFA. ◮ Formalize environment problem. ◮ Build abstract counting. ◮ Make it feasible: abstract garbage collection. ◮ Tour ∆CFA. ◮ Review applications. ◮ Look at related work.

12

slide-13
SLIDE 13

What is k-CFA?

k-CFA

Where do λ terms flow?

Example

(define map (λ (f lst) (if (pair? lst) (cons (f (car lst)) (map f (cdr lst))) ’()))) (map (λ (x) (+ x 1)) ’(1 2 3)) ; ’(2 3 4) (map (λ (x) (- x 1)) ’(1 2 3)) ; ’(0 1 2)

13

slide-14
SLIDE 14

What is k-CFA?

k-CFA

Where do λ terms flow?

Example

(define map (λ (f lst) (if (pair? lst) (cons (f (car lst)) (map f (cdr lst))) ’()))) (map (λ (x) (+ x 1)) ’(1 2 3)) ; ’(2 3 4) (map (λ (x) (- x 1)) ’(1 2 3)) ; ’(0 1 2)

14

slide-15
SLIDE 15

What is k-CFA?

k-CFA

Where do λ terms flow?

Example

(define map (λ (f lst) (if (pair? lst) (cons (f (car lst)) (map f (cdr lst))) ’()))) (map (λ (x) (+ x 1)) ’(1 2 3)) ; ’(2 3 4) (map (λ (x) (- x 1)) ’(1 2 3)) ; ’(0 1 2)

15

slide-16
SLIDE 16

What is k-CFA?

Example

class Animal { public void eat() { ... } } class Dog extends Animal { public void eat() { ... } } class Cat extends Animal { ... } ... Animal fido = ... ; fido.eat() ;

16

slide-17
SLIDE 17

What is k-CFA?

Example

class Animal { public void eat() { ... } } class Dog extends Animal { public void eat() { ... } } class Cat extends Animal { ... } ... Animal fido = ... ; fido.eat() ;

17

slide-18
SLIDE 18

What is k-CFA?

Example

class Animal { public void eat() { ... } } class Dog extends Animal { public void eat() { ... } } class Cat extends Animal { ... } ... Animal fido = ... ; fido.eat() ;

18

slide-19
SLIDE 19

What about environments?

Closure = λ term + environment Object = class + struct (define (f x) (λ (z) (+ x z))) (define (loop n) (display ((f n) n)) (loop (+ n 2))) (loop 0)

19

slide-20
SLIDE 20

What about environments?

Closure = λ term + environment Object = class + struct (define (f x) (λ (z) (+ x z))) (define (loop n) (display ((f n) n)) (loop (+ n 2))) (loop 0)

20

slide-21
SLIDE 21

What about environments?

Closure = λ term + environment Object = class + struct (define (f x) (λ (z) (+ x z))) (define (loop n) (display ((f n) n)) (loop (+ n 2))) (loop 0) [x → 0] [x → 2] [x → 4] [x → 6] [x → 8] [x → 10] [x → 12] ...

21

slide-22
SLIDE 22

What about environments?

Closure = λ term + environment Object = class + struct (define (f x) (λ (z) (+ x z))) (define (loop n) (display ((f n) n)) (loop (+ n 2))) (loop 0) [x → 0] [x → 2] [x → 4] [x → 6] [x → 8] [x → 10] [x → 12] ... Environments must merge during finite analysis.

22

slide-23
SLIDE 23

What about environments?

Closure = λ term + environment Object = class + struct (define (f x) (λ (z) (+ x z))) (define (loop n) (display ((f n) n)) (loop (+ n 2))) (loop 0) [x → int]

23

slide-24
SLIDE 24

Problem: Merging blocks reasoning

{x,y,z} w z y x {w} Concrete Space Abstract Space

Unsound reasoning

|x| = |y|, but x = y!

24

slide-25
SLIDE 25

Problem: Merging blocks reasoning

{x,y,z} w z y x {w} Concrete Space Abstract Space

Unsound reasoning

|a| = |w| = |b| does imply a = b.

25

slide-26
SLIDE 26

Problem: Inability to judge environments

(let ((f (λ (x h) (if (zero? x) (h) (λ () x))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline?

26

slide-27
SLIDE 27

Problem: Inability to judge environments

(let ((f (λ (x h) (if (zero? x) (h) (λ () x))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline?

27

slide-28
SLIDE 28

Problem: Inability to judge environments

(let ((f (λ (x h) (if (zero? x) (h) (λ () x))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline?

28

slide-29
SLIDE 29

Problem: Inability to judge environments

(λ () x) + [x → 3] (let ((f (λ (x h) (if (zero? x) (h) (λ () x))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline?

29

slide-30
SLIDE 30

Problem: Inability to judge environments

(λ () x) + [x → 3] (let ((f (λ (x h) (if (zero? x) (h) (λ () x))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline?

30

slide-31
SLIDE 31

Problem: Inability to judge environments

(λ () x) + [x → 3] (let ((f (λ (x h) (if (zero? x) (h) (λ () x))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline?

31

slide-32
SLIDE 32

Problem: Inability to judge environments

(λ () x) + [x → 3] (let ((f (λ (x h) (if (zero? x) ((λ () x)) (λ () x))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline?

32

slide-33
SLIDE 33

Problem: Inability to judge environments

(λ () x) + [x → 3] (let ((f (λ (x h) (if (zero? x) ((λ () 0)) (λ () 3))))) (f 0 (f 3 #f))) Fact: (λ () x) flows to (h). Question: Safe to super-β inline? Answer: No. Why: Only one variable x in program; but multiple dynamic bindings.

33

slide-34
SLIDE 34

Strategy

◮ Build k-CFA. ◮ Thread environment analysis through it.

34

slide-35
SLIDE 35

Tool: Factored environments in k-CFA

Env = Variable → Value

35

slide-36
SLIDE 36

Tool: Factored environments in k-CFA

Env = Variable → λ × Env

36

slide-37
SLIDE 37

Tool: Factored environments in k-CFA

Env = Variable → λ × Env

Must break recursion for analysis.

37

slide-38
SLIDE 38

Tool: Factored environments in k-CFA

Env = Variable → Time

38

slide-39
SLIDE 39

Tool: Factored environments in k-CFA

Env = Variable → Time Variable × Time

  • Binding

→ Value

39

slide-40
SLIDE 40

Tool: Factored environments in k-CFA

Env = Variable → Time Variable × Time

  • Binding

→ Value

Merge environments by partitioning Time into finite number of sets.

40

slide-41
SLIDE 41

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1 Abstract:

  • ς1

41

slide-42
SLIDE 42

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2

Abstract:

  • ς1

42

slide-43
SLIDE 43

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2 ς3

Abstract:

  • ς1

43

slide-44
SLIDE 44

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2 ς3 ς4

Abstract:

  • ς1

44

slide-45
SLIDE 45

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2 ς3 ς4 ς5 · · ·

Abstract:

  • ς1

45

slide-46
SLIDE 46

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2 ς3 ς4 ς5 · · ·

Abstract:

  • ς1

ς2

46

slide-47
SLIDE 47

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2 ς3 ς4 ς5 · · ·

Abstract:

  • ς1

ς2 ς3

47

slide-48
SLIDE 48

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2 ς3 ς4 ς5 · · ·

  • ς3.1,1

Abstract:

  • ς1

ς2 ς3

  • ς4
  • ς3.2,1

48

slide-49
SLIDE 49

Tool: Abstract interpretation

Definition

Abstract interpretation approximates set of reachable states.

Interpretation

Concrete: ς1

ς2 ς3 ς4 ς5 · · ·

  • ς3.1,1

ς3.1,2 Abstract:

  • ς1

ς2 ς3

  • ς4
  • ς3.2,1
  • 49
slide-50
SLIDE 50

Example

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 27 622 28 623 29 30 31 32 33 34 35 36 38 37 39 40 41 42 337 43 338 44 45 46 47 48 49 50 51 335 52 336 53 54 55 334 56 57 58 93 59 94 60 61 62 259 63 260 64 65 66 67 68 69 70 71 73 72 74 75 76 77 250 78 251 79 80 81 82 83 84 85 86 248 87 249 88 89 90 247 91 92 95 96 97 101 98 102 99 100 103 104 105 106 107 143 108 144 109 110 111 112 145 160 113 114 115 146 116 147 117 118 119 170 120 171 121 122 123 124 125 126 127 128 130 129 131 132 133 134 161 135 162 136 137 138 139 140 141 142 148 149 150 154 151 155 152 153 156 157 158 159 163 164 165 166 167 168 169 172 173 174 175 176 213 177 214 178 179 180 181 182 215 230 231 183 184 185 216 186 217 187 188 189 241 190 242 191 192 193 194 195 196 197 198 200 199 201 202 203 204 232 205 233 206 207 208 209 210 211 212 218 219 220 224 221 225 222 223 226 227 228 229 234 235 236 237 238 239 240 243 244 245 246 252 253 254 255 256 257 258 261 262 263 264 265 301 266 302 267 268 269 270 303 318 271 272 273 304 274 305 275 276 277 328 278 329 279 280 281 282 283 284 285 286 288 287 289 290 291 292 319 293 320 294 295 296 297 298 299 300 306 307 308 312 309 313 310 311 314 315 316 317 321 322 323 324 325 326 327 330 331 332 333 339 340 341 342 343 344 345 346 620 347 621 348 349 350 351 352 395 353 396 354 355 356 547 357 548 358 359 360 361 362 363 364 365 367 366 368 369 370 371 380 372 381 373 374 375 376 377 378 379 382 383 384 385 386 387 388 389 545 390 546 391 392 393 394 397 398 399 403 400 404 401 402 405 406 407 408 409 453 410 454 411 412 413 455 414 415 416 456 417 457 418 419 420 470 421 471 422 423 424 425 426 427 428 429 431 430 432 433 434 435 444 436 445 437 438 439 440 441 442 443 446 447 448 449 450 451 452 458 459 460 464 461 465 462 463 466 467 468 469 472 473 474 475 476 521 477 522 478 479 480 481 523 538 482 483 484 524 485 525 486 487 488 539 489 540 490 491 492 493 494 495 496 497 499 498 500 501 502 503 512 504 513 505 506 507 508 509 510 511 514 515 516 517 518 519 520 526 527 528 532 529 533 530 531 534 535 536 537 541 542 543 544 549 550 551 552 553 597 554 598 555 556 557 599 558 559 560 600 561 601 562 563 564 614 565 615 566 567 568 569 570 571 572 573 575 574 576 577 578 579 588 580 589 581 582 583 584 585 586 587 590 591 592 593 594 595 596 602 603 604 608 605 609 606 607 610 611 612 613 616 617 618 619 624 625 626 627 628 629 630 631 933 632 633 634 635 636 637 928 638 929 639 640 641 642 643 644 645 646 648 647 649 650 651 652 801 653 802 654 655 656 657 658 659 660 661 700 662 701 663 664 665 666 669 702 667 668 670 671 672 788 673 789 674 675 676 712 677 713 678 679 680 681 682 683 684 685 687 686 688 689 690 691 703 692 704 693 694 695 696 697 698 699 705 706 707 708 709 710 711 714 715 716 717 718 719 720 721 722 723 756 759 773 724 725 757 758 726 760 727 761 728 729 730 783 731 784 732 733 734 735 736 737 738 739 741 740 742 743 744 745 774 746 775 747 748 749 750 751 752 753 754 755 762 763 764 768 765 769 766 767 770 771 772 776 777 778 779 780 781 782 785 786 787 790 791 792 796 793 797 794 795 798 799 800 803 804 805 806 807 808 809 810 923 811 924 812 813 814 925 815 816 926 927 817 910 818 911 819 820 821 836 822 837 823 824 825 826 827 828 829 830 832 831 833 834 835 838 839 840 841 842 843 844 845 846 888 902 847 848 903 904 849 889 850 890 851 852 853 905 854 906 855 856 857 858 859 860 861 862 864 863 865 866 867 868 877 869 878 870 871 872 873 874 875 876 879 880 881 882 883 884 885 886 887 891 892 893 897 894 898 895 896 899 900 901 907 908 909 912 913 914 918 915 919 916 917 920 921 922 930 931 932

50

slide-51
SLIDE 51

Tool: Continuation-passing style (CPS)

Contract

◮ Calls don’t return. ◮ Continuations (procedures) are passed—to receive return values.

Definition

A continuation encodes the future of computation.

Grammar

e, f ∈ EXP ::= v | (λ (v1 · · · vn) call) call ∈ CALL ::= (f e1 · · · en)

51

slide-52
SLIDE 52

CPS narrows concern

λ is universal representation of control & env. Construct encoding fun call call to λ fun return call to λ iteration call to λ sequencing call to λ conditional call to λ exception call to λ coroutine call to λ . . . . . .

Advantage

Now λ is fine-grained construct.

52

slide-53
SLIDE 53

Strategy

◮ Define state machine: ς ⇒ ς′. ◮ k-CFA = abstract interpretation of ⇒.

53

slide-54
SLIDE 54

Semantics: Eval states

( , , , )

54

slide-55
SLIDE 55

Semantics: Eval states

([ [(f e1 · · · en)] ], , , ) Call site

55

slide-56
SLIDE 56

Semantics: Eval states

([ [(f e1 · · · en)] ], β, , ) Call site Var → Time

56

slide-57
SLIDE 57

Semantics: Eval states

([ [(f e1 · · · en)] ], β, ve, ) Call site Var → Time Var × Time → Val A(v, β, ve) =    let tbound = β(v) value = ve(v, tbound) in value

57

slide-58
SLIDE 58

Semantics: Eval states

([ [(f e1 · · · en)] ], β, ve, t) Call site Var → Time Var × Time → Val Timestamp A(v, β, ve) =    let tbound = β(v) value = ve(v, tbound) in value

58

slide-59
SLIDE 59

Semantics: Eval states

([ [(f e1 · · · en)] ], β, ve, t) ⇒( , , , ) A(v, β, ve) =    let tbound = β(v) value = ve(v, tbound) in value

59

slide-60
SLIDE 60

Semantics: Eval states

Procedure proc = A(f, β, ve) ([ [(f e1 · · · en)] ], β, ve, t) ⇒(proc, , , ) A(v, β, ve) =    let tbound = β(v) value = ve(v, tbound) in value A(lam, β, ve) = (lam, β)

60

slide-61
SLIDE 61

Semantics: Eval states

Procedure Arguments proc = A(f, β, ve) di = A(ei, β, ve) ([ [(f e1 · · · en)] ], β, ve, t) ⇒(proc, d, , ) A(v, β, ve) =    let tbound = β(v) value = ve(v, tbound) in value A(lam, β, ve) = (lam, β)

61

slide-62
SLIDE 62

Semantics: Eval states

Procedure Arguments proc = A(f, β, ve) di = A(ei, β, ve) ([ [(f e1 · · · en)] ], β, ve, t) ⇒(proc, d, ve, ) Var × Time → Val A(v, β, ve) =    let tbound = β(v) value = ve(v, tbound) in value A(lam, β, ve) = (lam, β)

62

slide-63
SLIDE 63

Semantics: Eval states

Procedure Arguments proc = A(f, β, ve) di = A(ei, β, ve) ([ [(f e1 · · · en)] ], β, ve, t) ⇒(proc, d, ve, t + 1) Var × Time → Val Timestamp A(v, β, ve) =    let tbound = β(v) value = ve(v, tbound) in value A(lam, β, ve) = (lam, β)

63

slide-64
SLIDE 64

Semantics: Apply states

( , , , )

64

slide-65
SLIDE 65

Semantics: Apply states

(([ [(λ (v1 · · · vn) call)] ], β′), d, ve, t)

65

slide-66
SLIDE 66

Semantics: Apply states

(([ [(λ (v1 · · · vn) call)] ], β′), d, ve, t) ⇒( , , , )

66

slide-67
SLIDE 67

Semantics: Apply states

(([ [(λ (v1 · · · vn) call)] ], β′), d, ve, t) ⇒(call, , , )

67

slide-68
SLIDE 68

Semantics: Apply states

(([ [(λ (v1 · · · vn) call)] ], β′), d, ve, t) ⇒(call, β′[vi → t], , )

68

slide-69
SLIDE 69

Semantics: Apply states

(([ [(λ (v1 · · · vn) call)] ], β′), d, ve, t) ⇒(call, β′[vi → t], ve[(vi, t) → di], )

69

slide-70
SLIDE 70

Semantics: Apply states

(([ [(λ (v1 · · · vn) call)] ], β′), d, ve, t) ⇒(call, β′[vi → t], ve[(vi, t) → di], t)

70

slide-71
SLIDE 71

Eval-state transition

proc = A(f, β, ve) di = A(ei, β, ve) ([ [(f e1 · · · en)] ], β, ve, t) ⇒(proc, d, ve, t + 1)

Apply-state transition

proc = ([ [(λ (v1 · · · vn) call)] ], β′) (proc, d, ve, t) ⇒(call, β′[vi → t], ve[(vi, t) → di], t)

Domains

ς ∈ Eval = CALL × BEnv × VEnv × Time + Apply = Proc × D∗ × VEnv × Time β ∈ BEnv = VAR → Time ve ∈ VEnv = VAR × Time → D proc ∈ Proc = Clo + {halt} clo ∈ Clo = LAM × BEnv d ∈ D = Proc t ∈ Time = infinite set of times (contours)

Lookup function

A(lam, β, ve) = (lam, β) A(v, β, ve) = ve(v, β(v))

71

slide-72
SLIDE 72

Eval-state transition

  • proc ∈

A(f, β, ve)

  • di =

A(ei, β, ve) ([ [(f e1 · · · en)] ], β, ve, t) ≈ > ( proc, d, ve, succ( t))

Apply-state transition

  • proc = ([

[(λ (v1 · · · vn) call)] ], β′) ( proc, d, ve, t) ≈ > (call, β′[vi → t], ve ⊔ [(vi, t) → di], t)

Domains

  • ς ∈

Eval = CALL × BEnv × VEnv × Time + Apply = Proc × D∗ × VEnv × Time

  • β ∈

BEnv = VAR → Time

  • ve ∈

VEnv = VAR × Time → D

  • proc ∈

Proc = Clo + {halt}

  • clo ∈

Clo = LAM × BEnv

  • d ∈
  • D

= P( Proc)

  • t ∈

Time = finite set of times (contours)

Lookup function

  • A(lam,

β, ve) = {(lam, β)}

  • A(v,

β, ve) = ve(v, β(v))

72

slide-73
SLIDE 73

Eval-state transition

  • proc ∈

A(f, β, ve)

  • di =

A(ei, β, ve) ([ [(f e1 · · · en)] ], β, ve, t) ≈ > ( proc, d, ve, succ( t))

Apply-state transition

  • proc = ([

[(λ (v1 · · · vn) call)] ], β′) ( proc, d, ve, t) ≈ > (call, β′[vi → t], ve ⊔ [(vi, t) → di], t)

Domains

  • ς ∈

Eval = CALL × BEnv × VEnv × Time + Apply = Proc × D∗ × VEnv × Time

  • β ∈

BEnv = VAR → Time

  • ve ∈

VEnv = VAR × Time → D

  • proc ∈

Proc = Clo + {halt}

  • clo ∈

Clo = LAM × BEnv

  • d ∈
  • D

= P( Proc)

  • t ∈

Time = finite set of times (contours)

Lookup function

  • A(lam,

β, ve) = {(lam, β)}

  • A(v,

β, ve) = ve(v, β(v))

73

slide-74
SLIDE 74

Environment analysis, Take 1: µCFA

74

slide-75
SLIDE 75

Environment problem refined

Input

Two abstract environments, β1 and β2.

75

slide-76
SLIDE 76

Environment problem refined

Input

Two abstract environments, β1 and β2.

Output

The set of variables on which their concrete counterparts agree.

76

slide-77
SLIDE 77

Strategy

◮ Count concrete counterparts to abstract bindings.

77

slide-78
SLIDE 78

Strategy

◮ Count concrete counterparts to abstract bindings. ◮ Apply principle: {x} = {y} =

⇒ x = y.

78

slide-79
SLIDE 79

Tool: Abstract counting

Abstract binding counter, µ : “Bindings” → {0, 1, ∞}.

Eval

([ [(f e1 · · · en)] ], β, ve,

  • t) ≈

> ( proc, d, ve,

  • succ(

t)) where

  • proc ∈

A(f, β, ve)

  • di =

A(ei, β, ve)

Apply

(([ [(λ (v1 · · · vn) call)] ], βb), d, ve,

  • t) ≈

> (call, β′, ve′,

  • t)

where     

  • β′ =

βb[vi → t]

  • ve′ =

ve ⊔ [(vi, t) → di]

79

slide-80
SLIDE 80

Tool: Abstract counting

Abstract binding counter, µ : “Bindings” → {0, 1, ∞}.

Eval

([ [(f e1 · · · en)] ], β, ve, µ, t) ≈ > ( proc, d, ve, µ, succ( t)) where

  • proc ∈

A(f, β, ve)

  • di =

A(ei, β, ve)

Apply

(([ [(λ (v1 · · · vn) call)] ], βb), d, ve, µ, t) ≈ > (call, β′, ve′, µ′, t) where     

  • β′ =

βb[vi → t]

  • ve′ =

ve ⊔ [(vi, t) → di]

  • µ′ =

µ ⊕ [(vi, t) → 1]

80

slide-81
SLIDE 81

µCFA environment condition

Basic Principle

If {x} = {y}, then x = y.

Theorem (Environment condition)

If

  • β1(v) =

β2(v), and

  • µ(v,

β1(v)) = µ(v, β2(v)) = 1, then β1(v) = β2(v).

81

slide-82
SLIDE 82

µCFA environment condition

Basic Principle

If {x} = {y}, then x = y.

Theorem (Environment condition)

If

  • β1(v) =

β2(v), and

  • µ(v,

β1(v)) = µ(v, β2(v)) = 1, then β1(v) = β2(v), where: (v, β1(v)) ∈ dom(ve), and |βi| ⊑ βi, and |ve|µ ⊑ µ.

82

slide-83
SLIDE 83

µCFA environment condition

Basic Principle

If {x} = {y}, then x = y.

Theorem (Environment condition)

If

  • β1(v) =

β2(v), and

  • µ(v,

β1(v)) = µ(v, β2(v)) = 1, then β1(v) = β2(v), where: (v, β1(v)) ∈ dom(ve), and |βi| ⊑ βi, and |ve|µ ⊑ µ.

Problem

Most counts hit ∞: almost every variable bound more than once!

83

slide-84
SLIDE 84

Making it feasible: ΓCFA

84

slide-85
SLIDE 85

Example: Abstract garbage collection

3-address concrete heap. 2-address abstract counterpart. concrete abstract

  • 1

a1

  • |
  • 1|

a2

ˆ

a1,2

  • a3

ˆ

a3

85

slide-86
SLIDE 86

Example: Abstract garbage collection

3-address concrete heap. 2-address abstract counterpart. concrete abstract

  • 1

a1

  • |
  • 1|

a2

ˆ

a1,2

  • a3

ˆ

a3 Object Address GC Root GC Root Address Object

86

slide-87
SLIDE 87

Example: Abstract garbage collection

3-address concrete heap. 2-address abstract counterpart. concrete abstract

  • 1

a1

  • |
  • 1|

a2

ˆ

a1,2

  • a3

ˆ

a3

87

slide-88
SLIDE 88

Example: Abstract garbage collection

Next: Allocate object o2 to address a3. Shift root to a3. concrete abstract

  • 1

a1

  • |
  • 1|

a2

ˆ

a1,2

  • a3

ˆ

a3

88

slide-89
SLIDE 89

Example: Abstract garbage collection

Next: Allocate object o3 to address a2. Point o2 to a2. concrete abstract

  • 1

a1

  • |
  • 1|

a2

ˆ

a1,2

  • 2

a3

  • ˆ

a3

  • |
  • 2|

89

slide-90
SLIDE 90

Example: Abstract garbage collection

Uh-oh! Zombie born. Concrete-abstract symmetry broken. concrete abstract

  • 1

a1

  • |
  • 1|
  • 3

a2

  • ˆ

a1,2

  • |
  • 3|
  • 2
  • a3
  • ˆ

a3

  • |
  • 2|
  • 90
slide-91
SLIDE 91

Example: Abstract garbage collection

Solution: Rewind and garbage collect first. concrete abstract

  • 1

a1

  • |
  • 1|
  • 3

a2

  • ˆ

a1,2

  • |
  • 3|
  • 2
  • a3
  • ˆ

a3

  • |
  • 2|
  • 91
slide-92
SLIDE 92

Example: Abstract garbage collection

As it was: concrete abstract

  • 1

a1

  • |
  • 1|

a2

ˆ

a1,2

  • 2

a3

  • ˆ

a3

  • |
  • 2|

92

slide-93
SLIDE 93

Example: Abstract garbage collection

After garbage collection: concrete abstract a1

  • a2

ˆ

a1,2

  • 2

a3

  • ˆ

a3

  • |
  • 2|

93

slide-94
SLIDE 94

Example: Abstract garbage collection

Try again: Allocate object o3 to address a2. Point o2 to a2. concrete abstract a1

  • a2

ˆ

a1,2

  • 2

a3

  • ˆ

a3

  • |
  • 2|

94

slide-95
SLIDE 95

Example: Abstract garbage collection

No overapproximation! concrete abstract a1

  • 3

a2

  • ˆ

a1,2

  • |
  • 3|
  • 2
  • a3
  • ˆ

a3

  • |
  • 2|
  • 95
slide-96
SLIDE 96

Correctness of garbage collection

Theorem

Garbage collection does not change the meaning of a program: ς0

  • ς1
  • ς2
  • ς3
  • ς4
  • · · ·

ς0

Γ

ς′

1 Γ

ς′

2 Γ

ς′

3 Γ

ς′

4 Γ

· · · 96

slide-97
SLIDE 97

Soundness of the analysis

Theorem (Correctness of ΓCFA)

ΓCFA simulates the concrete semantics. ς

  • |·|

|ς|

ς

≈ >

  • ς′

|·|

|ς′|

ς′

97

slide-98
SLIDE 98

Abstract garbage collection & polyvariance

Question

Consider (λ (... k) ...). To where will it return?

0CFA

To everywhere called: Flow set for k grows monotonically.

ΓCFA with 0CFA contour set

To last call, if tail-recursive or leaf procedure.

98

slide-99
SLIDE 99

Example: Forking

(define (identity x) x) (define mylock (identity lock)) (define myunlock (identity unlock)) (mylock mutex) (myunlock mutex) 99

slide-100
SLIDE 100

Example: Forking

(define (identity x) x) (define mylock (identity lock)) (define myunlock (identity unlock)) (mylock mutex) (myunlock mutex)

Without GC

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 21 23 24 25 26 27 43 28 44 29 30 31 32 33 34 35 36 37 38 39 40 41 42 45 46 47 48 49 52 50 53 51 54 55 56 57 58 59 60 61

100

slide-101
SLIDE 101

Example: Forking

(define (identity x) x) (define mylock (identity lock)) (define myunlock (identity unlock)) (mylock mutex) (myunlock mutex)

Without GC

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 21 23 24 25 26 27 43 28 44 29 30 31 32 33 34 35 36 37 38 39 40 41 42 45 46 47 48 49 52 50 53 51 54 55 56 57 58 59 60 61

With GC

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

101

slide-102
SLIDE 102

Vicious cycle

Less precision More forks

102

slide-103
SLIDE 103

Virtuous cycle

More precision Less forks

103

slide-104
SLIDE 104

Implementation & Results

104

slide-105
SLIDE 105

Without GC

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 27 622 28 623 29 30 31 32 33 34 35 36 38 37 39 40 41 42 337 43 338 44 45 46 47 48 49 50 51 335 52 336 53 54 55 334 56 57 58 93 59 94 60 61 62 259 63 260 64 65 66 67 68 69 70 71 73 72 74 75 76 77 250 78 251 79 80 81 82 83 84 85 86 248 87 249 88 89 90 247 91 92 95 96 97 101 98 102 99 100 103 104 105 106 107 143 108 144 109 110 111 112 145 160 113 114 115 146 116 147 117 118 119 170 120 171 121 122 123 124 125 126 127 128 130 129 131 132 133 134 161 135 162 136 137 138 139 140 141 142 148 149 150 154 151 155 152 153 156 157 158 159 163 164 165 166 167 168 169 172 173 174 175 176 213 177 214 178 179 180 181 182 215 230 231 183 184 185 216 186 217 187 188 189 241 190 242 191 192 193 194 195 196 197 198 200 199 201 202 203 204 232 205 233 206 207 208 209 210 211 212 218 219 220 224 221 225 222 223 226 227 228 229 234 235 236 237 238 239 240 243 244 245 246 252 253 254 255 256 257 258 261 262 263 264 265 301 266 302 267 268 269 270 303 318 271 272 273 304 274 305 275 276 277 328 278 329 279 280 281 282 283 284 285 286 288 287 289 290 291 292 319 293 320 294 295 296 297 298 299 300 306 307 308 312 309 313 310 311 314 315 316 317 321 322 323 324 325 326 327 330 331 332 333 339 340 341 342 343 344 345 346 620 347 621 348 349 350 351 352 395 353 396 354 355 356 547 357 548 358 359 360 361 362 363 364 365 367 366 368 369 370 371 380 372 381 373 374 375 376 377 378 379 382 383 384 385 386 387 388 389 545 390 546 391 392 393 394 397 398 399 403 400 404 401 402 405 406 407 408 409 453 410 454 411 412 413 455 414 415 416 456 417 457 418 419 420 470 421 471 422 423 424 425 426 427 428 429 431 430 432 433 434 435 444 436 445 437 438 439 440 441 442 443 446 447 448 449 450 451 452 458 459 460 464 461 465 462 463 466 467 468 469 472 473 474 475 476 521 477 522 478 479 480 481 523 538 482 483 484 524 485 525 486 487 488 539 489 540 490 491 492 493 494 495 496 497 499 498 500 501 502 503 512 504 513 505 506 507 508 509 510 511 514 515 516 517 518 519 520 526 527 528 532 529 533 530 531 534 535 536 537 541 542 543 544 549 550 551 552 553 597 554 598 555 556 557 599 558 559 560 600 561 601 562 563 564 614 565 615 566 567 568 569 570 571 572 573 575 574 576 577 578 579 588 580 589 581 582 583 584 585 586 587 590 591 592 593 594 595 596 602 603 604 608 605 609 606 607 610 611 612 613 616 617 618 619 624 625 626 627 628 629 630 631 933 632 633 634 635 636 637 928 638 929 639 640 641 642 643 644 645 646 648 647 649 650 651 652 801 653 802 654 655 656 657 658 659 660 661 700 662 701 663 664 665 666 669 702 667 668 670 671 672 788 673 789 674 675 676 712 677 713 678 679 680 681 682 683 684 685 687 686 688 689 690 691 703 692 704 693 694 695 696 697 698 699 705 706 707 708 709 710 711 714 715 716 717 718 719 720 721 722 723 756 759 773 724 725 757 758 726 760 727 761 728 729 730 783 731 784 732 733 734 735 736 737 738 739 741 740 742 743 744 745 774 746 775 747 748 749 750 751 752 753 754 755 762 763 764 768 765 769 766 767 770 771 772 776 777 778 779 780 781 782 785 786 787 790 791 792 796 793 797 794 795 798 799 800 803 804 805 806 807 808 809 810 923 811 924 812 813 814 925 815 816 926 927 817 910 818 911 819 820 821 836 822 837 823 824 825 826 827 828 829 830 832 831 833 834 835 838 839 840 841 842 843 844 845 846 888 902 847 848 903 904 849 889 850 890 851 852 853 905 854 906 855 856 857 858 859 860 861 862 864 863 865 866 867 868 877 869 878 870 871 872 873 874 875 876 879 880 881 882 883 884 885 886 887 891 892 893 897 894 898 895 896 899 900 901 907 908 909 912 913 914 918 915 919 916 917 920 921 922 930 931 932

105

slide-106
SLIDE 106

With GC

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 27 73 28 74 29 30 31 32 33 34 35 36 38 37 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 63 59 64 60 61 62 65 66 67 68 69 70 71 72 75 76 77 78 79 80 81 82

106

slide-107
SLIDE 107

Flow results: 0CFA & GC

2000 4000 6000 8000 10000 12000 14000 20 40 60 80 100 120 140 160 180 States Lines of Code 0CFA 0CFA+GC

107

slide-108
SLIDE 108

Counting results: 0CFA & GC

program % of variables with count ≤ 1 earley 94% int-fringe-coro 89% int-stream-coro 82% lattice 91% nboyer 98% perm 95% put-double-coro 92% sboyer 98%

108

slide-109
SLIDE 109

Results: 0CFA, GC, Counting & Widening

k = 0,c,no-GC k = 0,p k = 0,c k = 0,s earley 15% 258s 94% 24s 94% 15s 95% 90s int-fringe-coro 26% 8s 87% 5s 87% 2s 89% 2s int-stream-coro 14% 15s 79% 14s 79% 8s 82% 7s lattice 12% 59s 91% 10s 91% 6s OOM >71m nboyer 12% 68s 98% 93s 98% 48s 98% 18,420s perm 8% 90s 95% 2s 95% 6s 95% 2s put-double-coro 41% 2s 89% 2s 89% 1s 92% 0.8s sboyer OOM >1,024s 98% 95s 98% 50s OOM >20,065s ◮ GC wins for precision & speed. ◮ Widening costs little precision. ◮ On average, widening saves time.

109

slide-110
SLIDE 110

Results: 1CFA, GC, Counting & Widening

k = 1,p k = 1,c k = 1,s earley 94% 143s 94% 83s OOM >45m int-fringe-coro 88% 54s 88% 13s 92% 9s int-stream-coro 87% 72s 87% 11s 90% 8s lattice 91% 56s 92% 24s OOM >89m nboyer 99% 221s 99% 231s OOM >164,040s perm 95% 9s 95% 4s 95% 60s put-double-coro 90% 12s 90% 4s 93% 2s sboyer 98% 286s OOM >21,031s OOM >45,040s ◮ Widening costs little precision. ◮ On average, widening saves time. ◮ Small precision advantage to 1CFA. ◮ Large time cost to 1CFA.

110

slide-111
SLIDE 111

Results: Improvements in super-β inlining

0CFA+GC Program Inlines w/o Counting Inlines w/Counting fact-tail 2 4 fact-y-combinator 4 8 nested-loops 4 10 put-double-coroutines 28 55 integrate-fringe-coroutines 45 77 integrate-stream-coroutines 46 72 111

slide-112
SLIDE 112

Environment analysis, Take 2: ∆CFA

112

slide-113
SLIDE 113

Tool: Procedure strings

Classic model (Sharir & Pnueli, Harrison)

◮ Program trace at procedure level ◮ String of procedure activation/deactivation actions

Actions

control: call/return stack: push/pop

113

slide-114
SLIDE 114

Tool: Procedure strings

Classic model (Sharir & Pnueli, Harrison)

◮ Program trace at procedure level ◮ String of procedure activation/deactivation actions

Actions

control: call/return stack: push/pop

(fact 1)

call fact / call zero? / return zero? / call - / return - / call fact / call zero? / return zero? / return fact / call * / return * / return fact Note: Call/return items nest like parens.

114

slide-115
SLIDE 115

CPS & stacks

But wait! CPS is all calls, no returns! Procedure strings won’t nest properly: call a / call b / call c / call d / . . .

115

slide-116
SLIDE 116

CPS & stacks

But wait! CPS is all calls, no returns! Procedure strings won’t nest properly: call a / call b / call c / call d / . . . Not necessarily.

116

slide-117
SLIDE 117

User/continuation partition of CPS

Recursive factorial

(λt (n ktop) (letrec ((f (λf (m k) (%if0 m (λ1 () (k 1)) (λ2 () (- m 1 (λ3 (m2) (f m2 (λ4 (a) (* m a k) ))))))))) (f n ktop))) CPS conversion adds blue/red annotations, permitting frame-push/frame-pop execution model.

117

slide-118
SLIDE 118

Two control constructs

◮ Call a function. ◮ Call a continuation.

Problem

Meaning of call/return still a little murky.

Solution

Track stack behavior: push/pop.

118

slide-119
SLIDE 119

Frame strings

a

6|b 7|b 7|a 6

|q

38q 38|

r

21|r 21a 71|

a

4|b 5|b 5c 6|

Anatomy of a frame-string character

Procedure label

· · · ψ t | · · · |ψ t · · ·

frame-creation time stamp

119

slide-120
SLIDE 120

Modelling control/env with frame strings & CPS

A vocabulary for describing computational structure

Tail call (iteration): |γ

· · · · |γ · |l ·l ·|

Non-tail call: l

·|

Simple return: |γ

· · · · |γ · |l ·γ · |

Primop call: l

·||l ·γ · | or |γ · · · · |γ · |l ·l ·||l ·γ · |

“Upward” throw: |·

· · · · |· ·γ · |

“Downward” throw: |·

· · · · |· ·· ·| · · · · ·|γ · |

Coroutine switch: |·

· · · · |· ·· ·| · · · · ·|γ · |

Handles any stack-to-stack delta.

120

slide-121
SLIDE 121

Eval-state transition

  • [

[(f e∗ q∗)

κ]

], β, ve, t

  • ⇒ (proc, d, c, ve,

t) where                  proc = A β ve t f di = A β ve t ei cj = A β ve t qj

Apply-state transition

length(d) = length(u) length(c) = length(k) (([ [( λψ (u∗ k∗) call)] ], β, tb), d, c, ve, t) ⇒ (call, β′, ve′, t′) where            t′ = tick(t) β′ = β[ui → t′, kj → t′] ve′ = ve[(ui, t′) → di, (kj, t′) → cj] 121

slide-122
SLIDE 122

Eval-state transition

  • [

[(f e∗ q∗)

κ]

], β, ve, δ, t

  • ⇒ (proc, d, c, ve, δ′, t)

where                  proc = A β ve t f di = A β ve t ei cj = A β ve t qj ∇ς =

  • (ageδ proc)−1

f ∈ CEXP (youngestδ c)−1

  • therwise

δ′ = δ + (λt.∇ς)

Apply-state transition

length(d) = length(u) length(c) = length(k) (([ [( λψ (u∗ k∗) call)] ], β, tb), d, c, ve, δ, t) ⇒ (call, β′, ve′, δ′, t′) where            t′ = tick(t) β′ = β[ui → t′, kj → t′] ve′ = ve[(ui, t′) → di, (kj, t′) → cj] ∇ς = ψ

t′|

δ′ = (δ + (λt.∇ς))[t′ → ǫ] 122

slide-123
SLIDE 123

Eval-state transition

([ [(f e∗ q∗)

κ]

], β, ve, δ, t) ≈ > ( proc, d, c, ve, δ′, t) where                   

  • proc ∈

A β ve t f

  • di =

A β ve t ei

  • ci =

A β ve t qi ∆ p =

  • age

δ {

proc} −1 f ∈ EXPC youngest

δ

c −1

  • therwise
  • δ′ =

δ ⊕ (λ t.∆ p)

Apply-state transition

length

  • d
  • = length(u)

length( c) = length(k) (([ [( λψ (u∗ k∗) call)] ], β, tb), d, c, ve, δ, t) ≈ > (call, β′, ve′, δ′, t′) where             

  • t′ =

tick( t)

  • β′ =

β[ui → t′, kj → t′]

  • ve′ =

ve ⊔

  • (ui,

t′) → di, (kj, t′) → cj

p = |ψ

  • t′||
  • δ′ =
  • δ ⊕ (λ

t.∆ p)

  • t′ → |ǫ|
  • 123
slide-124
SLIDE 124

Soundness theorem

Theorem (Analysis safety)

∆CFA simulates the concrete semantics. ς

  • |·|

|ς|

ς

≈ >

  • ς′

|·|

|ς′|

ς′

124

slide-125
SLIDE 125

Connecting frame strings & environments

Interval notation for frame-string change

[t, t′] = δt′(t)

Theorem

Environments separated by continuation frame actions differ by the continuations’ bindings. ⌊[t0, t2] + [t1, t2]−1⌋ = |γ1

i1 ···|γn in γ′

1

t1 |···γ′

n

tm| =

⇒ βt1|B(γ′) = βt0|B(γ). (Note: inferring t0/t1 environment relationship from log at time t2.)

125

slide-126
SLIDE 126

Concrete super-β condition

In English

λ expression ψ may be inlined at call site κ if, whenever we call a procedure from call site κ,

◮ it is a closure over ψ, and ◮ the closure environment and the call-site environment have

identical bindings for the free vars of ψ.

As mathematics

Inlinable((κ, ψ), pr) = ∀([ [(f e∗ q∗)

κ]

], β, ve, δ, t) ∈ V(pr) : if κ = κ′ and (Lpr(ψ′), βb, tb) = A β ve t f then ψ = ψ′ βb|free(Lpr(ψ)) = β|free(Lpr(ψ))

126

slide-127
SLIDE 127

Correctness theorem

Theorem (Super-β transform safety)

Inlinable((κ, ψ), pr )-directed inlining does not change meaning of program. ς

||·|| S

  • ||ς||

S−1ςS

||·||

||·||

||ςS||

ςS

||·||

  • S−1
  • 127
slide-128
SLIDE 128

Concrete super-β conditions—in frame-string terms

Local-Inlinable((κ, ψ), pr) = ∀([ [(f e∗ q∗)

κ]

], β, ve, δ, t) ∈ V(pr) : if κ = κ′ and (Lpr(ψ′), βb, tb) = A β ve t f then    ψ = ψ′ ∃γ : ⌊[tb, t]⌋ ≻γ ǫ free(Lpr(ψ)) ⊆ B(γ). Escaping-Inlinable((κ, ψ), pr) = ∀([ [(f e∗ q∗)

κ]

], β, ve, δ, t) ∈ V(pr) : if κ = κ′ and (Lpr(ψ′), βb, tb) = A β ve t f then    ψ = ψ′ ∀v ∈ free(Lpr(ψ′)) : ∃γ : ⌊[β(v), t]⌋ ≻γ ⌊[tb, t]⌋ v ∈ B(γ). General-Inlinable((κ, ψ), pr) = ∀([ [(f e∗ q∗)

κ]

], β, ve, δ, t) ∈ V(pr) : if κ = κ′ and (Lpr(ψ′), βb, tb) = A β ve t f then

  • ψ = ψ′

∀v ∈ free(Lpr(ψ′)) : ⌊[β(v), t]⌋ = ⌊[βb(v), t]⌋. 128

slide-129
SLIDE 129

Abstract super-β conditions—in frame-string terms

  • Local-Inlinable((κ, ψ), pr) = ∀([

[(f e∗ q∗)

κ]

], β, ve, δ, t) ∈ V(pr) : if κ = κ′ and (Lpr(ψ′), βb, tb) = A β ve t f then    ψ = ψ′ ∃γ :

  • δ(

tb) γ |ǫ| free(Lpr(ψ)) ⊆ B(γ).

  • Escaping-Inlinable((κ, ψ), pr) ⇐

⇒ ∀([ [(f e∗ q∗)

κ]

], β, ve, δ, t) ∈ V(pr) : if κ = κ′ and (Lpr(ψ′), βb, tb) = A β ve t f then    ψ = ψ′ ∀v ∈ free(Lpr(ψ′)) : ∃γ :

  • δ(

β(v)) γ δ( tb) v ∈ B(γ).

  • General-Inlinable((κ, ψ), pr) =

∀([ [(f e∗ q∗)

κ]

], β, ve, δ, t) ∈ V(pr) : if κ = κ′ and (Lpr(ψ′), βb, tb) = A β ve t f then ψ = ψ′ ∀v ∈ free(Lpr(ψ′)) : δ( β(v)) = δ( βb(v)). 129

slide-130
SLIDE 130

Applications

130

slide-131
SLIDE 131

Application: Globalization

Transformation

Turn x into global variable.

Condition

Measure of x never exceeds 1.

Payoff

Smaller (possibly eliminated) environments in closures.

131

slide-132
SLIDE 132

Application: Register-allocated environments

Transformation

Allocate escaping variables to registers.

Condition

◮ Variables interfere if state exists where both have measure ≥ 1. ◮ Color interference graph with registers.

Payoff

Smaller environments, faster code.

132

slide-133
SLIDE 133

Application: Super-β copy propagation

Transformation

Replace reference x with reference z.

Condition

In states using x, value bound to x ≡ value bound to z.

Payoff

◮ May make x useless. ◮ Enables continuation promotion. ◮ Enables coroutine fusion.

133

slide-134
SLIDE 134

Application: Static closure allocation

Transformation

Allocate environment record for closure at compile time.

Condition

Measure of λ term never exceeds 1.

Payoff

◮ Eliminates stack and heap allocation. ◮ Eliminates record offset computation.

134

slide-135
SLIDE 135

Application: Super-β rematerialization

Transformation

Inline λ term where free variables not available.

Condition

Values of non-available free-variables are recomputable.

Payoff

Smaller (possibly eliminated) enviroment records for closures.

135

slide-136
SLIDE 136

Application: Super-β teleportation

Transformation

Inline λ term where free variables not available.

Condition

Free variables can be moved to common scope, e.g., globalized.

Payoff

Smaller (possibly eliminated) environment records for closures.

136

slide-137
SLIDE 137

Application: Must-alias analysis

Condition

◮ Two abstract addresses are equal. ◮ Both have measure 1.

Payoff

◮ Strong update: better precision. ◮ Double-free detection. ◮ Use of freed memory detection.

137

slide-138
SLIDE 138

Application: Escape analysis

Transformation

Turn heap allocation into stack allocation.

Condition

Net stack motion from creation to use is pushes.

Payoff

Cheaper allocation.

138

slide-139
SLIDE 139

Application: Lightweight continuation conversion

Transformation

Convert continuations from stacks to stack pointers.

Condition

Net stack motion from creation to use is pushes.

Payoff

Cheaper continuations in common case.

139

slide-140
SLIDE 140

Application: Static setjmp/longjmp verification

Condition

Net stack motion from creation to use is pushes.

Payoff

Program will never return to smashed stack.

140

slide-141
SLIDE 141

Application: Transducer/process fusion

Process Pipelines

◮ Unix pipes, e.g., find . | grep foo ◮ Graphics pipelines. ◮ Network stacks. ◮ DSP networks.

If only. . .

Input Output Compute Input Output Compute

141

slide-142
SLIDE 142

Application: Transducer/process fusion

Process Pipelines

◮ Unix pipes, e.g., find . | grep foo ◮ Graphics pipelines. ◮ Network stacks. ◮ DSP networks.

If only. . .

Compute Output Compute Input

142

slide-143
SLIDE 143

Application: Transducer/process fusion

Process Pipelines

◮ Unix pipes, e.g., find . | grep foo ◮ Graphics pipelines. ◮ Network stacks. ◮ DSP networks.

If only. . .

Input Compute/Compute Output

143

slide-144
SLIDE 144

Application: Transducer/process fusion

Process Pipelines

◮ Unix pipes, e.g., find . | grep foo ◮ Graphics pipelines. ◮ Network stacks. ◮ DSP networks.

If only. . .

144

slide-145
SLIDE 145

Application: Transducer/process fusion

Process Pipelines

◮ Unix pipes, e.g., find . | grep foo ◮ Graphics pipelines. ◮ Network stacks. ◮ DSP networks.

If only. . .

Thread #1 Thread #2 Thread #3 Thread #1 Thread #2 Thread #3

145

slide-146
SLIDE 146

Application: Transducer/process fusion

Process Pipelines

◮ Unix pipes, e.g., find . | grep foo ◮ Graphics pipelines. ◮ Network stacks. ◮ DSP networks.

If only. . .

Thread #1 Thread #3 Thread #3 Thread #2 Thread #2 Thread #1

146

slide-147
SLIDE 147

Application: Logic-flow analysis

Mechanical (flow): ˆ ς

ˆ

ς′

ˆ

ς′′

· · ·

Propositional (logic): Π

Π′ Π′′ · · · 147

slide-148
SLIDE 148

Application: Logic-flow analysis

Mechanical (flow): ˆ ς

  • ˆ

ς′

  • ˆ

ς′′

  • · · ·

Propositional (logic): Π

  • Π′
  • Π′′
  • · · ·

Counting bootstraps propositions from mechanical interpretation.

148

slide-149
SLIDE 149

Related work

Cousot2, 1977: Abstract interpretation. Sestoft, 1988: Globalization. Shivers, 1988: k-CFA. Harrison, 1989: Procedure strings. Shivers, 1991: Re-flow analysis. Wand & Steckler, 1994: Invariance-set analysis. Jagannathan et al., 1998: Higher-order must-alias analysis.

149

slide-150
SLIDE 150

Distinctions: Re-flow analysis

◮ k-CFA re-run for each contour of interest: Expensive. ◮ No abstract garbage collection. ◮ Assertion: Subsumed by µCFA.

150

slide-151
SLIDE 151

Distinctions: Invariance-set analysis

◮ Specific kind of environment analysis: lexical v. dynamic. ◮ No abstract garbage collection. ◮ Constraint-based. ◮ Fixed context-sensitivity: 0CFA. ◮ Less general: Supports fewer applications.

151

slide-152
SLIDE 152

Results: Γ+µCFA & Invariance-set Analysis

θ+Γ+ θ+Γ− θ−Γ+ θ−Γ−

Γ+/θ+

Timeθ TimeΓ earley 61 649 239 1100% 14s+2s 24s int-fringe-coro 136 24 25 117% 1s+ǫs 5s int-stream-coro 129 4 36 103% 5s+ǫs 14s lattice 79 70 40 200% 7s+ǫs 10s nboyer 231 44 22 188% 43s+5s 68s perm 140 149 17 206% 1s+ǫs 2s put-double-coro 72 17 7 123% ǫs+ǫs 2s sboyer 235 50 22 121% 49s+5s 95s ◮ Invariance-set analysis faster. ◮ Counting & collection more precise.

152

slide-153
SLIDE 153

Distinctions: Higher-order must-alias analysis

◮ Requires repeated runs of analysis. ◮ Uses flat lattice of cardinality. ◮ Constraint-based. ◮ Fixed widening: Per-point. ◮ Fixed context-sensitivity: 0CFA. ◮ Empirically subsumed by Γ+µCFA. ◮ Less general: Supports fewer applications.

153

slide-154
SLIDE 154

Results: MAA & Γ+µCFA

MAA1 k = 0,p k = 0,c† k = 0,s earley 15% 258s 94% 24s 94% 15s 95% 90s int-fringe-coro 26% 8s 87% 5s 87% 2s 89% 2s int-stream-coro 14% 15s 79% 14s 79% 8s 82% 7s lattice 12% 59s 91% 10s 91% 6s OOM >71m nboyer 12% 68s 98% 93s 98% 48s 98% 18,420s perm 8% 90s 95% 2s 95% 6s 95% 2s put-double-coro 41% 2s 89% 2s 89% 1s 92% 0.8s sboyer OOM >1,024s 98% 95s 98% 50s OOM >20,065s ◮ Counting & collection faster. ◮ Counting & collection more precise. † theoretical fixed point of iterated MAA.

154

slide-155
SLIDE 155

Future & ongoing work

◮ Tighter, unaided coroutine fusion. ◮ Reformulations for OO (Java-Shimple), imperative (LLVM-SSA). ◮ Invariance-flow analysis (ΘCFA). ◮ Anodized contours. ◮ Garbage-collectible model of pointer arithmetic. ◮ Partial abstract GC for polyvariance. ◮ Lazy configuration-widening for multithreaded programs. ◮ PDA-based abstractions for abstract frame strings in ∆CFA.

155

slide-156
SLIDE 156

Contributions

◮ Unified framework for general environment analysis. ◮ Two independent solutions to the environment problem:

◮ One based on counting. ◮ One based on frame strings.

◮ Proof of correctness for super-β inlining. ◮ Abstract GC: Enhanced precision via resource management.

156

slide-157
SLIDE 157

Thank you.

157

slide-158
SLIDE 158

How often do you garbage collect?

When zombie creation is imminent. In practice, one in four transitions.

158

slide-159
SLIDE 159

Accumulating propositions: Equality

Proposition

∀x ∈ Conc ˆ

ς(

b1) : ∀y ∈ Conc ˆ

ς(

b2) : x = y.

Condition for inclusion

◮ Binding

b1 to b2.

◮ Measure of both does not exceed 1.

Payoff

Boosts super-β rematerialization, copy propagation.

159

slide-160
SLIDE 160

Accumulating propositions: Conditions

Proposition

c in (if c etrue efalse).

Condition for inclusion

◮ Measure of c does not exceed 1. ◮ Assert c on fork to etrue. ◮ Assert not c on fork to efalse.

Payoff

Assists run-time check removal, verification.

160

slide-161
SLIDE 161

ΓCFA & Precision

(let* ((id (λ (x) x)) (y (id 3))) (id 4)) ΓCFA thinks... id → x → (id 3) → y → (id 4) →

161

slide-162
SLIDE 162

ΓCFA & Precision

(let* ((id (λ (x) x)) (y (id 3))) (id 4)) ΓCFA thinks...

  • 1. (λ (x) x) flows to id.

id → (λ (x) x) x → (id 3) → y → (id 4) →

162

slide-163
SLIDE 163

ΓCFA & Precision

(let* ((id (λ (x) x)) (y (id 3))) (id 4)) ΓCFA thinks...

  • 1. (λ (x) x) flows to id.
  • 2. Then, 3 flows to x.

id → (λ (x) x) x → 3 (id 3) → y → (id 4) →

163

slide-164
SLIDE 164

ΓCFA & Precision

(let* ((id (λ (x) x)) (y (id 3))) (id 4)) ΓCFA thinks...

  • 1. (λ (x) x) flows to id.
  • 2. Then, 3 flows to x.
  • 3. Then, 3 flows to y, (id 3);

x → 3 now dead. id → (λ (x) x) x → 3 / (id 3) → 3 y → 3 (id 4) →

164

slide-165
SLIDE 165

ΓCFA & Precision

(let* ((id (λ (x) x)) (y (id 3))) (id 4)) ΓCFA thinks...

  • 1. (λ (x) x) flows to id.
  • 2. Then, 3 flows to x.
  • 3. Then, 3 flows to y, (id 3);

x → 3 now dead.

  • 4. Then, 4 flows to x.

id → (λ (x) x) x → 3 / 4 (id 3) → 3 y → 3 (id 4) →

165

slide-166
SLIDE 166

ΓCFA & Precision

(let* ((id (λ (x) x)) (y (id 3))) (id 4)) ΓCFA thinks...

  • 1. (λ (x) x) flows to id.
  • 2. Then, 3 flows to x.
  • 3. Then, 3 flows to y, (id 3);

x → 3 now dead.

  • 4. Then, 4 flows to x.
  • 5. Then, 4 flows to (id 4).

id → (λ (x) x) x → 3 / 4 (id 3) → 3 y → 3 (id 4) → 4

166