Boost PC performance: How more available memory can improve productivity
Code Generation with MDA and xUML
1. Welcome A Practical Guide to Code Generation using Model Driven Architecture and Executable UML 25 Jun 2008 Chris Raistrick, Kennedy Carter [email_address] KC.COM
5. Elaboration Based Process The deliverables are up to 300% redundant… … and maintenance costs are correspondingly high Requirements (Text / Use Cases) This must be changed… or become obsolete This must be changed… or become obsolete This must be changed When this changes manually build a Platform Specific Model … PSM (UML) manually code a Platform Specific Implementation PSI (Ada/C++) manually build a Platform Independent Model … PIM (UML) Process definition Design policies Imp’n rules
6. Elaboration vs. Translation PSM (UML) Process definition Design policies Coding rules manually code a Platform Specific Implementation PSI (Ada/C++) manually build a Platform Independent Model … PIM (UML) Elaborate Translate manually build a Platform Specific Model … PSI (Ada/C/C++) automatically generate a Platform Specific Implementation using PIM-PSI mappings PIM-PSI Mappings (xUML) manually specify mappings onto the platform … manually build a Platform Independent Model … PIM (xUML) Requirement Change impact Technology Change impact
7. Translation Based Process Translate The knowledge in the heads of developers is: - Formalized - Accessible - Reusable - Refinable Process definition Design policies Coding rules PSI (Ada/C/C++) automatically generate a Platform Specific Implementation using PIM-PSI mappings PIM-PSI Mappings (xUML) manually specify mappings onto the platform … manually build a Platform Independent Model … PIM (xUML)
8. Formalized Application and Software Design Expertise PIM-PSI Mappings (xUML) automatically generate a Platform Specific Implementation using PIM-PSI mappings manually specify mappings onto the platform … manually build a Platform Independent Model … PIM (xUML) Rules and policies for organising aircraft Process definition Design policies Coding rules PSI (Code) Rules and policies for organising software
14. The Code Generator: Domains Populate Generate System Model Code Generator Generated Code xUML Runtime Layer Generated System Adaptation Layer The code generator itself is a set of domain models expressed using xUML. The domains represent the various components of an xUML system. (Part of) Code Generator Domain Chart xUML Model (PIM) Platform-Specific Configuration xUML-Code Mappings iCCG Code Generator
15. The Code Generator: Classes and Methods (Part of) Configurable Code Generator Domain Chart iCCG Code Generator Code Generator xUML-Code Mappings (Part of) Executable UML Class Model the classes in each domain represent the elements that make up those components. Method to Generate Java Method to Generate Ada Method to Generate C++ Method to Generate C … $FORMAT header_file typedef struct C[I:this.class_ID]_struct { /* "[T:this.class_name]" Class Header */ struct s_object *next_instance; $ENDFORMAT … Each element contains operations which specify how to map that xUML element onto a specific target language.
16.
17. Instantiate the Formalism Metamodel Domain Instance Class Instances Attribute Instances Populated Executable UML Class Model When the Executable UML domain is populated with the PIM components, we see these instances… Populate xUML Model (PIM) Platform-Specific Configuration System Model xUML-Code Mappings iCCG Code Generator Code Generator
18. The Metamodels Embody the Code Generation Rules Domain.generateCode Class.generateCode Attribute.generateCode The task of translation involves iterating through these instances and generating suitable code from them. iCCG Code Generator Code Generator xUML-Code Mappings
19. Generate the Code Platform Independent Model : Class Diagram Generated C Code Generate Generate xUML-Code Mappings iCCG Code Generator Code Generator Generated Code xUML Runtime Layer Generated System Adaptation Layer
20. We have illustrated generation of data structures from the class model. The process of generating code from the action language is the same, and based upon populating and translating instances in the “Action Language” domain… Generating Code from Action Language Note that the “generateCode” operation of the “ASL Statement” class is polymorphic, allowing us to implement rival versions of this method for each type of ASL statement, represented as the subclasses “Create Statement”, “Delete Statement” and so on polymorphic operation with different polymorphic methods to generate code for each different ASL statement
21. Generate the Code Generator Project Code Generator Pre-Existing Code Generator Project Domain Models Project Code Code Generator PIM (part of) xUML Metamodel Domain Class Attribute xUML Metamodels xUML to Code Mappings in ASL
22. Code Generation Overview Populate Generate xUML Model (PIM) Platform-Specific Configuration System Model xUML-Code Mappings iCCG Code Generator Code Generator Generated Code xUML Runtime Layer Generated System Adaptation Layer PLATFORM SPECIFIC CONFIGURATION FILE PROCESS "Process One" ONE 1 127.0.0.1 1000 1600 PROCESS "Process Two" TWO 1 127.0.0.1 1001 1601 CLASS-PROCESS WM TGT ONE CLASS-PROCESS WM WPN TWO (part of) xUML Metamodel Domain Class Attribute owning_domain = this -> R2 $FORMAT header_file typedef struct D[I:owning_domain.domain_ID]_C[I:this.class_ID]_struct { /* "[T:this.class_name]" Class Header */ struct s_object *next_instance; /* Linked list of */ struct s_object *prev_instance; /* object instances */ struct s_object *rel_ptr; /* list of rel'ns */ struct s_object *cpr_ptr; /* list of cp rel'ns */ $ENDFORMAT {attributes_in_class} = this -> R3 for the_attribute in {attributes_in_class} do [] = ATT1:generateCode [header_file] on the_attribute endfor $FORMAT header_file }; $ENDFORMAT Multi-node multi-process runtime Windows Vista adaptation layer
28. Optimized Instance Handles The first element is a status indicator: 0 means “undefined”, 1 means “defined”. The second element (which is defined only if the first element is 1) is an index into the attribute arrays of the object it references, i.e. an object “pointer”. An instance handle can be realised as a 2-element array of integers. Instance attributes can be realised as fixed-length arrays, with a flag for each index to indicate whether that instance exists Customer custId custName custAddress
29. Optimized Associations note that creating and deleting objects and links does not involve any dynamic memory management… … even though there are ‘create’ and ‘delete’ statements in the PIM A binary association is implemented as two 2-dimensional arrays. Each array implements the association in one direction only. Customer End Account End Customer 0 owns Account 2 Account 6 is owned by Customer 2 accountId dateOpened balance ownerId status Account owns is owned by 1..* 0..1 R1 Customer custId custName custAddress
47. MDA Limits the Impact of Business Rule and Technology Changes UML Metamodel Platform & implementation environment changes impact only here PIM Instantiate Business rule & requirement changes impact only here Manual or Automated PSM Metamodel Define Mapping PSM Apply Mapping PSI Metamodel Define Mapping PSI Apply Mapping
48. Reusable Mappings Are Defined at the Metamodel Level (part of) UML Metamodel Class Attribute Signal PSM Metamodel PSI Metamodel Define Mapping xUML Metamodel Define Mapping (part of) PSM Metamodel (object-based) Class PrivateDatum PublicMethod (part of) Ada 83 Metamodel Package BodyVariable SpecSubprogram
49. Reusable Mappings Are Defined at the Metamodel Level (part of) UML Metamodel Class Attribute Signal PSM Metamodel PSI Metamodel Define Mapping xUML Metamodel Define Mapping (part of) PSM Metamodel (object-based) Class PrivateDatum PublicMethod (part of) Java Metamodel Class Attribute Operation
55. Maintainability vs. Executability PSM (UML) manually build a Platform Specific Model … manually code a Platform Specific Implementation PSI (Code) manually build a Platform Independent Model … PIM (UML) Elaborate Compromise between maintainability and executability In classic approaches, the PSI (code) must be built to be maintainable, typically by incorporating layering and encapsulation … …which have a detrimental effect on speed and size of the executing system PSI (Code) automatically generate a Platform Specific Implementation using PIM-PSI mappings manually build a Platform Independent Model … PIM (xUML) Translate Built for executability Built for maintainability In translation-based approaches, the maintained entity (the PIM) is built for maintainability with layering and encapsulation… … while the executable entity (the PSI) is optimized for execution efficiency
56. The End A Practical Guide to Code Generation using Model Driven Architecture and Executable UML 25 Jun 2008 Chris Raistrick, Kennedy Carter [email_address] KC.COM
Hinweis der Redaktion
Make a sign. There are a number of slides that contain what might be called tedious but relevant detail. These were included for reference. My reserves of time, and I suspect your reserves of alertness, preclude detailed examination of these slides.
Components are lovingly handcrafted Each is subjected to its own personal design and implementation process clearly nobody would build components like this. Look at all these tables…
Imagine these are software engineers – which is quite hard. What happens if we take the classic analyse-design-code process in the context of MDA? Hard to swim up a waterfall What happens when a requirement changes? What happens to the PIM and PSM?
Look how sunny it is on the right The more environmentally responsible among you will have noticed a problem with the right hand picture. It contains pollution. However, this is due to an inappropriately selected piece of tacky clip art. As we shall see, MDA embodies its own anti-pollution policy.
MDA is about formalisation of expertise…both application and technology expertise
We can formalise the rules and policies about how we organise our software… …in exactly the same way that we formalise rules about how we organise aircraft… by building executable UML models of those two domains Design is just a subject matter for analysis.
The primary deliverable in this approach to MDA is the PIM. It is here that all rules and policies are defined. It is here that requirement changes are reflected. The PSM and the PSI are merely derived products.
We build a PIM that is technology agnostic, but this can be accompanied by platform-specific configuration data to influence the code generation process. The xUML Runtime layer provides the xUML virtual machine. It may not be present in highly compact targets. The adaptation layer provides services to map onto the underlying platform – operating system, language and middleware.
This process is predicated on the need to build precise, executable models. This precludes use of highly complex, semantically ambiguous notations (such as UML 2.x) Executable UML is a precise proper subset of UML, composed of a small set of simple notations, organised in a predictable and simple way.
Much of the complexity of UML 2.x exists because of the need to build PSMs, in which we must concern ourselves with: different types of communication data structures code structures (e.g. friends) node boundaries sw engineers have a long track record of migrating to more abstract formalisms
The code generator is just a set of domains… …representing the components to be mapped… …with embedded mappings Let’s walk through the steps of this process
This is an executable model of our code generation rules. When we generate code from this model, we get a code generator!
So our PIM is now just data – even the code!
To generate code for a domain, we write a “generateCode” operation on the Domain class… …which iterates across all classes… etc
In the olden days, we used to pile all our data into a global area and systematically rape and plunder it at will. Not pretty, but very fast.
If we have a complex implementation architecture, we do what all modellers do with complex things… …we model them. Here we have a model of the PSM components.
All this extra complexity would typically end up in the model, but with this approach the model can be kept in its simnplest form.
Design is just another subject matter for analysis
What characteristics, what constraints? - select a paradigm.