Domain-Level Observation and Control for Compiled Executable DSLs
MODELS 2019 Foundations Track − Münich, Germany
Erwan Bousse
University of Nantes – LS2N, France
Manuel Wimmer
CDL-MINT, Johannes Kepler University Linz, Austria
1/67
Domain-Level Observation and Control for Compiled Executable DSLs - - PowerPoint PPT Presentation
Domain-Level Observation and Control for Compiled Executable DSLs MODELS 2019 Foundations Track Mnich, Germany Erwan Bousse Manuel Wimmer University of Nantes LS2N, France CDL-MINT, Johannes Kepler University Linz, Austria 1/67
Erwan Bousse
University of Nantes – LS2N, France
Manuel Wimmer
CDL-MINT, Johannes Kepler University Linz, Austria
1/67
Behavioral models (eg. state machines) can conveniently describe the behaviors of systems under design. Domain-specic languages (DSLs) can be engineered and used to build such models. Dynamic analyses of behavioral models are crucial in early design phases to see how a described behavior unfolds over time. Require the possibility to execute models ⚙ !
Behavioral model
2/67
Behavioral models (eg. state machines) can conveniently describe the behaviors of systems under design. Domain-specic languages (DSLs) can be engineered and used to build such models. Dynamic analyses of behavioral models are crucial in early design phases to see how a described behavior unfolds over time. Require the possibility to execute models ⚙ !
Behavioral model
conforms to
DSL
3/67
Behavioral models (eg. state machines) can conveniently describe the behaviors of systems under design. Domain-specic languages (DSLs) can be engineered and used to build such models. Dynamic analyses of behavioral models are crucial in early design phases to see how a described behavior unfolds over time. Require the possibility to execute models ⚙ !
Behavioral model
conforms to
DSL
Dynamic Analysis
4/67
Behavioral models (eg. state machines) can conveniently describe the behaviors of systems under design. Domain-specic languages (DSLs) can be engineered and used to build such models. Dynamic analyses of behavioral models are crucial in early design phases to see how a described behavior unfolds over time. Require the possibility to execute models ⚙ !
Behavioral model
conforms to
DSL
Dynamic Analysis Model Execution
5/67
Model Procedure dependency conforms to input/output
6/67
Model Procedure dependency conforms to input/output
Interpreted DSL
7/67
Model Procedure dependency conforms to input/output
Interpreted DSL
Abstract Syntax (metamodel)
8/67
Model Procedure dependency conforms to input/output
Interpreted DSL
Abstract Syntax (metamodel) Model State Definition
9/67
Model Procedure dependency conforms to input/output
Interpreted DSL
Abstract Syntax (metamodel) Model State Definition Execution Steps Definition Interpretation Rules
10/67
Model Procedure dependency conforms to input/output
Interpreted DSL
Abstract Syntax (metamodel) Model State Definition Execution Steps Definition Interpretation Rules
Target interpreter
Engine
11/67
Model Procedure dependency conforms to input/output
Interpreted DSL
Abstract Syntax (metamodel) Model State Definition Execution Steps Definition Interpretation Rules
Target interpreter
Engine Executed Model
12/67
Model Procedure dependency conforms to input/output
Interpreted DSL
Abstract Syntax (metamodel) Model State Definition Execution Steps Definition Interpretation Rules
Target interpreter
Engine Executed Model State Steps
runtime data
13/67
Model Procedure dependency conforms to input/output
Interpreted DSL
Abstract Syntax (metamodel) Model State Definition Execution Steps Definition Interpretation Rules
Target interpreter
Engine Executed Model State Steps
runtime data Dynamic analysis services Tracer Debugger ...
14/67
Abstract Syntax input 1..*
1..*
Net Place
name: String initialTokens: Integer
Transition
name: String places * imports merges Model State Definition
Place
tokens: Integer Interpretation rules (summarized) run(Net) fire(Transition) : while there is an enabled transition, fires it. : removes a token from each input Place and adds one to each output Place. * transitions
15/67
Abstract Syntax input 1..*
1..*
Net Place
name: String initialTokens: Integer
Transition
name: String places * imports merges Model State Definition
Place
tokens: Integer Interpretation rules (summarized) run(Net) fire(Transition) : while there is an enabled transition, fires it. : removes a token from each input Place and adds one to each output Place. * transitions
p4 p5 t1 t2 t3
A
p3 p1 p2
16/67
Abstract Syntax input 1..*
1..*
Net Place
name: String initialTokens: Integer
Transition
name: String places * imports merges Model State Definition
Place
tokens: Integer Interpretation rules (summarized) run(Net) fire(Transition) : while there is an enabled transition, fires it. : removes a token from each input Place and adds one to each output Place. * transitions
p4 p5 t1 t2 t3
A
p3 p1 p2 p1 p3 p2 p4 p5 t1 t2 t3 p1 p3 p2 p4 p5 t1 t2 t3 p1 p3 p2 p4 p5 t1 t2 t3
fire(t1) fire(t2) fire(t3) run(net)
B C D
1 2 3 4 5 6
A
model state step
foo()
1
point
17/67
Abstract Syntax input 1..*
1..*
Net Place
name: String initialTokens: Integer
Transition
name: String places * imports merges Model State Definition
Place
tokens: Integer Interpretation rules (summarized) run(Net) fire(Transition) : while there is an enabled transition, fires it. : removes a token from each input Place and adds one to each output Place. * transitions
p4 p5 t1 t2 t3
A
p3 p1 p2 p1 p3 p2 p4 p5 t1 t2 t3 p1 p3 p2 p4 p5 t1 t2 t3 p1 p3 p2 p4 p5 t1 t2 t3
fire(t1) fire(t2) fire(t3) run(net)
B C D
1 2 3 4 5 6
A
model state step
foo()
1
point
Dynamic Analysis
18/67
19/67
What about DSLs built with a compiler (eg. a code generator) instead of an interpreter?
20/67
Model Procedure dependency conforms to input/output
21/67
Model Procedure dependency conforms to input/output
Compiled DSL
22/67
Model Procedure dependency conforms to input/output
Compiled DSL
Source Abstract Syntax
23/67
Model Procedure dependency conforms to input/output
Compiled DSL
Source Abstract Syntax Compiler
24/67
Model Procedure dependency conforms to input/output
Compiled DSL
Source Abstract Syntax Compiler
Target Language (interpreted)
Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target Engine
Target interpreter
25/67
Model Procedure dependency conforms to input/output
Compiled DSL
Source Abstract Syntax Compiler
Target Language (interpreted)
Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target Engine
Target interpreter
Source Model
26/67
Model Procedure dependency conforms to input/output
Compiled DSL
Source Abstract Syntax Compiler
Target Language (interpreted)
Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target Engine
Target interpreter
Source Model Target Model
27/67
Model Procedure dependency conforms to input/output
Compiled DSL
Source Abstract Syntax Compiler
Target Language (interpreted)
Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target Engine
Target interpreter
Source Model Target Model
Dynamic analysis services
Target State
Tracer Debugger
Source Steps Target Steps
... Target runtime data
28/67
Petri nets abstract syntax AD abstract syntax
Activity Edge Action ForkNode JoinNode InitialNode FinalNode
<<abstract>>
NamedElement
+name: String
source 1 target 1
* incoming * nodes * edges *
<<abstract>>
Node
transformActivity(Activity) transformEdge(Edge) transformAction(Action) ... : Creates a Net : Creates a Place : Creates a Place and two Transitions imports Compiler (summarized) imports
29/67
A B C e1 e2 e3 e4 e5 e6 e7 Init End J F
30/67
A B C e1 e2 e3 e4 e5 e6 e7 Init End J F
Init_node Init_offer A_node A_offer e1_edge A_take F_node F_take e2_edge e3_edge e4_edge F_offer B_node C_node B_take C_take B_offer C_offer e5_edge e6_edge J_take J_node J_offer e7_edge End_take
30/67
Model Procedure dependency conforms to input/output
Compiled DSL
Source Abstract Syntax Compiler
Target Language (interpreted)
Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target Engine
Target interpreter
Source Model Target Model
Dynamic analysis services
Target State
Tracer Debugger
Source Steps Target Steps
... Target runtime data
Problem: Dynamic analysis is performed at the level of the target domain!
31/67
32/67
33/67
Most general-purpose programming languages rely on ecient compilers for their semantics, either targeting some form of bytecode (eg. Java or Python) or machine code (eg. C or C++).
33/67
Most general-purpose programming languages rely on ecient compilers for their semantics, either targeting some form of bytecode (eg. Java or Python) or machine code (eg. C or C++). Most of these languages do provide an interactive debugger at the source domain level to step through the execution and observe the program state.
33/67
Most general-purpose programming languages rely on ecient compilers for their semantics, either targeting some form of bytecode (eg. Java or Python) or machine code (eg. C or C++). Most of these languages do provide an interactive debugger at the source domain level to step through the execution and observe the program state. But these debuggers result from ad-hoc language engineering work! This does not give us a systematic recipe for engineering new DSLs.
33/67
Most general-purpose programming languages rely on ecient compilers for their semantics, either targeting some form of bytecode (eg. Java or Python) or machine code (eg. C or C++). Most of these languages do provide an interactive debugger at the source domain level to step through the execution and observe the program state. But these debuggers result from ad-hoc language engineering work! This does not give us a systematic recipe for engineering new DSLs. How can we engineer compiled DSLs compatible with dynamic analyses at the source domain level, just as common general-purpose programming languages?
33/67
An architecture to support observation and control for compiled DSLs.
34/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
35/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
36/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
Source Model State Definition
b
37/67
38/67
Observing the execution of a model requires accessing its state as it changes (tokens, variables, activated elements, etc.).
38/67
Observing the execution of a model requires accessing its state as it changes (tokens, variables, activated elements, etc.). For interpreted DSLs, possible states are dened by a model state denition which extends the abstract syntax of the DSL with new dynamic properties and metaclasses (eg. tokens for the Petri nets DSL).
38/67
Observing the execution of a model requires accessing its state as it changes (tokens, variables, activated elements, etc.). For interpreted DSLs, possible states are dened by a model state denition which extends the abstract syntax of the DSL with new dynamic properties and metaclasses (eg. tokens for the Petri nets DSL). But for compiled DSLs, everything related to execution is delegated to the target language, including the state denition.
38/67
Observing the execution of a model requires accessing its state as it changes (tokens, variables, activated elements, etc.). For interpreted DSLs, possible states are dened by a model state denition which extends the abstract syntax of the DSL with new dynamic properties and metaclasses (eg. tokens for the Petri nets DSL). But for compiled DSLs, everything related to execution is delegated to the target language, including the state denition. Hence, necessary to extend a compiled DSL with a model state denition, to dene explicitly the possible states of conforming source models.
38/67
When executing a UML activity diagram, tokens ow through both nodes and edges of the model. We add a TokensHolder metaclass to reect that:
AD execution metamodel
Token
<<abstract>>
Node Edge
heldTokens * merges
Activity diagram abstract syntax <<abstract>>
TokenHolder
39/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
Source Model State Definition
b
40/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
Source Model State Definition
b
Source Execution Steps Definition
c
41/67
42/67
Observing and controlling require knowing the execution steps of the model execution, ie. what are the
42/67
Observing and controlling require knowing the execution steps of the model execution, ie. what are the
For interpreted DSLs, specic interpretation rules can be tagged as producers of execution steps (eg. the
fire step for Petri nets).
42/67
Observing and controlling require knowing the execution steps of the model execution, ie. what are the
For interpreted DSLs, specic interpretation rules can be tagged as producers of execution steps (eg. the
fire step for Petri nets).
For compiled DSLs, we propose a trivial step denition metamodel to declare possible execution steps.
42/67
Observing and controlling require knowing the execution steps of the model execution, ie. what are the
For interpreted DSLs, specic interpretation rules can be tagged as producers of execution steps (eg. the
fire step for Petri nets).
For compiled DSLs, we propose a trivial step denition metamodel to declare possible execution steps.
Step Definition Metamodel
StepDefinition
+name: String Metamodeling language
parameters *
StepParameter
+name: String
type 1
<<abstract>>
Classifier
+name: String
42/67
43/67
In UML activity diagrams, a node will take tokens from incoming edges, and oer tokens on its outgoing edges when it nishes its task.
43/67
In UML activity diagrams, a node will take tokens from incoming edges, and oer tokens on its outgoing edges when it nishes its task. We dene the following execution steps to reect that:
take(Node): taking of tokens by a Node from the incoming edges of the Node
;
executeNode(Node): taking and oering of tokens by a Node , i.e., a
composite step containing both an offer step and a take step;
executeActivity(Activity): execution of the Activity until no tokens
can be oered or taken, i.e., a composite step containing executeNode steps.
43/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
Source Model State Definition
b
Source Execution Steps Definition
c
44/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
Source Model State Definition
b
Source Execution Steps Definition
c
Feedback Manager
d
+ Compilation Links
Source State Source Steps Source Steps
45/67
46/67
Now remains the translation at runtime of states and steps of the target model back to the source model, to be observed by dynamic analysis tools.
46/67
Now remains the translation at runtime of states and steps of the target model back to the source model, to be observed by dynamic analysis tools. Our approach: denition of a feedback manager attached to the execution, which performs said translation on the y during the model execution.
46/67
Now remains the translation at runtime of states and steps of the target model back to the source model, to be observed by dynamic analysis tools. Our approach: denition of a feedback manager attached to the execution, which performs said translation on the y during the model execution. Proposed interface for feedback managers:
feedbackState: Update the source model state based on the set of changes
applied on the target model state in the last target execution step.
processTargetStepStart: Translate a target starting step into source steps. processTargetStepEnd: Translate a target ending step into source steps.
46/67
47/67
48/67
49/67
1
run(net)
50/67
1
run(net)
I
executeActivity(activity)
51/67
1
run(net)
2 3
fire(Init_offer)
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgeI
executeActivity(activity)
52/67
1
run(net)
2 3
fire(Init_offer)
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgeI
executeActivity(activity) executeNode(Init)
II.1
53/67
1
run(net)
2 3
fire(Init_offer)
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgeI
executeActivity(activity) executeNode(Init)
II.1
e1 e2 Init End AIII.1
II.2
54/67
1
run(net)
2 3
fire(Init_offer)
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgefire(A_take)
4
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgeI
executeActivity(activity) executeNode(Init)
II.1
e1 e2 Init End AIII.1
II.2
55/67
1
run(net)
2 3
fire(Init_offer)
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgefire(A_take)
4
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgeI
executeActivity(activity) executeNode(Init)
II.1
e1 e2 Init End AIII.1
II.2
executeNode(A)
III.2
56/67
1
run(net)
2 3
fire(Init_offer)
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgefire(A_take)
4
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgeI
executeActivity(activity) executeNode(Init)
II.1
e1 e2 Init End AIII.1
II.2
executeNode(A)
III.2
e1 e2 Init End AIV III.3
take(A)
57/67
1
run(net)
2 3
fire(Init_offer)
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgefire(A_take)
4
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgefire(A_offer) fire(End_take)
5 6 7
Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edge Init_node Init_offer A_take A_offer End_take e1_edge A_node e2_edgeI
executeActivity(activity) executeNode(Init)
II.1
e1 e2 Init End AIII.1
II.2
executeNode(A)
III.2
e1 e2 Init End AIV III.3
take(A)
V.3
e1 e2 Init End A e1 e2 Init End AVII VI.2 VI.1 V.2
executeNode(End) take(End)
V.1
58/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
Source Model State Definition
b
Source Execution Steps Definition
c
Feedback Manager
d
+ Compilation Links
Source State Source Steps Source Steps
59/67
Runtime services Target Language Source Language
Source Abstract Syntax Compiler Source Model Target Abstract Syntax Target Model State Definition Target Execution Steps Definition Interpretation Rules Target State
Tracer Debugger
Source Steps Target Steps
...
Target Engine
Target runtime data Source runtime data Target interpreter
Model Procedure dependency conforms to input/output
Compilation Results
Compilation Links Target Model
a
Source Model State Definition
b
Source Execution Steps Definition
c
Feedback Manager
d
+ Compilation Links
Source State Source Steps Source Steps Feedback Engine
e
60/67
Can we observe and control compiled models? In reasonable time?
61/67
Common parts (eg. glue code, APIs, integration layer) of the approach implemented for the GEMOC Studio, an Eclipse-based language workbench. The source code (Eclipse plugins written in Xtend and Java) is available on Github:
As he GEMOC Studio originally focused on interpreted DSLs, this is the rst attempt to support compiled DSLs in the GEMOC Studio. https://github.com/tetrabox/gemoc- compilation-engine
62/67
63/67
Given an interpreted DSL and a compiled DSL with trace-equivalent semantics, does the approach make it possible to observe the same traces with both DSLs?
63/67
Given an interpreted DSL and a compiled DSL with trace-equivalent semantics, does the approach make it possible to observe the same traces with both DSLs?
Does the approach enable the use of runtime services at the domain-level of compiled DSLs?
63/67
Given an interpreted DSL and a compiled DSL with trace-equivalent semantics, does the approach make it possible to observe the same traces with both DSLs?
Does the approach enable the use of runtime services at the domain-level of compiled DSLs?
What is the time overhead when executing compiled models with feedback management?
63/67
64/67
a subset of fUML activity diagrams, using Petri nets as a target language, a subset of UML state machines using a subset of Java as a target language. Each DSL implemented twice: one interpreted variant and one compiled variant.
64/67
a subset of fUML activity diagrams, using Petri nets as a target language, a subset of UML state machines using a subset of Java as a target language. Each DSL implemented twice: one interpreted variant and one compiled variant.
a trace constructor (ECMFA 2015, SoSym 2017) an omniscient debugger (SLE 2015, JSS 2018)
64/67
a subset of fUML activity diagrams, using Petri nets as a target language, a subset of UML state machines using a subset of Java as a target language. Each DSL implemented twice: one interpreted variant and one compiled variant.
a trace constructor (ECMFA 2015, SoSym 2017) an omniscient debugger (SLE 2015, JSS 2018)
100 fUML activity diagrams in 10 groups ranging from 10 to 100 nodes, 30 UML state machines from 10 to 100 states, and 3 scenarios per state machine.
64/67
65/67
all 130 generated models executed with the interpreted and the compiled variants of both executable DSLs no dierence found found when comparing traces
65/67
all 130 generated models executed with the interpreted and the compiled variants of both executable DSLs no dierence found found when comparing traces
both runtime services (trace constructor and omniscient debugger) work as expected at the domain-level
65/67
all 130 generated models executed with the interpreted and the compiled variants of both executable DSLs no dierence found found when comparing traces
both runtime services (trace constructor and omniscient debugger) work as expected at the domain-level
fUML activity diagrams → Petri nets: 1,6 times slower on average UML State Machines → MiniJava: 1,01 times slower on average
65/67
Observing and controlling the execution of compiled models is dicult, and there is a lack of systematic approach to design compiled DSLs with that goal in mind. Our proposal: a generic language engineering architecture to dene explicit feedback management in compiled DSLs
handling compilers dened as code generators; provide an easier way to dene feedback managers; managing stimuli sent to the source model during the execution; measuring the amount of eort required to dene a feedback manager as compared to dening an interpreter.
66/67
Github: Twitter: Email: https://github.com/tetrabox/gemoc-compilation-engine @erwan_bousse erwan.bousse@ls2n.fr
67/67