Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Representation Synthesis PLDI’2011 *, ESOP’12, PLDI’12 * CACM’12 Peter Hawkins, Stanford University Alex Aiken, Stanford University Kathleen Fisher,

Similar presentations


Presentation on theme: "Data Representation Synthesis PLDI’2011 *, ESOP’12, PLDI’12 * CACM’12 Peter Hawkins, Stanford University Alex Aiken, Stanford University Kathleen Fisher,"— Presentation transcript:

1 Data Representation Synthesis PLDI’2011 *, ESOP’12, PLDI’12 * CACM’12 Peter Hawkins, Stanford University Alex Aiken, Stanford University Kathleen Fisher, DARPA Martin Rinard, MIT Mooly Sagiv, TAU * Best Paper Award

2 Background High level formalisms for static program analysis – Circular attribute grammars – Horn clauses Interprocedural Analysis – Context free reachability Implemented in SLAM/SDV Shape Analysis – Low level pointer data structures

3 next table [0] [1] [2] [3] [4] [5] null index= 2index = 0index = 3index = 1index= thttpd: Web Server Conn Map Representation Invariants: 1.  n: Map.  v: Z. table[v] =n  n->index=v 2.  n: Map. n->rc =|{n' : Conn. n’->file_data = n}|

4 static void add_map(Map *m) { int i = hash(m); … table[i] = m ; … m->index= i ; … m->rc++; } thttptd:mmc.c Representation Invariants: 1.  n: Map.  v:Z. table[v] =n  index[n]=v 2.  n:Map. rc[n] =|{n' : Conn. file_data[n’] = n}| broken restored

5 filesystem=1 s_list s_files filesystem=2 s_list s_files filesystems file=14 f_list f_fs_list file=6 f_list f_fs_list file=2 f_list f_fs_list file=7 f_list f_fs_list file=5 f_list f_fs_list Composing Data Structures

6 Problem: Multiple Indexes Access Patterns Find all mounted filesystems Find cached files on each filesystem Iterate over all used or unused cached files in Least- Recently-Used order filesystem=1 s_list s_files filesystem=2 s_list s_files filesystems file=14 f_list f_fs_list file=6 f_list f_fs_list file=2 f_list f_fs_list file=7 f_list f_fs_list file=5 f_list f_fs_list file_in_use file_unused +Concurency

7 Disadvantages of linked shared data structures Error prone Hard to change Performance may depend on the machine and workload Hard to reason about correctness Concurrency makes it harder – Lock granularity – Aliasing

8 Our thesis Very high level programs – No pointers and shared data structures – Easier programming – Simpler reasoning – Machine independent The compiler generates pointers and multiple concurrent shared data structures Performance comparable to manually written code

9 Our Approach Program with “database” – States are tables – Uniform relational operations Hide data structures from the program – Functional dependencies express program invariants The compiler generates low level shared pointer data structures with concurrent operations – Correct by construction The programmer can tune efficiency Autotuning for a given workload

10 Conceptual Programming Model shared database query … insert … remove insert query … insert … remove …

11 Relational Specification Program states as relations – Columns correspond to properties – Functional dependencies define global invariants Atomic Operationmeaning r= emptyr := {} insert r s t if s  r then r = r  { } query r S CThe C of all the tuples in r matching tuple remove r sremove from r all the tuples which match s

12 The High Level Idea Concurrent Compositions of Data Structures, Atomic Transactions Compiler RelScala Scala Decomposition query {fs, file} List * query(FS* fs, File* file) { lock(fs) ; for (q= file_in_use; …) ….

13 Filesystem Three columns {fs, file, inuse} fs:int  file:int  inuse:Bool Functional dependencies – {fs, file}  { inuse} fsfileinuse 114F 27T 25F 16T 12F fsfileinuse 114F 27T 25F 16T 12F 12T

14 Filesystem (operations) fsfileinuse 114F 27T 25F 16T 12F query {fs, file }= [, ]

15 Filesystem (operations) fsfileinuse 114F 27T 25F 16T 12F insert fsfileinuse 114F 27T 25F 16T 12F 115T

16 Filesystem (operations) remove fsfileinuse 114F 27T 25F 16T 12F 115T fsfileinuse 27T 25F

17 Directed Graph Data Structure Three columns {src, dst, weight} src  dst  weight Functional dependencies – {src, dst}  { weight} Operations – query {dst, weight} – query {src, weight}

18 Plan Compiling into sequential code (PLDI’11) Adding concurrency (PLDI’12)

19 Mapping Relations into Low Level Data Structures Many mappings exist How to combine several existing data structures – Support sharing Maintain the relational abstraction Reasonable performance Parametric mappings of relations into shared combination of data structures – Guaranteed correctness

20 The RelC Compiler fs  file  inuse {fs, file}  {inuse} foreach  filesystems s.t. fs= 5 do … RelC C++ inuse fs, file fs list inuse file list array list Relational Specification Graph decomposition

21 Decomposing Relations Represents subrelations using container data structures A directed acyclic graph(DAG) – Each node is a sub-relation – The root represents the whole relation – Edges map columns into the remaining sub- relations – Shared node=shared representation

22 Decomposing Relations into Functions Currying fs  file  inuse {fs, file}  {inuse} fs  file  inuse fs  file file  inuse inuse group_by {fs, file} group-by {fs} group-by {inuse} group-by {file} FS  (FILE  INUSE) FILE  INUSE INUSE  FS  FILE FS  FILE  INUSE FS  (FILE  INUSE) INUSE  (FS  FILE  INUSE) fs file fs, file inuse

23 Filesystem Example fsfileinuse 114F 27T 25F 16T 12F inuse fs, file fs inuse file inuse 14F 6T 2F fileinuse 7T 5F F T F T F fs:1 fs:2 file:14 file:6 file:2 file:7 file:5 {fs, file, inuse}

24 Memory Decomposition(Left) inuse fs, file fs inuse file inuse:F inuse:T inuse:F Inuse:T Inuse:F fs:1 fs:2 file:14 file:6 file:2 file:7 file:5

25 Filesystem Example fsfileinuse 114F 27T 25F 16T 12F fsfile fsfile fs:2 file:7 inuse T T F F F fs:1 file:6 fs:1 file:14 fs:2 file:5 fs:1 file:2 inuse:T inuse:F inuse fs, file fs inuse file {fs, file}  { inuse}

26 Memory Decomposition(Right) fs:2 file:7 fs:1 file:6 fs:1 file:14 fs:2 file:5 fs:1 file:2 inuse:T inuse:F inuse:T inuse:FInuse:F inuse fs, file fs inuse file {fs, file}  { inuse}

27 Decomposition Instance fs:1 file:14 fs:1 file:6 fs:1 file:2 fs:2 file:7 fs:2 file:5 inuse:T inuse:F inuse:Tinuse:FInuse:TInuse:F fsfileinuse 114F 27T 25F 16T 12F fs:1 file:14 file:6 file:2 file:7 file:5 fs:2 fs  file  inuse {fs, file}  { inuse} inuse fs, file fs inuse file

28 Decomposition Instance fs:1 file:14 fs:1 file:6 fs:1 file:2 fs:2 file:7 fs:2 file:5 inuse:T inuse:F inuse:Tinuse:FInuse:TInuse:F fsfileinuse 114F 27T 25F 16T 12F fs:1 file:14 file:6 file:2 file:7 file:5 fs:2 fs  file  inuse {fs, file}  { inuse} fs  file  inuse {fs, file}  { inuse} inuse fs, file fs inuse file list array list s_list f_fs_list f_list

29 Decomposing Relations Formally(PLDI’11) fs  file  inuse {fs, file}  {inuse} inuse fs, file x yz w fs inuse file clist list array list let w: {fs, file,inuse}  {inuse} = {inuse} in let y : {fs}  {file, inuse} = {file}  list {w} in let z : {inuse }  {fs, file, inuse} = {fs,file}  list {w} in let x: {}  {fs, file, inuse} = {fs}  clist {y}  {inuse}  array {z}

30 Memory State fsfileinuse 114F 27T 25F 16T 12F fs  file  inuse {fs, file}  { inuse} inuse fs, file fs inuse file list array list filesystems filesystem=1 s_list s_files filesystem=2 s_list s_files file=14 f_list f_fs_list file=6 f_list f_fs_list file=2 f_list f_fs_list file=7 f_list f_fs_list file=5 f_list f_fs_list file_in_use file_unused

31 Adequacy A decomposition is adequate if it can represent every possible relation matching a relational specification Adequacy enforces sufficient conditions for adequacy Not every decomposition is a good representation of a relation

32 Adequacy of Decompositions All columns are represented Nodes are consistent with functional dependencies – Columns bound to paths leading to a common node must functionally determine each other

33 Respect Functional Dependencies file,fs inuse {file, fs}  {inuse}

34 Adequacy and Sharing fs, file fs inuse file inuse Columns bound on a path to an object x must functionally determine columns bound on any other path to x {fs, file}  {inuse, fs, file}

35 Adequacy and Sharing fs inuse file inuse Columns bound on a path to an object x must functionally determine columns bound on any other path to x  {fs, file}  {inuse, fs}

36 The RelC Compiler PLDI’11 Sequential Compositions of Data Structures Compiler ReLC C++ inuse fs, file fs inuse file list array list

37 Query Plans foreach  filesystems if inuse=T do … fs, file fs list inuse file inuse list array list scan Cost proportional to the number of files

38 Query Plans foreach  filesystems if inuse=T do … fs, file fs list inuse file inuse list array list access scan Cost proportional to the number of files in use

39 Removal and graph cuts remove fsfileinuse 114F 27T 25F 16T 12F filesystems fs:2 s_list s_files file:7 f_list f_fs_list file:5 f_list f_fs_list inuse:T inuse:F fs list file inuse list array list

40 Abstraction Theorem If the programmer obeys the relational specification and the decomposition is adequate and if the individual containers are correct Then the generated low-level code maintains the relational abstraction relation remove low-level state low-level state low level code remove  

41 Autotuner Given a fixed set of primitive types – list, circular list, doubly-linked list, array, map, … A workload Exhaustively enumerate all the adequate decompositions up to certain size The compiler can automatically pick the best performing representation for the workload

42 Directed Graph Example (DFS) Columns src  dst  weight Functional Dependencies – {src, dst}  {weight} Primitive data types – map, list … src dst weight map list src dst src weight map list map dst src weight map list dst weight map src map weight dst list src list

43 Synthesizing Concurrent Programs PLDI’12

44 Multiple ADTs Invariant: Every element that added to eden is either in eden or in longterm public void put(K k, V v) { if (this.eden.size() >= size) { this.longterm.putAll(this.eden); this.eden.clear(); } this.eden.put(k, v); }

45 OOPSLA’11 Shacham Search for all public domain collection operations methods with at least two operations Used simple static analysis to extract composed operations – Two or more API calls Extracted 112 composed operations from 55 applications – Apache Tomcat, Cassandra, MyFaces – Trinidad, … Check Linearizability of all public domain composed operations

46 47% Linearizable 38% Non Linearizable 15% Open Non Linearizable Motivation: OOPSLA’11 Shacham

47 Relational Specification Atomic operationmeaning r= emptyr := {} insert r s t if s  r then r := r  { } query r S CThe C of all the tuples in r matching tuple remove r sremove from r all the tuples which match s Program states as relations – Columns correspond to properties – Functional dependencies define global invariants

48 The High Level Idea Concurrent Compositions of Data Structures, Atomic Transactions Compiler RelScala Scala Concurrent Decomposition ConcurrentHashMap HashMap query {fs, file} List * query(FS* fs, File* file) { lock(…) for (q= file_in_use; …) ….

49 Two-Phase Locking Two phase locking protocol: Well-locked: To perform a read or write, a thread must hold the corresponding lock Two-phase: All lock acquisitions must precede all lock releases Attach a lock to each piece of data Theorem [Eswaran et al., 1976]: Well-locked, two-phase transactions are serializable

50 Two Phase Locking Attach a lock to every edge Problem 2: Too many locks DecompositionDecomposition Instance We’re done! Problem 1: Can’t attach locks to container entries Two Phase Locking  Serialiazability Butler Lampson/David J. Wheeler: “Any problem in computer science can be solved with another level of indirection.”

51 Two Phase Locking Attach a lock to every edge Problem 2: Too many locks DecompositionDecomposition Instance We’re done! Problem 1: Can’t attach locks to container entries Two Phase Locking  Serialiazability

52 Lock Placements 1. Attach locks to nodes DecompositionDecomposition Instance

53 Coarse-Grained Locking DecompositionDecomposition Instance

54 Finer-Grained Locking DecompositionDecomposition Instance

55 Lock Placements: Domination DecompositionDecomposition Instance Locks must dominate the edges they protect

56 Lock Placements: Path-Closure All edges on a path between an edge and its lock must share the same lock

57 Lock Ordering Prevent deadlock via a topological order on locks

58 Queries and Deadlock 2. lookup(tv) 1. acquire(t) 3. acquire(v) 4. scan(vw) Query plans must acquire the correct locks in the correct order Example: find files on a particular filesystem

59 Deadlock and Aliasing L1 L2 { lock(a) lock(b) // do something unlock(b) unlock(a) } { lock(a) lock(b) // do something unlock(b) unlock(a) } a a b b 

60 Decompositions and Aliasing A decomposition is an abstraction of the set of potential aliases Example: there are exactly two paths to any instance of node w

61 Autotuner Given a fixed set of primitive types – array, concurrentHashMap, concurrentSkipListMap, … A workload Exhaustively enumerate all the adequate decompositions up to certain size The compiler can automatically pick the best representation for the workload – Lock granularity

62 Directed Graph Example (DFS) Columns src  dst  weight Functional Dependencies – {src, dst}  {weight} Primitive data types – map, list … src dst weight map list src dst src weight map list map dst src weight map list dst weight map src map weight dst list src list

63 Concurrent Synthesis (Autotuner ) Find optimal combination of Decomposition Container Data Structures ConcurrentHashMap ConcurrentSkipListMap CopyOnWriteArrayList Array HashMap TreeMap LinkedList Lock Implementations ReentrantReadWriteLock ReentrantLock Lock Striping Factors Lock Placement

64 Concurrent Graph Benchmark Start with an empty graph Each thread performs 5 x 10 5 random operations Distribution of operations a-b-c-d (a% find successors, b% find predecessors, c% insert edge, d% remove edge) Plot throughput with varying number of threads Based on Herlihy’s benchmark of concurrent maps

65 Black = handwritten, isomorphic to blue = ConcurrentHashMap = HashMap... Results: % find successor, 35% find predecessor, 20% insert edge, 10% remove edge ConcurrentHashMap HashMap

66 (Some) Related Projects SETL Relational synthesis: [Cohen & Campbell 1993], [Batory & Thomas 1996], [Smaragdakis & Batory 1997], [Batory et al. 2000] [Manevich, 2012] … Two-phase locking and Predicate Locking [Eswaran et al., 1976], Tree and DAG locking protocols [Attiya et al., 2010], Domination Locking [Golan-Gueta et al., 2011] Lock Inference for Atomic Sections: [McCloskey et al.,2006], [Hicks, 2006], [Emmi, 2007]

67 Synchronization Methods Pessimistic Optimistic with rollback Non-Commutativity with future operations – Static analysis for inferring future – Efficient libraries for runtime synchronization – Guaranteed serializability and deadlock-freedom – No rollbacks – Reasonable performance

68 Summary Programming with uniform relational abstraction – Increase the gap between data abstraction and low level implementation Comparable performance to manual code Easier to evolve Automatic data structure selection Easier for program reasoning

69 Concurrent Libraries with Foresight PLDI’13 Guy Gueta(TAU) G. Ramalingam (MSR) M. Sagiv (TAU) E. Yahav (Technion)

70 Transactional Libraries with Foresight Enforce atomicity of arbitrary sequences The client declares intended operations – foresight The library utilizes the specification – Synchronize between operations which do not serialize with foresight Methodology for creating libraries with foresights – Maps Foresight can be automatically inferred by sequential static program analysis

71 Example: Positive Counter Operation  ) Operation  )

72 ComputeIfAbsent (single Map)

73 GossipRouter (multiple Maps)

74 Summary Methods for enforcing atomicity of sequences of operations Provably correct Simplifies reasoning – Sequential reasoning – High level data structures & invariants Is that efficient enough? – Pessimistic concurrency – Optimistic concurrency


Download ppt "Data Representation Synthesis PLDI’2011 *, ESOP’12, PLDI’12 * CACM’12 Peter Hawkins, Stanford University Alex Aiken, Stanford University Kathleen Fisher,"

Similar presentations


Ads by Google