Workflow MOF Reflection with C++ Example

1 downloads 0 Views 384KB Size Report
uml::Class* metaClassExp = package->get_Model_Experiment(); uml::Element* experimentM0 ... benchmark can be explained by the need of dynamic casts by ...
An EMF-like UML Generator for C++ Sven Jäger, Ralph Maschotta, Tino Jungebloud, Alexander Wichmann, and Armin Zimmermann Systems and Software Engineering Group  Computer Science and Automation Department  Technische Universität Ilmenau

Motivation The Eclipse Modeling Project (EMP) supports Model Driven Architecture (MDA): - Possible to build applications based on domain-specific meta-models - Set of modeling frameworks, tools and standard implementations based on Eclipse Modeling Framework (EMF) using Ecore Meta Metamodel - Produces Java classes for models and utilities to create and edit models - Well integrated for Java programming language - Weakly supported for other programming languages such as C++ EMF-like UML Generator for C++: - Using Acceleo to define Model2Text Generators - Based on Ecore to C++ Generator (also written with Acceleo, similar to [1]) - Use the Eclipse Modeling Project (Ecore) to formally describe Models using *.ecore and *.uml Files Purpose: - Describe structure and behavior with a domain-specific language - Build applications based on domain specific meta-models: - Model-to-Text, Model-to-Model or Text-to-Model transformations (load and save .xmi - Files) - Model execution (Behaviour), execute queries, check constraints (OCL) during runtime

Workflow The following figure depicts structure and dependencies of the elements which are necessary to achieve a UML-compliant C++ representation of a model. It is not enough to convert the classes to C++ code. A full-featured implementation needs the upper levels of the model hierarchy as well. Model Specifications Acceleo Model2Text C++ Source Code Executable Generator

M3

Meta Metamodel (Ecore)

Example Example UML model, representing an overview model of a so-called simulation-based application for planning and simulating wireless sensor networks in aircrafts [2]. Generated Factory: … ModelFactoryImpl::ModelFactoryImpl() { … m_creatorMap.insert("model::MAC_Hybrid", [this](){return this->createMAC_Hybrid();}); m_creatorMap.insert("model::Configuration", [this](){return this->createConfiguration();}); m_creatorMap.insert("model::Component", [this](){return this->createComponent();}) m_creatorMap.insert("model::Experiment", [this](){return this->createExperiment();}); … } …

Example Application: … int main(){… //M0 Model Instances Model::ModelFactory* factory = Model::ModelFactory::eInstance(); Model::Experiment* experiment = factory->createExperiment(); Model::Configuration* config = factory->createConfiguration(); experiment->setConfiguration(config);

Program output: uml operations: "run" …

//M1 Model Model::ModelPackage* package = factory->getModelPackage(); uml::Class* metaClassExp = package->get_Model_Experiment(); uml::Element* experimentM0 = factory->create(metaClassExp);

ecore operations: … "createOwnedOperation"

uml::Class* expMetaClass = experiment->getMetaClass(); QList* expOp=expMetaClass->getOwnedOperation(); printOperations(expOp);

"isMetaclass" "getExtensions" …

//M2 Meta-Model ecore::EClass* metaClass=expMetaClass->eClass(); QList* classOp=metaClass->getEOperations(); printEOperations(classOp);

ecore operations: … "isSuperTypeOf"

//M3 MetaMeta-Model ecore::EClass * metaMetaClass=metaClass->eClass(); QList* metaClassOp=metaMetaClass->getEOperations(); printEOperations(metaClassOp); …}

M2 Metamodel (UML)

"getEStructuralFeature" "getOperationCount" "getEOperation" …

Benchmark

M1 Model

M0 Application Supported features of Ecore to Cpp generator: - Class creation, structural and behavioral features, method implementation using annotations, relationships, generalization, model package and factory Annotations are used to specify: - Method implementation, visibility of methods, getter/setter renaming, union / subsets, C++ includes Supported features of UML generator for CPP (UML4Cpp): - Class creation, attributes, getter/setter, operation implementation using OpaqueBehavior (body and language), reflection package and factory, profiles with stereotypes, constraints, activities and actions

MOF Reflection with C++ Reflection is an essential aspect using generated code of meta models in generic software. The MOF (MetaObject Facility) - Reflection with C++ is realized as follows: M3 layer - Ecore Meta Metamodel: - Described with the Ecore Meta Metamodel M2 layer - UML Metamodel: - Described with the Ecore Meta Metamodel - Provides MOF-based reflection - Has access to M3 layer using eClass() M1 layer - Model: - Described with UML Metamodel - Imports reflection methods from upper layer - Access to M2 layer using getMetaclass() - Access to description of its own type M0 layer - Application: - Instances of model elements - Access to type description during runtime - Structure of an object can be queried via meta layer during runtime The reflection (as it is defined in OMG’s MOF standard) consists of the following classes. MOF-Reflection Object: - Base class for every element - Provides methods to access features (properties or methods) MOF-Reflection Element: - Extends the Element meta class of the UML - Access to upper meta level - Instances have access to description of its class - Allows querying the description - Gain access, discover and manipulate properties and methods of the instance MOF-Reflection Factory: - Creator class - Merges UML and MOF reflection package - UML Elements extended by aspects of reflection

Contact: http://www.tu-ilmenau.de/sse/

Performance of Java and C++ metamodel implementation are analyzed. Therefore these test Class are used. Benchmarks: Creation time of model elements: - Create 10,000 to 100,000 instances of test Class Time effort to move model elements: - Create 100,000 instances of test Class - 10 times: move all attributes to one class and undo movement Comparison of model elements: - Create 1000 instances in 2 packages - 10 times: search all instances of test Class of one package in other one Memory usage: - Memory HDD and RAM Discussion: - Result in move and compare benchmark can be explained by the need of dynamic casts by using multilevel inheritance hierarchy. - With a higher inheritance hierarchy, more time is needed for dynamic cast operations. The profiler confirmed already known behavior of dynamic casts. - Changes of the C++ implementation to avoid multilevel inheritance hierarchy can improve it

Results: creation time

1,400 ms

Java force GC C++ Java with GC

1,000 800 600 400 200 0 -200

10,000

20,000

30,000

40,000

50,000

60,000

70,000

80,000

#Objects

100,000

-400 -600

Benchmark

Java Mean

Move Compare

C++ Std

375.2 ms* 130.2 64.2 ms*

62.5

Mean

Std

1405.7 ms 107.2 6644.3 ms

Memory HDD

5.1 MB*

14.6 MB

Memory RAM

201.5 MB*

115.3 MB

58.9

General Setting: - standard windows PC (Intel Core i5-2520M, 2.50GHz) - Only one core is used - Java start-up time is not considered * without Java virtual machine (152 MB)

Conclusion The presented UML and Ecore generators for C++ can be used to create C++ code representations of: - Ecore Meta Metamodel and UML Metamodel - Models based on UML-Metamodel and Ecore Meta Metamodel It is now possible to use UML to define domain-specific languages for C++ software systems. It is now possible to build modeling toolchains similar to the Eclipse Modeling Project based on C++. Further work: - Define visualization properties of attributes model-based (e.g. using stereotypes and profile diagram) and visualize these attribute values in a proper way - Define constraints model based-using OCL and check defined constraints during runtime - Model based definition and execution of behavior, e.g., to execute activity diagrams using modelbased described execution engines e.g. fUML [3] First prototype, it still needs some further development. Features like the notification framework, proxies, polymorphic container and import of other metamodels are partly implemented or still missing. [1] A. S. González, D. S. Ruiz, and G. M. Perez: “Emf4cpp: a c++ ecore implementation.” in DSDM 2010 - Desarrollo de Software Dirigido por Modelos, Jornadas de Ingenieria del Software y Bases de Datos (JISBD 2010), Valencia, Spain, September 2010. [2] S. Jäger, T. Jungebloud, R. Maschotta, and A. Zimmermann: “Modelbased QoS evaluation and validation for embedded wireless sensor networks.” Systems Journal, IEEE, 2014. [3] A. Wichmann, S. Jäger, T. Jungebloud, R. Maschotta, and A. Zimmermann: “Specification and Execution of System Optimization Processes with UML Activity Diagrams.” in proc. of 10th IEEE Int. Systems Conference (SysCon 2016), 2016.