Lock Analysis for an Asynchronous Object Calculus Elena Giachino - - PowerPoint PPT Presentation

lock analysis for an asynchronous object calculus
SMART_READER_LITE
LIVE PREVIEW

Lock Analysis for an Asynchronous Object Calculus Elena Giachino - - PowerPoint PPT Presentation

Lock Analysis for an Asynchronous Object Calculus Elena Giachino Tudor A. Lascu Focus INRIA - Universit` a di Bologna 19 September 2012 http://www.hats-project.eu Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object


slide-1
SLIDE 1

Lock Analysis for an Asynchronous Object Calculus

Elena Giachino Tudor A. Lascu

Focus INRIA - Universit` a di Bologna 19 September 2012 http://www.hats-project.eu

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 0 / 25

slide-2
SLIDE 2

programme

◮ define a calculus for objects interacting asynchronously

Featherweight Java with futures (FJf)

◮ introduce contracts (behavioural types) ⇒ lock analysis for FJf ◮ natural extensions to FJf −

→ FJf+

◮ design framework evolution for lock analysis of FJf+

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 1 / 25

slide-3
SLIDE 3

the world as we see it

◮ objects execute concurrently ◮ an object’s activity ↔ set of tasks ◮ one lock per object – one active task per object ◮ asynchronous interaction

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 2 / 25

slide-4
SLIDE 4

scenarios

  • 1
  • 2
  • 3

T1 T2 T2 T3 T4 T5 T6

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 3 / 25

slide-5
SLIDE 5

scenarios

  • 1
  • 2
  • 3

T1 T2 T2 T3 T4 T5 T6

circularity = dangerous configuration

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 4 / 25

slide-6
SLIDE 6

language FJf

◮ based on Featherweight Java (FJ)

e ::= x | e.f | new C(¯ e) | e; e | e!m(¯ e) | e.get | e.await T ::= C | Fut(T)

◮ features

e!m(¯ e) method invocation is asynchronous e.get retrieve result, keeping lock e.await wait for result, releasing lock Fut(T) explicit future type

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 5 / 25

slide-7
SLIDE 7

type future

a variable X with type Fut(T) is:

◮ a placeholder for a value of type T that will be available

(when its computation ends)

X = e!m();

◮ used as a (future) reference to retrieve the actual value when ready

return X.get;

◮ typically used in calculi with asynchronous method calls

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 6 / 25

slide-8
SLIDE 8

analysis’ idea

◮ collect object name dependencies in a program ◮ by means of contracts (behavioural types) ◮ (automagically) through type-inference ◮ look for circularities

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 7 / 25

slide-9
SLIDE 9

method contracts

methods

type inference

− − − − − − − − → contracts

class C { C m() { return new C ;} C r(C x) { return x!m().get ;} }

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 8 / 25

slide-10
SLIDE 10

method contracts

methods

type inference

− − − − − − − − → contracts

class C { a[ ] ( ) { O } b[ ] C m() { return new C ;} a[ ] (b[ ]) { C.m b[ ] ( ). (a, b) } d[ ] C r(C x) { return x!m().get ;} }

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 9 / 25

slide-11
SLIDE 11

method contracts - structure

a[ ] (b[ ]) { C.m b[ ] ( ). (a, b) } d[ ] r(¯ s) {❝} r′ r

  • bject record

( ¯ s

  • parameter record

){ ❝

  • contract body

} r′

  • returned record

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 10 / 25

slide-12
SLIDE 12

future records

◮ (made of) object names ◮ used to (statically) track objects in a program

a fresh name for every new

◮ grammar

r ::= X

variable

a[¯ f : ¯ r]

  • bject’s structure

a r

access to r granted through a

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 11 / 25

slide-13
SLIDE 13

more method contracts

class A { Object f ; A m() { return new A(this.f) ; } Fut(A) n(A x) { return x!m() ; } A r(A x) { return x!m().await.get ; } }

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 12 / 25

slide-14
SLIDE 14

more method contracts

class A { Object f ; a[f : b] ( ) {O} a′[f : b] A m() { return new A(this.f) ; } a[f : X] (a′[f : Y ]) {A.m a′[f : Y ]( )} a′[f : Y ] a′′[f : Y ] Fut(A) n(A x) { return x!m() ; } a[f : X] (a′[f : Y ]) {A.m a′[f : Y ]( ). (a, a′)a} a′′[f : Y ] A r(A x) { return x!m().await.get ; } }

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 13 / 25

slide-15
SLIDE 15

expression contracts 1

◮ core of a method contract → contract body ◮ contains contract associated to expression in method’s body ◮ keeps info on object dependencies

❝ ::= O

no info

C.m r(¯ s)

method C.m invoked on r with parameters ¯

s C.m r(¯ s). (a, b)

” plus get operation on result

C.m r(¯ s). (a, b)a

” plus await operation on result

(a, b) get operation on a field (a, b)a await operation on a field ❝ ❝

sequential composition

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 14 / 25

slide-16
SLIDE 16

expression contracts 2

class C { a[ ] ( ) { O } b[ ] C m() { return new C ;} a[ ] (b[ ]) { C.m b[ ] ( ). (a, b) } d[ ] C r(C x) { return x!m().get ;} }

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 15 / 25

slide-17
SLIDE 17

lock analysis for FJf

◮ extracted contracts

compose

− − − − − → automaton

◮ states are sets of dependencies ◮ transitions model how are dependencies activated and discarded ◮ circularity ⇒ possible dead (or live-)lock

(a, b) (b, a) (a, c)

lock-free

(a, b) (b, a) (a, c) (c, b)

potential misbehaviour

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 16 / 25

slide-18
SLIDE 18

extensions - FJf+

◮ FJf is a functional language (just as FJ)

(fields only initialized, by constructor)

◮ let’s introduce notion of state by field update ◮ add this.f = e to the syntax of expressions

can we adjust previous framework?

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 17 / 25

slide-19
SLIDE 19

extensions - intuition

◮ consider x!m(); x!n() where

  • m() does this.f = e1
  • n() does this.f = e2

◮ no way to know order in which updates take place ◮ static analysis ⇒ keep track of all different possibilities

⇒ future records must contain sets of names r ::= X | a[¯ f : ¯ r] | a r

  • ld syntax

r ::= X |

A[¯

f : ¯ r] |

A r

new syntax

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 18 / 25

slide-20
SLIDE 20

extensions - side effects 1

now: possible to write pure livelocks (await-only circularities)

  • 1
  • 2

t1 t2

before: await-only circularities were non-problematic (by construction)

  • 1
  • 2

t1 t2 t3

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 19 / 25

slide-21
SLIDE 21

extensions - side effects 2

◮ essential to distinguish good from bad circularities ◮ need to introduce also names for tasks

֒ → dependencies btw. tasks

◮ create a new task name for every method invocation ◮ future record of invocation tagged by associated task: A ts ◮ states of the automaton contain also dependencies btw. tasks (t, t′)

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 20 / 25

slide-22
SLIDE 22

extensions - new vs. old judgement

the type system must also be tuned . . .

  • ld style: Γ ⊢a e : (T, r) , ❝

where:

◮ Γ → environment ◮ a → name of the object this ◮ e → FJf expression ◮ T → expression e’s (class or future) type ◮ r → expression e’s future record ◮ ❝ → expression e’s contract

updated version: Γ ⊢t

a e : (T, r) , ❝

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 21 / 25

slide-23
SLIDE 23

typing get expressions

  • ld rule:

Γ ⊢a e : (Fut(T), a′ s) , ❝ Γ ⊢a e.get : (T, s) , ❝ ≬ (a, a′)

new rule:

Γ ⊢t

a e : (Fut(T), A t′s) , ❝

Γ ⊢t

a e.get : (T, s) , ❝ ≬ (t, t′) ≬ (a, ai) ∀ai ∈ A

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 22 / 25

slide-24
SLIDE 24

conclusions

◮ start from ABS language

(programming lang. developed @HATS project (7th FP) - Highly Adaptable and Trustworthy Software using Formal Models)

◮ extract core (functional) fragment → FJf

(ref. Deadlock and Livelock Analysis in Concurrent Objects with Futures (MSCS’11) - Giachino, Laneve & Lascu)

◮ develop contracts for lock analysis of FJf

(ref. same as above)

◮ extend language → FJf+ ◮ ideas to adapt framework to FJf+

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 23 / 25

slide-25
SLIDE 25

future work

◮ improve analysis’ precision

(infinite names dealt with finite approximants)

◮ proof of concept prototype (under construction) ◮ fix analysis’ details with addition of tasks ◮ introduce null value ⇒

circular lists + recursive records ??

◮ extend analysis to (full) ABS language

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 24 / 25

slide-26
SLIDE 26

thanks!

Elena Giachino Tudor A. Lascu Lock Analysis for an Asynchronous Object Calculus 19/09/’12 25 / 25