Lecture Notes in Business Information Processing Series Editors Wil van der Aalst Eindhoven Technical University, The Netherlands John Mylopoulos University of Trento, Italy Norman M. Sadeh Carnegie Mellon University, Pittsburgh, PA, USA Michael J. Shaw University of Illinois, Urbana-Champaign, IL, USA Clemens Szyperski Microsoft Research, Redmond, WA, USA
33
Manuel Oriol Bertrand Meyer (Eds.)
Objects, Components, Models and Patterns 47th International Conference, TOOLS EUROPE 2009 Zurich, Switzerland, June 29-July 3, 2009 Proceedings
13
Volume Editors Manuel Oriol University of York Department of Computer Science Heslington, York, YO10 5DD, UK E-mail:
[email protected] Bertrand Meyer ETH Zurich Zurich, Switzerland E-mail:
[email protected]
Library of Congress Control Number: 2009929321 ACM Computing Classification (1998): D.2, H.1, K.6 ISSN ISBN-10 ISBN-13
1865-1348 3-642-02570-6 Springer Berlin Heidelberg New York 978-3-642-02570-9 Springer Berlin Heidelberg New York
This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, re-use of illustrations, recitation, broadcasting, reproduction on microfilms or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer. Violations are liable to prosecution under the German Copyright Law. springer.com © Springer-Verlag Berlin Heidelberg 2009 Printed in Germany Typesetting: Camera-ready by author, data conversion by Scientific Publishing Services, Chennai, India Printed on acid-free paper SPIN: 12705689 06/3180 543210
Preface
For the past 20 years the TOOLS conferences have continuously spread new technologies in the world of object-orientation, component technology and software engineering in general. They constitute a particularly important forum for software researchers and practitioners to present work that relies on producing tools. This year’s TOOLS continued the tradition and presented a strong program that included original contributions in all major fields of the object-oriented paradigm. As in TOOLS 2008, the concept of model occupied a considerable place; but other topics such as reflection, aspects, modelling languages, debugging, and virtual machines design were also strongly represented. While most conferences had a decrease in the number of submitted papers, TOOLS made the choice of quality and decided to lower its acceptance rate to 25%, as a fixed maximum announced in the Call for Papers. Out of 67 submitted contributions, the reviewing process led to the selection of 17 as full papers. For the first time, two short papers were also accepted for presentation at the conference. The 47th edition of the conference could not have seen the light without the numerous helpers that made it happen. The quality of the work of the Program Committee (PC) deserves particular acknowledgement; not only did the PC members work hard to produce helpful reviews on time, sometimes with the help of external referees, but extensive discussions followed the initial recommendations, leading to an excellent conference program and extensive advice to the authors. The Organizing Committee worked hard to schedule the events and make the conference a pleasant event. We take the opportunity to thank everyone who made this event happen in a way or another. April 2009
Manuel Oriol Bertrand Meyer
Organization
TOOLS EUROPE 2009 was organized by the department of Computer Science, ETH Zurich.
Chairpersons Conference Chair Program Chair Workshops Chair
Bertrand Meyer (ETH Zurich, Switzerland) Manuel Oriol (University of York, UK) Alexandre Bergel (INRIA Lille, France) Johan Fabry (University of Chile, Chile) Philippe Lahire (Universit´e de Nice, France) Marcus Denker (University of Bern, Switzerland) Ilinca Ciupa, Claudia G¨ unthart, Marco Piccioni
Publicity Chair
Organizing Committee
Program Committee Patrick Albert Balbir S. Barn Mike Barnett Claude R. Baudoin Bernhard Beckert Alexandre Bergel Judith Bishop Phil Brooke Cristiano Calcagno Ana Cavalcanti Dave Clarke Bernard Coulette Jing Dong St´ephane Ducasse Gregor Engels Patrick Eugster Manuel Fahndrich Jos´e Luiz Fiadeiro Michael Franz Judit Nyekyne Gaizler Benoˆıt Garbinato Carlo Ghezzi Tudor Girba Martin Glinz
ILOG Fellow, France Middlesex University, UK Microsoft Research, USA Schlumberger, France University of Koblenz, Germany INRIA Lille, France University of Pretoria, South Africa University of Teesside, UK Imperial College, UK University of York, UK KU Leuven, Belgium IRIT/University of Toulouse, France University of Texas at Dallas, USA INRIA Lille, France University of Paderborn, Germany Purdue University, USA Microsoft Research, USA University of Leceister, UK University of California, Irvine, USA Pazmany University, Hungary University of Lausanne, Switzerland Politecnico di Milano, Italy University of Bern, Switzerland University of Zurich, Switzerland
VIII
Organization
Martin Gogolla Jeff Gray Pedro Guerreiro Joseph Kiniry Ivan Kurtev Ralf Laemmel Philippe Lahire Mingshu Li Dragos Manolescu Erik Meijer Peter M¨ uller Jonathan Ostroff Richard Paige Marc Pantel Frederic Peschanski Alfonso Pierantonio Alexander Pretschner Bran Selic Anatoly Shalyto Friedrich Steimann Perdita Stevens ´ Eric Tanter Dave Thomas Laurence Tratt Antonio Vallecillo Roel Wuyts Amiram Yehudai Andreas Zeller
University of Bremen, Germany University of Alabama at Birmingham, UK Universidade do Algarve, Portugal University College Dublin, Ireland University of Twente, The Netherlands University of Koblenz-Landau, Germany Universit´e de Nice, France Chinese Academy of Sciences, China Microsoft, USA Microsoft, USA ETH Zurich, Switzerland York University, Canada University of York, UK IRIT/University of Toulouse, France LIP6 - UPMC Paris Universitas, France Universit` a degli Studi dell’Aquila, Italy TU Kaiserslautern/Fraunhofer IESE, Germany IBM, USA St. Petersburg State University ITMO, Russia Fernuniversit¨ at in Hagen, Germany University of Edinburgh, UK University of Chile, Chile Bedara, Canada Bournemouth University, UK Universidad de M´ alaga, Spain IMEC, Belgium Tel Aviv University, Israel Saarland University, Germany
External Referees Nicolas Arni-Bloch Martin Assmann Robert Atkey Jan-Christopher Bals Stephanie Balzer Hakim Belhaouari Manuel F. Bertoa Joel-Alexis Bialkiewicz Domenico Bianculli Luca Cavallaro Antonio Cicchetti Ilinca Ciupa Marcio Cornelio
Zekai Demirezen Simon Denier Marcus Denker Mauro Luigi Drago Martin Ernst Baris G¨ uldali Simon Hudon Ethan Jackson Mikolas Janota R´obert Kitlei Tam´as Kozsik Jannik Laval David Makalsky
Alessandro Margara Marjan Mernik Dimiter Milushev Tu Peng Fiona Polack Damien Pollet Jose Proenca Lukas Renggli Leila Ribeiro Jose E. Rivera Markku Sakkinen Tibor Somogyi Clifford Sule
Organization
Yu Sun Peter Swinburne Robert Tairas M´ at´e Tejfel
Faraz Torshizi Sarvani Vakkalanka Andreas W¨ ubbeke Ye Yang
Yajing Zhao
IX
Table of Contents
Invited Presentations On Realizing a Framework for Self-tuning Mappings . . . . . . . . . . . . . . . . . . Manuel Wimmer, Martina Seidl, Petra Brosch, Horst Kargl, and Gerti Kappel
1
Programming Models for Concurrency and Real-Time (Abstract) . . . . . . Jan Vitek
17
Reflection and Aspects CIF: A Framework for Managing Integrity in Aspect-Oriented Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Andrew Camilleri, Geoffrey Coulson, and Lynne Blair A Diagrammatic Formalisation of MOF-Based Modelling Languages . . . . Adrian Rutle, Alessandro Rossini, Yngve Lamo, and Uwe Wolter Designing Design Constraints in the UML Using Join Point Designation Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Vanessa Stricker, Stefan Hanenberg, and Dominik Stein Stream-Based Dynamic Compilation for Object-Oriented Languages . . . . Michael Bebenita, Mason Chang, Andreas Gal, and Michael Franz
18
37
57
77
Models Algebraic Semantics of OCL-Constrained Metamodel Specifications . . . . Artur Boronat and Jos´e Meseguer Specifying and Composing Concerns Expressed in Domain-Specific Modeling Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Aram Hovsepyan, Stefan Van Baelen, Yolande Berbers, and Wouter Joosen
96
116
Early Crosscutting Metrics as Predictors of Software Instability . . . . . . . . Jos´e M. Conejero, Eduardo Figueiredo, Alessandro Garcia, Juan Hern´ andez, and Elena Jurado
136
Extensibility in Model-Based Business Process Engines . . . . . . . . . . . . . . . Mario S´ anchez, Camilo Jim´enez, Jorge Villalobos, and Dirk Deridder
157
XII
Table of Contents
Theory Guaranteeing Syntactic Correctness for All Product Line Variants: A Language-Independent Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Christian K¨ astner, Sven Apel, Salvador Trujillo, Martin Kuhlemann, and Don Batory A Sound and Complete Program Logic for Eiffel . . . . . . . . . . . . . . . . . . . . . Martin Nordio, Cristiano Calcagno, Peter M¨ uller, and Bertrand Meyer
175
195
Components A Coding Framework for Functional Adaptation of Coarse-Grained Components in Extensible EJB Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Olivier Caron, Bernard Carr´e, Alexis Muller, and Gilles Vanwormhoudt A Leasing Model to Deal with Partial Failures in Mobile Ad Hoc Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Elisa Gonzalez Boix, Tom Van Cutsem, Jorge Vallejos, Wolfgang De Meuter, and Theo D’Hondt
215
231
Monitoring Reusing and Composing Tests with Traits . . . . . . . . . . . . . . . . . . . . . . . . . . . St´ephane Ducasse, Damien Pollet, Alexandre Bergel, and Damien Cassou
252
Flow-Centric, Back-in-Time Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adrian Lienhard, Julien Fierz, and Oscar Nierstrasz
272
A Classification Framework for Pointcut Languages in Runtime Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Karl Klose and Klaus Ostermann
289
Systems Generation Fast Simulation Techniques for Design Space Exploration . . . . . . . . . . . . . Daniel Knorreck, Ludovic Apvrille, and Renaud Pacalet PyGirl: Generating Whole-System VMs from High-Level Prototypes Using PyPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Camillo Bruni and Toon Verwaest
308
328
Short Papers Using Grammarware Languages to Define Operational Semantics of Modelled Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Daniel A. Sadilek and Guido Wachsmuth
348
Table of Contents
Automatic Generation of Integrated Formal Models Corresponding to UML System Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Helen Treharne, Edward Turner, Richard F. Paige, and Dimitrios S. Kolovos Author Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
XIII
357
369
On Realizing a Framework for Self-tuning Mappings Manuel Wimmer, Martina Seidl, Petra Brosch , Horst Kargl, and Gerti Kappel Vienna University of Technology, Austria
[email protected]
Abstract. Realizing information exchange is a frequently recurring challenge in nearly every domain of computer science. Although languages, formalisms, and storage formats may differ in various engineering areas, the common task is bridging schema heterogeneities in order to transform their instances. Hence, a generic solution for realizing information exchange is needed. Conventional techniques often fail, because alignments found by matching tools cannot be executed automatically by transformation tools. In this paper we present the Smart Matching approach, a successful combination of matching techniques and transformation techniques, extended with self-tuning capabilities. With the Smart Matching approach, complete and correct executable mappings are found in a test-driven manner.
1
Introduction
In this paper we present a self-tuning approach for information integration. Our approach—the Smart Matching approach—allows the derivation of high quality executable mappings for different kinds of schemas from small, simple examples defined by the user. Seamless information exchange between different sources is an important task in nearly every engineering area of computer science. This ubiquitous challenge recurs in various application domains starting from the exchange of data between databases over the exchange of ontology instances between semantic web services to the exchange of complete models between modeling tools. Although every engineering area has its own languages, formalisms, and storage formats, the problem is always the same. Two heterogeneous schemas have to be bridged in order to transform instances of the one schema to instances of the other. Thus, a generic information integration solution for the use in different application domains is highly valuable.
This work has been partly funded by FFG under grant FIT-IT-819584 and FWF under grant P21374-N13. Funding for this research was provided by the fFORTE WIT - Women in Technology Program of the Vienna University of Technology, and the Austrian Federal Ministry of Science and Research.
M. Oriol and B. Meyer (Eds.): TOOLS EUROPE 2009, LNBIP 33, pp. 1–16, 2009. c Springer-Verlag Berlin Heidelberg 2009
2
M. Wimmer et al.
On the one hand, matching techniques for automatically finding semantic correspondences between schemas have been developed in the context of information integration. On the other hand, transformation techniques have been established for automatically transforming data conforming to a schema A to data conforming to a schema B in a semantic preserving way. However, the combination of matching approaches and transformation approaches is accompanied with several difficulties due to the huge gap between detected alignments, mappings, and executable transformation code. For bridging this gap, two problems have to be solved. First, state-of-the-art matching techniques do not produce executable transformation code. Second, for the automatic execution of the transformation, correctness and completeness of the found alignments are indispensable. A solution for the first problem is presented in [7], where reusable mapping operators for the automatic transformation of models are introduced. A solution for the second problem is conceptually proposed in [8], where we discussed how to improve current integration techniques by the application of self-tuning methods in a test-driven manner resulting in the Smart Matching approach. Based on this work, we implemented the self-tuning matching framework Smart Matcher. In this paper we describe how the Smart Matcher increases the completeness and correctness of alignments based on predefined examples. In particular, we present the realization of the Fitness Function for self-evaluation and the Mapping Engine for self-adaptation which are the basis of the self-tuning. This paper is organized as follows. In Section 2 we present the Smart Matching approach at a glance and the running example of this paper. Sections 3 and 4 elaborate on the two core components of the Smart Matcher namely the Fitness Function and the Mapping Engine, respectively. In Section 5 we present an evaluation of our approach. Related work is discussed in Section 6. In Section 7 we conclude and give an outlook to future work.
2
Smart Matching at a Glance
In this section, we present the Smart Matcher and its underlying conceptual architecture at a glance. The Smart Matching method combines existing integration techniques, i.e., matching and transformation approaches, by introducing a dedicated mapping layer for bridging the gap between alignments, mappings, and executable transformation code as described in [1]. Feedback-driven self-tuning improves the quality of the mappings in an iterative way [9]. For the implementation of the self-tuning capabilities, the quality of mappings has to be evaluated. Therefore, we adopt test-driven development methods from software engineering [3] for developing integration solutions. The Smart Matcher’s architecture is illustrated in Fig. 1. Basically, the application of the Smart Matcher comprises eight phases which are described in the following. 1. Develop example instances. Like in test-driven software development, we specify an expected outcome for a specific input, i.e., instances for input and output schemas representing the same real world example are developed. Those instances are necessary to verify the mappings identified in later phases in order
On Realizing a Framework for Self-tuning Mappings 2 InitialMatcher
MappingLanguage Repository
CARMappingOperators CARMappingOperators pp g Operators p CAR CARMappingOperators Mapping CARMappingOperators
e.g.,COMA++,FOAM,... COMA FOAM
3 Alignments
Mapping Engine MappingEngine load
3
7
6
feedback
load
MappingModel 4
Schema
read
TransformationEngine
SchemaB
SchemaA instanceOf
Instance
write
instanceOf
instanceOf
actual
target
Bankomat Bankomat ExampleX Example X 1
1
describe
cas cashdispens cash dispens´ Example ExampleY Y´
cashdispenr pY cashdispr cash dispr Example ExampleY describe
Real World Real World Real World Bankomat Example Bankomat
FitnessFunction B d BasedonDiffͲOperator Diff O
5
Fig. 1. The Smart Matching approach at a glance
to follow a feedback-driven integration method. The user defined input instance is later called LHS (left-hand side) instance, the output instance is named target RHS (right-hand side) instance. This is the only time during the whole Smart Matching process where human input is necessary. 2. Generate initial alignments. Existing matching tools create initial alignments which may serve as input for the Smart Matcher. Every tool which supports the INRIA alignment format [4] may be used. This phase is optional, i.e., the Smart Matcher is also able to start from an empty set of alignments. 3. Interpret initial alignments. The alignments produced in Phase 2 are transformed into an initial mapping model. This task is performed by the Mapping Engine. 4. Transform instances. In this phase, the Transformation Engine executes the initial mapping model and thereby transforms LHS instances into actual RHS instances. 5. Calculate differences. The Fitness Function compares the actual and the target RHS instances by means of their contained objects, values, and links. The differences between the instances are collected in a Diff-Model, which expresses the quality of the mappings between the source schema and the target schema. 6. Propagate differences. The differences, i.e., missing and wrong objects, values, and links, identified by the Fitness Function are propagated back to the Mapping Engine. The feedback is based on the assumption that schema elements are not appropriately mapped if differences are calculated for their instances. 7. Interpret differences and adjust the mapping model. The Mapping Engine analyzes the feedback and adapts the mapping model between source and target
4
M. Wimmer et al.
schema by searching for and applying appropriate mapping operators. Depending on the types of schemas to be integrated and the used mapping language, different kinds of mapping strategies may be used. 8. Iteration. Now Phase 4 and Phase 5 are repeated. If the comparison in Phase 5 does not detect any differences or if a certain threshold value is reached, the process stops. Otherwise, the Smart Matcher’s Mapping Engine adapts the mapping model based on the identified differences and starts a new iteration by returning to Phase 4. In the following, we elaborate on the Fitness Function necessary for selfevaluation in Phase 5 and the Mapping Engine necessary in particular for the self-adaptation in Phase 7. Therefore, the next sections comprise detailed descriptions on the design rationale and implementation of these two components based on the example depicted in Fig. 2 (a). The schema on the LHS assigns a discount with a height to each customer who is characterized by name and famName. The schema on the RHS describes similar information, namely the rebate height of a person. Only the family a person belongs to is modeled by its own class. A correct mapping between those schemas should detect that the attribute famName ought to be mapped to the class family what is not given by the mapping shown in Fig. 2 (b) which has been produced from the automatically computed alignments (cf. Fig. 2 (a)).
3
A Fitness Function for Mapping Models
The aim of the Fitness Function is to provide feedback on the quality of the mapping models to the Mapping Engine. In the transformation scenario, the quality of a mapping model indicates the correctness of the transformation of the input model to the corresponding output model. Using a test-driven approach where input and output pairs (e.g., cf. Fig. 2 (c)) are given, the generated output model is compared with a given target output model (cf. Fig. 2 (d)). The smaller the differences between the actual output model and the target output model are, the better the quality of the mapping model is. This raises the question how to compute expressive differences between actual and target instance models. When using object-oriented schemas which typically consist of classes, attributes, and references, differences on the instance level appear between objects, values, and links. In the following, we describe our heuristic-based comparison method which is sufficient to compute the necessary feedback for the mapping engine without applying expensive comparison algorithms. Comparing Objects. In general, objects have a unique ID within an instance model (cf. Fig. 2 (c), e.g., f1:Family). However, when we want to compare actual instance models with target instance models which are independently created, one may not assume that two objects with the same ID are equivalent. This is because often IDs are arbitrarily assigned, e.g., based on the order the objects are instantiated. Therefore, we cannot rely on exact ID-based
On Realizing a Framework for Self-tuning Mappings LHSSchema
RHSSchema
SchemaMatching Output
Discount height ggets
~0.7
height
~0.6
gets
Discount height
Rebate height
A2A
gets
gets R2R
Person
~1.0
Person
label
Customer
~0.45
LHSInstances
c1:Customer name =homer famName =simpson
Family label
name famName
(c)
p1:Person
((d)) RHSActual RHS Actual Instances
p1:Person f1:Family
label =simpson
RHS Target Instances RHSTargetInstances
p1:Person label =homer
label =simpson
p2:Person
name =marge famName =simpson
label =marge
c3:Customer
p3:Person
f2:Family
p3:Person
name =ned famName =flenders
label =ned
label =flenders
label =flenders
height =10%
Family label
c2:Customer
d1:Discount
belongsTo g A2A
(a) (b)
RHSTargetInstances g
label =homer
label
C2C
Customer
belongsTo
name famName
RHSSchema
InitialMappingModel C2C
Rebate
~0.9
LHSSchema
p2:Person label =simpson
r1:Rebate height =10%
5
r1:Rebate height =10%
p2:Person
f1:Family label =simpson
label =marge
p3:Person
f2:Family
label =ned ned
label =flenders = flenders
r1:Rebate height =10%
Fig. 2. Running example: (a) alignments, (b) initial mapping model (c) user-defined test instances, (d) actual vs. target instances for initial mapping model.
comparison approaches, instead we have to apply a heuristic. The weakest condition, which is necessary but not sufficient, for verifying that two instance models are equivalent is to count the objects of a particular class in each instance model and compare the resulting numbers, i.e., compute the cardinalities for a given class. Consequently, having the same amount of objects for each class of the RHS schema (abbr. with rhsSchema) in the actual instance model (abbr. with actual) and in the target model (abbr. with target), is an indication that the applied mappings between the classes of the schemas ought to be correct and complete. This consideration leads to the following condition. Condition 1 := forall classes c in rhsSchema | actual.allObjects(c).size() = target.allObjects(c).size()
Because Condition 1 is not sufficient, it is possible that in certain cases the amount of objects is the same for a given class but the mappings are not correctly defined. Assume that for example a LHS class has a mapping to a RHS class, which is instantiated twice, but actually the LHS class should be mapped to another RHS class which is also instantiated twice. However, due to the fact that the RHS classes have both the same amount of instances, no difference can be determined when considering Condition 1 only. Thus, the mapping between the classes are falsely interpreted as correct. To be sure that two objects are equal, a deep comparison is necessary, meaning that attribute values and links of the objects under consideration have to match. Using deep comparison, this kind of false mappings between classes can be detected.
6
M. Wimmer et al.
Example. Fig. 2 (d) illustrates on the LHS the actual instances generated by the interpretation of the automatically computed alignments and on the RHS the given target instances. When Condition 1 is evaluated on these two models, the cardinalities of the classes Rebate and Person are the same for the actual model and for the target model. However, the cardinality of the class Family is obviously not equivalent for both instance models. The Family objects are totally missing in the actual model. Comparing Values. Having the same cardinalities for a specific class is a prerequisite for verifying that actual and target instance models are the same. To be sure that two objects, one in the actual and the other in the target instance model, are equal, these objects must contain exactly the same attribute values. Therefore, for each attribute of the RHS schema two sets of values are computed. The first one comprises all values of a specific attribute for the actual model and the second one does the same for the target model. In case these two sets comprise the same elements, the mapping for the RHS attribute seems to be correct. Otherwise the attribute mapping is assumed to be incorrect or missing. Condition 2 := forall attributes a in rhsSchema | actual.allValues(a) = target.allValues(a)
Example. When Condition 2 is evaluated for our running example, one can easily see that for the attribute Rebate.height Condition 2 holds. However, for the attribute Person.label the computed sets are totally different, namely for the actual instances the resulting set is {simpson, simpson, flenders} which has no match with the computed set for the target instances {homer, marge, ned}. Furthermore, Condition 2 does not hold for Family.label, because in the actual model there are no Family objects that may hold such values. Comparing Links. The last indication that the actual and target instance models are equal, and consequently that the mapping model between the schemas is correct, is that the structure of the instance models is the same, i.e., the links between objects must be equivalent. In particular, equal objects must have the same amount of incoming and outgoing links, which is in general hard and expensive to prove. In order to provide a fast comparison method for links, we decided only to check if the references of the RHS schema have the same amount of instantiated links. Condition 3 := forall references r in rhsSchema | actual.allLinks(r) = target.allLinks(r)
Example. Considering our running example, Condition 3 holds for the reference Person gets Rebate. However, for the reference Person memberOf Family Condition 3 does not hold. In the actual model we have no instantiations of this reference, thus the result of the allLinks operation is the empty set, whereas in the target model the operation allLinks produces a set with three entries. Preparing the feedback for the mapping engine. After evaluating these three conditions for all RHS schema elements, the feedback for the Mapping
On Realizing a Framework for Self-tuning Mappings
7
Engine is defined as the set of all RHS schema elements which do not fulfill the aforementioned conditions. For the adaptation of the mapping model done by the Mapping Engine, we decided that it is currently sufficient to know the schema elements for which differences on the instance level have been found. Therefore, these schema elements are collected for the feedback only, and not the actual differences, i.e., objects, values, and links. Concerning our running example, the following set is computed as feedback for the Mapping Engine {Family, Person.label, Family.label, Person partOf Family}.
4
A Feedback-Aware Mapping Engine
After the Fitness Function has computed the feedback, the Mapping Engine interprets it and adapts the current mapping model to improve its quality. In order to adapt mapping models in an appropriate and efficient way, we make use of two kinds of strategies. First, local strategies are needed to find out if a given mapping operator may be applied appropriately for a set of given schema elements. Second, a global strategy is needed to guide the mapping process in general and in particular for orchestrating the local strategies. 4.1
Local Strategies
As depicted in the Smart Matcher architecture (cf. Fig. 1), the LHS instance models are transformed into RHS actual instance models. Subsequently, the difference between the actual and target instance models is computed on the RHS which is then propagated back to the Mapping Engine. Consequently, the Smart Matcher always transforms form left to right but adapts the mapping models from right to left. For adaptation purposes, the Mapping Engine has to apply new mappings which can also replace existing ones. However, before a new mapping is applied, it has to be ensured that the selected mapping operator is applicable for a given set of schema elements, i.e., the mapping model should be executable and the execution should result in consistent RHS instances. In particular, each mapping operator needs a specific LHS structure and RHS structure as well as already applied mapping operators as context. Based on these constraints, local strategies can be derived for determining if a given mapping operator can be applied in a particular situation. Therefore, we have extended our mapping operators with a isApplicable method which checks for given LHS and RHS schema elements if a mapping can be applied in the current state of the mapping model. For determining the implementation of the isApplicable methods, information inherent in the mapping language is needed. This means, the local strategies can be derived from the abstract syntax and static semantic constraints of the mapping operators which have to be assured to generate correct and executable mappings. If the isApplicable method returns true for given LHS and RHS elements, the mapping operator can be applied. Thus, with the help of the local strategies, we are able to automatically build mappings between the schemas. However, until now, we have not defined how a mapping model is actually build. Therefore, in addition to the local strategies, a global strategy is needed which guides the overall mapping process.
8
M. Wimmer et al.
4.2
Global Strategies
Before a global strategy can be derived, one first has to think about how mapping models are manually developed. Generally, mapping models are developed in a three-step process. First, some prototypical mappings are established. Second, these mappings have to be interpreted, i.e., in the transformation scenario the RHS instances are generated from the LHS instances. Third, the output of the transformation has to be verified in order to be sure that the mappings were correctly developed. For automation purposes, these steps have to be covered by the global strategy. However, what aggravates the derivation of the global strategy is that there a several variations how to proceed in each step. For example, one user may prefer to build several mappings between classes in the first place before mappings between attributes and references are created. Whereas, another user may prefer to find only one mapping between two classes and then tries to find all attribute mappings for these two classes. These examples already show that the derivation of a global strategy is not as predetermined as the derivation of the local strategies. In particular, the following variation points for global strategies exist. – Sequence of mapping operator applications. The first decision that has to be made is the sequence in which the different types of mapping operators are applied. One possibility may be first finding structural commonalities between the schemas by applying symmetric operators, followed by bridging structural heterogeneities by applying asymmetric operators. – Depth-first vs. breadth-first search. Additionally to the application sequence of mapping operators, the global strategy may decide to find all C2C mappings first and afterwards A2A and R2R mappings are explored (breadth-first ) or find iteratively one C2C mapping and for this mapping all possible A2A and R2R mappings are searched (depth-first ). – All-at-once vs. incremental evaluation. Finally, it has to be decided, when and how often mappings are evaluated. The global strategy may find several possible mappings and evaluate them all together (all-at-once) or evaluate each found mapping individually (incremental ). The all-at-once approach is similar to the waterfall model in software engineering, with its disadvantage of spending much effort when working in the wrong direction. This can be avoided with the incremental approach; however, much more evaluation steps are necessary. Because there are different ways to define a global strategy, we decided to use a state-machine based implementation approach for global strategies. The major advantage of this approach is to separate basic functionality, such as transforming models, computing differences between models, as well as searching and applying mappings, from the global strategy guiding the overall mapping process. This allows us to reconfigure the global strategy faster than compared to reconfigurations on source code level, which is especially needed to empirically analyze various configurations of the aforementioned variation points. In the following, we present the most efficient configuration explored in our empirical
On Realizing a Framework for Self-tuning Mappings a
9
b [termination condition]
Init
[[not RHS_containClass && not RHS_containAtt && RHS_containRef]]
entry / computeRHS() entry / computeLHS()
[not RHS_containClass && RHS_containAtt]
[RHS_containClass]
Select RHS Class [inC2C_BL && not inA2C_BL] inA2C BL] [not inC2C_BL]
Search 4 LHS Class [not mapFound]
Search 4 LHS Attribute
do / isApplicable()
entry / isApplicable()
[mapFound] /apply()
[mapFound] /apply()
Evaluation entry / transform() entry / evaluate()
[cMapEval2True && cMapHasAtt]
Select RHS Att
[cMapEval2False || not cMapHasFeat]
a
[not inA2A_BL] inA2A BL]
[not mapFound]
Search 4 LHS Att [cMapHasAtt]
do / isApplicable() [[mapound] d] /apply()
Evaluation entry / transform() entry / evaluate() [not cMapIsApproved && not cMapHasFeat] /setCMap_eval2False a
[ not cMapHasAtt && cMapHasRef]
[cMapIsApproved &&
b not cMapHasFeat]
Select RHS Ref [not inR2R_BL]
[not mapFound]
Search 4 LHS Ref [cMapHasRef]
do / isApplicable() [mapFound] /apply
Evaluation entry / transform() entry / evaluate() [not cMapIsApproved && not cMapHasRef] /setCMap_eval2False() a
[cMapIsApproved &&
b not cMapHasRef]
Fig. 3. Incremental depth-first global strategy implemented as UML state machine
experiments. Fig. 3 illustrates this global strategy as an UML state diagram, which is a depth-first and incremental strategy regarding to the aforementioned variation points. The depth-first search also determines the application sequence of the mapping operators. Please note that only those parts of the global strategy are illustrated which are relevant for our running example. The first task of the global strategy is to calculate the not yet correctly mapped LHS and RHS schema elements based on the output of the Fitness Function. Then, it proceeds with the establishment of mappings able to act as context mappings for other mappings. More specifically, the idea is to examine one mapping between a RHS class and an arbitrary LHS element, and then attributes and references of this RHS class are used to approve the correctness of this context mapping. This means, if a mapping for a RHS class is found and this mapping fulfills the cardinality constraint (cf. Condition 1 in Section 3), in the next steps, mappings for its features, i.e., attributes and references, are searched. If at least one feature mapping is evaluated to true, i.e., fulfills Condition 2 or 3 of Section 3, the context
10
M. Wimmer et al.
mapping is approved. For the opposite case, the context mapping is marked as false, although the cardinality constraints are fulfilled. After giving an overview on the design rational of this strategy, we discuss the three major phases of this strategy based on the state machine illustrated in Fig. 3. Finding context mappings. As already mentioned before, the local strategies search from right to left. Hence, after the Init state where not yet correctly mapped LHS and RHS schema elements are computed, a RHS class is selected in the state Select RHS Class to establish a context mapping. The first choice is to select a LHS class to apply the C2C mapping operator (cf. state Search 4 LHS Class). If a C2C mapping has been found by the local strategy (cf. isApplicable method), it is applied and the state Evaluation is entered. Otherwise, the RHS class is stored in the C2C blacklist which has as impact that this RHS class will never be applied to a LHS class in future iterations (cf. condition [not in C2C BL]). Evaluating context mappings. Within the state Evaluate, the LHS instance model is transformed into a RHS actual instance model. After the transformation, the actual and the target instance models are compared and the output of the Fitness Function is analyzed. If the applied mapping is evaluated to true, e.g., for C2C mappings it is required that the cardinality constraint is fulfilled, consists of searching for feature mappings for the selected RHS class. In case the evaluation returned false, the RHS class and the LHS element are stored in the blacklist (i.e., this combination will never be applied again) and it is switched into the state Init. Approving context mappings. When the context mapping is evaluated to true, the current state is changed to Select RHS Att in which a not yet correctly mapped attribute of the RHS class is selected. Subsequently, the strategy looks for free LHS attributes. The structure and behavior of the following states for the application of attribute mappings is analogous to the aforementioned application of context mappings. After the evaluation of the found A2A mapping (cf. state Evaluation), three cases have to be distinguished. First, the A2A mapping is evaluated to true and the RHS class has no references, which results in an approved context mapping, i.e., it is not changeable in future iterations, and in a transition to the Init state. Second, no A2A mapping has been evaluated to true and the RHS class has no references which results also in a transition to the Init state but the context mapping is marked as evaluated to false, i.e., it is changeable in future iterations. Third, the RHS class has additional references, then the state is changed to Select RHS Ref independent of the evaluation of the A2A mapping. The mapping of the RHS references and approving of the context mapping is analogous to that of attributes. Running Example. For exemplifying the execution behavior of the presented global strategy, we make use of the running example. In Section 3, we have elaborated on the output of the Fitness Function for the initial mapping model which is summarized in Iteration 0 of Fig. 4. Now, it is explained how the global
On Realizing a Framework for Self-tuning Mappings Iteration 0
Iteration 1
C2C
Rebate
Discount A2A
height
Rebate
gets
R2R
height
A2A
heeight
gets
gets
C2C
D Discount
height
gets R2R
Person
Person Customer name famName
label
C2C
C Customer
belongsTo
naame famName
Family
A2A
label
C2C
belongsTo
Family l
A2C
label
label
c2:Customer name=marge famName=simpson p
p1:Person
p1:Person
label=simpson
label=homer
p2:Person 2P
T
c3:Customer
c1:Discount
label simpson label=simpson
p3:Person 3P
p3:Person
label=flenders
label=ned
f2:Family label=flenders
r1:Rebate
r1:Rebate
height=10%
height=10%
Feedback
p1:Person
nam me =homer h fam mName =simpson
c c2:Customer nam me=marge fam mName=simpson
label=marge
p2:Person
T
Rebate
gets
label=homer
f1:Family
p2:Person
label = simpson label=simpson
f2:Family
p3:Person
f3:Family
p3:Person 3P
f2 F il f2:Family
label =ned
label=ned
label=flenders
gets
R2R
C2C
Rebate height gets R2R
Person
Person Customer name famName
label
name n f famName
Family
label
C2C
Customer
belongsTo A2C agg
belongsTo
Family
A2C
label
label
Target
Actual
c1:Customer
p1:Person p
name =homer h famName =simpson
c2:Customer name=marge famName=simpson p
p2:Person p
p1:Person p
label =homer
label=homer
f1:Family
p2:Person
label=simpson
label =marge
p3:Person p
c3:Customer
Diff
f3:Family y
p3:Person
f2:Family
label =ned
label=ned
label=flenders
r1:Rebate
name =ned = ned famName =flenders
r1:Rebate
height=10%
height=10%
d1:Discount
Feedback
height=10%
{Person.label, Family, Family.label, Person.belongsTo}
Iteration 4
Rebate
name famName
c3:Customer
p3:Person
name =ned famName =flenders
label =simpson
Diff
{Person.label}
f1:Family
p2:Person
label=simpson
label=marge
f2:Family
p3:Person
f2:Family
label=ned
label=flenders
height=10%
Feedback
l b l h label=homer
label =flenders
r1:Rebate
d1:Discount height=10% e g t 0%
T Target t
p1:Person f1 F il f1:Family
p2:Person
p3:Person p label=ned
f2:Family y label=flenders
r1:Rebate
height=10%
height=10%
{Person.label, Family, Family.label, Person.belongsTo}
C2C
Rebate height
A2A
name n f famName
A t l Actual
T
f3:Family label =flenders
gets R2R
Person
p1:Person
c2:Customer
label=marge
Feedback
r1:Rebate height=10%
belongsTo A2A
Familyy
A2C agg
c c2:Customer
label
T Target t
A t l Actual
c c1:Customer
p1:Person
p1:Person
name =homer fam mName =simpson
name=marge mName=simpson fam
label
C2C
Customer
Family
c1:Customer
label=simpson
Diff
r1:Rebate
label
label
name=marge famName=simpson
p3:Person
d1:Discount
gets
belongsTo
name =homer famName =simpson simpson
f1:Family
p2:Person
f2:Family
c c3:Customer
h i ht height
R2R
A2C agg gg
p1:Person label=homer
Discount
height g gets
C2C
f1:Family label =simpson
label =simpson
name =ned fam mName =flenders = flenders
Person C t Customer
p2:Person
T
Iterration 5
C2C
A2A gets
c c2:Customer
height=10% he i h 10%
Discount height
p1:Person
name =homer fam mName =simpson
name =marge fam mName =simpson
label=marge
Target
Actual
c c1:Customer
f1:Family y f2:Family y
T
height=10%
Feedback {Person.label, Family, Family.label, Person.belongsTo}
A2A
h height
r1:Rebate
height=10%
d1 1:Discount
gets
C2C
label=marge
r1:Rebate
Discount
h i ht height
Diff
c c3:Customer
Iterration 3
C2C
A2A
p1:Person
label =homer
nam me =ned = ned fam mName =flenders
heigght=10%
Discount height
f1:Family
label =marge
{Person.label, Family, Family.label, Person.belongsTo}
Iteration 2
Target
Actual
c1:Customer f1:Family
p2:Person
Diff
label=simpson
name =ned = ned famName =flenders
height=10%
Target
Actual
c1:Customer name =homer h famName =simpson
11
T
label = homer label=homer
f1 F il f1:Family
p2:Person
label =simpson
Diff
l b l label=marge
c c3:Customer
label = homer label=homer
f1 F il f1:Family
p2:Person
label=simpson
l b l label=marge
p3:Person
f2:Family
p3:Person
l b l label=ned d
l b l =flenders label fl d
label=ned
r1:Rebate
name =ned f mName fam N =flenders fl d
height=10%
d1:Discount
Feedback
height=10%
{}
f2:Family label=flenders
r1:Rebate height=10%
Fig. 4. The Smart Matcher in action
strategy adapts the mapping model based on this input. In addition, the necessary iterations are illustrated in Fig 4. Iteration 1 and 2. When we reconsider the computed output of the Fitness Function, we find out that only one RHS class is not correctly mapped. In particular, the class Family has currently no mapping to a LHS element. Therefore, the global strategy switches from the Init state to the state Select RHS class
12
M. Wimmer et al.
in which the Family class is selected. On the LHS schema no free classes are available now. Thus, it is not possible to apply a C2C mapping and the global strategy searches for a free attribute on the LHS to apply a A2C mapping without aggregation. The Customer.name attribute is selected and an A2C mapping is applied. Subsequently, the Evaluation state is entered, the transformation is started, and the produced actual model is compared with the given target model. The evaluation results amongst others into differences for Family instances which is an indicator that the applied mapping is not correct. Thus, the found mapping is put onto the blacklist and the Init state is entered. Because there is another configuration possibility for the A2C operator, in iteration 2, an A2C mapping with aggregation is applied which is also not correct and therefore we end up again in the Init state. Iteration 3. The Init state computes the same unmapped RHS and LHS elements as in the previous iterations. Thus, we enter again the Select RHS class state where the class Family is selected. Again, no class on the LHS is free and a LHS attribute is selected. In this iteration, we already know that Customer.name is not the corresponding element. Therefore, another free attribute is searched which results in selecting Customer.famName. After building the A2C mapping marked without aggregation between Family and Customer.famName, the Evaluation state is entered. This time, the evaluation shows that the cardinalities of the class Family are not equal, but some attribute values overlap. However, for evaluating this mapping to true, the similarity value is too low. Therefore, the next iteration is started by switching to the Init state. Iteration 4. After entering the Init state, we have again the same set of incorrectly mapped RHS elements. Thus, the same path is followed as before. But this time, the applied A2C mapping is marked with aggregation. This means, only for unique values new objects are created. The evaluation of this mapping shows that no differences may be found for the focused RHS elements and the mapping is marked as evaluated to true. Because the Family class has no further unmapped features, the state Init is entered. Iteration 5. This time, the Init state computes that only one RHS attribute is not appropriately mapped. Therefore, we directly navigate to the Select RHS Att state in which Person.label is selected. Within the next state, Customer. name is selected, because this is the only free LHS attribute. The A2A mapping is applied and the evaluation computes no difference between the actual and target models. Thus, the whole mapping process terminates.
5
Evaluation
In the project ModelCVS1 which was aimed at finding solutions for the integration of modeling tools, the need for automatic model transformations arose. 1
www.modelcvs.org
On Realizing a Framework for Self-tuning Mappings
13
Fig. 5. The development of quality indicators over time
Due to the lack of appropriate tools for metamodel matching, and the strong relatedness of metamodels and ontologies [11], models were lifted to ontologies, and ontology matching tools where applied. Unfortunately, the quality of the resulting alignments did not meet our expectations [6] and we could not deduce reliable mappings for model transformation. Consequently, the Smart Matching approach was established. Although developed with a certain application domain in mind, the result was a generic matching tool which is not restricted to metamodels only. In the following we present results of a case study where elements of the UML class diagram 1.4 metamodel are matched to elements of the UML class diagram 2.0 metamodel. Both metamodels consist of about 60 elements. The user-defined instance models describe a gas station with about 40 elements for the source model and about 30 elements for the target model. For a detailed description of the setting please refer to our project page2 . Starting from an empty alignment set, the Smart Matcher achieves a precision of 0.963 and a recall of 0.897 resulting in an f-measure of 0.929. When we translate the UML class diagram 1.4 terms into German and match it against the English UML class diagram 2.0, we obtain the same results as the Smart Matcher follows an uninterpreted mapping approach. In contrast, COMA++, the most successful system in our matching systems evaluation [6], yields alignments with a precision of 0.833, a recall of 0.583, and an f-measure of 0.683. The results of the German UML class diagram 1.4 matched with the UML class diagram 2.0 clearly indicate the relevance of similarity information for COMA++: the precision decreases to 0.368 and the recall is 0.117 with an f-measure of 0.178. Fig. 5 shows the evolution of precision, recall, and f-measure with respect to the number of Smart Matching iterations. Whereas the precision value tends abruptly towards one, recall and f-measure steadily increase. At iteration 91, the precision slightly decreases. The found mapping is interpreted as correct with respect to the provided instance models, although it is not. This is due to our heuristic for references, which is not sufficient when two references which have the same amount of links are between the same classes. For additional information on the case study, we kindly refer again to our project page. 2
http://big.tuwien.ac.at/projects/smartmatcher
14
6
M. Wimmer et al.
Related Work
The enormous demand for matching systems in order to automatically solve information integration problems led to a vast number of different approaches (for surveys cf. [5,10]). Following the classification of [10] the Smart Matcher realizes a schema-based approach where user-defined instances are employed to verify and to improve the found alignments iteratively. In this sense, the Smart Matcher is based on supervised machine learning techniques. In addition to the source and the target schema, training data consisting of input/output pairs is provided and a relationship model is generated which maps the input instances to the output instances. Several systems have been proposed which incorporate machine learning techniques in order to exploit previously gathered information on the schema as well as on the data level. For example, LSD, Autoplex, and Automatch use Naive Bayes over data instances, SemInt is based on neural networks, and iMap analyses the description of objects found in both sources by the establishment of a similarity matrix (see [5] for an overview). The probably closest approach to ours is SPICY. Like the Smart Matcher, SPICY [2] enhances the mapping generation process with a repeated verification phase by comparing instances of the target schema with transformed instances. The similarity in conceptual architecture of these two approaches contrasts to the significant differences in their realization as well as the moment a human user has to intervent. Whereas SPICY only deals with 1:1 and 1:n alignments, the Smart Matcher is able to resolve more complex heterogenities due to the integration of the CAR-language. This results in very distinct search, comparison, and evaluation strategies. Furthermore SPICY assumes that instances of the target schema are a priori available (e.g. from a Web data source). In contrast, for the application of the Smart Matching approach a human user must explicitly engineer the same instances in the source and in the target schema as the Smart Matcher implements the idea of unit testing. When SPICY terminates, it returns a ranked list of transformations which has then to be evaluated and verified by the user. When the Smart Matcher terminates, the resulting mappings are correct and complete with respect to the source and target input instances. Finally, the eTuner [9] approach automatically tunes the configurations of arbitrary matching systems by creating synthetic schemas for which mappings are known. Hence, in contrast to the Smart Matcher which tunes the search process itself, the eTuner adjusts other systems externally in order to increase the accuracy of the found alignments.
7
Conclusion and Future Work
In this paper we have presented the realization of the Smart Matcher, which implements a generic method for the automatic detection of executable mappings between a source schema and a target schema. During the whole search process, human intervention is only necessary once, namely at the beginning. The
On Realizing a Framework for Self-tuning Mappings
15
user has to define instances which represent the same real world issue in the language of the source schema as well as in the language of the target schema. Those instances allow a permanent evaluation and an incremental improvement of the found mappings by the comparison of the user given target instances with the generated actual instances. The Smart Matcher’s feedback-driven approach guarantees that the resulting mappings are sound and complete with respect to those instances. Therefore an accurate engineering of the instances is inevitable for the successful application of the Smart Matcher, but the effort spent in the preparation phase is compensated with less effort necessary in later phases. For many schemas (e.g., UML diagrams, ontologies, database schemas) the creation of the instances is supported by comfortable editors and once the instances are established for one schema, those instances may be reused in multiple integration scenarios. Furthermore, the required size of the instances does not need to be large for obtaining a satisfying quality of the mappings, as we have experienced in our case study. In future work, we will focus on the development of appropriate methods for the definition of the example instances in order to provide recommendations and in order to guide the user during the preparation phase. Furthermore, we plan more extensive comparisons with other systems, especially with those which incorporate learning techniques. Concerning the Smart Matcher itself, we plan to improve the search strategies by enhancing them with sophisticated heuristics.
References 1. Bernstein, P.A., Melnik, S.: Model Management 2.0: Manipulating Richer Mappings. In: Proc. of the 2007 ACM SIGMOD Int. Conf. on Management of Data, pp. 1–12. ACM Press, New York (2007) 2. Bonifati, A., Mecca, G., Pappalardo, A., Raunich, S., Summa, G.: Schema Mapping Verification: The Spicy Way. In: Proc. of the 11th Int. Conf. on Extending Database Technology (EDBT 2008), pp. 85–96. ACM Press, New York (2008) 3. Erdogmus, H., Morisio, T.: On the Effectiveness of Test-first Approach to Programming. IEEE Transactions on Software Engineering 31(1), 226–237 (2005) 4. Euzenat, J.: An API for Ontology Alignment. In: McIlraith, S.A., Plexousakis, D., van Harmelen, F. (eds.) ISWC 2004. LNCS, vol. 3298, pp. 698–712. Springer, Heidelberg (2004) 5. Euzenat, J., Shvaiko, P.: Ontology Matching. Springer, Heidelberg (2007) 6. Kappel, G., Kargl, H., Kramler, G., Schauerhuber, A., Seidl, M., Strommer, M., Wimmer, M.: Matching Metamodels with Semantic Systems—An Experience Report. In: Workshop Proc. of the 12th GI-Fachtagung Datenbanksysteme f¨ ur Business, Technologie und Web (BTW 2007), pp. 38–52. Verlag Mainz (2007) 7. Kappel, G., Kargl, H., Reiter, T., Retschitzegger, W., Schwinger, W., Strommer, M., Wimmer, M.: A Framework for Building Mapping Operators Resolving Structural Heterogeneities. In: Proc. of the 2nd Int. United Information Systems Conf. (UNISCON 2008). LNBIP, vol. 5, pp. 158–174. Springer, Heidelberg (2008) 8. Kargl, H., Wimmer, M.: SmartMatcher—How Examples and a Dedicated Mapping Language can Improve the Quality of Automatic Matching Approaches. In: Proc. of the 2nd Int. Conf. on Complex, Intelligent and Software Intensive Systems (CISIS 2008), pp. 879–885. IEEE Computer Scociety, Los Alamitos (2008)
16
M. Wimmer et al.
9. Lee, Y., Sayyadian, M., Doan, A., Rosenthal, A.: eTuner: Tuning Schema Matching Software Using Synthetic Scenarios. VLDB Journal 16(1), 97–122 (2007) 10. Rahm, E., Bernstein, P.: A Survey of Approaches to Automatic Schema Matching. VLDB Journal 10(4), 334–350 (2001) 11. Wimmer, M., Reiter, T., Kargl, H., Kramler, G., Kapsammer, E., Retschitzegger, W., Schwinger, W., Kappel, G.: Lifting Metamodels to Ontologies: A Step to the Semantic Integration of Modeling Languages. In: Nierstrasz, O., Whittle, J., Harel, D., Reggio, G. (eds.) MoDELS 2006. LNCS, vol. 4199, pp. 528–542. Springer, Heidelberg (2006)
Programming Models for Concurrency and Real-Time Jan Vitek Computer Science Department Purdue University
[email protected]
Abstract. Modern real-time applications are increasingly large, complex and concurrent systems which must meet stringent performance and predictability requirements. Programming those systems require fundamental advances in programming languages and runtime systems. This talk presents our work on Flexotasks, a programming model for concurrent, real-time systems inspired by stream-processing and concurrent active objects. Some of the key innovations in Flexotasks are that it support both real-time garbage collection and region-based memory with an ownership type system for static safety. Communication between tasks is performed by channels with a linear type discipline to avoid copying messages, and by a non-blocking transactional memory facility. We have evaluated our model empirically within two distinct implementations, one based on Purdue’s Ovm research virtual machine framework and the other on Websphere, IBM’s production real-time virtual machine. We have written a number of small programs, as well as a 30 KLOC avionics collision detector application. We show that Flexotasks are capable of executing periodic threads at 10 KHz with a standard deviation of 1.2us and have performance competitive with hand coded C programs.
M. Oriol and B. Meyer (Eds.): TOOLS EUROPE 2009, LNBIP 33, p. 17, 2009. c Springer-Verlag Berlin Heidelberg 2009
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition Andrew Camilleri, Geoffrey Coulson, and Lynne Blair Computing Department Lancaster University LA1 4WA, UK {a.camilleri,g.coulson,l.blair}@lancaster.ac.uk http://www.infolab21.lancs.ac.uk
Abstract. Aspect Oriented Programming (AOP) is becoming increasingly accepted as an approach to deal with crosscutting concerns in software development. However, AOP is known to raise software integrity issues. For example, join point shadows may easily omit crucial join points or include inappropriate ones. In this paper, we propose an extensible framework called CIF that constrains aspect-oriented software design and composition with the intent to maintain the integrity of the final composed system. CIF controls the composition of aspects and the base application in three dimensions: where the composition occurs, how the composition is carried out and what exactly is being composed. The framework is intended to be used in a team-based software development environment. We demonstrate the applicability of the framework through an application case study.
1
Introduction
Aspect Oriented Programming [1] is becoming increasingly accepted as an approach to deal with crosscutting concerns in software development. However, the flexible approach to modularity and composition enabled by AOP has a potential downside: it can easily result in systems that behave in unintended and unanticipated ways – i.e. the integrity [2] of the system can easily become compromised (examples are given in the following paragraphs). According to our analysis, integrity violations can be conveniently grouped under three orthogonal headings: i) where an aspect-oriented composition occurs, ii) how the composition occurs and iii) what exactly is being composed. ‘Where’ refers to the quantification [3] of aspect composition as specified by a pointcut expression. Quantification is about choosing the ‘shadows’ [4] within which composition will occur. The difficulty here lies in getting the strength of the quantification right (and therefore the extent of the shadow). Over-strong (or over-specific) quantification can lead to compositions that miss crucial join points, whereas weak quantification can include unintended join points [5]. In M. Oriol and B. Meyer (Eds.): TOOLS EUROPE 2009, LNBIP 33, pp. 18–36, 2009. c Springer-Verlag Berlin Heidelberg 2009
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
19
either case the integrity of the resulting system can clearly be compromised. It is also worth noting that threats to system integrity posed by inappropriate quantification are commonly tangled with issues of maintainability and reusability – e.g. there is often a strong desire for weak quantification to help foster aspect reuse (i.e. to avoid ‘fragile pointcuts’ [6]). ‘How’ refers to the compositional semantics employed when weaving aspects; this is especially an issue where multiple aspects are woven at a common join point. Existing AOP systems provide considerable flexibility in this area, offering for example, options such as advice ordering; execution options like ‘before’, ‘after’ or ‘around’; compositional options like ‘call’ or ‘execution’; or aspect instantiation semantics such as ‘per-instance’, ‘per-class’, ‘per-call’ or ‘per-thread’. Inadvertent misuse of these dimensions of flexibility can easily result in integrity violations. For example, if a ‘distribution’ aspect is inadvertently woven before an ‘authentication’ aspect at the same join point, then the resultant system could erroneously make unauthenticated calls. As another example, it is desirable to limit the use of ‘around’ advice: reasoning about aspects that use ‘around’ advice is hard because the advice developer has the luxury to forfeit the original join point (i.e. not call proceed()). Finally, ‘what’ refers to the functionality encapsulated in an aspect. Inadvertent inclusion of inappropriate behaviour in an aspect can again lead to integrity violations; for example, deadlock might result if an aspect unexpectedly accesses a resource shared by the base code. It is also important to have confidence that a given aspect behaves as its name would suggest. For example, it could easily lead to confusion, especially in a team-based software development environment, if an aspect called ‘logging’ failed to call proceed() or used apparently inappropriate modules such as an authentication library. In general, therefore, the libraries and other code used by an aspect should be closely related to the associated concern. Diverging from this goal at the very least makes modular reasoning considerably harder. The contribution of this paper is to propose an extensible framework, called CIF (for “Composition Integrity Framework”), that constrains aspect-oriented software design and composition with the intent to avoid threats such as the above and therefore to maximise the integrity of the composed system. CIF is abstract and independent of any tool specific concepts (and as such is generally applicable to a range of AOP environments) and is designed to be employed in team-based software development environments. The constraint mechanisms offered by the framework closely follow the above analysis in terms of ‘where’, ‘how’ and ‘what’. The rest of the paper is organised as follows. Section 2 introduces CIF’s basic abstractions. Section 3 illustrates the use of these abstractions in an application case study, and Section 4 discusses our current implementation of CIF. Section 5 surveys related work, arguing that while elements of the integrity issue have been addressed in the literature, no work has yet considered the issue sufficiently comprehensively. Finally, Section 6 offers our conclusions.
20
2 2.1
A. Camilleri, G. Coulson, and L. Blair
CIF’s Basic Abstractions: Domains, Realms and Configurations Overview
The main contribution of this paper is to propose an extensible ‘integrity framework’ called CIF for aspect-oriented software development. Our objective is to specify and enforce limits for aspects in a very general way. Our approach is to specify what is permissible rather than to explicitly restrict behaviour (this is in line with the well-accepted principle of fail-safe defaults [7]). Although our work to date has largely considered compile-time AOP, our framework is inherently agnostic as to compile-time versus dynamic AOP. In more detail, our approach deals with AOP integrity in terms of programmerdefined, concern-specific, ‘boundaries’ or ‘ringfences’ that we refer to as domains. A domain scopes a specific concern and imposes its boundaries in terms of the ‘where’, ‘how’, ‘what’ analysis discussed in Section 1. Each aspect is then allowed to operate only within the limits of one or more associated domains.
Fig. 1. Composition Integrity Framework
On top of domains, CIF provides the higher-level abstraction of realms. The simplest function of a realm is to list and organise the set of domains defined for a given system. But beyond that, realms provide a way for domains to be combined and inter-related while preserving domain autonomy. This allows us, for example, to specify which domains depend on each other (like authorization and authentication), or to specify weaving priorities in cases where a join point falls simultaneously within multiple domains. In essence, a realm provides an abstraction over a set of domains and a discipline to preserve the integrity of their composition. Finally, on top of realms, CIF offers the coarser-grained abstraction of a configuration which allows us to use the foregoing abstractions to define multiple
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
21
alternative instantiations or ‘builds’ of a whole application, each of which may have its own dedicated integrity constraints. Architecturally, the CIF approach is to avoid interfering with the either the base code of a system or its associated aspects. Instead, CIF domain, realm, and configuration definitions sit alongside the system (see Figure 1) which remains oblivious to the existence of CIF. Essentially, CIF separates out the integrity concern (or ‘meta-concern’). CIF also operates throughout the development life cycle. In particular, the domain and realm abstractions constrain the design of aspects; and at build-time, a tool called the CIF verifier (see Section 4) checks the conformance of aspect implementations to domain and realm specifications, while the configuration abstraction (again, with tool support) helps ensure that application builds or deployments maintain pre-specified integrity constraints. CIF can even deal with run-time compositional constructs such as cflow. 2.2
Domains
In this and following sections we use a BNF-like notation1 to more precisely define the three main CIF abstractions and their supporting concepts. In terms of this notation, a domain is defined in Figure 2.
Fig. 2. Domain
As can be seen, a domain consists of a shadow-region (cf. ‘where’), a concernregion (cf. ‘what’), and a set of permissable-compositional-styles (cf. ‘how’). Before discussing these in detail we first expand on the general notion of a ‘region’. A region is a set of programmatic-element-instances in the target programming language environment such as specific classes, methods, fields, etc. The intention is that a region provides a means to ‘slice’ an application in some appropriate manner using a predicate, which picks up a specific set of 1
In this notation < > refers to a tuple; and { } to a set.
22
A. Camilleri, G. Coulson, and L. Blair
programming-element-instances. For example, in the case study that will be described in Section 3, we define predicates over the Java package structure of the system: healthwatcher.view.command.* in Figure 7 matches all the programmatic-element-instances (in this case classes) scoped within healthwatcher.view.command. Given this understanding of a region, a domain’s shadow-region refers to the set of programmatic-element-instances that fall within the scope of this domain. More specifically, when an aspect is assigned to this domain (see Section 2.4), and a pointcut expression is written to specify the composition of this aspect, the shadow defined by that pointcut expression is constrained by CIF to fall within the domain’s shadow region. This is useful in a number of ways; for example, if not so constrained, a pointcut that targets the execution join points of a class may inadvertently extend over all of the class’s subclasses which may be implemented by different team members who may be unaware of such a pointcut. The concern-region defines the ‘what’ of the domain; this aims to constrain the behaviour that embodies a particular concern. For example, an aspect implementing a distribution concern can be excluded from making use of the behaviour found in a database library. Finally, the permissable-compositional-styles constituent defines the ‘how’ of the domain. This is expressed as a combination of three other constructs: advicerelated-style deals with advice types, pointcut-related-style is a boolean expression that is written in terms of primitive-pointcut s, and instantiation-related-style deals with aspect instantiation options. Advice types are useful to constrain (using advice-related-style) in a number of scenarios. For example, a synchronization aspect using a semaphore should be restricted to use before and after for wait and release join points. (It is possible to use an around but we do not need to forfeit the original join point. In general, we should always strive for the simpler semantics since it reduces the possibility of introducing errors.) The pointcut-related-style is useful because it allows us to define any implicit assumptions which an advice might have. For example in AspectJ, the semantics of the implicit this2 object varies depending on captured join point [4]. We can easily violate integrity if we change a pointcut (in a manner that changes the context accessed through thisJoinPoint) without a corresponding change in how the corresponding this object is used. The arguments of an advice can also be a source of confusion and this can be alleviated by an explicit pointcut-relatedstyle. We may constrain the exposure of the arguments at a specific join point using the args pointcut instead of opting for an advice to access them using reflection. Similar reasoning applies for the instantiation-related-style. The benefits of permissable-compositional-styles are especially visible in scenarios where the pointcut is defined separately from the advice implementation; for example, AspectJ provides the use of abstract aspects. In such scenarios it is possible that implicit assumptions regarding the runtime context are violated (as described above), because each developer may have a different intuition of 2
The same reasoning applies for the implicit target object and the arguments at a join point. In AspectJ these are all accessed through the implicit thisJoinPoint.
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
23
how composition should occur. This is especially true if we take into account the subtle differences between certain primitive pointcuts; the classic example here is call and execution (in AspectJ the reference to the implicit target object is different for these pointcuts), but another possible example is within and cflow. These subtle problems are perhaps more common in environments that provide an asymmetric paradigm for the encapsulation of concerns [8,9]. As shown in Figure 2, the permissable-compositional-styles constituent is extensible and can comprise a range of mechanisms, the choice of which is dependent on the target AOP environment in which CIF is being applied3 . To summarise, the primary purpose of a domain is to constrain its associated aspect or aspects. We say that an aspect is suitably constrained by (conforms to) a domain iff: 1. all shadows specified by pointcuts applied to the aspect are contained within the domain’s shadow-region, 2. all programmatic-element-instances used by the aspect’s advice are contained within the domain’s concern-region, 3. the aspect’s composition is constrained by its associated domain’s permissable-compositional-styles definition. Examples of the use of the domain abstraction are given in Section 3. 2.3
Realms
The pseudo-BNF for the realm abstraction is shown in Figure 3. As can be seen, a realm is a set of one or more domains plus a regime that constrains relations between the domains. This regime is a boolean expression that is written in terms of an extensible set of so-called integrity functions. The initial set of integrity functions that we have employed in our work to date is shown in Figure 4. These integrity functions are all of type boolean and can express a variety of constraints between domains. In general, we differentiate between two types of integrity functions: static and dynamic. The key difference is that static integrity functions perform checks that deal more closely to the internal integrity of CIF and thus are applied before the start of the weaving process; dynamic functions are applied during the weaving process, performing checks or possibly influencing it in some manner (more about this in Section 4). In Figure 4 all of the functions are static, except for precedence(). The function dependent() declares dependencies between domains: i.e. d1 is dependent on d2. This might be used, for example, to provide a regime for domains that respectively address authorisation and authentication – i.e. the final system can only include authorisation (as a concern) if it also includes authentication. Similarly, the function exclusive() declares which domains are mutually exclusive i.e. d1 and d2 are mutually exclusive. For example, we may 3
Another possible ‘style’ that might be applied in an AspectJ [10] environment, for example, is the declare construct.
24
A. Camilleri, G. Coulson, and L. Blair
design a system that implements distribution as an aspect and want to leave open the possibility of using alternative distribution technologies (e.g. CORBA or Java RMI). In such a case we can construct separate domains for each technology and define them to be mutually exclusive. The closure() function determines the ‘level’ to which the domain’s concernregion is to be verified against an associated aspect. For example, with level = 0 only code directly included in the aspect’s advice is verified; with level = 1, verification extends to the top level of all the modules and other programmaticelement-instances that are referenced from within the advice; with level = ∞ the closure of all code referenced directly or indirectly from the advice is verified.
Fig. 3. Realm
Fig. 4. Example Integrity Functions
Finally, the function precedence() imposes a weaving order for advice between domains that share common shadows (thus addressing an element of the ‘how’ dimension that could not be addressed in individual domain definitions). In more detail, precedence() defines the advice precedence of d1 over d2 ; the shadow set argument is used to scope the set of shadows at which the precedence relation should apply4 . To round off the discussion of realms, we can summarise by saying that the purpose of a realm is twofold. First, it gives us an abstraction over all the domains that are relevant for a specific application. Second, using regimes we can express constraints over domains with the intent to preserve the integrity of a final application. In general, regimes (and their consituent integrity functions) are useful because they allow us to go beyond the programming language based constraints expressed using domains. Moreover, the fact that new integrity functions can be added provides CIF’s main mechanism for extensibility which enables us to cover arbitrary application-specific integrity issues. An example of the use of the realm abstraction is given in Section 3. 4
Incidentally, the precedence relation expressed as a sequence of aspects provided by most AOP environments, can be viewed as a special case of our precedence() function.
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
2.4
25
Configurations
The purpose of our final abstraction, that of a configuration, is to enable us to create different application builds from a set of domains. For example, we can use configurations to define application builds that are supported by different OSs, or debugging versions, or versions that include or omit security, etc. Intuitively, a configuration provides us with an instantiation of a realm.
Fig. 5. Configuration
In more detail, a configuration, as defined in Figure 5, specifies: i) a set of all the domains that are relevant to a particular application build; ii) a congruent set of aspects that are to be associated with and constrained by those domains; and iii) a realm definition that specifies the regime constraints associated with those mappings. Essentially, a configuration embodies the following assertions: 1. that each aspect conforms to its associated domain (or domains – as we have seen, an aspect can be mapped to multiple domains), 2. that the given realm’s regime evaluates to true. An example of the use of the configuration abstraction is given in Section 3. 2.5
CIF Syntax
Figures 2, 3 and 5 defined CIF’s main concepts in an abstract manner. In practice, CIF specifications employ a concrete syntax. Due to lack of space, we do not describe this syntax formally; rather we introduce it by example. More specifically, examples of concrete domain, realm and configuration specifications are given in Figures 7, 8 and 9. These CIF specifications are related to an application case study that will be described in Section 3. As can be seen in Figures 7, 8 and 9, the various constituents of the framework (regions, styles, etc.) each have their own corresponding labeled sections in a specification, and each of these sections comprises a set of definitions in which CIF-defined attributes are assigned values within curly brackets. Thus, Figure 7 shows a domains section which defines a number of domains (in this case two) together with their corresponding attributes – i.e. shadow and concern regions from the regions section, and permissible-compositional-styles from the compositional-styles section. The regions sub-section is in turn made up of region definitions that are associated with predicate-valued attributes that specify sets of programmaticelement-instances that should fall within the region being specified (the Method qualifier specifies that methods are the only programmatic element type of interest here). Similarly, the compositional-styles section is defined in terms
26
A. Camilleri, G. Coulson, and L. Blair
of advice-related-styles (with options like before, around, etc.), pointcut-related-styles (with options such as call, execution, etc.) and instantiation-related-styles (with options like singleton, per-thread, etc.). Likewise, Figures 8 and 9 respectively define realms and configurations, which employ the same syntactic approach. The realms section depends on subsections dealing with regimes and integrity functions. The configurations section simply lists a set of configurations, each of which is defined as a list of <domain, aspect> pairs.
3 3.1
Application Case Study Case Study Overview
The purpose of the following application case study is to further motivate CIF’s abstractions, but also to clarify the way we envisage CIF being used. The application on which the case study is based is discussed in detail in [11,12]. In outline, the application is called Health Watcher and is a health service complaint logging system which embodies a distributed client server architecture. It was originally implemented in Java, but later refactored to encapsulate crosscutting concerns using AspectJ. The refactored version employs aspects that address distribution, persistence and transaction concerns. The main reason for choosing this application (besides it being a real system) as our case study is the variety of configurations in which it is available, as shown in Figure 6 (which shows 4 distinct configurations). Thus, for example, the application could be accessed either through the web with a normal browser or using an application installed on the client side (thus explaining the need for different distribution technologies). Moreover, given a specific platform, the application developers had to cater for different options in terms of transaction and persistence mechanisms (in this case relational and object-oriented databases).
Fig. 6. Health Watcher Configurations
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
3.2
27
Using CIF’s Abstractions
The Health Watcher application provides an ideal ecosystem in which to encounter integrity violations because it is difficult to manage even such a modest set of concerns, given their multiple implementations. It should be obvious that the integrity of the final system can be easily violated if the corresponding aspects are not carefully combined together. CIF is useful in this situation because it gives an abstraction over the concerns and on how they can be combined. Turning to the specifics of the CIF specification, Figure 7 defines appropriate domains for the application’s distribution concern (which we will employ as our primary example concern). Two domains are specified, one for the client side and one for the server side. The concern-region of rmiserver-Domain specifies that only methods from the java.rmi.server package can be employed within aspects associated with this domain. This serves to eliminate, for example, an EJB based distribution implementation. The shadow region specified establishes an explicit set of programmatic-element-instances that constrain the compositional shadow for this domain. This prevents the aspects associated with this domain from accidentally composing with elements that are not listed in this region.
Fig. 7. Example Domains
The compositional-styles section constrains aspect oriented compositions for the client and the server, regardless of the concrete distribution technology. In this case, the pointcut-related-styles for the client and server side are constrained to use call and execution, respectively. This prevents us from confusing the advice arguments (exposed by a pointcut that is defined separately
28
A. Camilleri, G. Coulson, and L. Blair
from the advice implementation) for arguments of intercepted methods. If the style for composition is constrained through compositional-styles then we can have a uniform compositional view for all distribution concerns and our assumptions will always be sound. For example, we can choose to explicitly expose the intercepted method arguments by constraining the use of the args pointcut, instead of relying on each advice to access them through thisJoinPoint. Finally, both domains constrain their advice-related-styles to be around because the distribution aspects need to marshal data (i.e. method arguments) on both requests and replies. Using a before or an after here would be an error, since we want to replace the original join point. The respective instantiation-related-styles are restricted to be singleton since we only want one running instance of the client and of the server. Again, having this kind of constraint capability is useful to maintain a consistency amongst the alternative concern implementations.
Fig. 8. Example Realms
Figure 8 illustrates realm definitions employed in the case study. As one can see, the regime is a conjunction of five separate predicates. The dependent() integrity function is used to state that if a transaction concern is to be employed, a persistence concern is also required (this is to ensure safe storage for uncommitted data). Similarly, the exclusive() function is used to disallow the simultaneous use of RMI and EJB distribution concerns. The closure() function specifies that the full closure of the advice code of the server-side distribution aspect(s) should be verified for conformance to the server-side domain’s concern-region.
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
29
Fig. 9. Example Configurations
Finally, Figure 9 shows two sample configurations: one employs RMI-based distribution with object-oriented database persistence and transaction management; the other employs EJB distribution, with relational database persistence and transaction management. These two configurations correspond to Figures 6(a) and 6(d). The two configurations specified here correspond to RMI-based configuration and EJB-based configuration in Figure 10 (this figure gives an overview of the whole specification process). It is important to note that the configuration specifications are not effectively specifying any additional integrity constraints. They simply allow us to create our final application. Thus, given a specific realm, the mapping in the configuration can be specified (perhaps using an appropriate GUI) by a deployer who may be ignorant of the details of implementation, but simply requires to build a system which includes a specific set of concerns. The configuration allows us to do exactly this, while making sure that there are no integrity violations along the way. 3.3
Using CIF in a Team-Based Software Development Environment
The case study also enables us to illustrate how CIF can be applied in teambased software development environments. For example, consider a development environment that employs three major roles: i) a system architect, ii) a developer, and iii) a quality assurance officer. In such an environment, the system architect role would define the fundamental architecture of the application, plus CIF abstractions to constrain the subsequent definition and composition of the aspects envisaged in the design. In our particular case, this means defining the application’s basic client-server architecture, and its associated domains (e.g. rmiclient-Domain and rmiserver-Domain, plus domains for the persistence and transaction aspects as shown in Figure 10). The system architect would also constrain the way that these domains inter-relate by defining realms and associated regimes (e.g. in our case the system architect specifies that RMI and
30
A. Camilleri, G. Coulson, and L. Blair
Fig. 10. Health Watcher with CIF
EJB communications are mutually exclusive and that transactional functionality is dependent on the presence of persistence functionality). The developer role would then implement the base modules and aspects identified by the system architect. When complete, the various modules and aspects would all be delivered to the quality assurance officer who would test the delivered aspects against their associated domains (using the CIF verifier; see Section 4) and define prototype configurations (such as our RMI- and EJB-based configurations as shown in Figure 10) that exercise the system in various application-specific ways. Finally, the quality assurance role would feed back the results of testing these configurations (such as integrity violations) for refinement to the systems architects and developers as appropriate.
4
Implementation
We have built a prototype implementation of CIF for the AspectJ language using AspectBench [13]. The implementation is logically structured in two parts: a static part and a dynamic part. The static part comprises a verifier that ensures that aspects conform to domains, and that realm and configuration specifications are self-consistent e.g. ensuring that any dependencies and mutual exclusion relations (specified using the dependent() and exclusive() integrity functions) are honoured. Our current implementation supports only “closure(0)” semantics – i.e. only toplevel code is checked for conformance with regions (regions themselves are computed with assistance from the AspectBench weaver). Other application-specific integrity functions can also be added. For example, in a team-based software development scenario where multiple architects collaborate to define domains, an ignore(Region r) function could be defined to demarcate an application-level region that should never participate in the definition of any domain.
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
31
The second part of the implementation is a dynamic verifier integrated with the AspectBench weaver, and uses callbacks to realise extensible weave-time checking behavior. Integrity functions that are integrated with this part are allowed to have side effects. For example, a weaver callback associated with the precedence() integrity function directs weaving to occur according to precedences specified by this function. Figure 11 gives a layered view of our implementation. The CORE module implements the CIF’s central abstractions (domains, realms, and configurations) and performs the above-mentioned static consistency checks. Above this, the CIFParser module reads in and parses CIF specifications. The CORE and CIFParser modules are generic and entirely independent of any particular target AOP environment, the latter being represented primarily by the Weaver module. The generic parts are sheltered from the Weaver by semi-generic modules, namely the AspectLang, LangParser, and the DynamicVerifier modules: AspectLang provides an AOP-environment-specific adaptation layer between the CORE and the target AOP environment; LangParser takes care of parsing the programming language specific aspects that will participate in the composition; and DynamicVerifier provides the above-mentioned callback mechanism for integration with the weaver.
Fig. 11. CIF Implementation Architecture
We handle dynamic pointcuts (e.g. AspectJ’s cflow) in the following manner. Such pointcuts are commonly realised by inserting runtime checks (during compilation) at points (both for entry and exit control flows) where composition might occur [14,15]. In that light, our strategy5 is simply to ensure that these checks are constrained to occur only within appropriately defined shadow regions. This gives us an ‘upper limit’ for constraining dynamic composition without the need to be too restrictive. In future implementation work we plan to extend our exploration of runtime integrity support in dynamic environments. One key strategy here is to explore integrity functions that persist at runtime. For example, we could conceive of an integrity function that ensures that ‘around’ advice in a specified domain always calls proceed() [16,17]. 5
A possible alternative strategy could be to constrain only where composition should occur i.e. control flow exit points.
32
A. Camilleri, G. Coulson, and L. Blair
We also plan to provide an automated tool that would inspect all the aspects and pointcuts in an existing system and come up with corresponding domain specifications. This would relieve us of the burden of having to specify domains from scratch; it would provide an initial definition of regions for each aspect, which can be viewed and refined (at least by specifying integrity functions) as required. Complementary to this automated tool, we also plan to provide a GUI-based workbench to better evaluate the use of CIF in realistic software development environments.
5
Related Work
Although we argue that the literature has not yet comprehensively addressed the issue of integrity in AOP systems, we nevertheless acknowledge that a considerable body of work addresses a range of concerns within this general space. In terms of the where dimension, a number of approaches attempt to restrict the shadows specified by pointcut expressions. For example, [18,19,20,21] all offer ways to abstract the set of join points accessible to pointcut expressions so as to raise the semantic level and thereby increase the precision of the quantification. XPI [22] attempts to achieve similar ends through the use of an information hiding interface called ‘cross-cutting interfaces’. A complementary approach is adopted by [23] which offers a ‘negative’ pointcutting mechanism that allows sets of join points to be explicitly excluded from quantifications. In general, although this work enables greater control over the ‘where’ dimension, it does not at all address the ‘how’ or ‘what’ dimensions. Furthermore, all the proposed approaches lack an equivalent concept for domains and therefore restrict quantification in a coarse-grained manner: i.e. they do not allow per-aspect control over the quantification shadow. This is an important omission because shadow management is naturally a per-concern issue. In terms of the how dimension, most work to date has focused on how multiple aspects woven at a common join point should relate to each other. For example, [24] and [25] provide a comprehensive catalogue of aspect interactions and suggest how unwanted interactions can be detected; [26] provides a systematic means of composing multiple aspects, and detecting and resolving potential conflicts; and [16] provides a domain-specific language to define execution constraints for aspect interactions. This work is largely complementary to ours in offering greater semantic depth in specific focus areas. However, it does not address the comprehensive range of ‘how’ issues (e.g. accommodating ordering issues, aspect instantiation semantics, or execution options) that we cover (see Section 2). Our approach can also be viewed as an integrating framework for more focused work such as the above. In terms of the what dimension, [27] discusses the notion of a permission system for aspects – i.e. to control which parts of a system a given aspect can access; however, no concrete mechanisms are proposed. Other work (e.g. [28,29,30,31,32]) attempts to classify and categorise advice (e.g. in terms of whether it is read-only or, if not, the degree of invasiveness permitted). Our
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
33
approach, on the other hand (see Section 2), focuses on a finer-grained restriction of the behaviour that is applicable for a given advice type (i.e. in terms of the modules or libraries that can be used by advice). Furthermore, although the classifications provided by [28,29] seem very general and widely applicable, they do not deal, as we do, with concern interactions (see Section 2). Also, although [30,32] provide an intuitive classification, the reports generated by these tools require a lot of manual analysis, and each change requires the generation (and subsequent analysis) of a new report. Moreover, contrasting with [31], our approach does not require annotation of the underlying system. Finally, some research attempts to verify the behaviour of aspects in terms of static code analysis [33]. However this work (so far) only supports a limited source language, making it unsuitable for most real-world scenarios. “Design by contract” approaches can also be viewed as relating to the ‘what’ dimension. For example, the approach proposed by [34] divides aspects into ‘observers’ and ‘assistants’ to facilitate modular reasoning; and [35] provides a similar classification of aspects. Also, [36] describes the notion of ‘aspect integration contracts’ which attempts to preserve integrity by equipping aspects with ‘required’ and ‘provided’ denotations. Although these approaches directly target the integrity issue (albeit only in the ‘what’ dimension) their downside is that they tend to be intrusive, verbose and difficult to manage. In constrast, CIF avoids cluttering source code by factoring integrity specification out of both base modules and aspects. Finally, MAO [17] is an interesting system that addresses both ‘what’ and ‘where’ issues, but using an approach quite different from ours (see Section 2). In brief, they adopt a language-based annotation approach that enables programmers to explicitly characterise the effects of aspects. In terms of ‘what’, the programmer can, for example, write annotations that ensure that proceed() is called, that return values are returned unchanged, or that an advice may not change arguments. In terms of ‘where’, the programmer can constrain the quantification shadow of a given aspect. However, although MAO enables wideranging control over the integrity of an AOP system, it has significant disadvantages that mainly accrue from its language-based approach (again, compare our ‘factored out’ approach). In particular, MAO annotations are potentially complex and may need to be applied to base code as well as aspect code; moreover it is always difficult to find general acceptance of new language-level constructs.
6
Conclusion
As AOP gains more ground, it becomes increasingly important to provide a means to maintain a tight grip on the compositional flexibility it provides. We feel that the CIF approach offers a very promising way to achieve this, in a very practical manner. We are encouraged with the results we have achieved so far, but we also realize that there is more work to be done. Perhaps the most significant limitation of our design that we have discovered to date is the predicate-based region definition
34
A. Camilleri, G. Coulson, and L. Blair
approach. Experience has shown that this can be tricky to get right (especially using Java-inspired package predication) and may suffer from similar weaknesses as pointcuts – i.e. over strong or over weak predication. Currently, we are experimenting with alternative predication approaches and also with the integrity function facility to help minimise this weakness: for example, a ‘monitor’ function can keep track of complete enumeration (automatically, without any manual intervention) of programmatic elements picked out by specific regions and warn us when there are changes in this set. More generally, we believe that our approach to integrity management is unique in not restricting or even changing the aspect language or the base application: CIF simply sits alongside these two components, to provide the necessarily integrity-preserving machinery. It thus cleanly separates out the integrity concern (or ‘meta-concern’). Furthermore, we believe that our proposal is complementary to several of the more partial approaches discussed in Section 5, and that these could in future work be integrated into our approach. For example, XPIs [22] can be applied alongside CIF at design time to clarify and facilitate the selection of appropriate regions and compositional styles. Similarly, it seems feasible to accommodate the execution constraints defined in [16] by encapsulating them in integrity functions. We can also include advice classifications similar to augmentation and replacement [30,31,32] in advice-related-style, thus extending them with compositional styles. Finally, it seems conceivable to relate contracts, as described by [36], to domains and to therefore provide stronger guarantees that aspects comply with concern-specific semantics.
References 1. Kiczales, G., Lamping, J., Mendhekar, A., Maeda, C., Lopes, C., Loingtier, J.M., Irwin, J.: Aspect-oriented programming, pp. 220–242 (1997) 2. Clark, D.D., Wilson, D.R.: A comparison of commercial and military computer security policies. SP, 184 (1987) 3. Filman, R.E., Friedman, D.P.: Aspect-oriented programming is quantification and obliviousness. Technical report (2000) 4. Hilsdale, E., Hugunin, J.: Advice weaving in aspectj. In: AOSD 2004: Proceedings of the 3rd international conference on Aspect-oriented software development, pp. 26–35. ACM, New York (2004) 5. McEachen, N., Alexander, R.T.: Distributing classes with woven concerns: an exploration of potential fault scenarios. In: AOSD 2005: Proceedings of the 4th international conference on Aspect-oriented software development, pp. 192–200. ACM Press, New York (2005) 6. Stoerzer, M., Graf, J.: Using pointcut delta analysis to support evolution of aspectoriented software. ICSM, 653–656 (2005) 7. Saltzer, J.H., Schroeder, M.D.: The protection of information in computer systems. Proceedings of the IEEE 63, 1278–1308 (1975) 8. JBossAOP, http://www.jboss.org/jbossaop 9. Rajan, H., Sullivan, K.J.: Classpects: unifying aspect- and object-oriented language design. In: ICSE 2005: Proceedings of the 27th international conference on Software engineering, pp. 59–68. ACM, New York (2005)
CIF: A Framework for Managing Integrity in Aspect-Oriented Composition
35
10. AspectJ, http://www.eclipse.org/aspectj 11. Soares, S., Borba, P., Laureano, E.: Distribution and persistence as aspects. Softw. Pract. Exper. 36(7), 711–759 (2006) 12. Greenwood, P., Garcia, A., Rashid, A., Figueiredo, E., Sant’Anna, C., Cacho, N., Sampaio, A., Soares, S., Borba, P., Dosea, M., Ramos, R., Kulesza, U., Bartolomei, T., Pinto, M., Fuentes, L., Gamez, N., Moreira, A., Araujo, J., Batista, T., Medeiros, A., Dantas, F., Fernandes, L., Wloka, J., Chavez, C., France, R., Brito, I.: On the Contributions of an End-to-End AOSD Testbed. In: EARLYASPECTS 2007: Proceedings of the Early Aspects at ICSE, Washington, DC, USA, p. 8. IEEE Computer Society Press, Los Alamitos (2007) 13. AspectBench, http://abc.comlab.ox.ac.uk 14. Dinkelaker, T., Haupt, M., Pawlak, R., Benavides, L.D., Gasiunas, V.: Inventory of aspect-oriented execution models. Technical report, AOSD-Europe (2006) 15. Bockisch, C., Kanthak, S., Haupt, M., Arnold, M., Mezini, M.: Efficient control flow quantification. In: OOPSLA 2006: Proceedings of the 21st annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, pp. 125–138. ACM, New York (2006) 16. Pawlak, R., Duchien, L., Seinturier, L.: CompAr: Ensuring Safe Around Advice Composition. In: Steffen, M., Zavattaro, G. (eds.) FMOODS 2005. LNCS, vol. 3535, pp. 163–178. Springer, Heidelberg (2005) 17. Clifton, C., Leavens, G.T., Noble, J.: MAO: Ownership and effects for more effective reasoning about aspects. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 451–475. Springer, Heidelberg (2007) 18. Kiczales, G., Mezini, M.: Aspect-oriented programming and modular reasoning. In: ICSE 2005: Proceedings of the 27th international conference on Software engineering, pp. 49–58. ACM, New York (2005) 19. Aldrich, J.: Open modules: Modular reasoning about advice, pp. 144–168. Springer, Heidelberg (2005) 20. Gudmundson, S., Kiczales, G.: Addressing Practical Software Development Issues in AspectJ with a Pointcut Interface. In: Advanced Separation of Concerns (2001) 21. Lieberherr, K., Lorenz, D.H.: Aspectual Collaborations: Combining Modules and Aspects. The Computer Journal 46(5), 542–565 (2003) 22. Sullivan, K., Griswold, W.G., Song, Y., Cai, Y., Shonle, M., Tewari, N., Rajan, H.: Information hiding interfaces for aspect-oriented design. SIGSOFT Softw. Eng. Notes 30(5), 166–175 (2005) 23. Larochelle, D., Scheidt, K., Sullivan, K., Wei, Y., Winstead, J., Wood, A.: Join point encapsulation. In: AOSD 2003 Workshop on Software-engineering Properties of Languages for Aspect Technologies (2003) 24. Sanen, F., Truyen, E., De Win, B., Wouter, J., Loughran, N., Coulson, G., Rashid, A., Nedos, A., Jackson, A., Clarke, S.: Study on interaction issues. Technical report, AOSD-Europe (2006) 25. Katz, S., Katz, E., Havinga, W., Staijen, T., Taiani, F., Weston, N., Rashid, A., Sudholt, M., Ha Nguyen, D.: Detecting interference among aspects. Technical report, AOSD-Europe (2006) 26. Composition, reuse and interaction analysis of stateful aspects. In: AOSD 2004: Proceedings of the 3rd international conference on Aspect-oriented software development. ACM, New York (2004) 27. De Win, B., Piessens, F., Wouter, J.: How secure is aop and what can we do about it? In: SESS 2006: Proceedings of the 2006 international workshop on Software engineering for secure systems, pp. 27–34. ACM, New York (2006)
36
A. Camilleri, G. Coulson, and L. Blair
28. Sihman, M., Katz, S.: Superimpositions and aspect-oriented programming. The Computer Journal 46(5), 529–541 (2003) 29. Dantas, D.S., Walker, D.: Harmless advice. In: POPL 2006: Conference record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 383–396. ACM, New York (2006) 30. Rinard, M., Salcianu, A., Bugrara, S.: A classification system and analysis for aspect-oriented programs. SIGSOFT Softw. Eng. Notes 29(6), 147–158 (2004) 31. Munoz, F., Baudry, B., Barais, O.: Improving maintenance in aop through an interaction specification framework. In: IEEE International Conference on Software Maintenance, ICSM 2008, September 28-October 4, pp. 77–86 (2008) 32. Zhang, D., Hendren, L.: Static Aspect Impact Analysis. Technical report, AspectBench (2007) 33. Krishnamurthi, S., Fisler, K., Greenberg, M.: Verifying aspect advice modularly. In: SIGSOFT 2004/FSE-12: Proceedings of the 12th ACM SIGSOFT twelfth international symposium on Foundations of software engineering, pp. 137–146. ACM, New York (2004) 34. Clifton, C., Leavens, G.T.: Observers and assistants: A proposal for modular aspect-oriented reasoning. In: Foundations of Aspect Languages, pp. 33–44 (2002) 35. Lorenz, D.H., Skotiniotis, T.: Extending design by contract for aspect-oriented programming. CoRR, abs/cs/0501070 (2005) 36. Lagaisse, B., Joosen, W., De Win, B.: Managing semantic interference with aspect integration contracts. In: International Workshop on Software-Engineering Properties of Languages for Aspect Technologies (2004)
A Diagrammatic Formalisation of MOF-Based Modelling Languages Adrian Rutle1 , Alessandro Rossini2 , Yngve Lamo1 , and Uwe Wolter2 1
Bergen University College, P.O. Box 7030, 5020 Bergen, Norway aru,
[email protected] 2 University of Bergen, P.O. Box 7803, 5020 Bergen, Norway {rossini,wolter}@ii.uib.no
Summary. In Model-Driven Engineering (MDE) models are the primary artefacts of the software development process. The usage of these models have resulted in the introduction of a variety of modelling languages and frameworks. Many of these languages and frameworks are based on the Object Management Group’s (OMG) Meta-Object Facility (MOF). In addition to their diagrammatic syntax, these languages use the Object Constraint Language to specify constraints that are difficult to specify diagrammatically. In this paper, we argue for a completely diagrammatic specification framework for MDE, where by diagrammatic we mean specification techniques which are targeting graph-based structures. We introduce the Diagram Predicate Framework, which provides a formal diagrammatic approach to modelling based on category theory – the mathematics of graph-based structures. The development of a generic and flexible formalisation of metamodelling is the main contribution of the paper. We illustrate our approach through the formalisation of the kernel of the Eclipse Modeling Framework. Keywords: Model-Driven Engineering, Meta-Object Facility, Unified Modeling Language, Object Constraint Language, Eclipse Modeling Framework, Diagram Predicate Framework, diagrammatic specification.
1 Introduction Since the beginning of computer science, developing high-quality software at low cost has been a continuous vision. This has boosted several shifts of programming paradigms, e.g. machine code to compilers and imperative- to object oriented programming. In every shift of paradigm, raising the abstraction level of programming languages and technologies has proved to be necessary to increase productivity. One of the latest steps in this direction has lead to the usage of modelling languages in software development processes. Software models are indeed abstract representations of software systems which are used to tackle the complexity of present-day software by enabling developers to reason at a higher level of abstraction. In traditional software development processes, models are used either for sketching the architectural design at a high level of abstraction or for mere documentation purposes. On the contrary, in Model-Driven Engineering (MDE) models are first-class entities of the software development process. These models are used to generate M. Oriol and B. Meyer (Eds.): TOOLS EUROPE 2009, LNBIP 33, pp. 37–56, 2009. c Springer-Verlag Berlin Heidelberg 2009
38
A. Rutle et al.
(parts of) the software systems by means of model-to-model and model-to-text transformations. Hence, models in MDE are required to have two important properties. Firstly, they should be intuitive for humans, such as software developers, domain experts, managers and users. This has motivated for the usage of visual modelling and specification. Secondly, the models should have a precise syntax and semantics to enable analysis, validation, verification and transformation. This has motivated for the usage of formal modelling languages. The terms “diagrammatic-”, “visual-” and “graphical-” modelling are often used interchangeably. Here, we distinguish clearly between visualisation and diagrammatic syntax and focus on precise syntax (and semantics) of models independent of their visualisation. It is first and foremost due to the graph nature of models that we focus on diagrammatic modelling. By diagrammatic modelling we mean techniques which are targeting graph-based structures. Several diagrammatic specification frameworks have emerged in the last years as an attempt to facilitate modelling. The state-of-the-art of diagrammatic modelling languages includes the Unified Modeling Language (UML) [1] and the Eclipse Modeling Framework (EMF) [2]. These languages and frameworks share the same metamodel, the Meta-Object Facility (MOF) [3], which is a metamodelling and metadata repository standard developed by the Object Management Group (OMG). However, MOF is defined only semi-formally which may not guarantee the degree of precision required by MDE [4,5,6]. In this paper, we argue for a completely diagrammatic specification framework for MDE. We introduce the Diagram Predicate Framework (DPF) [7,8,9,10], which provides a formal diagrammatic approach to modelling based on category theory. The remainder of the paper is structured as follows. Section 2 motivates the necessity of formal diagrammatic modelling languages in MDE and presents a running example which we model by a UML class diagram. In the example, we introduce some modelling challenges which are difficult to express by UML alone. Section 3 introduces the basic concepts of our approach and shows how it can be used to model the motivating example precisely. Section 4 presents a generic and flexible scheme for the formalisation of metamodelling and discusses OMG’s 4-layered architecture in view of this scheme. Then in Section 5 the approach is illustrated for the metamodel of EMF in a case-study. Section 6 discusses some related works. Finally, Section 7 concludes the paper and outlines future work.
2 Motivation An appropriate approach to object-oriented modelling is to describe models – in a first approximation – as graphs. Graphs are a well-known, well-understood and frequently used means to represent system structures or states [11]. However, the expressive power offered by present-day MOF-based modelling languages – which are meant to deal with graph-based models – may not be sufficient to express certain constraints a software system must obey. As a consequence, OMG proposes the Object Constraint Language (OCL) 2.0 [12] for the definition of constraints in models defined by these languages [13]. This is just a special case of a general pattern where diagrammatic
A Diagrammatic Formalisation of MOF-Based Modelling Languages
39
modelling languages use textual languages to define constraints that are difficult to express by their own syntax and semantics. While this solution is to some extent accepted among software developers, there are two reasons why a completely diagrammatic approach is worth investigating. Firstly, OCL and MOF-based languages such as UML class diagrams live in different conceptual and technical spaces, which makes automatic reasoning about these models challenging. For example, any modification in a model structure must be reflected in the OCL constraints which are related to the modified structure, but, defining automatic synchronisation of OCL constraints for arbitrary model modifications is not possible [14]. Moreover, the identification of classes of modifications for which an automatic synchronisation of OCL constraints is possible requires a complex machinery to be implemented by tool vendors. Secondly, due to the graph nature of models, we are interested in investigating a completely diagrammatic approach for the specification and reasoning about structural models. This is also to obey the “everything is a model” vision of MDE by having both structure and constraints in the same model-centric format. Among the efforts which are done to clarify the semantics of diagrammatic modelling languages, are the introduction of MOF 2.0 [3] as a common metamodel for languages which are defined by OMG, and the so-called 4-layered modelling architecture. In this architecture, a model in each layer conforms to (or is an instance of ) a model in a higher layer, i.e. each layer represents a metamodel for the layer below it. In particular, a metamodel specifies the abstract syntax of a modelling language by defining the set of rules (or constraints) that can be used to determine whether a given model is well-formed. However, the relationship between a model and its metamodel remains imprecise. This is because how to determine that a model is well-formed according to its metamodel is only defined semi-formally [4,5,6]. Thus, although the usage of graphs for the representation of model structures is a success story, an enhancement of the formal basis is needed to: – Express well-formed diagrammatic constraints, especially constraints which span over multiple model elements, and which go beyond the structural constraints which are formalised as graph constraints [11,15]. – Formalise the relationship – conformance or instance of – between models in different layers. This relationship is expressed by the concepts of type- and typed graphs in graph theory [11], which does not capture the type of constraints mentioned above. A natural choice for such a formal enhancement of graph theory is category theory, and in particular the sketch formalism, which can be used to define semantics of diagrams, and thus of diagrammatic models, without the needs for a supplementary textual language. In the categorical sketch formalism, models are represented as graphs, and model properties are expressed by universal properties such as; limit, colimit, and commutativity constraints [16,17]. This approach has the benefit of being generic and at a high level of abstraction, but it turns models into a complex categorical structure with several auxiliary objects [7]. The proposed formalisation approach in this paper is DPF which is a generalisation and adaptation of the categorical sketch formalism, where user-defined diagrammatic
40
A. Rutle et al.
predicate signatures are allowed to represent the constructs of modelling languages in a more direct and adequate way. In particular, DPF is an extension of the Generalised Sketches [18] formalism originally developed by Diskin et al. in [4,19,20]. DPF aims to combine the mathematical rigour – which is necessary to enable automatic reasoning – with diagrammatic modelling. 2.1 Constraints in UML The motivating example illustrates the usage of some constraints which are not expressible by UML itself. These constraints are specified in OCL. We are convinced that software developers will benefit from a diagrammatic syntax capable of expressing these constraints.
Fig. 1. A UML class diagram for the management of employees and projects
In Fig. 1, a UML class diagram of an information system for the management of employees and projects is presented. We require that the following set of rules are satisfied at any state of the system: 1. 2. 3. 4. 5. 6. 7.
An employee must work for at least one department. An employee may be enrolled in none or many projects. A department may have none or many employees. A department may control none or many projects. A project must be controlled by at least one department. An employee enrolled in a project must work in the controlling department. A set of employees working for a controlling department must not be enrolled in the same controlled project more than once.
The rules above can be categorised into two groups based on their complexity. Rules 1-5 can be forced by constraints which involve one or two model elements. These rules can be expressed by UML syntax. For the rules 6 and 7, constraints which involve more than two elements are required. This can only be achieved by using the text-based OCL constraints as, for example:
A Diagrammatic Formalisation of MOF-Based Modelling Languages
41
1 context 2
3
4 5 6
Enrolment inv rule6: self.department.employees->includesAll(self. employee) inv rule7: Let enrolments:Set(Enrolment)=Enrolment. allInstances in (not enrolment->exists(enr|enr.project=self.project and enr.department=self.department and enr.employees=self.employees))
The solution above has the following drawbacks: 1. Checking the state of the system against the model will involve two steps which are done in two different technical spaces: firstly, checking the structure and some of the constraints in UML; then, checking the rest of the constraints by an OCL engine. 2. Since some the semantics of the model is hidden in the OCL code, the model development process may become complex and error-prone in the long run. In particular, domain experts may have difficulties in understanding the OCL code – something which may force the developers to use the list of rules in a natural language instead of the OCL rules. This may lead to misunderstandings [21]. A completely diagrammatic representation of the model in Fig. 1 is described in Section 3, Fig. 2.
3 Diagram Predicate Framework DPF is a graph-based specification format that takes its main ideas from both categorical and first-order logic (FOL), and adapts them to SE needs. While in FOL the arity of a predicate is given by a collection of nodes only, the arity of a predicate in DPF is given by a graph, i.e. a collection of nodes together with a collection of arrows between nodes. Besides, the main difference between FOL and DPF is that FOL is an “element-wise” logic, i.e. variables vary over elements of sets. In contrast, DPF uses a “sort-wise” logic where variables vary over sets and mappings. Diagrammatic reasoning can provide several benefits to software engineers. As an example we consider model evolution where the difference between artefacts is typically represented and reasoned about in a diagrammatic fashion. This is to help the developer to understand the rationale behind the modifications [22]. DPF has shown to be beneficial for the formalisation of version control systems in MDE. In particular, we exploit the formal foundation for the identification of commonalities and calculation/representation of differences between models [10]. In DPF, software models are represented by diagrammatic specifications. In the remainder of the paper, we use the terms “model” and “diagrammatic specification” interchangeably. In the next sections, we will discuss the syntax and semantics of these diagrammatic specifications.
42
A. Rutle et al.
3.1 Syntax of Diagrammatic Specifications Diagrammatic specifications are structures which consist of a graph and a set of constraints. The graph represents the structure of the model. Predicates from a predefined diagrammatic signature are used to add constraints to the graph. The concepts of signatures, constraints, and diagrammatic specifications are defined as follows. Definition 1 (Signature). A (diagrammatic predicate) signature Σ := (Π, α) consists of a collection of predicate symbols Π with a mapping that assigns an arity (graph) α(p) to each predicate symbol p ∈ Π. Definition 2 (Constraint). A constraint (p, δ) in a graph G is given by a predicate symbol p and a graph homomorphism δ : α(p) → G, where α(p) is the arity of p. Definition 3 (Diagrammatic Specification). A Σ-specification S := (G(S), S(Π)), is given by a graph G(S) and a set S(Π) of constraints (p, δ) in G(S) with p ∈ Π. Table 1 shows a sample signature Σ = (Π, α). The first column of the table shows the names of the predicates. The second and the third columns show the arities of predicates and a possible visualisation of the corresponding constraints, respectively. In the fourth column, the intended semantics of each predicate is specified. The predicates in Table 1 allow to specify properties and constraints that, according to our analysis, should be part of any modelling language which is used to define structural models. These predicates are just generalisations, or general patterns, for properties that are used in different areas of modelling. For example, [mult,(m,n)] for multiplicity constraint on associations in UML class diagrams, [total] for total constraint on relations in ER diagrams and [jointly-key] for uniqueness constraint (i.e. UNIQUE) in SQL. For a given signature the semantics of nodes, arrows and predicates has to be chosen in a way which is appropriate for the corresponding modelling environment. For structural models in object-oriented development, it is appropriate to interpret nodes as sets f
→ B as multi-valued functions f : A → ℘(B). The powerset ℘(B) of and arrows A − B is the set of all subsets of B, i.e. ℘(B) = {X | X ⊆ B}. 3.2 Constraints in DPF Fig. 2 shows an example of a Σ-specification S = (G(S), S(Π)). S specifies the structural model for the information system presented in Section 2.1. G(S) in Fig. 3 is the graph of S without any constraints on it. Here we will revisit some of the rules in Section 2.1. Recall that in rule 1 an employee must work for at least one department. In S, this is forced by the constraint ([total], δ1 ) on the arrow eDeps (see Table 2). Moreover, a property of S is that the functions eDeps and dEmps are inverse to each other, i.e. ∀e ∈ Employees, ∀d ∈ Departments : e ∈ dEmps(d) iff d ∈ eDeps(e). This is forced by the constraint ([inverse], δ3 ) on eDeps and dEmps. According to rule 6, an employee enrolled in a project must work in the controlling department. While this rule has to be forced by means of OCL constraints in the motivating example, we can specify it diagrammatically in S. The rule is forced by the constraint ([subset], δ8 ) between the arrows eEmps and eDep;dEmps. Note that
A Diagrammatic Formalisation of MOF-Based Modelling Languages
43
Table 1. A sample signature Σ p
α(p)
Proposed visualisat. Intended semantics
/2
A
/2
A
[total]
1
x
[key]
1
x
[singlevalued]
1
x
/2
A
[mult,(n,m)] 1
x
/2
A
1
x
/2
A
x
$
[cover]
[inverse]
•
∀a ∈ A : |f (a)| ≥ 1
f
/ B
∀a, a ∈ A : a = a implies f (a) = f (a )
[1]
f
/ B
∀a ∈ A : |f (a)| ≤ 1
/ B
∀a ∈ A : n ≤ |f (a)| ≤ m
2, B
∀b ∈ B : ∃a ∈ A | b ∈ f (a)
f [n,m] f
f
1d
2
A g
'
B
[INV]
/2 O
f
A
y
/ B O
[DC]
g
3 x
[subset]
1
f
$
:2 x
1
/2
y
/ B
∀a, a ∈ A : a = a implies f (a) = f (a ) or g(a) = g(a )
f / B >> 3 >[JK] >> h g > >
∀a, a ∈ A : a = a implies f (a) = f (a ) or g(a) = g(a ) or h(a) = h(a )
A
g f
[JK]2
C
1> >
x
/2
>>y >> >
z
4 [composition]
'
∀a ∈ A : f (a) ⊆ g(a)
[]
3 [jointlykey]
{f (a) | a ∈ A}∩ {g(c) | c ∈ C} = ∅ and {f (a) | a ∈ A} ∪ {g(c) | c ∈ C} = B
7 B
A
g
C
y
[jointlykey]
∀a ∈ A , ∀b ∈ B : b ∈ f (a) iff a ∈ g(b)
g
x
1
/ B
[KEY]
y
[disjointcover]
f
1> >
x
3
/2
>>z >> >
3
A
D
/ B >> >>f ;g g > [COMP] >> A
y
C f
∀a ∈ A : f ; g(a) ≡ f (a)}
{g(b) | b ∈
C
the arrow eDep;dEmps is the composition of the arrows eDep and dEmps. We believe that the usage of the [subset] predicate can help domain experts and developers in grasping the rationale of the constraint.
44
A. Rutle et al.
Fig. 2. A diagrammatic specification S = (G(S), S(Π))
Fig. 3. The graph G(S) of the diagrammatic specification S
Finally, rule 7 forces that a set of employees working for a controlling department must not be enrolled in the same controlled project more than once. Again, it is possible to specify such a rule diagrammatically by using the constraints ([jointly-key], δ8 ), ([single-valued], δ5 ) and ([single-valued], δ7 ). The semantics of the constraint [jointly-key] and [subset] are further explained in Example 2 (Section 3.3), where instances of S are taken into consideration. 3.3 Semantics of Diagrammatic Specifications In this section we discuss the semantics of diagrammatic predicates and show how this semantics is used to check whether a graph is an instance of a diagrammatic specification. As mentioned, for object-oriented modelling it is appropriate to interpret nodes in the underlying graph G(S) of a Σ-specification S by sets, and arrows by multi-valued functions. The main idea in these modelling languages is that the semantics of a model is given by a set of instances. To reflect this idea in DPF, we consider arbitrary graphs I together with a graph homomorphism ι : I → G(S) as instances of G(S). That is, a
A Diagrammatic Formalisation of MOF-Based Modelling Languages
45
Table 2. Some diagrams (p, δ) ∈ S(Π) (p, δ) ([total], δ1 )
α(p) 1
([cover], δ2 )
1
([inverse], δ3 )
1d
δ(α(p))
x
/2
x
/2
x
$
/ Employee
dEmps
Department
eDeps
2
/ Department
eDeps
Employee
Employee m
-
Department
dEmps
y x
/ 2 Enrolment
eDep
/ Department
([single-valued], δ5 ) 1
x
/ 2 Enrolment
eDep
/ Department
1
x
/2
([single-valued], δ7 ) 1
x
/2
x
$
([total], δ4 )
([total], δ6 )
([subset], δ8 )
1
1 1> > z
4
x
Enrolment
eP ro
/ P roject
eP ro
/ P roject
eEmps
:2
-
1 Employee
Enrolment eDep;dEmps
y
([jointly-key], δ9 )
Enrolment
/2
Enrolment P
3
Employee
>>y >> >
eDep / Department PPP PPeP PPro eEmps PPP P'
P roject
f
node A in G(S) is interpreted by the set ι−1 (A) of nodes in I; and an arrow A − →B in G(S) is interpreted by the multi-valued function from ι−1 (A) into ℘(ι−1 (B)) in I. The latter is represented by the set ι−1 (f ) of arrows in I (see Example 1). To define the concept of instance of a Σ-specification we have to fix, however, the semantics of the constraints offered by the signature Σ. We can mention at least three ways to define semantics of these constraints. In Table 1, we have used the “elementwise” language of set theory. In category theory, where the signature is limited to limit, colimit and commutativity constraints, the semantics of these constraints is mathematically “pre-defined” for any category according to the universal nature of these special constraints. In implementations of modelling languages, we rely on a less descriptive but more algorithmic way to define the semantics of constraints, e.g. we implement a validator for each constraint. However, in order to analyse and formalise MOF-based modelling languages and models which are defined by these languages, we do not need to decide for one of the mentioned possibilities. We just need to know that any of these possibilities defines “valid instance of predicates”. Definition 4 (Instances of Predicates). A semantic interpretation of a signature Σ = (Π, α) is given by a mapping that assigns to each p ∈ Π a set [[p]] of graph homomorphisms τ : O → α(p) called valid instances of p, written τ p, where O may vary over all graphs.
46
A. Rutle et al.
x / Example 1. We consider the (arity) graph 1 2 and the following instances of this graph: ⎛ ⎞ e1 / b1 a1 ⎜ ~? ⎟ x / ⎜ ⎟ e2 ~~ 2) τ1 : ⎜ ⎟ −→ (1 ~~ ~ ⎝ ⎠ ~~ a2 b2 ⎞ ⎛ e1 / b1 a1 ⎜ ~? ⎟ ⎟ x / ⎜ e2 ~~ 2) τ2 : ⎜ ⎟ −→ (1 ~~ ~ ⎠ ⎝ ~~ e3 / b2 a2 x / Note that the instances of 1 2 are what is often called “bipartite graphs”. These instances represent multi-valued functions f1 , f2 : {a1 , a2 } → ℘({b1 , b2 }), where ℘({b1 , b2 }) = {∅, {b1}, {b2 }, {b1 , b2 }}, with f1 (a1 ) = f1 (a2 ) = f2 (a1 ) = {b1 } and f2 (a2 ) = {b1 , b2 }. We have τ1 , τ2 [total] and τ2 [cover], but τ1 [cover].
To check the validity of a constraint in a given instance of G(S), it is obviously enough to inspect only that part of G(S) which is affected by the constraint. This kind of “restriction to a subpart” is described as the pullback construction, i.e. a generalisation of δ ι the inverse image construction. Given a span p − →G← − I the pullback PO
δ ι∗
O∗
/G O ι
P.B. δ∗
/I
is given by a graph O∗ and graph homomorphisms δ ∗ : O∗ → I, ι∗ : O∗ → P . Nodes in in O∗ are given by those nodes i in I such that there exists a node n in P with δ(n) = ι(i). Analogously, the arrows fa in O∗ are given by those arrows f in I such that there exists an arrow a in P with δ(a) = ι(f ). Moreover, we have δ ∗ (in ) = i, δ ∗ (fa ) = f and ι∗ (in ) = n, ι∗ (fa ) = a, respectively. In case f is injective there is no need to distinguish between different copies of nodes or arrows from I; thus we can drop the subscripts n or a, respectively, as we have done in Example 2. Definition 5 (Instance of Specification). An instance of a diagrammatic specification S = (G(S), S(Π)) is a graph I together with a graph homomorphism ι : I → G(S), written (I, ι), such that for each constraint (p, δ) ∈ S(Π) we have ι∗ ∈ [[p]], where ι∗ : O∗ → α(p) is given by the following pullback diagram α(p) O ι∗
O∗
δ
/ G(S) O ι
P.B. δ∗
/I
A Diagrammatic Formalisation of MOF-Based Modelling Languages
47
The following example revisits the motivating example in Section 2.1 and explains the usage of Definition 5 to check whether a given graph is an instance of the specification. Example 2. Fig. 4 shows an instance ι : I → G(S) of the diagrammatic specification S from Fig. 2. In Fig. 4, we have used some “user-friendly” notations: e.g. the roundedrectangle with the name Enrolment stands for the set ι−1 (Enrolment), the arrows eEmps1 and eEmps2 represent the set ι−1 (eEmps), and, the ellipsis with the elements e2 and e3 stands for one of the subsets in ℘(ι−1 (Employee)).
Fig. 4. An instance, ι : I → G(S), of the Σ-specification S in Fig. 2
To verify that (I, ι) is indeed an instance of S, we need to construct the pullback for each constraint (p, δ) in S(Π) (see Table 2). In this example, we validate three of these constraints. First, we look at the constraint ([jointly-key], δ9 ). The pullδ
ι
ι∗
9 G(S) ← − I will be α([jointly-key]) ←− back of α([jointly-key]) −→
δ∗
9 O∗ −→ I, where ι∗ : O∗ → α([jointly-key]) is as in Fig. 5. The graph homomorphism ι∗ is a valid instance of the predicate [jointly-key] since the semantics of the constraint which is set by the predicate is not violated. The constraint here is that every enri ∈ ι−1 (Enrolment) must be uniquely identified by a triple ℘(ι−1 (Employee)), ℘(ι−1 (Department)), ℘(ι−1 (P roject)) . Moreover, consider the constraint ([single-valued], δ5 ) ∈ S(Π). Since the arrow eDep is single-valued, the target of eDep1 and eDep2 must be singleton sets, i.e. |ι−1 (eDep)| ≤ 1, This constraint is not violated since the subsets {d1 } and {d2 } are both containing only one value from ι−1 (Department). In contrast, since the arrow eEmps is not marked with [single-valued], the target of eEmps2 , for example, is the subset {e1 , e2 } which contains more than one element from ι−1 (Employee). Finally, we will look at the subset constraint ([subset], δ8 ). We can check that this constraint is not violated by verifying that eEmps1 (enr1 ) ⊆ dEmps1 ( eDep1 (enr1 )) and eEmps2 (enr2 ) ⊆ dEmps2 (eDep2 (enr2 )).
48
A. Rutle et al.
Fig. 5. ι∗ : O∗ → α([jointly-key])
4 MOF-Based Modelling Languages In the previous sections, we argued that formal diagrammatic modelling languages are necessary in order to specify models which are of the quality that MDE requires. Most of present-day’s diagrammatic modelling languages share MOF as their metamodel. However, these languages have still some issues when it comes to their formal semantics, especially considering the relationship between models in different modelling layers. Therefore in this section, we focus on the formalisation of MOF-based modelling languages. First we explain the 4-layered modelling architecture of OMG standards. Then, we show how modelling languages are represented by modelling formalisms in DPF by presenting a generic and flexible scheme for the formalisation of metamodelling. Finally, the notions of metamodels and reflexive (meta)models will be formalised in terms of DPF. 4.1 The 4-Layered Modelling Architecture OMG defines four layers of modelling (Table 3). Models in the M0 -layer are called instances which represent the state of a running system. These instances must conform to models in the M1 -layer, which are structures specifying what instances should look like. These models, in their turn, must conform to a metamodel in the M2 -layer, against which models can be checked for validity. Metamodels correspond to modelling languages, for example UML and CWM (Common Warehouse Metamodel ). The highest modelling layer (as defined by OMG) is the M3 -layer where MOF is located. A model at this layer is often called meta-metamodel; it conforms to itself and it is used to describe metamodels (Fig. 6a). The concepts presented in Section 3 allow to model directly the layers M1 and M0 as Σ-specifications and instances (I, ι) of Σ-specifications, respectively. In Fig. 6b,
A Diagrammatic Formalisation of MOF-Based Modelling Languages
49
Table 3. OMG’s modelling layers Modelling layers M3 : Meta-metamodel M2 : Metamodel M1 : Model M0 : Instance
OMG Standards and examples MOF UML language A UML model: Class Person with attributes name and address An instance of Person: “Ola Nordmann” living in “Sotraveien 1, Bergen”
ιS3
conf ormsT o
MO 3 conf ormsT o
MO 2 conf ormsT o
MO 1 conf ormsT o
M0 (a) OMG’s 4-layered modelling hierarchy.
S3 (Π3 )
Π3 _ _ _/ G(S3 )
O
ιS2 S2 (Π2 ) Π2 _ _ _/ G(S2 )
O
ιS1 S1 (Π1 ) Π1 _ _ _/ G(S1 )
O
ιS0
S0 (b) OMG’s 4-layered modelling hierarchy in DPF.
Fig. 6. OMG’s 4-layered modelling hierarchy, and its formalisation in DPF
these two layers are shown as a Σ1 -specification S1 and an instance (S0 , ιS0 ). We have chosen the names Σ1 = (Π1 , α1 ), (S0 , ιS0 ) and S1 = (G(S1 ), S1 (Π1 )) to underline the correspondence to the modelling layers of OMG. In this section, the layers M2 and M3 will be formalised. 4.2 Modelling Formalisms Each modelling language L, which is located in the M2 layer, is reflected in DPF by a diagrammatic signature ΣL and a metamodel M ML . L-models are represented by ΣL -specifications where the underlying graphs are required to be instances of the metamodel M ML . Moreover, the metamodel M ML itself is assumed to be a ΣMML specification, for an appropriate meta-signature ΣMML . We will call such a triple (ΣL , M ML , ΣMML ) for a modelling formalism FL . In Section 3 we formalised the concept of a model and of instances of a model, i.e. we defined a syntax and a semantics for diagrammatic specifications. In this sense, metamodelling means that syntax of a model is treated as a semantic entity to be specified and constrained by a another model, i.e. by a syntax, at a higher level of abstraction. Especially, we are interested to constrain, in an appropriate way, the underlying graphs
50
A. Rutle et al.
of these models. This “recursion step” within modelling (from syntax to semantics) can be formalised by the following definitions. Definition 6 (Conformance). Given the diagrammatic signatures Σ1 = (Π1 , α1 ), Σ2 = (Π2 , α2 ) and a Σ2 -specification S2 = (G(S2 ), S2 (Π2 )), a Σ1 -specification S1 = (G(S1 ), S1 (Π1 )) conforms to S2 if there exists a graph homomorphism ιS1 : G(S1 ) → G(S2 ) such that (G(S1 ), ιS1 ) is an instance of S2 . S2 (Π2 ) Π2 _ _ _/ G(S2 ) O ιS1 S1 (Π1 )
Π1 _ _ _/ G(S1 ) Definition 7 (Modelling Formalism). A modelling formalism F = (Σ1 , S2 , Σ2 ) is given by diagrammatic signatures Σ1 = (Π1 , α1 ) and Σ2 = (Π2 , α2 ), and a Σ2 specification S2 = (G(S2 ), S2 (Π2 )) called the metamodel of F . An F -specification is a Σ1 -specification S1 = (G(S1 ), S1 (Π1 )) which conforms to S2 . 4.3 Meta-formalism and Reflexive (Meta)Models As discussed above, a modelling language L can be formalised as a modelling formalism F = (Σ1 , S2 , Σ2 ), i.e. (ΣL , M ML , ΣMML ). The idea is to describe the syntactic constraints on S2 by a meta-language M L, i.e. by another modelling formalism FML = (Σ2 , S3 , Σ3 ) such that S2 conforms to S3 (see Fig. 6). Note that the same instance-model pattern is used for the definition of the relationship between instances and model; between models and metamodel; as well as between metamodels and metametamodel. In principle, this chain of metamodelling, i.e. for a modelling formalism Fi = (Σi−1 , Si , Σi ) finding a meta-formalism Fi+1 = (Σi , Si+1 , Σi+1 ) such that Si conforms to Si+1 , can continue ad infinitum. However, if at every modelling layer i + 1, we choose Σi+1 as minimal as possible, i.e. only keep the predicates that are needed to constrain the underlying graph of models at layer i, then this chain ends in an endpoint. Moreover, since Σi+1 only specifies syntactic restrictions on the underlying graph of Si , it is likely Graph
O
ιSi
ιSi Si (Πi ) Πi _ _ _ _ _ _ _/ G(Si )
O
O
ιSi−1
ιSi−1 (Π
)
i−1 i−1 Πi−1 _ _ _ _ _ _/ G(Si−1 )
S
(a) Natural endpoint for metamodelling.
Si (Πi ) Πi _ _ _ _ _ _ _/ G(Si )
(Π
)
i−1 i−1 Πi−1 _ _ _ _ _ _/ G(Si−1 )
S
(b) A reflexive metamodel.
Fig. 7. Modelling layers and reflexive metamodels
A Diagrammatic Formalisation of MOF-Based Modelling Languages
51
that Πi+1 is less expressive than Πi . Thus, the natural endpoint of such a chain of decreasing expressiveness will be a modelling formalism Fn = (Σn−1 , Graph, ∅),
where by Graph we mean • (Fig. 7a). This indicates that graph is the basic structure on which the whole framework is based. Another way to avoid progress ad infinitum is to collapse a potentially infinite chain into a single loop, i.e. to stop when Σi+1 is expressive enough to describe the restrictions which are put on the underlying graph of Si+1 (see Fig. 7b). This motivates the concept of reflexive (meta)model. Definition 8 (Reflexive Metamodel). A Σ-specification S = (G(S), S(Π)) is reflexive if S conforms to itself, i.e. if S is a (Σ, S, Σ)-specification. Fig. 7b shows a reflexive metamodel Si of a modelling formalism Fi = (Σi−1 , Si , Σi ). Note that ιSi will not be, in general, the identity morphism (see Section 5). Examples of reflexive metamodels are MOF (Fig. 6) and Ecore (Fig. 8). A formalisation of the latter is outlined in the next section. ιM
instanceOf
Ecore O
Ecore
ΠEcore _ _ _ _ _ _/ G(MEcore )
instanceOf
M odel O
O
ιS S(ΠCore ) ΠCore _ _ _ _ _ _ _/ G(S)
O
instanceOf
ιI
Instance (a) EMF’s modelling hierarchy.
MEcore (ΠEcore )
I (b) EMF’s modelling hierarchy in DPF.
Fig. 8. EMF’s modelling hierarchy and its formalisation in DPF
5 Case-Study: Formalisation of EMF In this section, we will use DPF to build a diagrammatic modelling formalism for EMF. EMF is a Java open source framework for modelling, data integration and codegeneration [2]. EMF is an implementation of Essential MOF (EMOF), which is a subset of MOF 2.0, but its metamodel is called Ecore to avoid confusion with MOF. EMF is a widely-used modelling framework because: – It is considered a low cost entry to the employment of MDE. – It has a clear semantics due to the simplicity of its metamodel. – There are many tools which are built around EMF and made available as Eclipse plug-ins. Software models in EMF are represented by core models. Core models are located in the M1 -layer of the OMG architecture. These models specify the structure of instances – the M0 -layer. That is, the types of objects that make up instance models,
52
A. Rutle et al.
Fig. 9. MEcore , the metamodel of FEM F , as a ΣEcore-specification
the data they contain and the relationships between them [23]. The metamodel of core models – Ecore – specifies the structure of the core models and is located in the M2 layer of the OMG architecture. Moreover, Ecore is reflexive, meaning that it specifies its own structure (Fig. 8a). Note that EMF has only three layers since Ecore is not intended to be the metamodel of a collection of other languages as it is the case for MOF. Fig. 8b shows EMF’s modelling hierarchy in view of DPF. EMF corresponds to a modelling formalism FEMF = (ΣCore , MEcore, ΣEcore ), where ΣCore = (ΠCore , αCore ), ΣEcore = (ΠEcore , αEcore ), and the metamodel is a ΣEcorespecification MEcore = (G(MEcore ), MEcore(ΠEcore )). Core models correspond to ΣCore -specifications S = (G(S), S(ΠCore )) which conform to MEcore. In addition, MEcore is a ΣCore -specification which conforms to MEcore. This is because MEcore is reflexive and ΣEcore is part of ΣCore . In some application contexts, we extend ΣCore with additional constraints and validators for these constraints. This is to enable software modellers to put additional constraints on core models. These additional constraints may be needed since Ecore supports only a minimal set of constraints, such as; multiplicity constraints and containment- and bidirectional references. In practice, constraints in EMF models (which are specified in OCL or Java) will consist of writing an Eclipse plug-in based on the EMF Validation Framework, or will involve the usage of the EValidator API of EMF. In both cases, models and constraints live in two different technical spaces – something which may lead to challenges as mentioned in Section 2. In the following, we describe the kernel of the metamodel MEcore in terms of DPF; in addition, we show that the the metamodel is reflexive. The kernel of MEcore, which is adopted from [23], is shown in Fig. 9. Each model element in MEcore is typed over MEcore by the graph homomorphism ιMEcore : G(MEcore ) → G(MEcore ). This typing is as follows: ιMEcore (EClassifier) = ιMEcore (EDataType) = ιMEcore (EClass) = EClassifier ιMEcore (eSuperType1 ) = ιMEcore (eSuperType2 ) = ιMEcore (eReferences) = ιMEcore (eAttributes) = ιMEcore (eStructuralFeatures) = eStructuralFeatures
A Diagrammatic Formalisation of MOF-Based Modelling Languages
53
We have some concerns about the mixture of Ecore with Java, for example in MEcore the super-type (or superclass) of EClass and EDataType is an EClassifier. In other words, each instance of the metaclass EClassifier is the super-type of either an EClass or an EDataType. In the specification of Ecore as an EMF-model, the semantics of the super-type arrows is given by the semantics of the “extends” keyword in Java. That is, something outside the modelling language is used to specify Ecore. In contrast, we incorporate this constraint into the framework by means of a single predicate [disjoint-cover] (see Table 1).
6 Related Work Diagrammatic modelling and formalisation of metamodelling have been extensively discussed in the literature. Here we discuss some of the approaches to the specification of constraints and formalisation of MOF-based modelling languages. The work in [5] exploits the higher-order nature of constructive type theory to uniformly treat the syntax of models, metamodels as well as the MOF model itself. Models are formalised as terms (token models) and can also be represented as types (type models) by means of a reflection mechanism. This formalisation ensures that correct typing corresponds to provably correct models and metamodels. The works in [6,24] use algebraic specification to give formal semantics to MOF. In [6] MOF-based metamodels are considered to be graphs with attributed objects as nodes and references as arrows. These graphs are represented by specifications in Membership Equational Logic (MEL), i.e. the logical power of MEL is essentially used to define the concept of a finite (multi)set at different places and levels. This formal semantics is made executable by using the Maude language, which directly supports MEL specifications. In this formalisation, metamodels are seen to play several roles: as data, as type or as theory; these roles are formally expressed by metamodel definition, model type, and metamodel realisation, respectively. In [24] a metamodelling framework, which is also based on Maude, is presented. In this framework, graphs are represented as terms by taking advantage of the underlying term matching algorithm modulo associativity and commutativity. The ability of Maude to execute the specifications allows the implementation of some key operations on models, such as model subtyping, type inference, and metric evaluation. Epsilon Validation Language (EVL) is one of the languages in the Epsilon model management platform [25]. EVL extends OCL conceptually (as opposed to technically) to provide a number of features such as support for constraint dependency management and access to multiple models of different metamodels and technologies. Epsilon provides a mature tool support for management of Ecore-based models. It will be interesting to investigate the formal basis of this language and compare it to DPF in a future work. Visual OCL (VOCL) [26] is an effort to define a graphical visualisation for OCL. It extends the syntax of UML and is used to define constraints on UML models. VOCL allows developers to put models together with constraints without leaving the graphical level of abstraction. However, VOCL does not extend the formal semantics of OCL. It only visualises constraints which are specifiable in OCL. An interesting and open
54
A. Rutle et al.
questions is whether the OCL constraints that are visualised can indeed be seen as sortwise constraints, and thus formalised in DPF. Alloy [27] is a structural modelling language which is capable of expressing complex structural constraints and behaviour. Model analysis in Alloy is based on the usage of FOL to translate specifications into boolean expressions which are automatically evaluated by a boolean satisfiability problem (SAT) solver. Then for a given logical formula F , Alloy attempts to find a model which satisfies F . Alloy models are checked by using the Alloy analyser which attempts to find counterexamples within a limited scope which violates the constraints of the system. Even though Alloy cannot prove the system’s consistency in an infinite scope, the user receives immediate feedback about the system’s consistency.
7 Conclusion and Future Work Independent of the importance of an appropriate and unambiguous visualisation we focus in DPF on the precise syntax (and semantics) of diagrammatic constraints. We allow diagrammatic constraints which modellers can use and reason about. An advantage of using these diagrammatic constraints is that they belong to the same conceptual space as the models which they constrain. This saves software developers from the challenges caused by mixing different technical and conceptual spaces. The paper argues that DPF is a promising candidate for an appropriate diagrammatic specification framework for MDE. Besides the diagrammatic appearance, this is mainly due to the rigorous mathematical foundation of the DPF. We have shown DPF’s usage as a formal diagrammatic framework for the definition of models and modelling languages. In particular, we have presented a generic and flexible scheme for the formalisation of metamodelling and discussed the 4-layered architecture of OMG in view of this scheme. This scheme has justified the extension of type- and typed graph concepts [11] with support for diagrammatic constraints. In view of graph transformations, a characterisation of our approach can be given by considering diagrammatic specifications as type graphs with constraints, and instances as typed graphs which satisfy those constraints. Moreover, an application of the approach is illustrated by representing EMF in DPF. The version of DPF presented in the paper distinguishes clearly between signatures and (meta)models. And it seems that only this “separation of concerns” allows for a clean and well-structured formalisation of metamodelling. In most modelling languages, however, predicates and constraints are internalised in the sense that predicates are represented by classes in the metamodel and constraints by corresponding objects. It seems that such kind of internalisation can be formalised by adapting and generalising an abstract categorical construction presented by Makkai in [18]. We intend to investigate this conjecture in one of our more foundational future work. The proposed visualisation of the predicates can be modified to meet the taste of the developers of the modelling language which uses the signature. A formalisation of parts of UML within DPF is presented in [4,28]. In a future work, we intend to define a transformation for the combination of UML with OCL to DPF. This will provide users of the framework with means to specify their models formally and diagrammatically
A Diagrammatic Formalisation of MOF-Based Modelling Languages
55
without the steep learning curve of a new visualisation or notation. To define such a transformation we need to investigate to what extend OCL constraints can be considered as sort-wise constraints. Due to space limitations we have not considered dependencies between predicates [7] even if they are highly relevant for practical applications of DPF. These dependencies provide a kind of rudimentary logic for DPF. The development of a fully fledged logic for DPF, allowing especially to reason about and to verify models, is one of our main future objectives. The development of a prototype implementation of the DPF framework based on the Eclipse platform is now in its early stage; we plan to boost this development in a near future. The final prototype will also support version control, whose underlying techniques are analysed in [10].
References 1. Object Management Group: Unified Modeling Language Specification (November 2007), http://www.omg.org/cgi-bin/doc?formal/2007-11-04 2. Eclipse Modeling Framework, http://www.eclipse.org/emf/ 3. Object Management Group: Meta-Object Facility Specification (January 2006), http://www.omg.org/cgi-bin/doc?formal/2006-01-01 4. Diskin, Z.: Mathematics of UML: Making the Odysseys of UML less dramatic. In: Practical foundations of business system specifications, pp. 145–178. Kluwer Academic Publishers, Dordrecht (2003) 5. Poernomo, I.: A Type Theoretic Framework for Formal Metamodelling. In: Reussner, R., Stafford, J.A., Szyperski, C. (eds.) Architecting Systems with Trustworthy Components. LNCS, vol. 3938, pp. 262–298. Springer, Heidelberg (2006) 6. Boronat, A., Meseguer, J.: An Algebraic Semantics for MOF. In: Fiadeiro, J.L., Inverardi, P. (eds.) FASE 2008. LNCS, vol. 4961, pp. 377–391. Springer, Heidelberg (2008) 7. Diskin, Z., Wolter, U.: A Diagrammatic Logic for Object-Oriented Visual Modeling. In: ACCAT 2007: 2nd Workshop on Applied and Computational Category Theory. ENTCS, vol. 203, pp. 19–41. Elsevier Science Publishers B.V., Amsterdam (2008) 8. Rutle, A., Wolter, U., Lamo, Y.: A Diagrammatic Approach to Model Transformations. In: EATIS 2008: Euro American Conference on Telematics and Information Systems (to appear) 9. Rutle, A., Wolter, U., Lamo, Y.: A Formal Approach to Modeling and Model Transformations in Software Engineering. Technical Report 48, Turku Centre for Computer Science, Finland (2008) 10. Rutle, A., Rossini, A., Lamo, Y., Wolter, U.: A Category-Theoretical Approach to the Formalisation of Version Control in MDE. In: Chechik, M., Wirsing, M. (eds.) FASE 2009. LNCS, vol. 5503, pp. 64–78. Springer, Heidelberg (2009) 11. Ehrig, H., Ehrig, K., Prange, U., Taentzer, G.: Fundamentals of Algebraic Graph Transformation. Springer, Heidelberg (March 2006) 12. Object Management Group: Object Constraint Language Specification (May 2006), http://www.omg.org/cgi-bin/doc?formal/2006-05-01 13. Warmer, J., Kleppe, A.: The Object Constraint Language: Getting your models ready for MDA, 2nd edn. Addison-Wesley, Reading (2003) 14. Markovi´c, S., Baar, T.: Refactoring OCL annotated UML class diagrams. Software and System Modeling 7(1), 25–47 (2008) 15. Taentzer, G., Rensink, A.: Ensuring Structural Constraints in Graph-Based Models with Type Inheritance. In: Cerioli, M. (ed.) FASE 2005. LNCS, vol. 3442, pp. 64–79. Springer, Heidelberg (2005)
56
A. Rutle et al.
16. Barr, M., Wells, C.: Category Theory for Computing Science, 2nd edn. Prentice Hall International Ltd., Hertfordshire (1995) 17. Fiadeiro, J.L.: Categories for Software Engineering. Springer, Heidelberg (May 2004) 18. Makkai, M.: Generalized Sketches as a Framework for Completeness Theorems. Journal of Pure and Applied Algebra 115, 49–79, 179–212, 214–274 (1997) 19. Diskin, Z., Kadish, B.: Generic Model Management. In: Encyclopedia of Database Technologies and Applications, pp. 258–265. Idea Group (2005) 20. Diskin, Z., Dingel, J.: Mappings, Maps and Tables: Towards Formal Semantics for Associations in UML2. In: Nierstrasz, O., Whittle, J., Harel, D., Reggio, G. (eds.) MoDELS 2006. LNCS, vol. 4199, pp. 230–244. Springer, Heidelberg (2006) 21. Bottoni, P., Koch, M., Parisi-Presicce, F., Taentzer, G.: A Visualization of OCL Using Collaborations. In: Gogolla, M., Kobryn, C. (eds.) UML 2001. LNCS, vol. 2185, pp. 257–271. Springer, Heidelberg (2001) 22. Cicchetti, A., Di Ruscio, D., Pierantonio, A.: A Metamodel Independent Approach to Difference Representation. Journal of Object Technology (Special Issue on TOOLS Europe 2007) 6(9), 165–185 (2007) 23. Budinsky, F., Merks, E., Steinberg, D.: EMF: Eclipse Modeling Framework 2.0, 2nd edn. Addison-Wesley Professional, Reading (2006) 24. Romero, J.R., Rivera, J.E., Durán, F., Vallecillo, A.: Formal and Tool Support for Model Driven Engineering with Maude. Journal of Object Technology 6(9), 187–207 (2007) 25. Epsilon: Book, http://epsilonlabs.wiki.sourceforge.net/Book 26. Visual OCL: Project Web Site, http://tfs.cs.tu-berlin.de/vocl/ 27. Alloy: Project Web Site, http://alloy.mit.edu/community/ 28. Diskin, Z., Easterbrook, S.M., Dingel, J.: Engineering Associations: From Models to Code and Back through Semantics. In: Paige, R.F., Meyer, B. (eds.) TOOLS Europe 2008. LNBIP, vol. 11, pp. 336–355. Springer, Heidelberg (2008)
Designing Design Constraints in the UML Using Join Point Designation Diagrams Vanessa Stricker1, Stefan Hanenberg2, and Dominik Stein2 1 Software Systems Engineering. Data Management Systems and Knowledge Representation Institute for Computer Science and Business Information Systems, University of Duisburg-Essen 45117 Essen, Germany
[email protected] [email protected] [email protected] 2
Abstract. Design errors cause high costs during the development of software, since such errors are often detected quite late in the software development process. Hence, it is desirable to prevent design errors as early as possible, i.e. it is necessary to specify constraints on the software design. While there are a number of approaches available that permit to specify such constraints, a common problem of those is that the developers need to specify constraints in a different language than their design language. However, this reduces the acceptance of such approaches, as developers need a different language just for the purpose of specifying constraints. This paper proposes an approach that permits to specify constraints within the UML by using Join Point Designation Diagrams (JPDDs).
1 Introduction Checking constraints from the very beginning of the software development process is essential for the success of the resulting software. It is commonly accepted that errors in the early stages of software development cause very high costs later on. This also applies to recent approaches such as model-driven software development [16]. In this case, it is even more crucial to check whether the design artifacts (i.e. the models) fulfill their constraints since models are the main fragments that are used to generate the resulting software from. Disregards of any constraint at design time are most often detected not before code generation time or (even worse) when the generated code is finally being tested. Since the generation of code from non-trivial models can easily take several hours, disregards of design constraints are a critical factor for the success of a software project. Typically, a number of design constraints result from architectural decisions, or from (external) techniques that are (or have to be) applied in a project. Furthermore, software companies usually have a number of development guidelines that must be followed by the developers. While there are design constraints that cannot be expressed in a formal manner (e.g. guidelines such as “names of classes and methods M. Oriol and B. Meyer (Eds.): TOOLS EUROPE 2009, LNBIP 33, pp. 57–76, 2009. © Springer-Verlag Berlin Heidelberg 2009
58
V. Stricker, S. Hanenberg, and D. Stein
should reflect their semantics”) a large amount of constraints and guidelines can be formally expressed. Instead of defining such constraints in an external document, it is desirable to specify them such that they can be immediately deployed in order to identify corrupt model elements. There are already a number of approaches that permit to specify constraints [27]. However, in practice such approaches did not turn out to be easily applicable in actual projects. The main reason for this is that constraints need to be specified in languages that developers are not familiar with. As a consequence, developers need to learn new languages (in addition to their proper design language) in order to specify constraints. This also implies that developers need to learn a set of new tools that come with the constraint language. Such an approach is costly as developers need to be trained on the language and the tools. Furthermore, applying a new language is a potential source of errors because most often constraint languages introduce concepts that do not (or not directly) appear in the utilized design language. Furthermore, developers that check their models using some constraints (in case a constraint rejects a model) need to understand what exactly the intention of the constraint is and how the model can be adapted in a way that fulfills the constraint’s underlying motivation: in case they do not understand precisely the constraint language, it is hard for them to fix their model in order to fulfill given constraints. Software developers that are using graphical design languages such as the UML [21] are familiar with the language’s concepts as well as with its graphical notation (i.e. with the language's concrete syntax). In order to reduce the previously described problems, it is desirable to provide developers with means to specify constraints in terms of the design language (i.e. UML in this case) itself. That means that the constructs provided by the constraint language as well as their graphical representation should correspond to the constructs provided by the design language. This permits developers to communicate their design constraints in terms of constructs and notational means they already know. Such an approach would increase the ability to understand constraints as well as the ability to specify constraints. Furthermore, it would reduce the training costs as well as the potential sources of errors (caused by applying a new language). This paper presents a constraint language based on the (concrete syntax of) UML in order to increase the developers’ abilities to specify and to communicate design constraints in terms of a design language they are familiar with. This constraint language is based on Join Point Designation Diagrams (JPDDs, see [6, 24, 25, 26]) that were originally developed to model aspect-oriented software in the UML. In order to exemplify the urge for such a constraint language, section 2 presents a real-world problem scenario from a medium-sized company. Section 3 gives detailed description of the underlying problem. Section 4 introduces Join Point Designation Diagrams. Then, section 4 explains how JPDDs are being deployed for the specification of design constraints. Section 5 revisits the problem and expresses it in term of JPDDs. Section 6 presents related work. Finally, section 7 discusses and concludes the paper.
2 Motivation The following example describes a real-world scenario of a medium-sized software company that provides products for health-care insurance companies. Examples for
Designing Design Constraints in the UML Using Join Point Designation Diagrams
59
such products are information systems for insurants, configurations of insurances as well as billing. The company deploys a model-driven software development approach based on UML that requires the software developers to specify most parts of the software with UML models. The company provides its own code generator that generates about 95% of the code base. The remaining code is hand-coded at well-defined hooks provided by the generator. The company generates server-sided code for both the business logic and the middleware connections as well as client-sided code for the user interface. The product under consideration consists of about 15.000 UML classes whose transformation to code takes about eight hours. (Automated) deployment and testing takes about 3 days. The resulting application runs in a J2EE environment. Developers that specify UML models have to follow a large number of constraints which come from different origins. There are constraints that represent the best practices of the company, others are forced by the underlying architecture. Furthermore, there are technical constraints from the underlying code generator. For motivation purposes, we want to cite here a simple (and simplified) example of a constraint in use which needs to be considered by developers that are responsible for designing the user interface. The user interface is based on the Model-View-Controller pattern (MVC, [22, 2]). This pattern suggests the encapsulation of the model, the view and the controller in separate elements. The view is responsible for visualizing data, the controller handles events of the user, and the model represents the data being visualized by the view. For reasons of simplicity we will neglect the model in the pattern, i.e. we only consider controller and view in the following discussion. «view» MyView
1..* view
has
1 «controller» controller MyController
Fig. 1. Correct model of views and controllers
The company’s code generator (as well as the company’s best practices) requires that a view and a controller are represented by separate UML classes. Furthermore, the generator requires that each view is annotated with a stereotype «view» and that each controller is annotated with the stereotype «controller». Each view must be connected to a controller (and vice versa) by a bi-directional association. The connection must have the name “has” and the role names “view” and “controller” respectively. The cardinality of the association is restricted, too: while the cardinality of the controller role must be 1, the cardinality of the view role may be 1..*. Figure 1 illustrates an extraction of a class diagram that fulfills these constraints. Figure 2 illustrates a model that does not fulfill the constraints: the first view does not have the required stereotype. Furthermore, the association between the second view and the controller does not comply with the constraint (since the role name “controller” is missing). Each disregard of the above design constraints had an immensely negative impact on the subsequent development process as erroneous connections between views and controllers would make either the code generation or (even) the final program execution crash. So the company decided to install model checking facilities in order to prevent this.
60
V. Stricker, S. Hanenberg, and D. Stein
1..* view
has
FirstView
1 controller
«controller» ControllerA
«view» SecondView
1..* view
has
1
«controller» ControllerB
Fig. 2. Incorrect model of views and controllers
3 Problem Statement The company’s approach to install model checking facilities was to write Java programs that read the UML models (i.e. their XMI [20] files) and check their validity by consecutively invoking hard-coded constraint-checker functions on them. Figure 3 shows a code fragment that illustrates the specification of the constraint presented above. Furthermore, the company provided its developers with a natural language description of the constraints they had to obey. public void checkViewControllers() { Collection cls = ... get the UML classes... for(Iterator it=cls.iterator(); it.hasNext() ; ) { UMLClass c = (UMLClass) it.next(); if(c.hasSterotypeNamed(“view”) { Collection as = c.getAssociationsNamed(“has”); if (!as.isEmpty()) { ...
...check rolenames.....check cardinality...
for(Iterator it2 = as.iterator(); it2.hasNext() ;) { UMLClass controller = ...
...check for sterotype “controller”
} } else ...throw an Exception...
} ... }
Fig. 3. Constraint specified in Java
Doing so led to two new problems, though: First, the constraints in the Java programs and their natural explanations had to be synchronized. Secondly, it had to be guaranteed that there are no ambiguities in the natural language description. Otherwise developers would not be able to determine why their models were considered erroneous. Due to the complexity of a large number of constraints, a natural language description of the constraints turned out to be satisfying at all: developers were not satisfied with the natural descriptions because of their unclear semantics as well as their - from their point of view - inappropriate representation. One option to overcome these synchronization and ambiguity problems is to make all developers read and understand the constraint semantics already specified in Java. This option comes along with an immense learning effort: Developers need to learn the (Java) data model of the UML diagrams, its API and its usage. This option has not been considered as a serious solution by the company: the programming skills of the developers that mainly use the UML to express their artifacts were not considered to be strong enough. Furthermore, it turned out that developers still require too much time to
Designing Design Constraints in the UML Using Join Point Designation Diagrams
61
someUmlModel.contents ->select(c: Class | c.stereotype->exists(st | st.name='view') and not ( c.associations->exists(a | a.name='has' and a.allConnections->size=2 and a.allConnections->select(ae | ae.participant = self)->exists(ae | ae.name = 'view' and ae.isNavigable = true and ae.multiplicity.range.lower >= 1 and ae.multiplicity.range.upper <= unlimited ) and a.allConnections->select(ae | ae.participant <> self)->exists(ae | ae.name = 'controller' and ae.isNavigable = true and ae.multiplicity.range.lower = 1 and ae.multiplicity.range.upper = 1 and (let c1: Class = ae.participant.oclAsType(Class) in c1.stereotype->exists(st | st.name='controller') ) ) ) ) ) someUmlModel.contents ->select(c: Class | /* analogously for each controller */ )
Fig. 4. Constraint specified in OCL
understand the semantics of the constraint. I.e. a code representation did not turn out to be effective to understand and communicate design constraints among developers. Unfortunately, the option of using a common (model) constraint specification means such as the OCL [27] does not do better in that regard (Figure 4 illustrates a corresponding constraint specified by using the OCL): In order to understand OCL constraints, developers need to spend a large amount of their time to get familiar with this new (i.e. new for them) language – just as in the previous case. Apart from learning keywords, operators, syntax and semantics of OCL, they would furthermore be confronted with the full complexity of UML's meta-model – something that they usually do not encounter during daily work. Again, they would face a significant mapping problem since there are plenty of UML (meta)model elements which have no explicit visual representation in UML's concrete syntax. As a result, the representation of the constraints in terms of OCL is significantly different from the representational means they are familiar with. Although Visual OCL [1, 12] tries to overcome some of these disadvantages, it does not solve these problems. The existing UML notation elements which are used as much as possible within Visual OCL are not rich enough to express all elements defined in the OCL meta-model, which is why developers need to get used to the new notation elements and still would have to learn the semantics of the OCL constructs. Hence, while the real-world scenario described above showed the urgent need to check constraints at design time, the investigation of possible options to do so – in a synchronized, unambiguous way – points to the problems of using a second/a different language for specifying the constraints. Since the representation of the constraints differs fundamentally from the representation of the models themselves, it is hard for developers to understand the relationship between the constraint specification and their models. Consequently, the semantics of the constraints remains unclear to the developer whose model is in conflict with an existing constraint, which hinders him/her from comprehending and correcting his/her design errors. In other words: Current techniques are sufficient and mature enough to detect design errors. However, what is lacking is a means which can be used by constraint developers to easily communicate their design constraints to the application developers (so that
62
V. Stricker, S. Hanenberg, and D. Stein
they know what they have to look for), and which at the same time can be used to automatically check the compliance of the models to the constraints.
4 Specifying Design Constraints This section introduces a graphical constraint language based on the UML. Therefore, so-called Join Point Designation Diagrams (JPDDs) are introduced, which permit to specify queries on UML models. Based on that, the use of JPDDs for the purpose of specifying constraints is explained1. 4.1 Join Point Designation Diagrams (JPDDs) «Join Point Designation Diagrams» (JPDDs [24, 26]) are extensions of the UML [21] in order to specify queries on software artifacts specified in the UML. Hence, JPDDs permit developers to express selections on UML models in terms of the UML itself (i.e. its own concrete syntax). Although JPDDs provide general-purpose constructs for expressing such selections (cf. [24, 26]), the original motivation for proposing JPDDs came from the domain of aspect-oriented software development, where JPDDs have been applied to select those artifacts that need to be handled by aspects (see [6]). Due to their background, JPDDs provide means to specify static selection criteria (e.g. selection criteria on classdiagrams etc.) as well dynamic selection criteria (e.g. selection criteria on interactions, etc.). For the purpose of specifying design constraints that need to be statically checked, the dynamic selection criteria are irrelevant. Hence, the following subsections introduce constructs for specifying static selection criteria, whereas constructs for specifying dynamic selection criteria are neglected. For reasons of simplicity, we furthermore explain the semantics of JPDDs in an informal way. A specification of its semantics in OCL can be found in [26]. JPDDs are defined with help of the graphical notation provided by the UML. That notation makes use of symbols from existing and well-established graphical notations, such as interaction sequence diagrams, state diagrams, activity diagrams, and class/object diagrams. Nevertheless, in order to provide reasonable selection semantics, a small set of constructs needed to be added. This is described in the next subsection. Afterwards, the semantics of selection patterns is explained by means of an example. Finally, relationships between JPDDs are explained. 4.1.1 Extensions to the UML In order to provide reasonable selection semantics, JPDDs extend the UML by the following elements: Identifiers, parameter boxes, regular expressions, list-wildcards, and indirections. Within a selection pattern, a tuple of identifiers (see Figure 5a) may be assigned to particular elements in order to designate those parts of the queried software artifact that should be actually selected by the JPDD. JPDDs possess an export parameter box at their lower right corner (see Figure 5b) which lists the identifiers of all elements that have to be selected. 1
A tool-support for JPDDs and constraint checking using JPDDs can be found at http://www.dawis.wiwi.uni-due.de/forschung/foci/aosd/jpdds/
Designing Design Constraints in the UML Using Join Point Designation Diagrams
63
(c) Deviation Specification Means
(a) Identifiers prin t* identifiers
Stri
regular expressions
[0..*] [0..*]
(b) Export Parameter Box
.* : .* [0..*]
?jp ?obj
paths (set.*|get.*) (..) or-operator list-wildcard
exposed elements
Fig. 5. JPDD-specific symbols (cf. [26])
JPDDs come with a set of means to specify deviations in search patterns. Examples are regular expressions which permit to specify name patterns of elements to be selected as well as the dot-dot-wildcard (..) which abstracts over an arbitrary number of parameters in a parameter list (see Figure 5c). Furthermore, JPDDs provide means to postulate the existence of paths (of arbitrary length) along class/object associations ( ), the inheritance hierarchy ( ), or the call graph ( ). All indirect paths can be annotated with a cardinality which indicates the length of the path by specifying a minimum and maximum bound. The cardinality [0..*] specified in Figure 5c states that the paths may have an arbitrary length (including length 0 meaning that the two modeled classes are the same). Further explanations on the effects of these deviation specification means and examples of their usage will be given in the subsequent subsections. 4.1.2 Example JPDD JPDDs can be specified based on an arbitrary kind of model in the UML (see [24, 26]). Due to our motivation, we consider only class diagrams till now. GUIPOSelection GUI Element
Persistent Object [0..*]
[0..*] .*
.* .*
.* .*
Attributes
.* : .* Operations
set.*(.. ) : .*
?C ?PC
Fig 6. A structural JPDD
Figure 6 illustrates a sample JPDD named GUIPOSelection. The JPDD exports the variables ?C and ?PC. ?C is bound to all classes that fulfill the following requirements: each class must directly or indirectly extend class GUIElement. Furthermore,
64
V. Stricker, S. Hanenberg, and D. Stein
the class must have at least one directed association to a class which is a (direct or indirect) descendant of PersistentObject. Furthermore, that descendant must have at least one attribute and one set-method. Such a class is bound to the variable ?PC. Figure 7 shows a class diagram that the previous JPDD can be applied to. Since POA as well as POB fulfill the criterion of being a PersistentObject and since ClassA as well as ClassB are are descendants of GUIElement that have relationships to POA and POB, a corresponding result set is created. The result set has three elements. The first one binds ?C to ClassA and ?PO to POA. Furthermore, for each relationship between ClassB and a persistent object (i.e. POA and POB), a tuple is returned. GUI Element
Persistent Object
r1
ClassA
POA Attributes
f: F
r2
ClassB
g: G
Operations
setF (f:F ) : void
r3
POB Attributes
Operations
setG (g:G ): void
Result: { {?C=ClassA, ?PC= POA }, {?C=ClassB, ?PC= POA }, {?C=ClassB, ?PC= POB }}
Fig. 7. UML model and result of JPDD
4.1.3 Relationships between JPDDs In order to create modules of JPDDs that can be combined with others, different types of relationships between JPDDs are provided which allow such a combination (cf. [25]). Three different kinds of relationships are defined: union (symbol ∪), confinement (symbol ∩) and exclusion (symbol \). Figure 8 shows how these combination relationships can be defined between two JPDDs. For each relationship it is necessary to specify which variables are considered for the combination of the JPDDs. The union combines the result sets of the source JPDD_D with the target JPDD_A. A confinement considers in the result of the source JPDD_D only those tuples whose JPDD_A
?jpd = ?jpa
JPDD_B
?jpa
?jpb
∪
∩ ?jpd = ?jpb
JPDD_D ?jpd
\
JPDD_C ?pjc
?jpd = ?jpc
Fig. 8. Relationships between JPDDs (cf. [25])
Designing Design Constraints in the UML Using Join Point Designation Diagrams
65
variables have values that are also bound to the corresponding variables in the result set of the target JPDD_B. An exclusion removes all elements from the result set of the source JPDD_D that bind the variables to values that appear in the corresponding variables in the result set of the target JPDD_C. Figure 9 illustrates an application of an exclusion relationship whereby the JPDD GUIPOSelection corresponds to the JPDD specified in Figure 6 (internal details are omitted here). The JPDD Preselection binds the variable ?C to the class ClassA. As specified in the mapping specification (attached to the combination relationship) the exclusion removes all elements from the result set of JPDD GUIPOSelection that bind the variable ?C to values that appear in the corresponding variable ?C in the result set of the target JPDD (i.e. ClassA). Consequently, the result set of GUIPOSelection, applied to the model from Figure 7 is “{?C=ClassB, ?PO=POA}, {?C=ClassB, ?PO=POB}”. Preselection
ClassA ?C
\ ?C=?C GUIPOSelection
?C ?PC
Fig 9. Example of exclusion relationship
4.2 Designing Constraints Using JPDDs This section explains how JPDDs can be used to specify design constraints. The following section discusses aspects that have to be considered when specifying constraints are specified by using JPDDs. A special focus is on the use of identifiers. Then, a necessary extension of JPDDs in order to specify constraints is explained. 4.2.1 Specifying Design Violations Before discussing how to design constraints using JPDDs, it is necessary to determine what a violation of a constraint is. Mostly, constraints are specified in a form of an all quantifier: for all elements that fulfill a certain predicate certain other predicates have to be fulfilled. For example, in order to revisit the motivating example, all classes that fulfill the view predicate (i.e. which have the corresponding stereotype) must have a corresponding relationship to a controller. Of course, an alternative would be to replace the all quantifiers by a negation of an existence qualifier. As a result, a constraint violation would be detected by finding a single element that does not comply with the constraint. A consequence of applying these considerations to JPDDs is that it is sufficient to encode a violation of a constraint in terms of one JPDD. Then, it needs to be checked whether the JPDD specifies a situation that can be found in a set of models to be checked.
66
V. Stricker, S. Hanenberg, and D. Stein
IteratorMethod .*
Iterator
f:Attributes F Operations
.*Iterator(..) : {not} .*
[0..*] .*
Fig. 10. Iterator-method constraint
Although theoretically correct, the previous consideration has a practical disadvantage. Developers who check whether their models fulfill all constraints are not only interested in a result like “the model does not fulfill the constraints”. Such developers are interested in error messages that guide them to those places in their models that violate a constraint so that they can correct the design errors quickly (if possible). Figure 10 illustrates a simple constraint from the same company introduced in section 2. The constraint expresses that each method whose name has the postfix Iterator must have Iterator (or a subtype of Iterator) as return type. Note, that the identifier ?It appears twice in this example: In the return type of the method and as a class. Figure 11 illustrates an excerpt from a class model that violates the constraint: Since there is a method mapIterator within the class IteratorFactory that does not return a subtype of Iterator, the JPDD can detect a violation. Furthermore, there is a method linkedListIterator that returns MyObjectB, which is also not a subtype of Iterator. Factories Iterator
IteratorFactory f:Attributes F Operations
collectionIterator(c:Collection) : Iterator listIterator(l:List) : ListIterator treeIterator(t:Tree) : TreeIterator mapIterator(m:map) : MyObjectA linkedListIterator(l:LinkedList): MyObjectB …
ListIterator TreeIterator MyObjectA
MyObjectB
Fig. 11. Model violating the constraint IteratorMethod
It seems obvious that the constraint checker should notify the developer about both methods that are considered to be wrong. However, a general problem is that it cannot be concluded from the JPDD itself what the failing elements in the model are. Possible wrong elements are the package that contains IteratorFactory, the IteratorFactory, the methods mapIterator and linkedListIterator, or the classes MyClassA and MyClassB (or maybe even combinations of them). Consequently, it cannot be concluded from the JPDD how many design errors exist, nor where the developer should start his/her search for finding and correcting the design errors.
Designing Design Constraints in the UML Using Join Point Designation Diagrams
67
IteratorMethod Attributes
Iterator
.*
Operations
.*Iterator(..) : {not} .*
[0..*] .*
?m
Fig. 12. Iterator-method constraint (revised)
Due to this ambiguity, developers of constraints need to make explicit which elements should be told to the developer who checks his/her model for validity. This is done by specifying corresponding export parameters. Constraint checking based on JPDDs evaluates constraints and creates an error notification for each bound value in the result set of the selection. According to this, figure 12 revises the previous constraint by adding an additional identifier ?m. The identifier binds the method with the postfix Iterator and the wrong return type, and exports it via the parameter box. Consequently, the developer now considers only the method to be wrong. The classes MyObjectA and MyObjectB are not considered to violate the constraint. 4.2.2 Extension of JPDDs for constraints In order to specify constraints using JPDDs it is necessary to annotate those JPDDs that represent constraints. Examples of JPDDs that do not represent constraints are those ones that are used by another JPDD by means of JPDD combination relationships. Such JPDDs should not be evaluated alone in order to determine design errors. ClassesWithCapitalLetters {A-Z}.* ?C
\ ?C=? C WrongClassName .* ?C
Fig. 13. Constraint consisting of more than one JPDD
Figure 13 illustrates an example of such a JPDD. The JPDD ClassesWithCapitalLetters selects all classes whose name starts with capital letters (expressed by the corresponding regular expression {A-Z}.*). The JPDD WrongClassName selects all classes that start with just any letters. The intention of the constraint is to make explicit the correct designation of class names (in ClassesWithCapitalLetters) and to select all classes that do not comply with it. From the example, it seems obvious that the JPDD ClassesWithCapitalLetters should not be executed on a model alone, but only in combination with WrongClassName.
68
V. Stricker, S. Hanenberg, and D. Stein
However, from the relationship between both JPDDs this cannot be concluded: it is also possible that WrongClassName is only an extension/refinement of a previous selection. Hence, JPDDs need to be extended in order to handle constraints. Therefore, we extend JPDDs by means of a special stereotype «Constraint». Only JPDDs annotated with this stereotype are considered for constraint checking, all others are not. 4.2.3 Representing Design Errors While the detection of erroneous UML elements according to the above description is not hard, a problem occurs in the representation of errors. The company mentioned in section 2 has diagrams that consist of more than thousand classes and it turned out that sometimes a few hundred methods, fields or classes violate the set of constraints. Because of that, a pure textual representation of error messages is not acceptable, because it is hard to determine for developers in which parts of the models the constraint violations occur. Furthermore, for developers it is essential that error messages can be used in a way that permits developers to see directly where a given violation of constraints comes from. Due to this, constraint checking based on JPDDs considers the representation of design errors in terms of the UML: the result of a constraint check is a UML diagram in which all elements that violate a given constraint are annotated. This annotation is achieved by special stereotypes that are constructed only for the purpose of representing design errors. Such stereotypes are prefixed with the string “false_” in addition to the name of the responsible constraint. In order to make it easier for developers to determine within a large set of diagrams which elements are erroneous, all elements that contain erroneous elements are annotated with a special stereotype prefixed with “containsFalse_” followed by the corresponding constrained name. <
> Factories
<> IteratorFactory f:Attributes F Operations
collectionIterator(c:Collection) : Iterator listIterator(l:List) : ListIterator treeIterator(t:Tree) : TreeIterator <> mapIterator(m:map) : MyObjectA <> linkedListIterator(l:LinkedList): MyObjectB …
Fig. 14. Model violating the constraint IteratorMethod
Figure 14 illustrates the representation of design errors of the Iterator method constraint (Figure 12) applied to the previous UML model (Figure 11). The constraint exports the failing methods as parameter. Consequently, the corresponding methods are annotated with the stereotype <>. All owning elements (the class IteratorFactory as well as the package Factories) receive the stereotype <>.
Designing Design Constraints in the UML Using Join Point Designation Diagrams
69
By annotating owning members that contain erroneous elements, it is easy for the developer to navigate with his/her UML tool to the corresponding element that cause the violation of the constraint.
5 Revisiting the Problem In this section we revisit the specification of constraints in the context of the ModelView-Controller architectural pattern. We discuss how we specify a corresponding constraint definition and what the implications of such constraint definitions are. First, the correct relationships between views and controllers are specified in a JPDD ViewsControllers (see Figure 15). The class descriptions just contain the required stereotypes and the association between the classes. The association has the necessary name “has” with the corresponding role names “view” and “controller”. Since it is permitted to have cardinalities 1 as well as 1..* on the view-side, we specify a corresponding criterion [1..*] which matches both. Since on the controller side only a cardinality of 1 is permitted, our specification includes this cardinality. The specified JPDD matches all classes which have the corresponding stereotypes as well as the corresponding relationship. The JPDD itself does not describe a selection criterion of elements that contradict with the constraint we are about to define. Hence, the JPDD is not annotated with the stereotype «constraint». The benefit of a diagram such as Figure 15 is that it directly illustrates the underlying architectural guideline. Instead of specifying what is not valid, the constraint includes a JPDD that can be directly used by the developers as a template to create their valid models. Since this diagram directly illustrates the correct use of view and models, we consider it as easily readable and understandable. ViewsControllers <> .* view
[1..*] has
[1] controller
<< controller>> .* ?v ?c
Fig. 15. Correct use of views and models
We need to decide which elements should be bound to and exported by variables. In principle, we have the possibility to bind all elements (classes, associations, association names, cardinalities) to corresponding identifiers. The positive benefit of such an approach would be that errors can be communicated on a very fine-grained level: For example, it would be possible to indicate for an association that has e.g. wrong cardinalities which of those cardinalities contradict the constraint. However, the negative impact would be that the diagram becomes polluted with identifiers, since in such a case the export box would have seven instead of two parameters. Furthermore, each element in the diagram would have a corresponding identifier, which from our point of view has a negative impact on the readability and understandability of the JPDD.
70
V. Stricker, S. Hanenberg, and D. Stein
∪
ViewsControllers ?v
?v =?v ?c=?c
?c
AbstractViews <> .*
∪
?v ?c
?v =?v ?c=?c
AbstractControllers <> .* ?v ?c
Fig. 16. Consideration of abstract views and controllers
Since our main intention is to make constraint definitions more understandable for the developers, we decide here to export only the classes. Note that for understanding the constraint definition in Figure 15, it is only necessary to know the binding mechanism of variables in JPDDs and the export of such variables. Based on the ViewsControllers we need to add the possibility that views as well as controllers which are abstract do not violate the constraint. Consequently, we specify a selection criterion that selects all views and controllers which are abstract (and thus extend our "template" of valid elements). Figure 16 illustrates the corresponding two JPDDs in which the classes to be selected are specified to be abstract due to the class identifiers written in italics. Again, the essential part of these JPDDs is the selection of abstract classes by using familiar UML notations.
AbstractControllers
/
?v ?c
?v =?v
<>Views
/
<> .* ?v
?c =?c
<>Controllers <> .* ?c
Fig. 17. Constraints for views and controllers
Based on these JPDDs we are able to specify the constraint (Figure 17): we need to select all views and controllers that do not match the previous selection criterions. Since we are interested in notifying developers about errors in view as well as in controller definitions, we specify a constraint for views as well as for controllers. Both constraints have an exclusion relationship to the AbstractControllers selection. The specification of the view-controller constraint requires five JPDDs. Two of them are the constraints – a single constraint handles the corresponding wrong views and controllers. Only two variables are exposed by the non-constraint JPDDs. As
Designing Design Constraints in the UML Using Join Point Designation Diagrams
71
discussed above, a consequence of this is a slightly reduced way of error notification of the results but a better understandable constraint specification.
6 Tool Support The Modeller for JPDDs (M4JPDD) is an Eclipse-based tool which has specially been implemented to support users with an interface to create, to save and to load JPDDs. It is implemented as an Eclipse plugin which is based on several other Eclipse plugins that allow creating graphical editors within the workbench of Eclipse. These plugins are the Eclipse Modeling Framework (EMF), the Graphical Editing Framework (EMF) and UML2. Thus, the M4JPDD editor is also based on the UML meta-model since it uses the UML2 Eclipse plugin that defines all elements of the UML specification. Besides these UML elements, the models of the M4JPDD contain some JPDDspecific selection mechanisms like identifiers etc., which are defined in the editor by using the UML build-in extension mechanisms. It uses a UML2 profile to adapt the UML2 meta-model to its own needs. The JPDDs are stored as XMI-files, which support the interchange of the diagrams with other EMF/UML-based tools. The availability of this format is essential for the constraint checker as no vendor-relevant information has to be considered. It is easy to traverse tree structures when searching for elements of the models and enables the annotation of the found constraint violations that can be interpreted by all UML2 based modeling tools. The constraint checker is an extension of the M4JPDD. It includes specific modeling elements as part of the UML2 profile and uses the XMI files of the constraint models to extract the modeled query. The query is performed on the XMI files of the models that have to be checked.
7 Related Work Currently, OCL is the de facto standard in UML to define design constraints. Thus, a lot of approaches and tools have been developed that resort to OCL as a constraint specification means. A survey about such approaches and tools can be found in [3]. One of the first systems supporting OCL was the UML Specification Environment (USE) [23]. This approach makes use of snapshots that represent system states at a particular point in time and that can be used to check the constraints. The approach is limited to the check of dynamic behavior of the system, and thus it cannot be used to check design constraints, which is the focus of this paper. Other examples of OCL tools are the Dresden OCL Toolkit2, OCL Environment (OCLE) [4], or Octopus3. These tools are a great help in specifying OCL constraints and verifying their compliance in a given model. However, they do not provide a graphical means for modeling the constraints. Furthermore, they mainly focus on the evaluation of well-formedness-rules and/or invariants. The approach presented in this paper, on the contrary, takes a different (slight and subtle) perspective on the 2 3
http://dresden-ocl.sourceforge.net/ http://octopus.sourceforge.net/
72
V. Stricker, S. Hanenberg, and D. Stein
specification of constraints (i.e. specification of design guidelines instead of the specification of invariants, etc.), and it provides a visual notation to represent them. Checking Design Constraints An approach that specifically focuses on checking the correct usage of design patterns in UML models is presented in [14]. The approach uses patterns described in a Role Based Metamodelling Language (RBML) [13] that defines patterns in terms of pattern roles. The patterns and the models that have to be checked are composed into blocks. If all blocks are correct the class diagram is assumed to be correct regarding the pattern. Tool support is provided by a prototype which is an add-in for Rational Rose. However, a graphical visualization of errors is not supported. Another (rule-based) approach that aims at finding inconsistencies which go beyond the well-formedness-rules of UML is presented in [15]. Different classes of inconsistencies, which also include the class ‘Conformance to Constraints and Standards’, are defined. This class explicitly examines design aspects which are not within the scope of the requirements but are caused by design patterns and standards. The presented tool RIDE can be integrated in existing UML tools but does not support any graphical notation of constraints or support for error correction. There are also approaches for using (aspect-oriented) programming language constructs for checking design failures. First, the programming language AspectJ [5] provides language constructs (so-called error or warning declaration) that permit to specify constraints that are checked at compile time. However, due to the rather restrictive pointcut language, the constraints that can be expressed using such language features are rather trivial. A similar approach is proposed by Morgan et al. [18]: a language is proposed, which is called Program Description Logic (PDL), similar to AspectJ, which actually allows specifying violations of design rules and detecting them. “PDL is based on a fully static and expressive pointcut language.” Instead of imposing design rules on pointcuts, this approach rather uses them to specify design rules on object-oriented systems. Constraint Visualization Other approaches to visualize constraints include Constraint Diagrams [11] or Visual OCL [1, 12]. Constraint Diagrams, as well as their successors Spider Diagrams [8], represent a graphical notation to specify invariants on objects and their associations (i.e., links) depending on the state they are in. They strictly focus on runtime constraints. As a consequence, the notation does not permit the specification of design constraints (which are static). For example, the notation does not provide means to refer to particular attributes and operations, and thus no design constraints can be specified on their signatures. Visual OCL is a graphical notation to express OCL constraints. It provides graphical symbols for all OCL keywords. Although Visual OCL tries to use existing UML notation elements, these are not rich enough to express all elements defined in the OCL meta-model so that developers need to get used to the new notation elements. These symbols are part of every diagram, which sometimes adds significant 'noise' to the visualization. When specifying design constraints, such as those presented in this paper, Visual OCL constraints would be specified in terms of UML meta-model elements – rather than in terms of UML's concrete syntax, as the approach presented in
Designing Design Constraints in the UML Using Join Point Designation Diagrams
73
this paper does. In consequence, developers are burdened with the full complexity of UML's metamodel – something which they usually do not encounter get in touch with during daily work. Use of Concrete Syntax The idea of specifying something in terms of user entities rather than in terms of metadescriptions compares to the approach of Query-By-Example (QBE) [29], which is a common query technique in the database domain nowadays. The idea is to specify sample model entities, having sample properties, and determine how selected model elements must relate to (may deviate from) such samples. JPDDs have followed this idea since a long time (cf. [24]). The idea has been adopted recently by other modeldriven approaches, too, such as model transformation languages (e.g. [9, 28]). Model Queries As proposed in this paper, design constraints on models can be specified in terms of (sequential) model queries. Accordingly, the approach presented in this paper relates to the magnitude of query and transformation languages in the domain of modeldriven development. Examples are UMLAUT [7], KerMeta [17], MOLA [10], and QVT [19]. A common problem of these transformation languages is that they specify model queries in terms of meta-model entities. This is of great value (if not inevitable) when a transformation needs to be applied to multiple model elements of different metatypes, or to model elements that have no explicit graphical representation in user model diagrams. However, it hinders the comprehension of the query by the uneducated developer.
8 Discussion and Conclusion In this paper we described the specification of design constraints on UML models using Join Point Designation Diagrams (JPDDs). We motivated the need for such an approach by describing the difficulties developers have who are familiar with the UML but not with the constraint language. The motivation was given by a concrete industry setting in the area of model-driven development. We introduced JPDDs which are lightweight extensions of the UML and which provide means to specify constraints using JPDDs. We discussed the impact of constraint design using JPDDs by illustrating the use of the provided relationships and identifiers. Furthermore, we described the need for a visual representation of design error notifications in order to guide the developers through finding and fixing design errors. Finally, we showed the applicability of JPDD-based constraints by means of an example. We consider the main advantage of JPDD-based constraints that they permit to specify constraints in a way that developers are immediately aware how a model that does not violate a given constraint should look like. For example, as exemplified in the MVC-example, developers directly see from the constraint specification (in the JPDD ViewsControllers) how views and controllers are related to each other. Consequently, the understanding of constraints and detecting errors in models becomes relatively easy. Furthermore, since JPDDs are closely related to the UML, developers
74
V. Stricker, S. Hanenberg, and D. Stein
can be relatively easy motivated to express further design constraints – although they are not educated in a further, additional constraint language. Although we are able to express most of the constraints desired by the mentioned company, there are situations where the expressiveness of JPDDs is not sufficient. The main reason for this problem is that the value bindings of export parameters are not ordered. Furthermore, we currently see situations where it is desirable to provide identifiers which are not only bound to single variables, but to collections of variables. We currently cannot estimate how essential such language features are and how they can be integrated into JPDDs. Hence, such a study is future work to be done. Our proposal of error visualization turned out to be very useful for the practical application of JPDDs. Nevertheless, we also see difficulties. For example, an element can be considered to be erroneous due to some missing owned elements. In such a situation is seems desirable not only to mark this element as erroneous, but to make a proposal as to which owned elements are missing. Our current approach is not able to make such a proposal, but we are investigating means to integrate such proposals. Our current tool support for JPDDs is quite restricted. We heavily rely on the XMI format provided by the current UML2 API. This reduces the applicability of JPDDbased constraints, since in order to specify such constraints in other tools, it is currently necessary to convert XMI formats. Although these problems exist, we are convinced that constraints on models should be expressed in terms of the modeling language itself, since this reduces the effort for developers to learn and understand the constraint language itself as well as constraints written in it. From our point of view, JPDDs can significantly improve the development of software developed in a model-driven way.
References 1. Bottoni, P., Koch, M., Parisi-Presicce, F., Taentzer, G.: A Visualization of OCL Using Collaborations. In: Gogolla, M., Kobryn, C. (eds.) UML 2001. LNCS, vol. 2185, pp. 257–271. Springer, Heidelberg (2001) 2. Buschmann, F., Meunier, R., Rohnert, H., Sommerlad, P., Stal, M.: Pattern-Oriented Software Architecture: A System of Patterns. John Wiley & Sons, Chichester (1996) 3. Cabot, J., Teniente, E.: Constraint Support in MDA Tools: A Survey. In: Rensink, A., Warmer, J. (eds.) ECMDA-FA 2006. LNCS, vol. 4066, pp. 256–267. Springer, Heidelberg (2006) 4. Chiorean, D., Paşca, M., Cârcu, A., Botiza, C., Moldovan, S.: Ensuring UML models consistency using the OCL Environment. In: Workshop Proc. on OCL 2.0 – Industry Standard or Scientific Playground?, November 2004. ENTCS, vol. 102, pp. 99–110. Elsevier, Amsterdam (2004) 5. Colyer, A., Clement, A., Harley, G., Webster, M.: Eclipse AspectJ: Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools. Addison-Wesley, Reading (2005) 6. Hanenberg, S., Stein, D., Unland, R.: From aspect-oriented design to aspect-oriented programs: tool-supported translation of JPDDs into code. In: Proc. of AOSD 2007, Vancouver, Canada, March 2007, pp. 49–62. ACM, New York (2007)
Designing Design Constraints in the UML Using Join Point Designation Diagrams
75
7. Ho, W.M., Jézéquel, J.M., Le Guennec, A., Pennaneac’h, F.: UMLAUT: An Extendible UML Transformation Framework. In: Proc. of ASE 1999, Cocoa Beach, Florida, October 1999, pp. 275–278. IEEE, Los Alamitos (1999) 8. Howse, J., Molina, F., Taylor, J., Kent, S., Gil, J.Y.: Spider Diagrams: A Diagrammatic Reasoning System. Journal of Visual Languages & Computing 12(3), 299–324 (2001) 9. Jayaraman, P., Whittle, J., Elkhodary, A., Gomaa, H.: Model composition in product lines and feature interaction detection using critical pair analysis. In: Engels, G., Opdyke, B., Schmidt, D.C., Weil, F. (eds.) MODELS 2007. LNCS, vol. 4735, pp. 151–165. Springer, Heidelberg (2007) 10. Kalnins, A., Barzdins, J., Celms, E.: Model Transformation Language MOLA. In: Aßmann, U., Aksit, M., Rensink, A. (eds.) MDAFA 2003. LNCS, vol. 3599, pp. 62–76. Springer, Heidelberg (2005) 11. Kent, S.: Constraint Diagrams: Visualizing Assertions in Object-Oriented Models. In: Proc. of OOPSLA 1997, Atlanta, Georgia, October 1997, pp. 327–341. ACM, New York (1997) 12. Kiesner, C., Taentzer, G., Winkelmann, J.: Visual OCL: A Visual Notation of the Object Constraint Language, TR 2002/23, Technical University Berlin (2002) 13. Kim, D., France, R., Ghosh, S., Song, E.: A Role-Based Metamodeling Approach to Specifying Design Patterns. In: Proc. of COMPSAC 2003, Dallas, Texas, November 2003, pp. 452–459. IEEE, Los Alamitos (2003) 14. Kim, D.-K., Shen, S.: An approach to evaluating structural pattern conformance of UML Models. In: Proc. of SAC 2007, Seoul, Korea, March 2007, pp. 1204–1208. ACM Press, New York (2007) 15. Liu, W.Q., Easterbrook, S., Mylopoulos, J.: Rule-Based Detection of Inconsistency in UML Models. In: Workshop Proc. on Consistency Problems in UML-Based Software Development, UML 2002, Dresden, Germany, October 2002, pp. 106–123 (2002) 16. Mellor, S., Scott, K., Uhl, A.: MDA Distilled: principles of model-driven architecture. Addison-Wesley Professional, Reading (2004) 17. Muller, P.A., Fleurey, F., Jézéquel, J.M.: Weaving executability into object-oriented metalanguages. In: Briand, L.C., Williams, C. (eds.) MoDELS 2005. LNCS, vol. 3713, pp. 264–278. Springer, Heidelberg (2005) 18. Morgan, C., Volder, K.D., Wohlstadter, E.: A static aspect language for checking design rules. In: Barry, B.M., de Moor, O. (eds.) Proceedings of the 6th International Conference on Aspect-Oriented Software Development (AOSD 2007), Vancouver, British Columbia, Canada, March 12-16, 2007. ACM International Conference Proceeding Series, vol. 208, pp. 63–72. ACM, New York (2007) 19. OMG, MOF QVT final adopted specification, Version 1.0 beta 2 (OMG Document: ptc/05-11-01) (November 2005) 20. OMG, MOF XMI Mapping Specification, Version 2.1 (OMG Document: formal/05-09-01) (September 2005) 21. OMG, Unified Modeling Language Specification, Version 1.5 (OMG Document: formal/03-03-01) (March 2003) 22. Reenskaug, T.: Models - Views - Controllers, Xerox PARC technical note (December 1979) 23. Richters, M., Gogolla, M.: Validating UML Models and OCL Constraints. In: Evans, A., Kent, S., Selic, B. (eds.) UML 2000. LNCS, vol. 1939, pp. 265–277. Springer, Heidelberg (2000)
76
V. Stricker, S. Hanenberg, and D. Stein
24. Stein, D., Hanenberg, S., Unland, R.: A Graphical Notation to Specify Model Queries for MDA Transformations on UML Models. In: Aßmann, U., Aksit, M., Rensink, A. (eds.) MDAFA 2003. LNCS, vol. 3599, pp. 77–92. Springer, Heidelberg (2005) 25. Stein, D., Hanenberg, S., Unland, R.: On relationships between query models. In: Hartman, A., Kreische, D. (eds.) ECMDA-FA 2005. LNCS, vol. 3748, pp. 254–268. Springer, Heidelberg (2005) 26. Stein, D., Hanenberg, S., Unland, R.: Query Models. In: Baar, T., Strohmeier, A., Moreira, A., Mellor, S.J. (eds.) UML 2004. LNCS, vol. 3273, pp. 98–112. Springer, Heidelberg (2004) 27. Warmer, J., Kleppe, A.: The Object Constraint Language: Precise Modelling with UML. Addison-Wesley, Reading (1998) 28. Whittle, J., Moreira, A., Araújo, J., Rabbi, R., Jayaraman, P., Elkhodary, A.: An expressive aspect composition language for UML state diagrams. In: Engels, G., Opdyke, B., Schmidt, D.C., Weil, F. (eds.) MODELS 2007. LNCS, vol. 4735, pp. 514–528. Springer, Heidelberg (2007) 29. Zloof, M.: Query-by-Example: A Data Base Language. IBM Systems Journal 16(4), 324–343 (1977)
Stream-Based Dynamic Compilation for Object-Oriented Languages Michael Bebenita, Mason Chang, Andreas Gal, and Michael Franz University of California, Irvine
Abstract. Traditional just-in-time compilers operate at the granularity of methods. Compiling a method in such a compiler is an atomic operation that can require substantial amounts of processing time, resulting in execution pauses in interactive computing environments. We describe a new software architecture for dynamic compilers in which the granularity of compilation steps is much finer, forming a “pipeline” with completely linear runtime behavior, and in which there are only two write barriers. This means that on future many-core platforms, the compiler itself can be parallelized, providing high-throughput dynamic compilation without execution pauses. As our prototype for Java demonstrates, stream-based compilation lends itself very naturally to an object-oriented implementation.
1 Introduction Most just-in-time (JIT) compilers operate at the granularity of methods. Apart from the fact that it happens at run-time, the actual process of compilation is often not much different from the way this is done in traditional compilers: First, an intermediate representation incorporating a control-flow graph is built for the entire method. Then, a series of optimization steps is applied, until finally a program in the target instruction set is obtained. An important downside of this approach is that the compilation of each method is an atomic operation that cannot be decomposed, due to complex internal data structures and interdependencies. We have been working on an alternative compilation strategy in which no controlflow graph is ever constructed, but in which relevant (i.e., frequently executed) control flows are instead discovered lazily during execution. We have built a family of compilers [12,8,11] that dynamically detect “hot” code paths, so-called “traces,” and that then generate code on-the-fly for exactly these code paths—all other parts of the program are executed by interpretation only. In this paper, we will focus on our dynamic JIT compiler for the Java Virtual Machine (JVM) bytecode language (JVML). Our compiler first dynamically detects loop headers and then incrementally discovers alternative paths through the resulting loops. For example, an if statement inside of a while statement corresponds to two different paths through the while loop. Each time that a new path through the loop that hasn’t been recorded before becomes sufficiently “hot,” we recompile all known paths through the loop, re-balancing the processor resources expended on the alternatives. In the following, we report how re-compiling the different code paths through a loop can be pipelined in a compiler and implemented quite elegantly in an object-oriented M. Oriol and B. Meyer (Eds.): TOOLS EUROPE 2009, LNBIP 33, pp. 77–95, 2009. c Springer-Verlag Berlin Heidelberg 2009
78
M. Bebenita et al.
fashion as a series of filters through which a program passes on its way from intermediate representation to target code. Each compiler phase is implemented as a separate filter that manipulates the instruction “stream” by altering, inserting, re-ordering, or removing instructions as the “stream” passes through it. Even more interestingly, the pipeline requires only two synchronization points, meaning that the compilation activity can be highly parallelized on a a future many-core platform in which there are idle processor resources available. The remainder of this paper is organized as follows. In Section 2, we describe how alternative paths through a program are discovered lazily and recorded in a representation that we call a “Trace Tree”. In Section 3, we show how such Trace Trees can be serialized in such a way that correct compilation semantics result from a set of linear passes over the serialized tree. This is the basis for the idea of pipelining these passes, which is discussed in Section 4. In Section 5 we report on a series of benchmarks that demonstrate the performance of our compiler pipeline. In particular, run-time is directly proportional to the length of the serialized tree. Related work is discussed in Section 6. We conclude in Section 7.
2 Trace Trees Our stream-based JIT compiler for the Java Virtual Machine (JVM) bytecode language (JVML) is embedded in a mixed-mode execution environment, i.e., bytecode is initially interpreted and only frequently executed (“hot”) code is ever compiled. To detect such “hot” code regions that are suitable candidates for dynamic compilation, we use a simple heuristic first introduced by Bala et al. [2]. In this scheme, the interpreter keeps track of backward branches; the targets of such branches are often loop headers. For each target of a backward branch, we keep a counter of how often a backward branch has terminated at this location. When the counter exceeds a certain threshold, a loop header has been discovered. The interpreter then records the instruction path subsequently taken, starting with the loop header. If that path leads back to the loop header within a certain observation window and fulfills certain other criteria, then we have recorded an initial trace through the loop. There may be other paths through the loop that may be disovered later. The trace is then compiled and the resulting target code is executed. Forward branches inside of a trace indicate alternative paths that may not yet have been discovered by our compiler. For example, in the case of our if statement inside of a while statement, when we initially discover the loop, we only follow one path through the loop. If indeed the if condition is so biased that only one of the two alternatives is ever taken sufficiently often, then our compiler will never generate code for the rare alternative. If the second path is common, then it will eventually be compiled as well. Branches to paths that have not yet been seen by our compiler are compiled into guard instructions. When such a guard fails, that means that we have arrived at a path that has not yet been compiled. This is called a “side exit” from the loop. In this case, the compiled code hands control back to the interpreter. Since this can be expensive, our
Stream-Based Dynamic Compilation for Object-Oriented Languages
79
JIT compiler attempts to compile the alternative path that led to the side exit as well. For this, at every side exit we resume interpretation, but at the same time we restart the trace recorder to record instructions starting at the side exit point. These secondary traces are completed when the interpreter revisits the original loop header. This results in a tree of traces, spanning all observed paths through the “hot” code region. The rest of this paper explains how we compile such Trace Trees. We also inline method invocations into the trace. In case of a static method invocation, the target method is fixed and no additional runtime checks are required. For dynamically dispatched methods, the trace recorder inserts a guard instruction to ensure that the same actual method implementation that was found during the trace recording is executed. If the guard fails, a regular dynamic dispatch is repeated in the interpreter. If the guard succeeds, we have effectively performed method specialization on a predicted receiver type. Since our compiler can handle multiple alternative paths, eventually our compiler specializes method invocations for all commonly occurring receiver classes. Creating separate traces for all alternative paths through a loop can potentially lead to very large Trace Trees, especially if separate specialized versions of the same code are being generated for many different receiver classes. Hence, current trace compilers use heuristics to limit tree growth. While this is necessary in contexts in which resources are limited, such as just-in-time compilers for embedded and portable computers, it may not be the best strategy for server-class dynamic compilers. The work presented here shows that if memory consumption is not a concern and a just-in-time compiler keeps growing Trace Trees to very large sizes to capture all executed program paths, compilation effort will still be linear in the size of the tree. Moreover, compilation itself can possibly be parallelized. This means that it may very well be beneficial to capture all the paths through a server program. The linear runtime complexity behavior that we report in this paper is a significant result that will hopefully aid future designers of server-class dynamic compilers, while the simplicity and elegance of the pipeline-based approach will likely appeal to compiler designers across the whole spectrum of target platforms.
3 Compiling Traces Trees with Tree Serialization During trace recording, we perform stack deconstruction and generate an equivalent three address code intermediate representation of JVM bytecode. Each instruction points to the instructions that generated the values of its operands and also points to the instruction immediately preceding it. If a side exit occurs, we link the first instruction in the side trace to the guard instruction that caused the side exit. Thus, a guard instruction can connect at most two traces and each node in a Trace Tree can have at most two successors linking to it. Effectively, a Trace Tree is structured like a binary tree with reversed edges. For example, the code fragment in Figure 1 is eventually transformed into a Trace Tree such as the one in Figure 2. The exact order in which the different paths through the code are discovered and ultimately appear in the tree is correlated to their execution frequency.
80
M. Bebenita et al.
while (...) do { . . . D := ...; // initial definition of D . . . if (... != ...) then { . . . ... := ...D...; // first use of D in an expression . . . ... := ...D...; // second use of D in an expression } else { . . . ... := ...D...; // third use of D in an expression . . . if (... <= ...) then { . . . } else { . . . ... := ...D...; // 4th use of D in an expression . . . } } }
Fig. 1. A code fragment for the purpose of illustrating Trace Tree dominator ordering. Inside a loop, value D is computed and subsequently used in 4 other expressions. Note that D may be a subexpression identified by the compiler and need not necessarily be explicitly assigned to a variable.
The branches of a Trace Tree observe an inherent ordering in which dominating instructions always precede dominated ones, which follows naturally from the way traces are recorded. A preorder depth first traversal of the Trace Tree guarantees that all instruction definitions are seen before any of the uses while the reverse of this guarantees that all uses are seen before any of the definitions. This reversed preorder traversal allows us to serialize arbitrary Trace Trees without losing any information. Since a preorder depth first traversal is not possible using our reversed binary tree data structure, we maintain a back pointing linked list of tail instructions as shown in Figure 2 which allows us to traverse the tree in reversed preorder. This is the order in which Trace Trees are serialized for the compilation pipeline. 3.1 Compilation Pipeline The compilation pipeline is organized as a series of filters that are chained together. At each point in the pipeline, a filter can remove instructions, modify already existing instructions, re-order instructions, or simply introduce new instructions. Trace Trees are serialized and piped through the first filter in the compilation pipeline. Each filter receives one instruction at a time and forwards it to the next filter until the instruction reaches the final compilation filter, where the instruction is removed from the pipeline. Filters that remove instructions from the pipeline simply do not forward them along, while filters that introduce instructions forward extra instructions. This pipelined architecture makes it easy to construct complex instruction assembly lines. Further in the paper we discuss how the pipeline can be extended to provide various levels of parallelism.
Stream-Based Dynamic Compilation for Object-Oriented Languages
81
HEADER Definition
D
!= Use
U1 U3 U2
> U4
TAIL
TAIL
TAIL
0
1
2
Reverse Dominator Order
Fig. 2. Example of a Trace Tree for the code fragment in Figure 1. Code paths are added to the Trace Tree in the order in which they are discovered, with the respective branch condition reversed as necessary. As alternative paths through the loop are discovered, they are connected to the guards for the respective branch conditions. The dotted line shows the reversed dominator order used to serialize Trace Trees through the pipeline. This order guarantees that all uses of an instruction are seen before its definition. The reversed dominator order for instructions referencing value D in this tree is U4, U3, U2, U1, D.
3.2 Object-Oriented Modeling: Instruction Class Hierarchy We make extensive use of the “Visitor” Pattern [22,13] in our compiler architecture. Each compilation filter is in fact a visitor over a sequence of instruction objects. Instructions in our intermediate representation are modeled as class objects and are organized in a class hierarchy based on the instruction’s form. The base class of the instruction hierarchy is the abstract Instruction class. From this base class, we derive classes based on the instruction’s operands such as the UnaryInstruction and BinaryInstruction classes. The ADD instruction, for instance, is derived from the BinaryInstruction class as it operates on two operands. This architecture allows us to write optimizations that operate at various levels in the class hierarchy rather than just on leaf classes. It also enables us to neatly separate the implementation of our optimization algorithms from the details of our intermediate representation by making use of the Visitor Pattern.
82
M. Bebenita et al.
Message
Control Messages
Instruction
Unary Instruction
Binary Instruction
Neg
Add
Fig. 3. Partial view of the instruction class hierarchy. Instructions are organized based on instruction form. The root of the hierarchy is the Instruction class, however from an implementation standpoint it is convenient to create another level of abstraction, the message class.
Instruction i = new Instruction.ADD(leftOperand, rightOperand); i.accept(new InstructionVisitor() { @Override void visit(Instruction.BinaryInstruction i) { // visited for all binary instructions } });
Fig. 4. Example code using the visitor method hierarchy to implement a visitor action for an entire class of instructions at once (here binary instructions).
The pipeline architecture necessitates a demarcation of individual trees and traces. When Trace Trees are serialized, a TreeBegin notification is sent down the pipeline, followed by a TraceBegin notification, followed by a sequence of instructions, and then terminating with a TraceEnd and TreeEnd notification. If a tree has multiple traces, then multiple trace begin/end notifications are sent. These control messages extend the Instruction hierarchy to include the root Message class from which both Instruction and each of the individual control message classes inherit (Figure 3). In our architecture, the Instruction class provides an abstract accept method with an InstructionVisitor object as an argument. Each concrete implementation of the Instruction class overrides the accept method and invokes the visit method on the visitor object using the instruction’s own declared type. The default implementation of the InstructionVisitor class defines visit methods for all instruction class types. Figure 4 shows a Java program that uses the visitor method hierarchy to implement a visitor action for an entire class of instructions at once. The Instruction.ADD class provides a concrete implementation of the accept method declared in
Stream-Based Dynamic Compilation for Object-Oriented Languages
83
Instruction. Here, the visit(Instruction.ADD) method is invoked on the visitor object that is passed into the accept method. The base class implementation of the method visit(Instruction.ADD) forwards the invocation to the base class virtual method visit(Instruction.BinaryInstruction), which in turn invokes the catch-all method visit(Instruction). This chain of invocations that bubble up to the root of the instruction hierarchy allows us to hook into the instruction hierarchy at any level by extending the InstructionVisitor class and overriding a visit method. In this example program, by overriding the implementation of the method visit(Instruction.BinaryInstruction) in the anonymous class, we provide an implementation for all binary instructions including the Instruction.ADD instruction which derives from BinaryInstruction. 3.3 Filter Pattern In our pipelined compiler architecture, compilation filters are implemented as classes derived from Filter (Figure 5), which derives from InstructionVisitor. Filters also implement the Sink interface which exposes the receive method. This is the entry point through which instructions are fed into a filter. Filters accept the incoming instruction and visit it using themselves as an instruction visitor. By default, filters bubble up instructions through a chain of accept method invocations all the way to the root of the instruction hierarchy, at which point instructions are forwarded to the next filter. The code for a compilation filter that performs Common Subexpression Elimination using Value Numbering [23] is shown in Figure 6. In this example, the CSE class overrides the visit methods for unary, binary, and constant instructions. All other instructions are allowed to pass through the filter untouched. However, for the above mentioned instructions, the CSE filter performs value numbering and keeps a list of previously seen values. If an instruction’s value has been seen before, the instruction whose value has been seen takes the place of the current instruction. This is done by keeping a pointer in every instruction to an instruction that replaces it. Further in the pipeline, instructions that are not referenced are eliminated. The CSE filter cannot eliminate redundant instructions because it has no knowledge of future instructions that may reference a redundant instruction. Therefore a forwarding pointer is used instead to indicate that an instruction is substituted with another. Throughout the pipeline, we follow this forwarding chain of instructions every time an operand is accessed. 3.4 Baseline Compiler Our baseline non-optimizing compiler is assembled from only two filters (Figure 7), a Clone filter followed by the Assembler filter. The Clone filter makes a copy of every instruction it receives and forwards along the copy instead of the original. This is done to ensure that the compilation pipeline does not adversely change the instructions in the original Trace Tree data structure which is constantly extended and recompiled as new traces are added to the tree. The Assembler filter performs platform specific register allocation and instruction selection/assembly. The final machine code output is then executed by the interpreter once it reaches the Trace Tree’s anchor instruction.
84
M. Bebenita et al.
MessageVisitor void visit(Message m) {} void visit(BeginTree m) { visit((Message)m); } void visit(EndTree m) { visit((Message)m); } ...
InstructionVisitor void visit(Instruction i) { visit((Message)m); } void visit(BinaryInstruction i) { visit((Instruction)i); } void visit(Add i) { visit((Instruction)i); } ...
Filter Sink receiver; Filter(Sink receiver) { this.receiver = receiver; } void receive(Message m) { m.accept(this); } @Override void visit(Message m) { receiver.receive(m); }
<> Sink void receive(Message m);
Fig. 5. UML diagram of the filter architecture. The Filter class extends the Instruction Visitor class and implements the Sink interface. Messages received by the filter through the receive(Message) method are accepted and visited using the filter itself, i.e. m.accept(this). Messages that bubble up the instruction hierarchy are eventually caught in the visit(Message m) method and forwarded to the next filter.
In order to notify the interpreter that some compiled code is available, we utilize a custom tag object. The tag object is associated with a program counter (PC). The tag object contains information specific to the PC including: whether or not this PC is being recorded, if this PC has a compiled trace attached to it, the associated compiled code, and the number of times the PC has been jumped to. The tag object is always
Stream-Based Dynamic Compilation for Object-Oriented Languages
85
public class CSE extends Filter { private IdentityHashMap avail = new IdentityHashMap(); public CSE(Sink receiver) { super(receiver); } private void process(Instruction i) { Value v = i.getValue(); if (avail.containsKey(v)) i.redirectTo(avail.get(v)); else avail.put(v, i); receiver.receive(i); } public void visit(Instruction.UnaryInstruction i) { process(i); } public void visit(Instruction.BinaryInstruction i) { process(i); } public void visit(Instruction.Constant i) { process(i); } }
Fig. 6. Example for a compilation filter that performs Common Subexpression Elimination using Value Numbering. Only constants and unary and binary instructions are processed, all other instructions and messages are passed through to the next filter (receiver). Redundant instructions are replaced by equivalent instructions that were previously observed.
1 2
3
6
Trace Tree Serialization
4 5
7
8
8
7
6
5
4
3
2
1
Clone
Assembler
Fig. 7. The Baseline Compiler pipeline is assembled from only two filters. The Trace Tree is serialized in reverse order through a clone filter, which makes a copy of the Trace Tree data structure, and then through the Assembler filter which assembles machine code.
initialized to a default state of unrecorded. The state of the tag object is changed to compiling when a trace head is attached to it. Finally, the state is changed to compiled once the assembler has finished generating the appropriate code. By exploiting the tag object, we can execute any compiled code as soon as possible. We do this by a simple check in the interpreter. Every time the interpreter does a backwards branch, the tag associated with the branch target is checked to see if the tag has a compiled trace associated with it. If the tag does not have a compiled trace, the fre-
86
M. Bebenita et al.
quency counter on the tag is increased by the interpreter, to note that another backwards branch to the same PC has been taken. Once the frequency counter on the tag passes a threshold, the compiler is invoked, and the compiled code is attached to the tag. Now, the tag will note that it has a compiled trace associated with it. The interpreter then fetches the trace code from the tag, stops interpreting, and executes the compiled code. 3.5 Optimizing Compiler The optimizing compiler pipeline extends the baseline pipeline by inserting a sequence of optimization filters between the Clone and Assembler filters. The optimization pipeline is partitioned into three stages. These stages are separated by Barrier filters. Barrier filters are pipeline buffers that collect instructions and flush them back once all instructions have been collected. We detect that all instructions have been collected when a TreeEnd message is found. In a pipeline without barriers, each instruction traverses the entire pipeline before the next instruction can be sent down the pipeline. This behavior is undesirable for optimization filters that need a full code analysis before proceeding. The full code analysis, which is implemented as a filter, must complete before the optimization filter can start. For this reason we introduce instruction buffers between filters with this type of dependency. The instruction buffer, or barrier, ensures that the code analysis filter has seen the entire Trace Tree before the optimization filter sees any instructions. The architecture of the optimized compiler pipeline (Figure 8) is presented below. Most pipeline filters expect Trace Trees to be serialized in forward or reverse order, with the exception of the Clone, Reverse, Fork, Barrier and Proxy filters which operate on trees serialized in any order. The Reverse filter reverses the order in which Trace Trees are serialized. Trace Trees are always serialized in reverse order. By having trees serialized in reverse order, the use of an instruction is always seen before its definition. This property is useful for the assembler which performs register allocation, while most optimization and analysis filters need to see the definition of an instruction before its use. By reversing the default Trace Tree serialization order we can ensure this property. Therefore we apply the Reverse filter right after the Clone filter at the beginning of the optimization pipeline. At the very end of the pipeline we reverse the order again since our assembler performs bottom up code generation. The Fork filter connects the previous filter to two receiving filters. Thus any instruction that is received by a Fork filter will be forwarded to the two receiving filters. This is useful for debugging purposes, as we can send all instructions to a filter which prints all instructions in the pipeline, while sending the instructions to compilation filters. The Proxy filter is described later in the paper. The first stage of the optimized compiler pipeline is designed to perform basic optimizations and prepare the intermediate code for more complex optimizations that follow later in the second stage of the pipeline. The first optimization filter, Invariant Code Analysis, annotates loop invariant instructions with information that is used in subsequent filters. Following this filter, constant propagation and arithmetic optimizations are performed. These optimizations reduce arithmetic expression complexity. The last optimizations in the first stage are induction variable analysis, which determines the monotonicity of loop variables; escape analysis which identifies objects that escape
Stream-Based Dynamic Compilation for Object-Oriented Languages
87
1 2
3
6
Trace Tree Serialization
4 5
7
8
8
7
6
5
4
3
2
1
Clone
Load Propagation
Reverse
Common Subexpression Elimination
Invariant Code Analysis
Guard Elimination
Constant Propagation
Invariant Code Motion
Arithmetic Optimization
Barrier
Induction Variable Analysis
Constant Propagation
Escape Analysis Invariant Allocation Analysis Barrier
Arithmetic Optimization Common Subexpression Elimination Reverse
Assembler
Fig. 8. The optimizing compiler pipeline is assembled from 19 filters, two of which are pipeline barriers. The Trace Tree is serialized in reverse order through a clone filter, and then through a series of basic optimization and analysis filters which make up the first stage of the pipeline. In the second stage, we perform four complex optimizations. Finally in the last stage, we re-apply basic optimizations and assemble machine code.
into memory along a trace; and finally the invariant allocation analysis. Invariant allocation analysis determines if new object allocations are contained along a trace, and can instead be allocated only once and shared in subsequent iterations. The second stage of the pipeline uses the results of the analysis filters in the first stage to actually perform optimizations. Load propagation is the first optimization in this
88
M. Bebenita et al.
stage. Load propagation uses the results of the escape analysis and invariant allocation analysis filter to eliminate memory load instructions. In certain cases where load instructions follow store instructions with the same address, load instructions can be eliminated by replacing them with the value that was originally stored by the store instructions. In cases where the address written to belongs to an object that was determined to be non-escaping by escape analysis, the store can also be eliminated. Following the load propagation filter we perform common subexpression elimination and then guard elimination. Guard elimination is a very important optimization where redundant guards are eliminated. During trace recording, guards are inserted to ensure that the execution of compiled code does not diverge from the path that was originally recorded by the interpreter. Guard instructions are inserted whenever a branch was taken by the interpreter or whenever an implicit type check, array bounds check, or null check occurred during interpretation. The number of guards has a negative impact on compilation performance as well as on the final produced machine code. For every non-optimized guard the compiler must emit code to test the guard at runtime and potentially restore the interpreter state in case the guard fails. Restoring state is done by executing a code stub that is emitted by the compiler for each individual guard instruction. Guard instructions pose a significant overhead and it is therefore especially important to eliminate as many guard instructions as possible. The last filter in the second stage is the Invariant Code Motion filter which hoists invariant instructions out of loop traces into a prolog region that is executed only once. The third and last stage of the pipeline performs constant propagation, arithmetic optimization and common subexpression elimination again. This is because the second pipeline stage may have exposed new optimizations. Following these filters, a reverse filter changes the order of instructions and feeds them into the assembler.
4 Parallel Compilation and Parallel Pipelining Two techniques can be used to take advantage of machine-level parallelism to speed up compilation: by either having a parallel compilation, a parallel pipeline, or both simultaneously. These are completely independent of each other. Parallel compilation refers to the use of a separate thread to compile Trace Trees while the main thread continues to interpret the program. A parallel pipeline splits up sections of the pipeline and each section runs its own thread in parallel. In each of these implementations, the threads are controlled via a thread pool. Every compiler phase that requires a thread implements the Runnable interface, and asks for a thread from the thread pool to execute. In case of parallel compilation, the Java interpreter continues executing the main program while the Trace Tree is optimized and compiled. For this, the compiler requests a new thread from the thread pool and begins to compile the recorded trace in that new thread. At the same time, the interpreter continues to interpret the program. Once the final compilation result is available, the compilation thread (or the last compilation thread in case of pipelined compilation) notifies the interpreter that a compiled version of the frequently executed bytecode region is available by annotating the loop header bytecode instruction with a pointer to the compiled code.
Stream-Based Dynamic Compilation for Object-Oriented Languages
89
Blocking Queue
Filter Thread Proxy Filter 1
Filter
Filter
Thread Proxy Filter 2
Fig. 9. Visual representation of a parallel pipeline. A proxy object sits between two connecting segments of the pipeline. The proxy itself utilizes and controls the thread it is given. When the proxy receives a new message, it forwards the instruction through all the filters in its segment. Once the instruction has passed through its segment, the thread continues to wait for new instructions. The proxy releases its thread when it receives a TreeEnd message.
In case of a parallel pipeline, we split sections of the pipeline into separate independent threads. Each of these segments are connected via a proxy filter. This proxy filter implements the Runnable interface, and uses a message queue to forward incoming messages (instructions) to a new thread that then invokes the receive method of the receiver filter (which is the next filter in the pipeline). It is possible to have a proxy filter between compiler phases. Our current prototype pipeline runs in parallel in 19 different threads. This is, however, not very efficient due to the communication overhead of the message queue. Instead, we split the pipeline into segments, each segment containing multiple filters (Figure 9). The proxy object contains a LinkedBlockingQueue of messages. Filter A, once it has finished processing its current message, adds the message to the LinkedBlockingQueue of the proxy class. The proxy’s run method constantly polls the LinkedBlockingQueue looking for new messages in the queue. When a new message is discovered, the proxy passes the message and directly calls the filter that the proxy designates as the receiving item, which in the case above is filter B. The proxy thread then takes the message, and runs through all filters in the pipeline segment. When the thread reaches the end of the pipeline segment, the thread will go back to waiting for a new message to arrive in the linked queue in the proxy class. The proxy will return and release its hold on the thread once a TreeEnd message type is found in the queue. Parallel compilation and the parallel pipeline, can be enabled/disabled independently. We can utilize this to scale the trace compiler to use as many cores as the system provides, by tweaking how many threads are used in the pipeline. Our trace compiler can also use as few as two threads by parallelizing the compilation process itself or by parallelizing the pipeline.
5 Benchmarks We have implemented a prototype dynamic compiler that compiles Trace Trees using a compiler pipeline. The prototype compiler compiles Trace Trees recorded for Java programs. The compiler and the compiler pipeline are also implemented in Java [1,21].
90
M. Bebenita et al.
Compilation Time vs. Tree Size 6,000
Time (ms)
5,000 4,000 3,000 2,000 1,000 0
2,500
5,000
7,500
10,000 12,500 15,000 17,500 20,000 22,500 25,000 27,500
Size (Instructions) Sample
Fitted Regression Line
Compilation Time vs. Tree Size 1,500
Time (ms)
1,250 1,000 750 500 250 0
2,500
5,000
7,500
10,000 12,500 15,000 17,500 20,000 22,500 25,000 27,500
Size (Instructions) Sample
Fitted Regression Line
Fig. 10. Linear Regression - Compilation Time vs. Tree Size. The first graph shows the compilation times when executing our compiler through bytecode interpretation. The second graph shows compilation times for running the compiler pipeline as compiled native code.
Our system runs on top of Apple’s Java VM 6 (Developer Preview). All benchmarks were performed on a Apple MacBook 2.16 Ghz Intel Core 2 Duo with 2 GB RAM. To compensate for measurement errors, each test was run ten times. Our graphs aggregate the results for all ten samples. Figure 10 shows the results for compiling Trace Trees with increasing size using the prototype compiler pipeline. The compilation time increases linearly with the size of the Trace Tree. The upper part of the figure shows a graph that was recorded by running our compiler on top of an interpreting Java VM. The slower execution reduces the impact of measurement errors and influences such as garbage collection. The lower graph shows the performance of the compiler when running as compiled code, in which case our compiler as almost 6 times faster and compiles and optimizes graphs with more than 27,000 instructions in less than one second.
Stream-Based Dynamic Compilation for Object-Oriented Languages
91
Compilation Time vs. Tree Size 5,500 5,000 4,500
Time (ms)
4,000 3,500 3,000 2,500 2,000 1,500 1,000 500 0
2,500
5,000
7,500
10,000 12,500 15,000 17,500 20,000 22,500 25,000 27,500
Size (Instructions) Sample
Fitted Regression Line
Fig. 11. Linear Regression - Compilation Time vs. Tree Size (Mixed Mode)
Figure 11 shows the same benchmark for an underlying “mixed mode” environment that has both a compiler and an interpreter. The performance is still linear in trend, but there are some outliers representing the cases in which the underlying justin-time compiler doesn’t kick in fast enough to accelerate our compilation pipeline. We are confident that in practical use these cases could be handled by appropriate hinting mechanisms to jump-start these particular compilation steps. We performed several experiments with different parallelization granularities, executing different parts of the compiler pipeline in parallel using “Proxy” filters. Our compiler is extremely fast and scales very well. However, the overhead of using a message queue between two threads running different parts of the pipeline for now outweighs the performance gain from overlapping those parts of the pipeline. Splitting the pipeline in 4 threads and compiling a large tree with 27,000 instructions, for example, requires sending 108,000 message across the various message queues involved. Amongst others, this requires allocating 108,000 temporary heap objects to transport the messages, and the threads involved have to perform a synchronization protocol to avoid race conditions. Hence, on current hardware our method is not yet efficient, but the balance will tip in favor of our architecture as many-core processors with higher levels of parallelism become available.
6 Related Work Trace-based dynamic compilation is related to trace scheduling, which was proposed by Fisher [10] to efficiently generate code for VLIW (very long instruction word) architectures. In Fisher’s system, all code was compiled using trace scheduling. Dynamic detection and optimization of “hot” program traces was first introduced in the Dynamo system by Bala et al. [2]. Dynamo is a transparent binary optimizer that records frequently executed traces and optimizes instructions in those traces. In contrast to Dynamo, which optimized only individual traces, our system can optimize
92
M. Bebenita et al.
hierarchies of (potentially nested) traces. Our work also significantly improves on Dynamo in that we are able to optimize away the creation of activation records for inlined procedures and methods. This requires a mechanism that can dynamically create all the “missing” activation records on-the-fly when a “deep bailout” occurs from a guard inside of such an inlined piece of code. The trace-tree representation is closely related to superblocks. In particular, Chang et al.’s work on tail duplication [9] produces an intermediate representation that closely resembles trace-trees. However, in contrast to most superblock approaches that use static analysis to form superblocks [15], our representation is built dynamically at runtime. Our method of selecting only certain “compilation-worthy” parts of methods is similar to region-based compilation by Suganuma et al. [24]. Region-based compilation uses runtime profiling to select code regions for compilation and uses partial method inlining to inline profitable parts of method bodies only. The authors observed not only a reduction in compilation time, but also achieved better code quality due to rarely executed code being excluded from analysis and optimization. Whaley [26] also found that excluding rarely executed code when compiling a program significantly increases compilation performance and code quality. Our approach further reduces the cost for analysis and optimization by eliminating complex control-flows altogether, merely operating on linear sequences of instructions. Path profiling was first proposed by Ball et al. [3]. To collect profiling information about program paths, the authors use a path encoding that produces unique index numbers for program paths. Profiling code is injected into the code such that a unique index number is generated when a certain sequence of basic blocks (path) is executed, and a profiling counter is associated with each such index number that counts the execution frequency. Our trace-based compilation approach is similar to path profiling in that we perform path specific optimization along each trace. Also, the iterative extension of Trace Trees can be seen as a form of dynamic hot path graph construction. The most significant difference is that we do not incur the actual path profiling runtime overhead, because path specificity is an inherent property of our intermediate representation. Thus, we also do not have to deal with compensation code generation, because we already implicitly perform tail duplication as we record traces. Dynamic compilation with traces uses dynamic profile information to identify and record frequently executed code traces (paths). By dynamically adding them to a Trace Tree, and thus iteratively extending that Trace Tree as more traces are discovered, we perform a form of feedback directed optimization, which was first proposed by Hansen [16]. Feedback-directed optimization was used heavily in the SELF system [7] to produce efficient machine code from a prototype-object based language. Feedback directed optimization was subsequently also used in conjunction with other highly dynamic languages such as Scheme [6], Smalltalk [14], and Java. H¨olzle later extended the SELF system to not only use profile-guide compilation, but also adaptive code re-compilation [17]. Kistler and Franz [19,20] further extended this idea and proposed a continuous program optimizer for the Oberon system that continuously re-schedules program instructions and dynamically rearranges the layout of objects during execution to maximize performance.
Stream-Based Dynamic Compilation for Object-Oriented Languages
93
Similar to traditional feedback-oriented and continuous compilers, our trace compiler compiles an initial version of a Trace Tree consisting of a single trace, and then iteratively extends the Trace Tree by recompiling the entire tree. Berndl et al. [4] also investigated the use of traces in a Java Virtual Machine. However, while providing a mechanism for trace selection, the authors do not actually implement any code compilation or optimization techniques based on those traces. Bradel et al. [5] propose using traces for inlining methods calls in a Java Virtual Machine. Similar to our work they use trace recording to extract only those parts of a method that are relevant for the specific caller site. Off-loading dynamic compilation to another execution unit while continuing interpretation is frequently used in commercial virtual machines such as Sun’s Hotspot Virtual Machine [25] and IBM’s J9 virtual machine [18]. Our compilation differs significantly, because it is not merely parallelizable on a macro level at the atomic unit of a method. Instead, its parallelizable in itself and individual compiler passes can execute overlappingly on different execution units. In our own work, our original Trace Tree based compiler [12] for the Java Virtual Machine’s bytecode language has evolved into a family of related compilers based on the same underlying principles, including a just-in-time compiler for Adobe’s Flash language [8] and the TraceMonkey just-in-time compiler for JavaScript that is shipping as part of Mozilla’s Firefox Web browser from version 3.1 onwards [11].
7 Conclusions and Outlook We have presented a new architecture for dynamic compilers that uses a pipeline of “filters” implementing individual compiler phases. Mapping this architecture onto an object-oriented implementation is completely natural and leads to a clear and elegant solution. In our architecture, a Trace Tree is dynamically recorded and extended at runtime and is compiled by serializing the traces in the tree into a single linear sequence of instructions. It is possible to serialize trees in this fashion because the dominance information between traces is preserved if the serialization occurs in reverse recording order of traces. In the resulting serialized stream, every definition occurs before all of its uses. To compile such a serialized tree, it is sent through the pipeline. Each filter in the pipeline can manipulate the instruction stream by modifying, inserting, removing, and re-ordering instructions. The optimization and compilation filters can be put together in different configurations. By directly connecting the final instruction assembly filter to the tree serialization output, for example, we obtain a non-optimizing compiler. Without modifying either of these filters, we can insert optimization filters in between to obtain an optimizing compiler. Beyond being clear and elegant, the object-oriented stream-based architecture of our compiler pipeline lends itself very well for parallelization. “Proxy” filters can be inserted to execute parts of the compiler pipeline in a separate thread. The compiler pipeline in our prototype compiler only requires two synchronization points that cannot be overlapped with the rest of the pipeline. In the benchmarking section we provided a preliminary evaluation of the runtime performance of our compiler. In particular, the compilation cost of the pipeline
94
M. Bebenita et al.
architecture increases linearly with the size of the compiled Trace Trees. This result is remarkable, considering that we provide several aggressive compiler optimizations that have highly non-linear performance characteristics in traditional compilers. Key to the linearity of our compiler’s performance is the linearity of the underlying data structure. On current few-core processors, the communication overhead of using a pipeline in this manner outweighs the advantage of parallelizing compilation. The main contributions of our paper are the decoupling of key components via the object-oriented stream model, and the fact that our compiler pipeline architecture is parallelizable at all. We are not aware of any other dynamic compiler architecture that has the potential to reduce the compilation time for individual compilation units using parallelism. As hardware manufacturers create many-core platforms in which processing resources are abundantly available, the attractiveness of our software architecture will rise quickly.
Acknowledgements The authors would like to thank the anonymous referees for their constructive comments. Parts of this effort have been sponsored by the National Science Foundation under grants CNS-0615443 and CNS-0627747, as well as by the California MICRO Program and industrial sponsor Sun Microsystems under Project No. 07-127. Further support in the form of generous unrestricted gifts has come from Google and from Mozilla, for which the authors are immensely grateful. The U.S. Government is authorized to reproduce and distribute reprints for Governmental purposes notwithstanding any copyright annotation thereon. Any opinions, findings, and conclusions or recommendations expressed here are those of the author and should not be interpreted as necessarily representing the official views, policies or endorsements, either expressed or implied, of the National Science foundation (NSF), any other agency of the U.S. Government, or any of the companies mentioned above.
References 1. Arnold, K., Gosling, J.: The Java Programming Language, 2nd edn. ACM Press/AddisonWesley Publishing Co., New York (1998) 2. Bala, V., Duesterwald, E., Banerjia, S.: Transparent Dynamic Optimization: The Design and Implementation of Dynamo. Hewlett Packard Laboratories Technical Report HPL-1999-78 (June 1999) 3. Ball, T., Larus, J.: Efficient Path Profiling. In: Proceedings of the 29th Annual International Symposium on Microarchitecture, pp. 46–57 (1996) 4. Berndl, M., Hendren, L.: Dynamic Profiling and Trace Cache Generation for a Java Virtual Machine. Technical Report, McGill University (2002) 5. Bradel, B.: The Use of Traces in Optimization. PhD Thesis, University of Toronto (2004) 6. Burger, R.: Efficient Compilation and Profile-Driven Recompilation in Scheme. PhD Thesis, Department of Computer Science, Indiana University (1997) 7. Chambers, C., Ungar, D., Lee, E.: An Efficient Implementation of SELF, a DynamicallyTyped Object-Oriented Language Based on Prototypes. Higher-Order and Symbolic Computation 4(3), 243–281 (1991)
Stream-Based Dynamic Compilation for Object-Oriented Languages
95
8. Chang, M., Smith, E., Reitmaier, R., Gal, A., Bebenita, M., Wimmer, C., Eich, B., Franz, M.: Tracing for Web 3.0: Trace Compilation for the Next Generation Web Applications. In: 5th International Conference on Virtual Execution Environments (VEE) (2009) 9. Chang, P., Mahlke, S., Chen, W., Warter, N., Hwu, W.: IMPACT: An Architectural Framework for Multiple-Instruction-Issue Processors. In: Proceedings of the 18th Annual International Symposium on Computer Architecture, pp. 266–275 (1991) 10. Fisher, J.: Trace Scheduling: A Technique for Global Microcode Compaction. IEEE Transactions on Computers 30(7), 478–490 (1981) 11. Gal, A., Eich, B., Shaver, M., Anderson, D., Kaplan, B., Hoare, G., Mandelin, D., Zbarsky, B., Orendorff, J., Ruderman, J., Smith, E., Reitmaier, R., Haghighat, M.R., Bebenita, M., Chang, M., Franz, M.: Trace-based Just-in-Time Type Specialization for Dynamic Languages. In: ACM SIGPLAN 2009 Conference on Programming Language Design and Implementation (PLDI) (2009) 12. Gal, A., Probst, C., Franz, M.: HotpathVM: An Effective JIT Compiler for ResourceConstrained Devices. In: Proceedings of the 2nd International Conference on Virtual Execution Environments (VEE), pp. 144–153 (2006) 13. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Longman Publishing Co., Inc., Boston (1995) 14. Goldberg, A., Robson, D.: Smalltalk-80: the Language and its Implementation. Addison-Wesley Longman Publishing Co., Inc., Boston (1983) 15. Hank, R., Mahlke, S., Bringmann, R., Gyllenhaal, J., Hwu, W.: Superblock Formation Using Static Program Analysis. In: MICRO 26: Proceedings of the 26th Annual International Symposium on Microarchitecture, pp. 247–255. IEEE Computer Society Press, Los Alamitos (1993) 16. Hansen, G.: Adaptive Systems for the Dynamic Run-Time Optimization of Programs. PhD Thesis, Department of Computer Science, Carnegie-Mellon University (March 1974) 17. H¨olzle, U.: Adaptive Optimization for Self: Reconciling High Performance with Exploratory Programming. PhD Thesis, Stanford University, Department of Computer Science (1994) 18. IBM. WebSphere Everyplace Custom Environment J9 Virtual Machine (October 2006), http://www-306.ibm.com/software/wireless/wece/ 19. Kistler, T., Franz, M.: Continuous Program Optimization: Design and Evaluation. IEEE Transactions on Computers 50(6), 549–566 (2001) 20. Kistler, T., Franz, M.: Continuous Program Optimization: A Case Study. ACM Transactions on Programming Languages and Systems (TOPLAS) 25(4), 500–548 (2003) 21. Lindholm, T., Yellin, F.: The Java Virtual Machine Specification, 2nd edn. The Java Series. Addison Wesley Longman, Inc., Amsterdam (1999) 22. Palsberg, J., Jay, C.: The Essence of the Visitor Pattern. In: The Twenty-Second Annual International Computer Software and Applications Conference, COMPSAC 1998. Proceedings, pp. 9–15 (1998) 23. Rosen, B., Wegman, M., Zadeck, F.: Global Value Numbers and Redundant Computations. In: POPL 1988: Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 12–27. ACM Press, New York (1988) 24. Suganuma, T., Yasue, T., Nakatani, T.: A Region-Based Compilation Technique for Dynamic Compilers. ACM Transactions on Programming Languages and Systems (TOPLAS) 28(1), 134–174 (2006) 25. Sun Microsystems. The Java Hotspot Virtual Machine v1.4.1 (September 2002) 26. Whaley, J.: Partial Method Compilation Using Dynamic Profile Information. In: ACM Conference on Object-Oriented Programming Systems, Languages and Applications, pp. 166–179. ACM Press, New York (2001)
Algebraic Semantics of OCL-Constrained Metamodel Specifications Artur Boronat1 and Jos´e Meseguer2 1
2
Department of Computer Science, University of Leicester [email protected] Department of Computer Science, University of Illinois at Urbana-Champaign [email protected]
Abstract. In the definition of domain-specific modeling languages a MOF metamodel is used to define the main types of its abstract syntax, and OCL invariants are used to add static semantic constraints. The semantics of a metamodel definition can be given as a model type whose values are well-formed models. A model is said to conform to its metamodel when it is a value of the corresponding model type. However, when OCL invariants are involved, the concept of model conformance has not yet been formally defined in the MOF standard. In this work, the concept of OCL-constrained metamodel conformance is formally defined and used for defining style-preserving software architecture configurations. This concept is supported in MOMENT2, an algebraic framework for MOF metamodeling, where OCL constraints can be used for both static and dynamic analysis. Keywords: Membership equational logic, OCL invariants, MOF metamodel, static and dynamic analysis of models.
1
Introduction
Model-driven development (MDD) constitutes a paradigm for representing software artifacts with models, for manipulating them and for generating code from them in an automated way. A model can be defined with a so-called domainspecific modeling language, which provides high-level modeling primitives to capture the semantics of a specific application domain, such as business processes, configuration files or web-based languages (see [1] for an annotated bibliography), or it can be defined using a general-purpose modeling language such as the UML. In both cases, the corresponding modeling language is constituted by an abstract syntax and a concrete syntax, which can be either graphical or textual. In this paper, we focus on the formal semantics of a modeling language, by considering its abstract syntax, when it is enriched with additional semantic requirements specified by OCL constraints. M. Oriol and B. Meyer (Eds.): TOOLS EUROPE 2009, LNBIP 33, pp. 96–115, 2009. c Springer-Verlag Berlin Heidelberg 2009
Algebraic Semantics of OCL-Constrained Metamodel Specifications
97
The Meta-Object Facility (MOF) [2] standard provides a UML-based modeling language for defining the abstract syntax of a modeling language as a metamodel M , where types are metarepresented in a UML-like class diagram. A MOF metamodel M provides the abstract syntax of a modeling language, but not the semantics of the model conformance relation. We identified this problem and provided a formal framework where the notions of metamodel realization, of model type M and of model conformance are formally specified [3,4]. These notions are implemented in MOMENT2 [5], where a metamodel realization is algebraically characterized by a theory in membership equational logic (mel) [6] that is automatically generated from a MOF metamodel M . Within this theory, the carrier of a specific sort in the initial algebra of the metamodel realization constitutes a model type M , which defines the set of well-formed models M that conform to the metamodel M . We call such a relation the structural conformance relation, denoted M : M . The static semantics of a metamodel M can be enriched by adding constraints such as invariants, where the concepts that are defined in M can be used. These invariants can be defined with the standard Object Contraint Language (OCL) [7], enhancing the expressiveness of MOF. However, in the MOF and OCL standards, it is not clear how OCL constraints affect the semantics of a model type M defined in a metamodel M , and only implementation-oriented solutions are provided. In this paper, we extend the executable algebraic semantics of MOF metamodels [4] by considering OCL constraints. We build on previous experience on encoding OCL expressions as equationally defined functions [8]. The main new contributions of this work are: (i) the notion of metamodel specification as a pair (M , C ), where M is a MOF metamodel and C is a set of OCL constraints that are meaningful for M ; (ii) an algebraic semantics for metamodel specifications, so that the structural conformance relation is enriched with the satisfaction of OCL constraints and characterized by equational axioms; (iii) the use of OCL expressions for dynamic analysis using Maude-based verification techniques [9]; and (iv) the implementation of these new concepts in the MOMENT2 framework by enabling the validation of OCL constraints over models in the Eclipse Modeling Framework (EMF) [10]. In the following subsection, we describe the application of OCL constraints to definitions of style-preserving software architecture configurations. We use this as a running example throughout the paper. 1.1
An Example: Architectural Style Preservation
To illustrate our approach we use a basic specification of a software architecture component type, shown in Fig. 1.(a), where a component can be defined as client or server (type attribute) and can be connected to other components. This component type is given as a MOF metamodel M . As explained above, such a metamodel metarepresents a model type M , whose terms constitute well-formed software architecture configurations. By using such a model type M , we can define a specific software architecture configuration where client component instances can connect to other clients or servers, as shown
98
A. Boronat and J. Meseguer
Fig. 1. (a) Metamodel M . (b) Valid configuration. (c) Non style-preserving configuration.
in Fig. 1.(b). A software architecture configuration is a model M that conforms to the model type M , denoted M : M . While a given configuration of component instances can be changed to improve communication among components, there may still be some structural constraints that must be preserved. Constraints of this kind are know as architectural styles, which are specified by sets of rules indicating which components can be part of the architecture and how they can be legally interconnected [11]. In this paper, we use as an example the client/server architectural style, in which client component instances can only connect to server component instances. The OCL invariant in Fig. 1.(a) represents such an architectural style in the software architecture definition of the example. We can therefore view the client/server architecture as a metamodel specification (M , C ), where M is the above-defined metamodel for connecting components, and where C consists of the single OCL constraint just mentioned. A style-conformant configuration for the client/server architecture is then a wellformed architectural model M that satisfies the previous OCL invariant. The configuration provided in Fig. 1.(c) is not client/server-conformant due to the marked link between the objects c1 and c2. In this paper we provide an algebraic, executable semantics for the constrained conformance relation to both formalize the use of OCL invariants for the definition of the static semantics of a domain-specific modeling language by means of a metamodel specification (M , C ), and to provide automatic verification of the constrained conformance relation. From an operational point of view, this formalization does not only provide a mechanism to check whether or not a model conforms to a metamodel specification (M , C ) but also enhances the use of OCL constraints for verifying behavioral specifications of DSMLs with model checking techniques. In Section 2, we summarize preliminary concepts about mel and Maude. Section 3 gives a summary of the main concepts of the algebraic semantics for MOF: model type M and structural conformance between a model M and its metamodel M , i.e., M : M . These concepts are used in Section 4 to define an algebraic, executable semantics for OCL expressions. Section 5 gives the algebraic semantics for metamodel specifications (M , C ), illustrating how OCL can be used for static analysis. Section 6 shows how OCL can be used for
Algebraic Semantics of OCL-Constrained Metamodel Specifications
99
dynamic, model checking analysis in MOMENT2. Section 7 compares our approach with other approaches that formalize OCL for different purposes, and Section 8 summarizes the main contributions of the paper.
2
Preliminaries
A membership equational logic (mel) [6] signature is a triple (K, Σ, S) (just Σ in the following), with K a set of kinds, Σ = {Σw,k }(w,k)∈K ∗ ×K a many-kinded signature and S = {Sk }k∈K a K-kinded family of disjoint sets of sorts. The kind of a sort s is denoted by [s]. A mel Σ-algebra A contains a set Ak for each kind k ∈ K, a function Af : Ak1 × · · ·× Akn → Ak for each operator f ∈ Σk1 ···kn ,k and a subset As ⊆ Ak for each sort s ∈ Sk , with the meaning that the elements in sorts are well-defined, while elements without a sort are errors. TΣ,k and TΣ (X)k denote, respectively, the set of ground Σ-terms with kind k and of Σ-terms with kind k over variables in X, where X = {x1 : k1 , . . . , xn : kn } is a set of kinded variables. Given a mel signature Σ, atomic formulae have either the form t = t (Σequation) or t : s (Σ-membership) with t, t ∈ TΣ (X)k and Σ s ∈ Sk ; and sentences are conditional formulae of the form (∀X) ϕ if i pi = qi ∧ j wj : sj , where ϕ is either a Σ-equation or a Σ-membership, and all the variables in ϕ, pi , qi , and wj are in X. A mel theory is a pair (Σ, E), with Σ a mel signature and E a set of Σ-sentences. The paper [6] gives a detailed presentation of (Σ, E)-algebras, sound and complete deduction rules, and initial and free algebras. In particular, given a mel theory (Σ, E), its initial algebra is denoted T(Σ/E) ; its elements are E-equivalence classes of ground terms in TΣ . Under appropriate executability requirements explained in [9], such as confluence, termination, and sort-decreasingness modulo A, a mel theory (Σ, E), where E = E0 ∪ A, becomes executable by rewriting with the equations and memberships E0 modulo some structural axioms A. Furthermore, the initial algebra T(Σ/E) then becomes isomorphic to the canonical term algebra Can Σ/E0 ,A whose elements are Aequivalence classes of ground Σ-terms that cannot be further simplified by the equations and memberships in E0 . A rewrite theory [12] is a triple R = (Σ, E, R), where (Σ, E) is a mel theory, and R is a collection of (possibly conditional) rewrite rules of the form t −→ t if C, where t, t are Σ-terms of the same kind, and C is the rule’s condition. Intuitively, what the rewrite theory R specifies is a concurrent system, whose states are elements of the algebraic data type TΣ/E defined by the mel theory (Σ, E), and whose concurrent transitions are specified by the rules R. That is, a rule t −→ t if C specifies transitions in which a fragment of the current state matches the pattern t, and then in the resulting state that state fragment is transformed by the corresponding instance of t , provided that the condition C is satisfied.
100
A. Boronat and J. Meseguer
2.1
Maude
Maude [9] is a declarative language where programs are rewrite theories, and where Maude computations are logical deductions using the axioms specified in the theory/program. We use an example of a simplified vending machine for illustrating how Maude can be used to specify systems. A mel theory is represented as a functional module in Maude, enclosed within fmod. . .endfm, where types are syntactically represented as sorts and terms (data) are defined by means of constructors for these sorts. In the module below, we have the sorts Coin, Item and Marking where the sort Marking represents the state of the system. Constants are constructors with no arguments, for instance, $ is a constant of sort Coin, representing a coin, and c, a are constants of sort Item, representing a cake and an apple, respectively. The constructor (blank space) has two arguments of sort Marking. The subsorts Coin Item < Marking are subtype declarations indicating that coins and items is defined as associative and are also terms of sort Marking. The operator commutative. Therefore, a term of sort Marking is a multiset of coins and items. For instance, we could represent two coins, an apple and a cake in our system as a term $ $ a c. fmod VENDING-MACHINE-SIGNATURE is sorts Coin Item Marking . op $ : -> Coin . op c : -> Item . op a : -> Item . subsorts Coin Item < Marking . op __ : Marking Marking -> Marking [assoc comm] .
As described in the Section 2 a mel theory may also contain equationally defined functions. Below we define a boolean predicate that indicates when a vending machine state (a term of sort Marking) only contains apples. The first and second equations indicate that the predicate fails if we find either a coin $ or a cake c in the multiset of sort Marking. The last equation indicates that the predicate holds when no other equations can be applied, i.e., when there are only apples a. Note that c M:Marking is a term pattern that is applied modulo associativity and commutativity. op eq eq eq
onlyApples? : Marking -> onlyApples?( $ M:Marking onlyApples?( c M:Marking onlyApples?( M:Marking )
Bool . ) = false . ) = false . = true [owise] .
In the following sections, we encode models as multisets of objects where pattern matching modulo associativity and commutativity is used to match the links between objects. To illustrate the use of memberships, we define a subsort AppleMarking of Marking for categorizing states that only contain apples. The
Algebraic Semantics of OCL-Constrained Metamodel Specifications
101
carrier (set of values) of the sort AppleMarking is defined by means of a membership indicating that only those states M:Marking in which there are no cakes can be found in AppleMarking, that is onlyApples?(M:Marking) = true. sort AppleMarking . subsort AppleMarking < Marking . cmb M:Marking : AppleMarking if onlyApples?(M:Marking) = true . endfm
To check whether a machine state has no cakes, we only have to check that the corresponding term of sort Marking belongs to the sort AppleMarking as follows reduce ($ $ c a) :: AppleMarking . rewrites: 5 in 0ms cpu (0ms real) (238095 rewrites/second) result Bool: false reduce ($ $ a a) :: AppleMarking . rewrites: 7 in 0ms cpu (0ms real) (3500000 rewrites/second) result Bool: true
In the following sections, this notion of membership is used to define the set of models that satisfy OCL constraints, which are encoded as boolean functions for a metamodel specification (M , C ). Some dynamics are added to the system by means of two simple rules to buy an apple with a coin (buy-a) and to buy a cake with two coins (buy-c). Rewrite theories are defined in so-called system modules, enclosed in between mod. . .endm. mod VENDING-MACHINE is including VENDING-MACHINE-SIGNATURE . var M : Marking . rl [buy-a] : $ => a . rl [buy-c] : $ $ => c . endm
Maude provides several verification techniques, including model checking, for systems specified as rewrite theories. For instance, the search command allows one to explore (following a breadth-first strategy) the reachable state space in a system. In the example below, system states are terms of sort Marking and we search all canonical terms that can be reached from the initial state $ $ where there are two coins. search $ $ =>! M:Marking .
The solutions that the search command provides are two states in which we obtained either a cake or two apples. Solution 1 (state 1) states: 3 rewrites: 2 in 0ms cpu (0ms real) (125000 rewrites/second) M --> c
102
A. Boronat and J. Meseguer
Solution 2 (state 3) states: 4 rewrites: 3 in 0ms cpu (0ms real) (32967 rewrites/second) M --> a a No more solutions.
We show how the search command is applied to model analysis with OCL invariants in Section 6.
3
Algebraic Semantics of MOF Metamodels
In this section, basic notions of the MOF standard and their formalization are presented. These notions are specified in the MOMENT2 framework and constitute the basis for the rest of the paper. MOF is a semiformal approach to define modeling languages by defining their abstract syntax in a so-called metamodel M , which metarepresents a model type M . What this metamodel describes is, of course, a set of models. We call this the extensional semantics of M , and denote this semantics by M , which can be informally defined as follows: M = {M | M : M }. In [4], we presented a formalization of the MOF framework in which the informal MOF semantics just described is made mathematically precise in terms of the initial algebra semantics of mel. Let MOF denote the set of all MOF metamodels M , and let SpecMEL denote the set of all mel specifications. Our algebraic semantics is then defined as a function : MOF −→ SpecMEL that associates to each MOF metamodel M a corresponding mel specification (M ), which constitutes the metamodel realization. Recall that any mel signature Σ has an associated set S of sorts. Therefore, in the initial algebra T(Σ,E) each sort s ∈ S has an associated set of elements T(Σ,E),s . The key point is that in any mel specification of the form (M ), there is always a sort called Model , whose data elements in the initial algebra are precisely the data representations of those models that conform to M . That is, the sort Model syntactically represents the model type M associated to a metamodel M . The structural conformance relation between a model and its metamodel is then defined mathematically by the equivalence M :M
⇔
M ∈T
(M ),Model .
Therefore, we can give a precise mathematical semantics to our informal MOF extensional semantics by means of the defining equation M = T
(M ),Model .
Algebraic Semantics of OCL-Constrained Metamodel Specifications
103
Note that this algebraic semantics gives a precise mathematical meaning to the entities lacking such a precise meaning in the informal semantics, namely, the notions of: (i) model type M , (ii) metamodel realization (M ), and (iii) conformance relation M : M . For the metamodel M in Fig. 1.(a), the model depicted in Fig. 1.(c) can be defined as a term of sort Model in the (M ) theory as follows: << < ’c1 : Component | type = "client", connectsTo = ’c2 ’c3 ’c4 > < ’c2 : Component | type = "client", connectsTo = ’c4 > < ’c3 : Component | type = "server", connectsTo > < ’c4 : Component | type = "server", connectsTo > >>,
where each tuple < Oid : ClassName | Properties > represents an object that is typed with a specific object type of the corresponding metamodel. Objects are defined with properties of two kinds: attributes, typed with simple data types, and references, typed with object identifier types. Each property is defined by a pair (name = value). All the constructors that are used in the previous term are defined in the signature of the (M ) theory. Note that a term of this kind represents an attributed typed graph with labelled unidirectional edges where the type graph is the metamodel. This representation of models (graphs) as algebraic terms is automatically generated by MOMENT2 from EMF models.
4
Algebraic Semantics of OCL Expressions
In this section, we introduce the algebraic, executable specification of OCL available in MOMENT2, which is based on [8,3]. OCL permits defining expressions that are useful to perform queries upon models M that conform to a given metamodel M . OCL expressions are parameterized with user-defined types, such as classes, that are provided in a metamodel M . In MOMENT2, OCL expressions acquire an algebraic semantics that can be used for many purposes. One of them is the executable formalization of the constrained conformance relation between a model M and a metamodel specification (M , C ) in the following section. Let OclExpression denote the set of well-formed OCL expressions. Not all OCL expressions in OclExpression make sense for a given metamodel. We say that a specific OCL expression e, such that e ∈ OclExpression, is meaningful for a metamodel M , denoted by (M , e), iff all user-defined types, if any, that are used in the expression e are metarepresented in M . An OCL expression is evaluated over a root object in a model M from which other objects in the model can be traversed. In the example in Fig. 1.c), we can traverse components through the connectsTo reference. In particular, those objects that are reachable through references can be traversed. In the OCL expression, the object type of the root object is indicated in the so-called context of the OCL expression. In this setting, the object type is called contextual type and the root object, to which an OCL expression is applied, is called contextual instance. In an OCL expression, the contextual instance can be explicitly referred to by means of the self keyword.
104
A. Boronat and J. Meseguer
In MOMENT2, we represent the concrete syntax of OCL as a membership equational theory OCLGrammar having a sort OclExpressionCS whose terms represent syntactically well-formed OCL expressions1 . Therefore, the following OCL expression is a valid term of sort OclExpressionCS: ’self . ’connectsTo -> forAll( ’c | ’c . ’type == # "server")
and it is a meaningful OCL expression for the metamodel M of the example if we take into account the object type Component as contextual type of the expression. 4.1
Algebraic Executable Semantics of Meaningful OCL Expressions
OCL expressions can be defined by using generic OCL types, such as collections, and user-defined types. The generic OCL types can be split in two groups: basic datatypes and collection types. OCL provides a set of operators that can be applied on values of these types. In particular, among collection operators we can distinguish between regular operators and loop operators. On the one hand, regular operators provide common functionality such as the size of a collection or the inclusion of elements within a collection. On the other hand, loop operators constitute second-order operators that receive a user-defined OCL expression as argument, normally called loop body expression, and apply it to the elements of a collection depending on the nature of the operator. For example, the forAll operator receives a boolean loop body expression and checks that all the elements in the collection satisfy the predicate. The algebraic semantics of a meaningful OCL expression (M , e) is given by the partial function
: MOF × OclExpression SpecMEL, which is defined for all meaningful OCL expressions (M , e) and maps (M , e) to a mel theory (M , e) such that (M ) ⊆ (M , e). In addition, the (M , e) theory provides an algebraic specification for OCL basic datatypes and OCL collection types, where their operators are provided as equationally-defined functions2 . The function can be viewed as an internal compiler from OCL to mel. The function traverses the term-based abstract syntax tree of the input OCL expression e by generating equationally-defined functions for user-defined OCL expressions, such as loop body expressions, in a top-down manner. The outermost OCL expression e is represented by an equationally-defined function of the form exp : Object × Model −→ OclType , 1
2
There are a few minor syntactic differences with the concrete syntax of OCL: identifiers are preceded by a quote, literal values are wrapped by the # operator, and the equals operator symbol = is ==. In this paper we have abstracted from the different types of collections that can be used in OCL. See [3] for a detailed explanation of the complete algebraic specification of OCL.
Algebraic Semantics of OCL-Constrained Metamodel Specifications
105
where exp is a symbol that is generated for the corresponding OCL expression e, Object represents the set of objects that can be defined with user-defined types from a metamodel M , Model is the model type that corresponds to M , and OclType represents a valid OCL type depending on the type of e. In our running example, we obtain exp : Object Model -> Bool.
OCL expressions can then be executed over a contextual instance o in a model definition M by means of a term of the form exp(o, M ), whose return type depends on the user-defined expression. For the expression ’self . ’connectsTo -> forAll( ’c | ’c . ’type == # "server"),
the exp function is defined by the equation: exp(c , M) = c . ’connectsTo(M) -> forAll ( body ; empty-env ; M ),
where body is a constant that identifies the function that represents the loop body expression, c . ’connectsTo(M) projects all the objects in the model M that can be traversed from the object c through the reference connectsTo, empty-env is a list of environment variables (used when there are variables that are bound in an outer OCL expression), and M is a variable that represents the model M . The following equation indicates how to apply the boolean body expression of the forAll operator to each member Obj of a collection of objects recursively (where Col is a collection of objects, B is a body, E is an environment of variables, and M is a model): Obj Col -> forAll(B ; E ; M) = Obj . B( E ; M ) and Col -> forAll(B ; E ; M) .
and the expression Obj . B( E ; M ) is again defined by an equation that evaluates the expression ’type == # "server" for an object Obj Obj . body( E ; M ) = Obj . get("type") == "server"
If we denote the model in Fig. 1.(c) by model2 and the objects with identifiers c1 and c2 by o1 and o2, repectively, we obtain the following results with the above OCL expression: exp(o1, model2) = false and exp(o2, model2) = true. Therefore, the function provides an algebraic executable semantics of meaningful OCL expressions (M , e) by means of an executable mel theory where all OCL datatypes are algebraically defined, and where user-defined OCL expressions are available as equationally defined functions. The presented OCL formalization can be used for evaluating OCL queries within a MOF-like modeling environment, such as the Eclipse Modeling Framework through MOMENT2. In addition, and even more importantly, this algebraic semantics for OCL expressions can be used at a theoretical level to provide a formal semantics to concepts that are not yet sufficiently precise in the MOF standard, such as the constrained conformance relation, and, at a more practical level, to enhance static and dynamic model analysis with OCL invariants.
106
5
A. Boronat and J. Meseguer
Algebraic Executable Semantics of Metamodel Specifications
OCL permits imposing constraints upon specific object types in a metamodel M , thus constraining the set of models M that conform to M . We call the resulting conformance relation the constrained conformance relation. In this section, we define the concept of metamodel specification (M , C ), which is used to attach a set C of meaningful OCL constraints to a metamodel M . Relying on the aforementioned algebraic semantics of OCL expressions, the algebraic semantics of a metamodel specification (M , C ) is also given, defining how a model type can be semantically enriched with OCL constraints. 5.1
Metamodel Specifications
An OCL invariant c is a constraint that is defined using a boolean body expression that evaluates to true if the invariant is satisfied. The body expression of an invariant c, denoted body(c), is a well-formed boolean OCL expression, i.e.,