prescient memory: exposing weak memory model behavior...

84
Prescient Memory: Exposing Weak Memory Model Behavior by Looking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA MICHAEL D. BOND 1

Upload: others

Post on 30-Sep-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory: Exposing Weak Memory Model Behavior by Looking into the Future

MAN CAO

JAKE ROEMER

ARITRA SENGUPTA

MICHAEL D. BOND

1

Page 2: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Parallel Programming is Hard

2

Page 3: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Parallel Programming is Hard•Shared-memory

3

Main Memory

CPU

Cache

CPU

Cache

CPU

Cache

CPU

Cache

Page 4: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Parallel Programming is Hard•Shared-memory

•Difficult to be both correct and scalable

4

Main Memory

CPU

Cache

CPU

Cache

CPU

Cache

CPU

Cache

Page 5: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Parallel Programming is Hard•Shared-memory

•Difficult to be both correct and scalable

•Data race

5

Main Memory

CPU

Cache

CPU

Cache

CPU

Cache

CPU

Cache

Page 6: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Parallel Programming is Hard•Shared-memory

•Difficult to be both correct and scalable

•Data race

-Fundamentally, lacks strong semantic guarantees

6

Main Memory

CPU

Cache

CPU

Cache

CPU

Cache

CPU

Cache

Page 7: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #1: Weak Semantics

7

T1 T2

data = new Foo();flag = true;

if (flag)data.bar();

Foo data = null;boolean flag= false;

Page 8: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #1: Weak Semantics

8

Null pointer exception!

T1 T2

data = new Foo();flag = true;

if (flag)data.bar();

Foo data = null;boolean flag= false;

Page 9: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #1: Weak Semantics

9

No data dependence

T1 T2

data = new Foo();flag = true;

Foo data = null;boolean flag= false;

Null pointer exception!

if (flag)data.bar();

Page 10: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors of Data Races•Existing Approaches• Dynamic analyses

• Model checkers

10

Page 11: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors of Data Races•Existing Approaches• Dynamic analyses

- Limitation: coverage

• Model checkers

- Limitation: scalability

11

Page 12: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors of Data Races•Existing Approaches• Dynamic analyses

- Limitation: coverage

• Model checkers

- Limitation: scalability

•Prescient Memory (PM)

Dynamic analysis with better coverage

12

Page 13: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Outline•Memory Models and Behaviors of Data Races

•Design• Prescient Memory (PM)

• PM-profiler

• PM Workflow

•Evaluation

13

Page 14: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Memory Model

14

•Defines possible values that a load can return

Page 15: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Memory Model•Defines possible values that a load can return

15

• Sequential Consistency (SC)

• Impractical to enforceStrong

Page 16: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Memory Model•Defines possible values that a load can return

16

• Sequential Consistency (SC)

• Impractical to enforceStrong

• Enables compiler & hardware optimizations

• DRF0, C++11, JavaWeak

Page 17: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed by Memory Models

17

DRF0 Memory Model

Java Memory Model (JMM)

Page 18: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed by Memory Models

18

DRF0 Memory Model

Java Memory Model (JMM)

Racy execution No semantics

Data-race-free execution

Strong semantics (SC)

Page 19: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed by Memory Models

19

DRF0 Memory Model

Java Memory Model (JMM)

Racy execution No semantics

Data-race-free execution

Strong semantics (SC)

Racy execution Weak semantics

Data-race-free execution

Strong semantics (SC)

Page 20: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed by Memory Models

20

DRF0 Memory Model

Java Memory Model (JMM)

Racy execution No semantics

Data-race-free execution

Strong semantics (SC)

Racy execution Weak semantics

Data-race-free execution

Strong semantics (SC)

Racy execution can still lead to surprising behaviors!

Page 21: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #1: Revisit

21

T1 T2

data = new Foo();flag = true;

if (flag)data.bar();

Foo data = null;boolean flag= false;

Page 22: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #1: Revisit

22

T1 T2

data = new Foo();flag = true;

if (flag)data.bar();

Foo data = null;boolean flag= false;

stale value

latest value

Page 23: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #1: Revisit

23

Null pointer exception!

T1 T2

data = new Foo();flag = true;

if (flag)data.bar();

Foo data = null;boolean flag= false;

stale value

latest value

Page 24: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #1: Revisit

24

T1 T2

data = new Foo();flag = true;

if (flag)data.bar();

Foo data = null;boolean flag= false;

Returning stale value can trigger the exception

Page 25: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #2

25

r = data;flag = 1;

T1 T2

int data = flag = 0;

while (flag == 0) {}data = 1;

assert r == 0;

Page 26: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #2

26

r = data;flag = 1;

T1 T2

int data = flag = 0;

while (flag == 0) {}data = 1;

assert r == 0;

Page 27: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #2

27

r = data;flag = 1;

T1 T2

int data = flag = 0;

while (flag == 0) {}data = 1;

assert r == 0;

latest value

future value

Page 28: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #2

28

r = data;flag = 1;

T1 T2

int data = flag = 0;

while (flag == 0) {}data = 1;

assert r == 0;

latest value

future value

Valid due to lack of happens-before

ordering

Page 29: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #2

29

r = data;flag = 1;

T1 T2

int data = flag = 0;

while (flag == 0) {}data = 1;

assert r == 0;

latest value

future value

Assertion failure!

Page 30: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #2

30

r = data;flag = 1;

T1 T2

int data = flag = 0;

while (flag == 0) {}data = 1;

assert r == 0;

Assertion failure!

Page 31: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed in JMM #2

31

r = data;flag = 1;

T1 T2

int data = flag = 0;

while (flag == 0) {}data = 1;

assert r == 0;

Requires returning future value or reordering to trigger the assertion failure

Page 32: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #3

32

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 1) {r3 = y;x = r3;

} else x = 1;

assert r2 == 0;

int x = y = 0;

Page 33: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #3

33

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 1) {r3 = y;x = r3;

} else x = 1;

assert r2 == 0;

int x = y = 0;

JMM disallows r2 == 1 because

of causalityrequirements

– Ševčík and Aspinall, ECOOP, 2008

Page 34: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #3

34

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 1) {r3 = r2;x = r3;

} else x = 1;

assert r2 == 0;

int x = y = 0;

However, in a JVM, after

redundant read elimination

Page 35: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #3

35

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 1) {r3 = r2;x = r3;

} else x = 1;

assert r2 == 0;

int x = y = 0;

However, in a JVM, after

redundant read elimination

r2 = y;If (r2 == 1)x = r2;

else x = 1;

Page 36: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #3

36

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 1) {r3 = r2;x = r3;

} else x = 1;

assert r2 == 0;

int x = y = 0;

However, in a JVM, after

redundant read elimination

r2 = y;x = 1;

r2 = y;If (r2 == 1)x = r2;

else x = 1;

Page 37: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Example #3

37

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 1) {r3 = r2;x = r3;

} else x = 1;

assert r2 == 0;

int x = y = 0;

However, in a JVM, after

redundant read elimination

r2 = y;x = 1;

r2 = y;If (r2 == 1)x = r2;

else x = 1;

Assertion failure

possible!

Page 38: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed by Memory Models and JVMs

38

DRF0 Memory Model

Java Memory Model

Typical JVMs

Page 39: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Behaviors Allowed by Memory Models and JVMs

39

DRF0 Memory Model

Java Memory Model

Typical JVMs

Unsatisfactory, impractical to enforce

Page 40: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors of Example #3

40

T1 T2

int x = y = 0;Consider

future value

r1 = x; y = r1;

r2 = y;if (r2 == 1) {r3 = y;x = r3;

} else x = 1;

assert r2 == 0;

Page 41: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors of Example #3

41

r1 = x; // r1 = 1y = r1; // y = 1

T1 T2

r2 = y; // r2 = 1if (r2 == 1) {r3 = y; // r3 = 1x = r3; // x = 1

} else x = 1;

assert r2 == 0;

int x = y = 0;Consider

future value

Page 42: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors of Example #3

42

r1 = x; // r1 = 1y = r1; // y = 1

T1 T2

r2 = y; // r2 = 1if (r2 == 1) {r3 = y; // r3 = 1x = r3; // x = 1

} else x = 1;

assert r2 == 0;

int x = y = 0;Consider

future value

r1 = 1 justified!

Assertion failure!

Page 43: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors of Example #3

43

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 1) {r3 = y;x = r3;

} else x = 1;

assert r2 == 0;

int x = y = 0;

Requires returning future value or compiler optimization and reordering to

trigger the assertion failure

Page 44: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors with Dynamic Analyses•Typical approaches• Simulate weak memory models behaviors [1,2,3]

• Explore multiple thread interleavings [4, 5]

44

1. Adversarial Memory, Flanagan & Freund, PLDI’092. Relaxer, Burnim et al, ISSTA’113. Portend+, Kasikci et al, TOPLAS’154. Replay Analysis, Narayanasamy et al, PLDI’075. RaceFuzzer, Sen, PLDI’08

Page 45: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposing Behaviors with Dynamic Analyses•Typical approaches• Simulate weak memory models behaviors [1,2,3]

• Explore multiple thread interleavings [4, 5]

•Coverage Limitation• Return stale values only, not future values

• Cannot expose assertion failures in Examples #2, #3

45

1. Adversarial Memory, Flanagan & Freund, PLDI’092. Relaxer, Burnim et al, ISSTA’113. Portend+, Kasikci et al, TOPLAS’154. Replay Analysis, Narayanasamy et al, PLDI’075. RaceFuzzer, Sen, PLDI’08

Page 46: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Relationship among memory models and exposed behaviors

46

DRF0 Memory Model

Java Memory Model

Existing Dynamic Analyses

Typical JVMs

Page 47: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Relationship among memory models and exposed behaviors

47

DRF0 Memory Model

Our Goal

Java Memory Model

Existing Dynamic Analyses

Typical JVMs

Page 48: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Relationship among memory models and exposed behaviors

48

DRF0 Memory Model

Our Goal

Java Memory Model

Existing Dynamic Analyses

Typical JVMs

Example #1data = new Foo(); if (flag)flag = true; data.bar();

Example #2r = data; while (flag == 0) {}flag = 1; data = 1;

Example #3r1 = x; r2 = y;y = r1; if (r2 == 1) {

r3 = y;x = r3;

} else x = 1;

Page 49: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Relationship among memory models and exposed behaviors

49

DRF0 Memory Model

Our Goal

Java Memory Model

Existing Dynamic Analyses

Typical JVMs

Example #1data = new Foo(); if (flag)flag = true; data.bar();

Example #2r = data; while (flag == 0) {}flag = 1; data = 1;

Example #3r1 = x; r2 = y;y = r1; if (r2 == 1) {

r3 = y;x = r3;

} else x = 1;

Real-world evidence is

valuable here!

Page 50: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Outline•Memory Models and Behaviors of Data Races

•Design• Prescient Memory (PM)

• PM-profiler

• PM Workflow

•Evaluation

50

Page 51: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory: Key Idea•Speculatively “guess” a future value at a load

•Validate the speculative value at a later store

51

Page 52: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory: Key Idea•Speculatively “guess” a future value at a load

•Validate the speculative value at a later store

52

Page 53: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Returning Future Values is Tricky

53

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 0)x = 1;

assert r1 == 0 || r2 == 0;

int x = y = 0;

Page 54: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Returning Future Values is Tricky

54

r1 = x;y = r1;

T1 T2

assert r1 == 0 || r2 == 0;

int x = y = 0;

r2 = y;if (r2 == 0)x = 1;

Page 55: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Returning Future Values is Tricky

55

T1 T2

int x = y = 0;

r1 = x; // r1 = 1 y = r1; // y = 1

assert r1 == 0 || r2 == 0;

r2 = y; // r2 = 1if (r2 == 0)x = 1;

Page 56: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Returning Future Values is Tricky

56

T1 T2

int x = y = 0;

r1 = x; // r1 = 1 y = r1; // y = 1

assert r1 == 0 || r2 == 0;

r2 = y; // r2 = 1if (r2 == 0)x = 1;

r1 = 1 not justified

Page 57: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Returning Future Values is Tricky

57

T1 T2

int x = y = 0;

r1 = x; // r1 = 1 y = r1; // y = 1

assert r1 == 0 || r2 == 0;

r2 = y; // r2 = 1if (r2 == 0)x = 1;

r1 = 1 not justified

Invalidexecution!

Page 58: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Returning Future Values is Tricky

58

T1 T2

int x = y = 0;

r1 = x; y = r1;

assert r1 == 0 || r2 == 0;

r2 = y;if (r2 == 0)x = 1;

Should never fail!

Page 59: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Returning Future Values is Tricky

59

r1 = x;y = r1;

T1 T2

r2 = y;if (r2 == 0)x = 1;

assert r1 == 0 || r2 == 0;

int x = y = 0;

Validating speculative values is necessary to prevent nonsensical results

Page 60: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory: Key Idea•Speculatively “guess” a future value at a load

•Validate the speculative value at a later store

60

Page 61: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory: Key Idea•Speculatively “guess” a future value at a load

•Validate the speculative value at a later store

61

Valid future value

Store writes the same value

Store races with load

Page 62: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory: Key Idea•Speculatively “guess” a future value at a load• Maintain a per-variable speculative read history

• Records <logical timestamp, speculative value>

•Validate the speculative value at a later store

62

Valid future value

Store writes the same value

Store races with load

Page 63: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

PM Example

63

1: r = x;2: y = 1;

T1 T2

int x = y = 0;

3: while (y == 0) {}

4: x = 1;

assert r == 0;

S[x] = ∅

Timestamp: K1 Timestamp: K2

Page 64: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

PM Example

64

1: r = x;2: y = 1;

T1 T2

int x = y = 0;

3: while (y == 0) {}

4: x = 1;

1 ⇠ predict(…) // guess value 1S[x] = {<K1, 1>}

S[x] = ∅

assert r == 0;

Timestamp: K1 Timestamp: K2

Page 65: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

PM Example

65

1: r = x;2: y = 1;

T1 T2

int x = y = 0;

3: while (y == 0) {}

4: x = 1;

S[x] = ∅

validate S[x]:K1 ⋢ K2 && 1 == 1

1 is a valid future value!assert r == 0;

Timestamp: K1 Timestamp: K2

1 ⇠ predict(…) // guess value 1S[x] = {<K1, 1>}

Page 66: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Challenges•How to guess a future value?

66

predict(…) ?

Page 67: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Challenges•How to guess a future value?• Which load should return a future value?

• What value should be returned?

67

Page 68: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Challenges•How to guess a future value?• Which load should return a future value?

• What value should be returned?

•Solution• Profile possible future values in a prior run

68

Page 69: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Profiling Future ValuesHelper Dynamic Analysis: PM-profiler

•Maintains a per-variable concrete read history

•At a load, records:• <logical timestamp, instruction ID, set of visible values>

69

Page 70: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Profiling Future ValuesHelper Dynamic Analysis: PM-profiler

•At a store, detects:

70

Potential future value for a previous load

Store races with the previous load

Store writes a value distinct from visible values of the previous load

Page 71: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory Workflow

71

Data race detector

PM-Profiler PM

Racy accesses

Potential future values and loads

First Execution

Second Execution

Page 72: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory Workflow

72

Data race detector

PM-Profiler PM

Racy accesses

Potential future values and loads

First Execution

Second Execution

Run-to-run nondeterminism affects validatable future values

Page 73: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory Workflow

73

Data race detector

PM-Profiler PM

Racy accesses

Potential future values and loads

First Execution

Second Execution

Run-to-run nondeterminism affects validatable future values• Solution: record and replay

Page 74: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory Workflow

74

Data race detector

PM-Profiler PM

Fuzzy ReplayRecord

Racy accesses

Potential future values and loads

Page 75: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Prescient Memory Workflow

75

Data race detector

PM-Profiler PM

Fuzzy ReplayRecord

Racy accesses

Potential future values and loads

Returning a future value could diverge from the record execution• Best-effort, fuzzy replay

Page 76: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Outline•Memory Models and Behaviors of Data Races

•Design• Prescient Memory (PM)

• PM-profiler

• PM Workflow

•Evaluation

76

Page 77: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Methodology and Implementation

◦ Compare with

Adversarial Memory (AM) [Flanagan & Freund, PLDI’09]: a dynamic analysis that only uses stale values

77

Page 78: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Methodology and Implementation

◦ Compare with

Adversarial Memory (AM) [Flanagan & Freund, PLDI’09]: a dynamic analysis that only uses stale values

◦ Platform

Jikes RVM 3.1.3

DaCapo Benchmark 2006, 2009 and SPEC JBB 2000 & 2005

4-Core Intel Core i5-2500

Record and Replay [Replay, Bond et al. PPPJ’15]

78

Page 79: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Methodology and Implementation

◦ Compare with

Adversarial Memory (AM) [Flanagan & Freund, PLDI’09]: a dynamic analysis that only uses stale values

◦ Platform

Jikes RVM 3.1.3

DaCapo Benchmark 2006, 2009 and SPEC JBB 2000 & 2005

4-Core Intel Core i5-2500

Record and Replay [Replay, Bond et al. PPPJ’15]

◦ Implementation limitation

Does not support reference-type fields

79

Page 80: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposed Erroneous BehaviorsProgram AM PM

hsqldb Non-termination Data corruption

hsqldb None Performance bug

avrora Data corruption Data corruption

lusearch (GNU Classpath) Performance bug None

sunflow Null ptr exception Null ptr exception

jbb2000 Non-termination Data corruption

jbb2000 Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption None

80

Page 81: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposed Erroneous Behaviors

81

PM found 3 new erroneous behaviors!

Program AM PM

hsqldb Non-termination Data corruption

hsqldb None Performance bug

avrora Data corruption Data corruption

lusearch (GNU Classpath) Performance bug None

sunflow Null ptr exception Null ptr exception

jbb2000 Non-termination Data corruption

jbb2000 Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption None

Page 82: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposed Erroneous Behaviors

82

PM exposes most bugs that AM found.

Program AM PM

hsqldb Non-termination Data corruption

hsqldb None Performance bug

avrora Data corruption Data corruption

lusearch (GNU Classpath) Performance bug None

sunflow Null ptr exception Null ptr exception

jbb2000 Non-termination Data corruption

jbb2000 Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption None

Page 83: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Exposed Erroneous Behaviors

83

Paper contains detailed analysis of each bug.

Program AM PM

hsqldb Non-termination Data corruption

hsqldb None Performance bug

avrora Data corruption Data corruption

lusearch (GNU Classpath) Performance bug None

sunflow Null ptr exception Null ptr exception

jbb2000 Non-termination Data corruption

jbb2000 Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption Data corruption

jbb2005 (GNU Classpath) Data corruption None

Page 84: Prescient Memory: Exposing Weak Memory Model Behavior …web.cse.ohio-state.edu/~bond.213/prescient-memory-ismm-2016-talk.pdfLooking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA

Conclusion• First dynamic analysis to expose legal behaviors

due to future values in large, real programs

• Successfully found new harmful behaviors due to future values in real programs

• Reaffirms that “benign” races are harmful

• Helps future revisions to language specificationsby finding evidence of controversial behaviors in real programs

84