<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Adding a HenshinEngine to GEMOC Studio</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Stefen Zschaler</string-name>
          <email>szschaler@acm.org</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Informatics, King's College London London</institution>
          ,
          <country country="UK">UK</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Executable DSMLs (xDSMLs) are becoming more popular as a means of eficiently building domain-specific high-level models that are testable through simulations. To develop an xDSML, one needs to provide the abstract and concrete syntax, but also the operational semantics of the language. GEMOC Studio provides a language workbench for developing xDSMLs and their associated tooling. To date, it supports the expression of operational semantics in a number of imperative formats. GEMOC Studio is intended to easily support also operational semantics in other formats, but this idea has so far not been tested. In this paper, I report on my experience implementing a new execution engine for GEMOC Studio that allows operational semantics to be expressed declaratively using graph-transformation rules written in Henshin. I hope that this experience report helps to (a) explore the current flexibility of GEMOC Studio and provide insights into areas that may benefit from refactoring, and (b) give some guidance to others wishing to develop their own execution engines for GEMOC Studio.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>INTRODUCTION</title>
      <p>
        Executable modelling languages have been discussed for some time
[
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], but recently have seen increased interest through projects such
as GEMOC1 and MOLIZ2. The key idea is that by specifying
operational semantics in addition to abstract and concrete syntax,
simulators and other dynamic analysis tools can be easily (and
possibly automatically) derived for these executable domain-specific
modelling languages (xDSMLs).
      </p>
      <p>
        The key issue, then, is how to specify the operational semantics
for an xDSML. Two diferent approaches have been taken: (1) Using
imperative definitions—for example added to the abstract syntax
through new operations [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] or by defining fUML-based
actions—and (2) Using declarative definitions—typically using endogenic
graph-transformation systems (GTSs) [
        <xref ref-type="bibr" rid="ref10 ref2">2, 10</xref>
        ].
      </p>
      <p>
        Imperative definitions are close to how programmers think and
can be expressed in languages programmers are already familiar
with (e.g., Kermeta-based languages use Xtend to express individual
operations). However, their imperative nature also makes it more
dificult to reason about the semantics of such languages and to
safely compose diferent language semantics. The primary means of
composition of languages with imperatively expressed operational
semantics is by a variant of role-based composition [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ], but this
cannot easily provide guarantees about semantic preservation.
      </p>
      <p>
        On the other hand, declarative definitions of operational
semantics using graph transformations (e.g., [
        <xref ref-type="bibr" rid="ref10 ref2">2, 10</xref>
        ]) may be less
immediately intuitive for programmers, but ofer strong reasoning
1http://gemoc.org/
2http://www.modelexecution.org/?page_id=2
opportunities, including giving guarantees for semantics
preservation in the face of composition [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. However, they are currently
somewhat underrepresented in the xDSML literature.
      </p>
      <p>
        Figure 1 shows an example model in a (toy) language for
describing production-line systems [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. I show here only the concrete
syntax in a Sirius-based diagram. The language allows modelling the
lfow of parts (heads, handles, and hammers) through a
productionline system. In Fig. 1, for example, we can see that a handle has
been produced and is currently waiting to be processed by the
assembly machine. Figure 2 shows the rules defining the operational
semantics of this language. The two generate. . . rules define
the behaviour of generators, while the assemble rule defines how
hammers are assembled. Finally, rule moveAlong defines how parts
are transferred from conveyors onto trays.
      </p>
      <p>
        In this paper, I report on my experience building a new
execution engine for the GEMOC Studio [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], a state-of-the-art language
workbench for xDSML development. The resulting implementation
is available on Github3. One aim of the GEMOC Studio was to easily
support the integration of diferent forms of operational
semantics, but so far this has only been tested for imperatively defined
semantics. Here, I explore what it takes to extend GEMOC Studio
with support for xDSMLs with GTS-defined semantics. Specifically,
I report on building a GEMOC HenshinEngine, for semantics
expressed using the popular Henshin graph-transformation tool [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ].
      </p>
      <p>Beyond the execution engine itself, I hope that this paper can
make two contributions to the community:
(1) Provide some insights into the current flexibility of GEMOC
Studio and, potentially, some lessons about which areas may
benefit from further refactoring and generalisation; and
(2) Provide some guidance to others integrating new execution
engines for operational semantics expressed in other formats.</p>
      <p>The remainder of this paper is structured as follows: In Sect. 2, I
introduce the key elements of the GEMOC-Studio architecture that
are relevant to the introduction of a new execution engine. This
is followed, in Sect. 3, by a description of key aspects of the
HenshinEngine implementation and some lessons learned in Sect. 4.
Finally, Sect. 5 concludes the paper.
2</p>
    </sec>
    <sec id="sec-2">
      <title>GEMOC STUDIO</title>
      <p>
        GEMOC Studio is a language workbench for developing xDSMLs [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
It provides an interpreter infrastructure that takes a language with
abstract syntax defined in Ecore [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], concrete syntax defined in
Sirius [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], and an operational semantics that can be interpreted by one
of the existing execution engines. From this, the infrastructure
provides integration with Eclipse’s launch mechanism so that models
can be executed like other programs. When models are executing,
GEMOC can use Sirius to provide visual animation of execution
progress as well as language-agnostic debug functionality.
      </p>
      <p>
        GEMOC Studio currently ofers execution engines that can
interpret language semantics defined in Kermeta, fUML, and a
concurrency coordination language called BCOoL [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. An execution
engine, essentially, performs the following steps:
(1) Initialise engine, using the model already pre-loaded by GEMOC
      </p>
      <p>Studio (see below);
(2) Initialise model, if needed—for example to create initial
dynamic-state elements; and
(3) Execute individual semantics steps in a loop.</p>
      <p>The final step in the execution is the central step. For existing
engines, this invokes a so-called execution-entry point, an
operation of one of the model elements, specially annotated to mark
it as the entry point. This will usually run a loop in which
individual steps, operations annotated as semantic steps are executed.
For each step, GEMOC inserts some functionality before and
after the step which allow it to trace model execution and provide
additional functionality, including debugging and animation, on
top of the execution. For GTS-based xDSMLs such an entry-point
method does not exist. Instead, we will need to provide our own
interpretation of steps and communicate these to GEMOC
Studio. To this end, we can build on functionality encapsulated in
AbstractSequentialExecutionEngine: before each step is
executed, we invoke a beforeStep method. After each step is executed,
we invoke an afterStep method. These two calls enable GEMOC
Studio to trace model execution as well as ofer users control and
allow them to stop execution at any time.
3</p>
    </sec>
    <sec id="sec-3">
      <title>CREATING THE HENSHINENGINE</title>
      <p>I consider the semantics of a model to be given by a graph grammar
with the model as the starting graph, and the metamodel and the
Algorithm 1 performStep algorithm
1: function findNextMatch
2: rules ← semanticRules
3: while rules not empty do
4: rule ← remove random element from rules
5: match ← find match for rule
6: if match not null then
7: return match
8: return null
9: procedure performStep
10: match ← findNextMatch
11: if match not null then
12: beforeStep(match.rule.name)
13: apply match.rule at match
14: afterStep
semantics rules as the graph-transformation system.4 Thus, any
sequence of rule applications from the starting model is considered
to be a valid trace in the semantics. Such semantics can be
nondeterministic. Non-determinism is useful to represent the degree
of concurrency in our problem: heads and handles are generated
independently of each other, and hammers are produced
independently of the generators, as long as suficient numbers of heads and
handles are available.</p>
      <p>In my execution engine, I implement these semantics by
executing one randomly chosen trace5. As a result, two individual
executions of the same model may produce diferent results.</p>
      <p>Deciding which rule to apply is a two-stage process: we first
randomly pick a rule and then we pick a random match for this rule
in the current model. An arbitrarily picked rule may well not have a
match in the current model, so we need to know about rule matches
before picking rules. Checking whether a rule matches is, however,
the computationally hard part of graph transformation, so we want
to do as little as possible of it. The easiest solution would be to
hand all of this work to Henshin, by asking the matching engine
to try to apply a randomly chosen rule: if the application succeeds
a step has been taken and we move on. Otherwise, we randomly
pick a diferent rule to try. If none of the rules can be applied, the
execution stops. In the process, we make use of Henshin’s capability
for non-deterministic matching, which ensures we get a diferent
match for rules with multiple matches at every execution.</p>
      <p>However, GEMOC Studio requires a step operation name before
executing a step6. With the above naïve implementation, we can
only provide a generic name, such as ‘invokeRule’ as we do not
yet know which rule will be invoked. We solve this by splitting the
processing of a single step into two sub-steps: (1) determine the
rule and (non-deterministic) match to apply; (2) apply the identified
match. We then call beforeStep between these two sub-steps and
can thus provide more precise tracing information. Algorithm 1
shows a summary of the core execution-engine behaviour.</p>
      <p>
        The current launch infrastructure of GEMOC Studio assumes
Melange-defined languages [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. Melange only supports a limited
4A graph grammar defines a language of graphs from a starting graph and a
graphtransformation system. Any graph reachable from the starting graph is considered
part of the language.
5See the discussion in Sect. 5 for other options
6In the call to the beforeStep operation
number of ways in which language-semantics are defined, all of
them imperative in nature. As a result, I had to create my own
launcher, which takes a model and a set of Henshin rules as input.
      </p>
    </sec>
    <sec id="sec-4">
      <title>4 LESSONS LEARNED</title>
      <p>In this paper, I have reported on a deep embedding of GTS-based
semantics into GEMOC Studio. An alternative would have been
to create a shallow embedding, reusing the existing K3 engine,
which expects the semantics to be expressed as operations on the
meta-model. Our execution entry point could have been an
operation that invokes the performStep operation in an infinite loop.
performStep would look like the operation above except for the
beforeStep and afterStep calls. Instead, the operation would
have been annotated as a @Step. The obvious advantage of such
a shallow embedding is that it can completely reuse the
implementation of existing execution engines and launch infrastructure.
However, a shallow embedding also means that the actual semantics
become a second-class citizen, only indirectly loaded and referenced
from a K3-based ‘meta-semantics’. As a result, details of the
semantics, such as rule names become more dificult to report to the wider
GEMOC infrastructure, which only sees the K3 semantics. This
creates problems when debugging models and recording traces.
More importantly, it would create challenges when later trying to
provide more dedicated support based on the specific semantics
expression, such as advanced support for concurrency and analysis.</p>
      <p>Implementing and integrating this new execution engine into
GEMOC Studio has highlighted some areas of dificulty, where
GEMOC Studio may benefit from some additional refactoring:
(1) Assumption of operations-based semantics. GEMOC has a
builtin assumption that all semantics are defined through operations
on the meta-model. For every step, GEMOC logs the name of a
meta-class and meta-operation that was ‘executed’. These
information are, for example, exposed to the user in the generic debug
interface. Rule-based semantics do not have meta-operations.
Instead, these need to be mocked up when tracing a step. This
may cause problems, in particular where some operations exist
and their names (perhaps accidentally) overlap with rule names.
(2) Inflexible launch infrastructure. The current launcher
infrastructure is tightly linked in with Melange-based language
definitions. For languages that are not defined in Melange, it is
necessary to implement a new launcher and launch
configuration. Unfortunately, the Melange-dependent and independent
launcher code is not well separated and reusable, which leads
to code cloning in any new launchers.</p>
      <p>Overall, integrating the Henshin engine has been surprisingly
straightforward: the core engine consists of only 2 classes with a
total of 268 LOC Xtend code. Infrastructure made up the bulk of
the code: 567 LOC of Xtend and Java code over 6 classes7
implement the launcher infrastructure; only 2 classes provide bespoke
behaviour. There are some 47 LOC of configuration data. Including
investigating parts of the GEMOC-Studio sources in depth to
identify appropriate hooks for extension, the engine was developed in
a week. While improvements are still clearly possible, I consider
this a reasonable amount of efort to spend on a task that will not
need to be repeated for every new language.
7Some copied from existing code in GEMOC Studio because of export settings</p>
    </sec>
    <sec id="sec-5">
      <title>5 CONCLUSIONS</title>
      <p>I have integrated a new execution engine for Henshin-based
language semantics into GEMOC Studio. Overall, the claim that GEMOC
Studio is easy to extend has been upheld. Developers of new
extensions can choose between deep embeddings (by developing a
new execution engine, as shown here) or shallow embeddings (by
encoding the interpretation of semantics in a K3-based semantics).
Some areas of the GEMOC-Studio framework are currently still
tightly coupled to languages whose operational semantics are
deifned using operations on the meta-model, and where the language
definition can be expressed in Melange. Refactoring these areas of
GEMOC Studio would substantially increase the ease with which
new execution engines can be integrated.</p>
      <p>
        Language semantics expressed as a GTS are inherently
nondeterministic, typically, capturing concurrent execution. Latombe et
al. [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] describe support for concurrent semantics in GEMOC. In
future work, I intend to build on this for a new version of the Henshin
Engine. Support for concurrent execution is less well abstracted in
GEMOC Studion and, therefore, more dificult to reuse and extend.
Latombe [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] introduces a separate specification of the concurrency
model of a language. Such a concurrency model is very useful for
further analysis and eficient execution. With a GTS-based
semantics it should be possible to infer the concurrency model instead. I
hope to explore this in future work. Additionally, I would like to
extend the current Henshin Engine to support timed rules in a
similar fashion to e-Motions [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ], which would open up opportunities
for building bespoke advanced analysers for high-level,
domainspecific models. Finally, I will explore supporting more complex
operational semantics that use rule scheduling (called units in
Henshin). This creates challenges around identifying execution steps
and larger-scale rollback.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>E</given-names>
            <surname>Bousse</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T</given-names>
            <surname>Degueule</surname>
          </string-name>
          , et al.
          <year>2016</year>
          .
          <article-title>Execution framework of the GEMOC studio (tool demo)</article-title>
          .
          <source>In SLE'16.</source>
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>A</given-names>
            <surname>Corradini</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R</given-names>
            <surname>Heckel</surname>
          </string-name>
          , and
          <string-name>
            <given-names>U</given-names>
            <surname>Montanari</surname>
          </string-name>
          .
          <year>2000</year>
          .
          <article-title>Graphical Operational Semantics</article-title>
          . In Workshop on Graph Transformation and Visual Modelling Techniques.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>T</given-names>
            <surname>Degueule</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B</given-names>
            <surname>Combemale</surname>
          </string-name>
          , et al.
          <year>2015</year>
          .
          <article-title>Melange: A Meta-language for Modular and Reusable Development of DSLs</article-title>
          . In SLE'
          <volume>15</volume>
          . https://doi.org/10.1145/2814251. 2814252
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>F</given-names>
            <surname>Durán</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A</given-names>
            <surname>Moreno-Delgado</surname>
          </string-name>
          , et al.
          <year>2017</year>
          .
          <article-title>Amalgamation of Domain Specific Languages with Behaviour</article-title>
          .
          <source>JLAMP 86 (Jan</source>
          .
          <year>2017</year>
          ).
          <article-title>Issue 1</article-title>
          . https://doi.org/10. 1016/j.jlamp.
          <year>2015</year>
          .
          <volume>09</volume>
          .005
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>F</given-names>
            <surname>Durán</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S</given-names>
            <surname>Zschaler</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J</given-names>
            <surname>Troya</surname>
          </string-name>
          .
          <year>2013</year>
          .
          <article-title>On the Reusable Specification of Nonfunctional Properties in DSLs</article-title>
          .
          <source>In SLE'12 (LNCS)</source>
          , Vol.
          <volume>7745</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>IBM.</surname>
          </string-name>
          <year>2006</year>
          .
          <article-title>Ecore API Documentation</article-title>
          . http://download.eclipse.org/modeling/ emf/emf/javadoc/2.4.0/org/eclipse/emf/ecore/package-summary.html. (
          <year>2006</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>M. E. Vara</given-names>
            <surname>Larsen</surname>
          </string-name>
          ,
          <string-name>
            <surname>J. DeAntoni</surname>
          </string-name>
          , et al.
          <year>2015</year>
          .
          <article-title>A Behavioral Coordination Operator Language (BCOoL)</article-title>
          .
          <source>In MODELS'15</source>
          . https://doi.org/10.1109/MODELS.
          <year>2015</year>
          . 7338249
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>F</given-names>
            <surname>Latombe</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X</given-names>
            <surname>Crégut</surname>
          </string-name>
          , et al.
          <year>2015</year>
          .
          <article-title>Weaving concurrency in executable domainspecific modeling languages</article-title>
          .
          <source>In SLE'15</source>
          .
          <fpage>125</fpage>
          -
          <lpage>136</lpage>
          . https://doi.org/10.1145/2814251. 2814261
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>S.</given-names>
            <surname>Mellor</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Balcer</surname>
          </string-name>
          .
          <year>2002</year>
          .
          <article-title>Executable UML: A Foundation for Model-Driven Architecture</article-title>
          .
          <source>Addison Wesley.</source>
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>J</given-names>
            <surname>Rivera</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F</given-names>
            <surname>Durán</surname>
          </string-name>
          , and
          <string-name>
            <given-names>A</given-names>
            <surname>Vallecillo</surname>
          </string-name>
          .
          <year>2009</year>
          .
          <article-title>A graphical approach for modeling time-dependent behavior of DSLs</article-title>
          . In VL/HCC'09. https://doi.org/10.1109/VLHCC.
          <year>2009</year>
          .5295300
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>D</given-names>
            <surname>Strüber</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K</given-names>
            <surname>Born</surname>
          </string-name>
          , et al.
          <year>2017</year>
          .
          <article-title>Henshin: A Usability-Focused Framework for EMF Model Transformation Development</article-title>
          .
          <source>In ICGT'17.</source>
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>V.</given-names>
            <surname>Viyović</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Maksimović</surname>
          </string-name>
          , and
          <string-name>
            <given-names>B.</given-names>
            <surname>Perisić</surname>
          </string-name>
          .
          <year>2014</year>
          .
          <article-title>Sirius: A rapid development of DSM graphical editor</article-title>
          .
          <source>In INES'14</source>
          . https://doi.org/10.1109/INES.
          <year>2014</year>
          .6909375
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>C</given-names>
            <surname>Wende</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N</given-names>
            <surname>Thieme</surname>
          </string-name>
          , and
          <string-name>
            <given-names>S</given-names>
            <surname>Zschaler</surname>
          </string-name>
          .
          <year>2010</year>
          .
          <article-title>A Role-Based Approach towards Modular Language Engineering</article-title>
          .
          <source>In SLE'09 (LNCS)</source>
          , Vol.
          <volume>5969</volume>
          . https://doi.org/10. 1007/978-3-
          <fpage>642</fpage>
          -12107-4_
          <fpage>19</fpage>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>