Lecture 11: Core State Machines I 2016-12-08 Prof. Dr. Andreas - - PowerPoint PPT Presentation

lecture 11 core state machines i
SMART_READER_LITE
LIVE PREVIEW

Lecture 11: Core State Machines I 2016-12-08 Prof. Dr. Andreas - - PowerPoint PPT Presentation

Software Design, Modelling and Analysis in UML Lecture 11: Core State Machines I 2016-12-08 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universitt Freiburg, Germany 11 2016-12-08 main Content Recall :


slide-1
SLIDE 1

– 11 – 2016-12-08 – main –

Software Design, Modelling and Analysis in UML

Lecture 11: Core State Machines I

2016-12-08

  • Prof. Dr. Andreas Podelski, Dr. Bernd Westphal

Albert-Ludwigs-Universität Freiburg, Germany

slide-2
SLIDE 2

Content

– 11 – 2016-12-08 – Scontent –

2/34

  • Recall: Basic Causality Model
  • Event Pool
  • insert, remove, clear, ready.
  • System Configuration
  • implicit attributes:

stable, st, and friends.

  • system state plus event pool
  • Actions
  • simple action language.
  • transformer: effects of actions.
slide-3
SLIDE 3

– 11 – 2016-12-08 – main –

3/34

Roadmap: Chronologically

– 10 – 2016-12-01 – Sstmover –

17/32 Syntax: (i) UML State Machine Diagrams. (ii) Def.: Signature with signals. (iii) Def.: Core state machine. (iv) Map UML State Machine Diagrams to core state machines. Semantics: The Basic Causality Model (v) Def.: Ether (aka. event pool) (vi) Def.: System configuration. (vii) Def.: Event. (viii) Def.: Transformer. (ix) Def.: Transition system, computation. (x) Transition relation induced by core state ma- chine. (xi) Def.: step, run-to-completion step. (xii) Later: Hierarchical state machines.

UML

Model Instances

N S W E

CD, SM S = (T, C, V, atr ), SM M = (D

S , AS , SM )

OCL expr CD, SD S , SD B = (QSD, q0, AS , SD, FSD) = (0, 0)

(cons0,Snd0)

  • u0

(1, 1)· · · w = ((i, consi, Snd i))iN G = (N, E, f)

Mathematics

OD

UML

  • !
  • !

!

slide-4
SLIDE 4

– 11 – 2016-12-08 – main –

4/34

15.3.12 StateMachine (OMG, 2011b, 574)

– 10 – 2016-12-01 – Sstmcaus –

28/32

  • Event occurrences are detected, dis-

patched, and then processed by the state machine, one at a time.

  • The semantics of event occurrence pro-

cessing is based on the run-to- comple- tion assumption, interpreted as run-to- completion processing.

  • Run-to-completion processing means

that an event [...] can only be taken from the pool and dispatched if the processing

  • f the previous [...] is fully completed.
  • The processing of a single event occur-

rence by a state machine is known as a run-to-completion step.

  • Before

commencing

  • n

a run-to- completion step, a state machine is in a stable state configuration with all entry/exit/internal-activities (but not necessarily do-activities) completed.

  • The same conditions apply after the run-

to-completion step is completed.

  • Thus, an event occurrence will never be

processed [...] in some intermediate and in- consistent situation.

  • [IOW,] The run-to-completion step is the

passage between two state configurations

  • f the state machine.
  • The run-to-completion assumption sim-

plifies the transition function of the StM, since concurrency conflicts are avoided during the processing of event, allowing the StM to safely complete its run-to- completion step.

  • The order of dequeuing is not defined,

leaving open the possibility of modeling different priority-based schemes.

  • Run-to-completion may be implemented

in various ways. [...]

slide-5
SLIDE 5

– 11 – 2016-12-08 – main –

5/34

Example

– 10 – 2016-12-01 – Sstmcaus –

29/32

C

x : Int

D

s1 s2 s3

  • E[n 6= ]/x := x + 1; n ! F

/n := F/x := 0

SMC: s1 s2

  • F/

/p ! F

:SMD

n

0..1

p

0..1

h hsignali i

E

h hsignali i

F

(1, 1)

u1 : C x = 27 st = s1 stb = 1 u2 : D st = s1 stb = 1 n p u3 : E to u1

(2, 2)

u1 : C x = 28 st = s2 stb = 0 u2 : D st = s1 stb = 1 n p u4 : F to u2

(3, 3)

u1 : C x = 28 st = s3 stb = 0 u2 : D st = s1 stb = 1 p u4 : F to u2

(4, 4)

u1 : C x = 28 st = s3 stb = 0 u2 : D st = s2 stb = 0 p

({E}, {F}) u1 (, ) u1 ({F}, ) u2

slide-6
SLIDE 6

Ether

– 11 – 2016-12-08 – main –

6/34

slide-7
SLIDE 7

Recall: 15.3.12 StateMachine (OMG, 2011b, 563)

– 11 – 2016-12-08 – Sether –

7/34

  • The order of dequeuing is not defined,

leaving open the possibility of modeling different priority-based schemes.

slide-8
SLIDE 8

Ether and OMG (2011b)

– 11 – 2016-12-08 – Sether –

8/34

The standard distinguishes (among others)

  • SignalEvent (OMG, 2011b, 450) and Reception (OMG, 2011b, 447).

On SignalEvents, it says

A signal event represents the receipt of an asynchronous signal instance. A signal event may, for example, cause a state machine to trigger a transition. (OMG, 2011b, 449) [...]

slide-9
SLIDE 9

Ether and OMG (2011b)

– 11 – 2016-12-08 – Sether –

8/34

The standard distinguishes (among others)

  • SignalEvent (OMG, 2011b, 450) and Reception (OMG, 2011b, 447).

On SignalEvents, it says

A signal event represents the receipt of an asynchronous signal instance. A signal event may, for example, cause a state machine to trigger a transition. (OMG, 2011b, 449) [...] Semantic Variation Points The means by which requests are transported to their target depend on the type of requesting action, the target, the properties of the communication medium, and numerous other factors. In some cases, this is instantaneous and completely reliable while in others it may involve transmission delays of variable duration, loss of requests, reordering, or duplication. (See also the discussion on page 421.) (OMG, 2011b, 450)

slide-10
SLIDE 10

Ether and OMG (2011b)

– 11 – 2016-12-08 – Sether –

8/34

The standard distinguishes (among others)

  • SignalEvent (OMG, 2011b, 450) and Reception (OMG, 2011b, 447).

On SignalEvents, it says

A signal event represents the receipt of an asynchronous signal instance. A signal event may, for example, cause a state machine to trigger a transition. (OMG, 2011b, 449) [...] Semantic Variation Points The means by which requests are transported to their target depend on the type of requesting action, the target, the properties of the communication medium, and numerous other factors. In some cases, this is instantaneous and completely reliable while in others it may involve transmission delays of variable duration, loss of requests, reordering, or duplication. (See also the discussion on page 421.) (OMG, 2011b, 450) Our ether (→ in a minute) is a general representation of many possible choices. Often seen minimal requirement: order of sending by one object is preserved.

slide-11
SLIDE 11

Ether aka. Event Pool

– 11 – 2016-12-08 – Sether –

9/34

  • Definition. Let S = (T, C, V, atr , E ) be a signature with signals and D a

structure. We call a tuple (Eth, ready, ⊕, ⊖, [ · ]) an ether over S and D if and only if it provides

  • a ready operation which yields a set of events (i.e., signal instances) that

are ready for a given object, i.e. ready : Eth × D(C ) → 2D(E )

  • a operation to insert an event for a given object, i.e.

⊕ : Eth × D(C ) × D(E ) → Eth

  • a operation to remove an event, i.e.

⊖ : Eth × D(E ) → Eth

  • an operation to clear the ether for a given object, i.e.

[ · ] : Eth × D(C ) → Eth.

slide-12
SLIDE 12

Example: FIFO Queue

– 11 – 2016-12-08 – Sether –

10/34

A (single, global, shared, reliable) FIFO queue is an ether:

  • Eth = (D(C ) × D(E ))∗

the set of finite sequences of pairs (u, e) ∈ D(C ) × D(E )

  • ready : Eth × D(C ) → 2D(E )

((u1, e).ε, u2) →

  • {(u1, e)}

, if u1 = u2 ∅ , otherwise

  • ⊕ : Eth × D(C ) × D(E ) → Eth

(ε, u, e) → ε.(u, e)

  • ⊖ : Eth × D(E ) → Eth

(ε.(u, e1), e2) →

  • ε

, if e2 = e1 ε.(u, e1) , otherwise

  • [ · ] : Eth × D(C ) → Eth

remove all (u, e) from ε

slide-13
SLIDE 13

Other Examples

– 11 – 2016-12-08 – Sether –

11/34

  • One FIFO queue per active object is an ether.
  • One-place buffer.
  • Priority queue.
  • Multi-queues (one per sender).
  • Trivial example: sink, “black hole”.
  • Lossy queue (⊕ needs to become a relation then).
  • ...
slide-14
SLIDE 14

System Configuration

– 11 – 2016-12-08 – main –

12/34

slide-15
SLIDE 15

System Configuration

– 11 – 2016-12-08 – Sstmscnf –

13/34

  • Definition. Let S0 = (T0, C0, V0, atr 0, E ) be a signature with signals, D0 a structure of

S0, (Eth, ready, ⊕, ⊖, [ · ]) an ether over S0 and D0. Furthermore assume there is one core state machine MC per class C ∈ C . A system configuration over S0, D0, and Eth is a pair (σ, ε) ∈ ΣD

S × Eth

where

  • S = (T0 ˙

∪ {SMC | C ∈ C0}, C0, V0 ˙ ∪ {stable : Bool, −, true, ∅} ˙ ∪ {stC : SMC, +, s0, ∅ | C ∈ C } ˙ ∪ {paramsE : E0,1, +, ∅, ∅ | E ∈ E0}, {C → atr 0(C) ∪ {stable, stC} ∪ {paramsE | E ∈ E0} | C ∈ C }, E0)

  • D = D0 ˙

∪ {SMC → S(MC) | C ∈ C }, and

  • σ(u)(r) ∩ D(E0) = ∅ for each u ∈ dom(σ) and r ∈ V0.
slide-16
SLIDE 16

System Configuration: Example

– 11 – 2016-12-08 – Sstmscnf –

14/34 C

x : Int

  • signal
  • E

b : Bool

  • signal
  • F

a : Int

SMC:

s1 s2 s3

  • c

0..1

S0 = (T0, C0, V0, atr 0, E ), D0; (σ, ε) ∈ ΣD

S × Eth where

  • S = (T0 ˙

∪ {SMC | C ∈ C }, C0, V0 ˙ ∪ {stable : Bool, −, true, ∅} ˙ ∪ {stC : SMC, +, s0, ∅ | C ∈ C } ˙ ∪ {paramsE : E0,1, +, ∅, ∅ | E ∈ E0}, {C → atr 0(C) ∪ {stable, stC} ∪ {paramsE | E ∈ E0} | C ∈ C }, E0)

  • D = D0 ˙

∪ {SMC → S(MC) | C ∈ C }, and

  • σ(u)(r) ∩ D(E0) = ∅ for each u ∈ dom(σ) and r ∈ V0.
slide-17
SLIDE 17

System Configuration Step-by-Step

– 11 – 2016-12-08 – Sstmscnf –

15/34

  • We start with some signature with signals S0 = (T0, C0, V0, atr0, E ).
  • A system configuration is a pair (σ, ε) which

comprises a system state σ wrt. S (not wrt. S0).

  • Such a system state σ wrt. S provides, for each object u ∈ dom(σ),
  • values for the explicit attributes in V0,
  • values for a number of implicit attributes, namely
  • a stability flag, i.e. σ(u)(stable) is a boolean value,
  • a current (state machine) state, i.e. σ(u)(st) denotes one of the states of core state

machine MC,

  • a temporary association to access event parameters for each class, i.e. σ(u)(paramsE)

is defined for each E ∈ E .

  • For convenience require: there is no link to an event except for paramsE.
slide-18
SLIDE 18

Stability

– 11 – 2016-12-08 – Sstmscnf –

16/34

Definition. Let (σ, ε) be a system configuration over some S0, D0, Eth. We call an object u ∈ dom(σ) ∩ D(C0) stable in σ if and only if σ(u)(stable) = true.

slide-19
SLIDE 19

Where are we?

– 11 – 2016-12-08 – Sstmscnf –

17/34

C

x : Int

D

s1 s2 s3

  • E[n = ∅]/x := x + 1; n ! F

/n := ∅ F/x := 0

SMC: s1 s2

  • F/

/p ! F

:SMD

n

0..1

p

0..1

  • signal
  • E
  • signal
  • F

(σ1, ε1)

u1 : C x = 27 st = s1 stb = 1 u2 : D st = s1 stb = 1 n p u3 : E to u1

(σ2, ε2)

u1 : C x = 28 st = s2 stb = 0 u2 : D st = s1 stb = 1 n p u4 : F to u2

(σ3, ε3)

u1 : C x = 28 st = s3 stb = 1 u2 : D st = s1 stb = 1 p u4 : F to u2

(σ4, ε4)

u1 : C x = 28 st = s3 stb = 1 u2 : D st = s2 stb = 0 p

({E}, {F}) u1 (∅, ∅) u1 ({F}, ∅) u2

slide-20
SLIDE 20

Transformer

– 11 – 2016-12-08 – main –

18/34

slide-21
SLIDE 21

Recall

– 11 – 2016-12-08 – Strafo –

19/34

  • The (simplified) syntax of transition annotations:

annot ::=

  • event

[ ‘[’ guard ‘]’ ] [ ‘/’ action]

  • Clear: event is from E of the corresponding signature.
  • But: What are guard and action?
slide-22
SLIDE 22

Recall

– 11 – 2016-12-08 – Strafo –

19/34

  • The (simplified) syntax of transition annotations:

annot ::=

  • event

[ ‘[’ guard ‘]’ ] [ ‘/’ action]

  • Clear: event is from E of the corresponding signature.
  • But: What are guard and action?
  • UML can be viewed as being parameterized in expression language

(providing guard) and action language (providing action).

slide-23
SLIDE 23

Recall

– 11 – 2016-12-08 – Strafo –

19/34

  • The (simplified) syntax of transition annotations:

annot ::=

  • event

[ ‘[’ guard ‘]’ ] [ ‘/’ action]

  • Clear: event is from E of the corresponding signature.
  • But: What are guard and action?
  • UML can be viewed as being parameterized in expression language

(providing guard) and action language (providing action).

  • Examples:
  • Expression Language:
  • OCL
  • Java, C++, ...expressions
  • ...
  • Action Language:
  • UML Action Semantics, “Executable UML”
  • Java, C++, ...statements (plus some event send action)
  • ...
slide-24
SLIDE 24

Needed: Semantics

– 11 – 2016-12-08 – Strafo –

20/34

In the following, we assume that we’re given

  • an expression language Expr for guards, and
  • an action language Act for actions,
slide-25
SLIDE 25

Needed: Semantics

– 11 – 2016-12-08 – Strafo –

20/34

In the following, we assume that we’re given

  • an expression language Expr for guards, and
  • an action language Act for actions,

and that we’re given

  • a semantics for boolean expressions in form of a partial function

I · ( · , · ) : Expr × ΣD

S × D(C )

→ B which evaluates expressions in a given system configuration,

Assuming I to be partial is a way to treat “undefined” during runtime. If I is not defined (for instance because of dangling-reference navigation or division-by-zero), we want to go to a designated “error” system configuration.

  • a transformer for each action: for each act ∈ Act, we assume to have

tact ⊆ D(C ) × (ΣD

S × Eth) × (ΣD S × Eth)

slide-26
SLIDE 26

Transformer

– 11 – 2016-12-08 – Strafo –

21/34

Definition. Let ΣD

S the set of system configurations over some S0, D0, Eth.

We call a relation t ⊆ D(C ) × (ΣD

S × Eth) × (ΣD S × Eth)

a (system configuration) transformer.

slide-27
SLIDE 27

Transformer

– 11 – 2016-12-08 – Strafo –

21/34

Definition. Let ΣD

S the set of system configurations over some S0, D0, Eth.

We call a relation t ⊆ D(C ) × (ΣD

S × Eth) × (ΣD S × Eth)

a (system configuration) transformer. Example:

  • t[ux](σ, ε) ⊆ ΣD

S × Eth is

  • the set (!) of the system configurations
  • which may result from object ux
  • executing transformer t.
slide-28
SLIDE 28

Transformer

– 11 – 2016-12-08 – Strafo –

21/34

Definition. Let ΣD

S the set of system configurations over some S0, D0, Eth.

We call a relation t ⊆ D(C ) × (ΣD

S × Eth) × (ΣD S × Eth)

a (system configuration) transformer. Example:

  • t[ux](σ, ε) ⊆ ΣD

S × Eth is

  • the set (!) of the system configurations
  • which may result from object ux
  • executing transformer t.
  • tskip[ux](σ, ε) = {(σ, ε)}
  • tcreate[ux](σ, ε) : add a previously non-alive object to σ
slide-29
SLIDE 29

Observations

– 11 – 2016-12-08 – Strafo –

22/34

  • In the following, we assume that
  • each application of a transformer t
  • to some system configuration (σ, ε)
  • for object ux

is associated with a set of observations Obst[ux](σ, ε) ∈ 2(D(E ) ˙

∪ {∗,+})×D(C ).

  • An observation

(ue, udst) ∈ Obst[ux](σ, ε) represents the information that, as a “side effect” of object ux executing t in system configuration (σ, ε), the event ue has been sent to udst. Special cases: creation (’∗’) / destruction (’+’).

slide-30
SLIDE 30

A Simple Action Language

– 11 – 2016-12-08 – Sactlang –

23/34

In the following we use ActS = {skip} ∪ {update(expr 1, v, expr 2) | expr 1, expr 2 ∈ ExprS , v ∈ atr} ∪ {send(E(expr1, ..., expr n), expr dst) | expr i, expr dst ∈ ExprS , E ∈ E } ∪ {create(C, expr, v) | C ∈ C , expr ∈ Expr S , v ∈ V } ∪ {destroy(expr) | expr ∈ ExprS } and OCL expressions over S (with partial interpretation) as ExprS .

slide-31
SLIDE 31

Transformer Examples: Presentation

– 11 – 2016-12-08 – Sactlang –

24/34

abstract syntax concrete syntax

  • p

intuitive semantics

...

well-typedness

...

semantics

((σ, ε), (σ′, ε′)) ∈ top[ux] iff ...

  • r

top[ux](σ, ε) = {(σ′, ε′) | where ...}

  • bservables

Obsop[ux] = {. . . }

(error) conditions

Not defined if ...

slide-32
SLIDE 32

Transformer: Skip

– 11 – 2016-12-08 – Sactlang –

25/34

abstract syntax concrete syntax

skip

intuitive semantics

do nothing

well-typedness

./.

semantics

tskip[ux](σ, ε) = {(σ, ε)}

  • bservables

Obsskip[ux](σ, ε) = ∅

(error) conditions

slide-33
SLIDE 33

Transformer: Update

– 11 – 2016-12-08 – Sactlang –

26/34

abstract syntax concrete syntax

update(expr1, v, expr2)

intuitive semantics

Update attribute v in the object denoted by expr1 to the value denoted by expr2.

well-typedness

expr1 : TC and v : T ∈ atr(C); expr2 : T; expr1, expr2 obey visibility and navigability

semantics

tupdate(expr1,v,expr2)[ux](σ, ε) = {(σ′, ε)} where σ′ = σ[u → σ(u)[v → Iexpr 2(σ, ux)]] with u = Iexpr1(σ, ux).

  • bservables

Obsupdate(expr1,v,expr2)[ux] = ∅

(error) conditions

Not defined if Iexpr 1(σ, ux) or Iexpr2(σ, ux) not defined.

slide-34
SLIDE 34

Update Transformer Example

– 11 – 2016-12-08 – Sactlang –

27/34

SMC: s1 s2

/x := x + 1

tupdate(expr1,v,expr2)[ux](σ, ε) = (σ′ = σ[u → σ(u)[v → Iexpr2(σ, ux)]], ε), u = Iexpr 1(σ, ux)

σ: u1 : C x = 4 y = 0 u1 : C x = 5 y = 0 :σ′ ε: :ε′

slide-35
SLIDE 35

Transformer: Send

– 11 – 2016-12-08 – Sactlang –

28/34

abstract syntax concrete syntax

send(E(expr1, ..., exprn), exprdst)

intuitive semantics

Object ux : C sends event E to object exprdst, i.e. create a fresh signal instance, fill in its attributes, and place it in the ether.

well-typedness E ∈ E ; atr(E) = {v1 : T1, . . . , vn : Tn}; expr i : Ti, 1 ≤ i ≤ n;

expr dst : TD, C, D ∈ C \ E ; all expressions obey visibility and navigability in C

semantics (σ′, ε′) ∈ tsend(E(expr 1,...,expr n),expr dst)[ux](σ, ε) if σ′ = σ ˙ ∪ {u → {vi → di | 1 ≤ i ≤ n}}; ε′ = ε ⊕ (udst, u); if udst = Iexpr dst(σ, ux) ∈ dom(σ); di = Iexpr i(σ, ux) for 1 ≤ i ≤ n; u ∈ D(E) a fresh identity, i.e. u ∈ dom(σ), and where (σ′, ε′) = (σ, ε) if udst ∈ dom(σ).

  • bservables

Obssend[ux] = {(ue, udst)} (error) conditions Iexpr(σ, ux) not defined for any expr ∈ {expr dst, expr 1, . . . , expr n}

slide-36
SLIDE 36

Send Transformer Example

– 11 – 2016-12-08 – Sactlang –

29/34

SMC: s1 s2

/n ! F(x + 1)

tsend(exprsrc,E(expr 1,...,expr n),exprdst)[ux](σ, ε) ∋ (σ′, ε′) iff ε′ = ε ⊕ (udst, u); σ′ = σ ˙ ∪ {u → {vi → di | 1 ≤ i ≤ n}}; udst = Iexpr dst(σ, ux) ∈ dom(σ); di = Iexpri(σ, ux), 1 ≤ i ≤ n; u ∈ D(E) a fresh identity;

σ: u1 : C x = 5 :σ′ ε: :ε′

slide-37
SLIDE 37

Sequential Composition of Transformers

– 11 – 2016-12-08 – Sactlang –

30/34

  • Sequential composition t1 ◦ t2 of transformers t1 and t2 is canonically defined as

(t2 ◦ t1)[ux](σ, ε) = t2[ux](t1[ux](σ, ε)) with observation Obs(t2◦t1)[ux](σ, ε) = Obst1[ux](σ, ε) ∪ Obst2[ux](t1(σ, ε)).

  • Clear: not defined if one the two intermediate “micro steps” is not defined.
slide-38
SLIDE 38

Transformers And Denotational Semantics

– 11 – 2016-12-08 – Sactlang –

31/34

Observation: our transformers are in principle the denotational semantics of the actions/action sequences. The trivial case, to be precise. Note: with the previous examples, we can capture

  • empty statements, skips,
  • assignments,
  • conditionals (by normalisation and auxiliary variables),
  • create/destroy (later),

but not possibly diverging loops. Our (Simple) Approach: if the action language is, e.g. Java, then (syntactically) forbid loops and calls of recursive functions. Other Approach: use full blown denotational semantics. No show-stopper, because loops in the action annotation can be converted into transition cycles in the state machine.

slide-39
SLIDE 39

Tell Them What You’ve Told Them. . .

– 11 – 2016-12-08 – Sttwytt –

32/34

  • A ether is an abstract representation of different possible

“event pools” like

  • FIFO queues (shared, or per sender),
  • One-place buffers,
  • ...
  • A system configuration consists of
  • an event pool (pending messages),
  • a system state over a signature with

implicit attributes for

  • current state,
  • stability,
  • etc.
  • Transitions are labelled with actions, the effect
  • f actions is explained by transformers,

transformers may modify system state and ether.

slide-40
SLIDE 40

References

– 11 – 2016-12-08 – main –

33/34

slide-41
SLIDE 41

References

– 11 – 2016-12-08 – main –

34/34 OMG (2011a). Unified modeling language: Infrastructure, version 2.4.1. Technical Report formal/2011-08-05. OMG (2011b). Unified modeling language: Superstructure, version 2.4.1. Technical Report formal/2011-08-06.