Permission Example public void deposit(unique Account account, immutable Amount amount) {...} public void withdraw(unique Account account, immutable Amount amount) {...} public void transfer(unique Account from, unique Account to, immutable Amount amount) { withdraw(from, amount); deposit(to, amount); unique immutable // to: from: amount: unique } 40
Permission Example public void deposit(unique Account account, immutable Amount amount) {...} public void withdraw(unique Account account, immutable Amount amount) {...} public void transfer(unique Account from, unique Account to, immutable Amount amount) { withdraw(from, amount); deposit(to, amount); // to: from: amount: unique unique immutable } 41
Permission Example public void deposit(unique Account account, immutable Amount amount) {...} public void withdraw(unique Account account, immutable Amount amount) {...} public void transfer(unique Account from, unique Account to, immutable Amount amount) { withdraw(from, amount); deposit(to, amount); // to: from: amount: unique unique immutable } 42
Permission Example public void deposit(unique Account account, immutable Amount amount) {...} public void withdraw(unique Account account, immutable Amount amount) {...} unique public void transfer(unique Account from, unique Account to, unique immutable immutable Amount amount) { immutable withdraw(from, amount); deposit(to, amount); // to: from: amount: amount: } 43
Using Permissions for Parallelization • infer permissions flow based on lexical order • define operations can run in parallel iff intersection of their required permissions does not contain unique permissions 44
Dataflow Example unique unique immutable immutable transfer(unique Account from, unique Account to, immutable Amount amount) from: to: amount: 45
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) unique unique immutable immutable from: to: amount: 46
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) unique unique immutable immutable from: to: amount: withdraw(from, amount) deposit(to, amount) 47
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) unique unique immutable immutable from: to: amount: amount: split withdraw(from, amount) deposit(to, amount) 48
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) unique unique from: to: split immutable immutable amount: amount: withdraw(from, amount) deposit(to, amount) 49
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) split unique immutable immutable unique from: amount: amount: to: withdraw(from, amount) deposit(to, amount) 50
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) split unique immutable immutable unique from: amount: amount: to: withdraw(from, amount) deposit(to, amount) 51
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) split withdraw(from, amount) deposit(to, amount) unique immutable immutable unique from: amount: amount: to: 52
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) split withdraw(from, amount) deposit(to, amount) unique immutable immutable unique from: amount: amount: to: join } 53
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) split withdraw(from, amount) deposit(to, amount) unique unique from: to: join immutable immutable amount: amount: } 54
Dataflow Example transfer(unique Account from, unique Account to, immutable Amount amount) split withdraw(from, amount) deposit(to, amount) join unique unique immutable immutable from: to: amount: amount: } 55
Dataflow Example unique immutable immutable unique transfer(unique Account from, unique Account to, immutable Amount amount) split withdraw(from, amount) deposit(to, amount) join from: to: amount: amount: } 56
Shared Data Issues • causes non-determinism but sometimes order matters • e.g., object that needs to follow protocol • all accesses to shared objects require synchronization • sometimes shared permissions are unavoidable • e.g., doubly linked list 57
Data Groups • bundle shared objects into data groups • abstract collection of objects • disjoint partitions of heap 58
Data Groups • bundle shared objects into data groups • abstract collection of objects • disjoint partitions of heap 58
Data Groups • bundle shared objects into data groups • abstract collection of objects • disjoint partitions of heap 58
Data Groups • bundle shared objects into data groups • abstract collection of objects • disjoint partitions of heap 58
Data Groups Permissions • similar to access permissions for data groups • manual split/joining by user • user controlled mechanism for granularity 59
Data Groups Permissions • similar to access permissions for data groups • manual split/joining by user • user controlled mechanism for granularity 59
Data Groups Permissions • data groups are embedded in objects • strong encapsulation, ownership • group permissions are derived from receiver permissions 60
Group Permissions Exclusive Permission • aliases = 1 • access= RW exclusive shared shared • “thread local” • no synchronization 61
Group Permissions Shared Permission • aliases = N split • access= none exclusive • “shared data” shared protected shared • requires synchronization 62
Group Permissions atomic Permission • aliases = 1 exclusive • access= RW • “protected ” shared shared • is synchronized atomic protected 63
Group Permissions Shared Permission • aliases = N split • access= none exclusive • “shared data” shared protected shared • requires synchronization 64
Group Permissions Exclusive Permission • aliases = 1 • access= RW exclusive shared shared • “thread local” • no synchronization 65
Data Group Example class DLLItem { O1 O2 O3 public Object data; public DLLItem prev; DLL I1 I2 I3 public DLLItem next; } public class DLL { private DLLItem head; public void add(Object data) { DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 66
Data Group Example class DLLItem { O1 O2 O3 public Object data; public DLLItem prev; DLL I1 I2 l3 public DLLItem next; } public class DLL { private DLLItem head; public void add( Object data) { DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 67
Data Group Example class DLLItem { O1 O2 O3 public Object data; public shared DLLItem prev; DLL I1 l2 l3 public shared DLLItem next; } public class DLL { private shared DLLItem head; public void add( Object data) { shared DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 68
Data Group Example class DLLItem { O1 O2 O3 public unique Object data; public shared DLLItem prev; DLL I1 l2 l3 public shared DLLItem next; } public class DLL { private shared DLLItem head; public void add(unique >> none Object data) { shared DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 69
Data Group Example class DLLItem { O1 O2 O3 public unique Object data; public shared DLLItem prev; DLL I1 l2 l3 public shared DLLItem next; } public class DLL { private shared DLLItem head; public void add(unique >> none Object data) : unique { shared DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 70
Data Group Example class DLLItem { O1 O2 O3 public unique Object data; public shared DLLItem prev; DLL I1 l2 l3 public shared DLLItem next; } public class DLL { private shared DLLItem head; public void add(unique >> none Object data) : unique { shared DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 71
Data Group Example class DLLItem { O1 O2 O3 public unique Object data; public shared DLLItem prev; DLL I1 l2 l3 public shared DLLItem next; } public class DLL { private shared DLLItem head; public void add(unique >> none Object data) : unique { shared DLLItem li = new DLLItem(); this.head.prev = li; ERROR: li.next = this.head; li.data = data; Access shared this.head = li; } data } 71
Data Group Example class DLLItem { public unique Object data; O1 O2 O3 public shared DLLItem prev; public shared DLLItem next; DLL I1 l2 l3 } public class DLL { private shared DLLItem head; public void add(unique >> none Object data) : unique { atomic { shared DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } } 72
Data Group Example class DLLItem { public unique Object data; O1 O2 O3 public shared DLLItem prev; public shared DLLItem next; DLL I1 l2 l3 } public class DLL { private shared DLLItem head; public void add(unique >> none Object data) : unique { atomic { shared DLLItem li = new DLLItem(); this.head.prev = li; li.next = this.head; li.data = data; Unique receiver this.head = li; } means no aliases } } 72
Data Group Example class DLLItem { public unique Object data; O1 O2 O3 public shared DLLItem prev; public shared DLLItem next; } DLL I1 l2 l3 public class DLL { group nodes; private shared DLLItem head; public void add(unique >> none Object data) : unique { shared DLLItem li = new DLLItem (); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 73
Data Group Example class DLLItem<G> { public unique Object data; O1 O2 O3 public shared DLLItem<G> prev; public shared DLLItem<G> next; } DLL I1 l2 l3 public class DLL { group nodes; private shared DLLItem head; public void add(unique >> none Object data) : unique { shared DLLItem li = new DLLItem (); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 74
Data Group Example class DLLItem<G> { public unique Object data; O1 O2 O3 public shared DLLItem<G> prev; public shared DLLItem<G> next; } DLL I1 l2 l3 public class DLL { group nodes; private shared DLLItem head; public void add(unique >> none Object data) : unique { shared DLLItem<nodes> li = new DLLItem<nodes>(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 75
Data Group Example class DLLItem<G> { public unique Object data; O1 O2 O3 public shared DLLItem<G> prev; public shared DLLItem<G> next; } DLL I1 l2 l3 public class DLL { group nodes; private shared DLLItem head; public void add(unique >> none Object data) : unique { shared DLLItem<nodes> li = new DLLItem<nodes>(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } 75
Data Group Example class DLLItem<G> { public unique Object data; O1 O2 O3 public shared DLLItem<G> prev; public shared DLLItem<G> next; } DLL I1 l2 l3 public class DLL { group nodes; private shared DLLItem head; public void add(unique >> none Object data) : unique { unpack { shared DLLItem<nodes> li = new DLLItem<nodes>(); this.head.prev = li; li.next = this.head; li.data = data; this.head = li; } } } 76
Data Group Example public void add(unique >> none Object data) : unique { unique unique // this: data: unpack { ... li.data = data; } } 77
Data Group Example public void add(unique >> none Object data) : unique { // this: data: unique unique unpack { ... li.data = data; } } 78
Data Group Example public void add(unique >> none Object data) : unique { unpack { // this: this.nodes: data: unique unique exclusive ... li.data = data; } } 79
Data Group Example public void add(unique >> none Object data) : unique { unpack { ... // this: this.nodes: data: unique unique exclusive li.data = data; } } 80
Data Group Example public void add(unique >> none Object data) : unique { unpack { ... data: li.data = data; unique // this: this.nodes: unique exclusive } } 81
Recommend
More recommend