Transcript Slide 1

Automated Cost-Of-Service
Tracking using the Abstract
State Machine Language
(AsmL)
Joel Rivendell
Supervisor: Heinz Schmidt
Abstract State Machine
Computation
Originated with Finite State Machine
Computation work by Yuri Gurevich
 Gurevich came to generalise Turing’s
thesis and build upon Dijkstras algorithms
to formulate “evolving algebras”
 Gurevich claimed for every sequential
algorithm that exists, regardless of the
abstraction level, there exists a sequential
abstract state machine (Gurevich, 1999)

Abstract State Machine Language
(AsmL)
Microsoft Research - Foundations of
Software Engineering (FSE)
 Features –

– Executable Specifications
– Runtime Conformance Testing
– Design by Contract
– Non-Deterministic computation (i.e. Sets)
– Parallel update (State to State)
– Built on .NET
Abstract State Machine Language
(AsmL) Problems
AsmL is predominantly a functionally
oriented formal contract language
 Extra-functional or Cost-of-Service
characteristics such as performance,
reliability, etc are not naturally catered for
in AsmL constructs
 In 2003 Rupak Das looked at ways to
address this problem and came up with a
Counter construct

Research Gap
A preprocessor was suggested as future
work
 There was also need to be able to easily
specify time and space complexity
constraints via AsmL constructs for
performance measurement and constraint

Aspect-Oriented Programming
(AOP) in AsmL
AsmL Runtime Verification uses a runtime
“observer” construct that matches a model to an
implementation and enforces conformance.
 The “observer” is inserted in the method and
matches signatures and return values
 The “observer” is as such an aspect-oriented
programming construct that monitors behaviour
and throws an exception if verification fails

Aims

This honours thesis looked at a number of
elements and tried to synthesize them
– An automated and time-saving way to implement CoS
specifications via a GUI proof of concept for ease of
use
– A performance construct based on temporal contracts
in addition to Rupaks Counter construct which can be
used for space complexity assessment
– A intermediate language syntax that satisfied the
above two criteria
Method
Cost Assertion Language (CAL) intermediate
language is minimalistic and increases
productivity for a developer
 CAL allows CoS tracking to be abstracted from
the main AsmL specification so that the user can
more easily differentiate functional from nonfunctional specifications
 The Time construct created allows a
programmer to measure time complexity in
terms of a contract language

Technology and Tools Used

.NET
–
–
–
–
–
–
–
Common Language Runtime (CLR)
Common Library Specification (CLS)
Common Type System (CTS)
Common Intermediate Language (CIL)
Just in Time (JIT) compiler
Interoperable
AsmL models can be conformance tested with any
.NET derived Dynamic Link Library (*.dll) from over
30 languages (some are more optimized than others)
Technology and Tools

ANTLR
– Compiler constructor for parsing the intermediate
language (Cost Assertion Language(*.cal)) and
inserting the constructs into the source AsmL file

C#
– Used to create the proof of concept GUI
implementation and handle input
– This language was perfect for GUI construction
because of Windows Forms libraries
How they work together
AsmL Source
ANTLR Parser
GUI
CAL
AsmL
Output
CAL Tool GUI
Does most of the work for you by declaring
everything
 Enters the details needed to insert Cost
assertions (i.e. Counter and/or Time Construct)
 Update variable (counters) insertion, increment,
decrement, equations, guards, return, methods
all in an easy to use and minimalistic interface to
maximize productivity and abstraction of Cost
 Design by contract by local and global assertions

CAL Tool GUI
CAL Tool GUI
CAL

Cost Assertion Language
– Not fully formulated as an independent syntax
– You can use the tool to directly input from the
.cal file instead of using the GUI input if
required making it quasi-text based as well

namespace ReaderWriterDriver



[EntryPoint]
public class Reader
var numberOfReaders as Integer = 0










[EntryPoint]
BegRead()
UpdateReaders()
[EntryPoint]
Read()
BegRead()
WriteLine("Reading ...")
EndRead()


[EntryPoint]
EndRead()
UpdateReaders()


[EntryPoint]
UpdateReaders()

[EntryPoint]
Readers() as Integer
step
return numberOfReaders



Example
Example
Cost Assertion Language (CAL)
ASML Source File

namespace ReaderWriterDriver



interface ICounter
CounterValue() as Integer
Increment()
Decrement()


















class Counter implements ICounter
var counter as Integer = 0
CounterValue() as Integer
step
return counter
Increment()
step
counter := counter + 1
Decrement()
step
counter := counter - 1
[EntryPoint]
public class Reader
var numberOfReaders as Integer = 0
var NReq_Reader = new Counter()
var NBeg_Reader = new Counter()
var NEnd_Reader = new Counter()

cn {1} @ReaderWriterDriver.Reader
Example































[EntryPoint]
BegRead()
step NReq_Reader.Increment()
step NBeg_Reader.Decrement()

upd {1} ++Reader.R @Reader.BegRead()
Upd {2} --Reader.B @Reader.BegRead()

upd {3} ++Reader.R $Reader.Read() if (numberOfReaders >= 0) return

upd {4} #Reader @Reader.UpdateReaders() := numberOfReaders

mr {1} @ReaderWriterDriver.Reader.TotalReaders

UpdateReaders()
[EntryPoint]
Read()
BegRead()
WriteLine("Reading ...")
EndRead()
step
if (numberOfReaders >= 0) then
return NReq_Reader.Increment()
[EntryPoint]
EndRead()
UpdateReaders()
[EntryPoint]
UpdateReaders()
step numberOfReaders :=
NBeg_Reader.CounterValue() –
NEnd_Reader.CounterValue()
[EntryPoint]
Readers() as Integer
step
return numberOfReaders
[EntryPoint]
TotalReaders() as Integer
step
return NEnd_Reader.CounterValue()
Time Construct

namespace ReaderWriterDriver





interface ITimeCounter
TimeValue() as Double
AccTimeValue() as Double
Start()
Stop()


















class TimeCounter implements ITimeCounter
var time as Double = 0
var totalTime as Double = 0
var t1 as Double = 0
var t2 as Double = 0
TimeValue() as Double
step
return time
AccTimeValue() as Double
step
return totalTime
Start()
step
t1 := System.DateTime.Now.Ticks as Double
Stop()
step t2 := System.DateTime.Now.Ticks as Double
step time := ((t2 - t1)/10000000)
step totalTime := ((t2 - t1)/10000000) + totalTime


public class Reader
var T_Reader = new TimeCounter
@[email protected]
Case Study – Reader/Writer

Multiple Reader Writer Problem
– Synchronisation
– Counting Readers, Writers and Writers
Waiting and using the Cost assertions to track
– Fair implementation using Alternating Reader
Writer algorithm
– Similar to Rupak Das example except the
COST code is generated by the CAL
Case Study - KD-Tree

K-D Trees
– Computationally intensive
– Good for performance measurement
K-dimensional binary branched data structure
used for orthogonal range searching and other
spatial applications
 Given a KD-Tree of the points in a range search
it is possible to find the resulting points in
O(sqrt(n)+k) time where n is the number of
points and k is the number of points in the result
 Live example…

The Road Less Travelled…
The “Observer” (mediator.dll) construct in AsmL
I originally planned to manipulate via adding the
time construct to it that would go with the
observer to additionally perform runtime
verification for specially designed CAL temporal
assertions. Unfortunately after extensive
correspondence with Mike Barnett from FSE, the
information I needed came too late to
incorporate.
 Temporal logic contract extensions

Difficulties and Realities
Illness
 Microsoft proprietary policy
 Time constraints and other commitments
 The CAL Tool still contains many bugs as it
is just a proof of concept prototype

Conclusions





The Time Construct appears to be a new
concept in terms of contract languages like
AsmL
Productivity
Usability
Allows the CoS contract aspect to be abstracted
from the functional specification aspect
CAL is interoperable and as an extension of
AsmL enjoys many of the features this evolving
language possesses
Future Directions
CAL could be extremely useful if
developed further for a contract language
such as AsmL.
 Extrapolate the time construct idea further
to temporal logic assertions and runtime
verification with enforced performance
constraints.

Acknowledgements

Like to thank –
– Hienz Schmidt, Supervisor
– Rupak Das
– Mike Barnett, Microsoft FSE
– CSSE peers
Thank You

Questions?