Exercise 3. Code Generator Memory Options

What This Exercise Is About

Using the PurchaseOrder model, you will experiment with how to tune the impact that generated code has on memory footprint. In particular, you will enable memory-related generator options.

For your reference, here again is the UML class diagram describing the purchase order model:

Extended PO model


What You Should Be Able To Do

At the end of the lab, you should be able to:

Required Materials

General Advice / Warnings

Exercise Instructions

This exercise is carried out entirely using the Eclipse Software Development Kit (SDK) version 3.2 with the Eclipse Modeling Framework (EMF) 2.2 installed into it. The exercise instructions refer to this product as either Eclipse or as "the workbench".

These instructions are located in the exercises/Exercise3_CodeGen_Memory_Options folder. If you browse into this location by expanding the folders, you should find one additional folder: org.eclipse.emf.tutorial.advanced.po. This is an Eclipse project that you will import into your workspace to complete this exercise.

The folder exercises/Solution3 contains examples of the files you will create during this exercise.


Directions

Step A: Verify workbench configuration

  1. See Exercise 1, Step A.

Step B: Import the project into the workspace

  1. See Exercise 1, Step B.

Step C: Customize the Generator to Enable Virtual Feature Delegation

  1. Set the Feature Delegation generator model property in the PurchaseOrder generator model.
    1. Open the PurchaseOrder.genmodel file available in the model folder of the project imported in step B (if not already open).
    2. Select the topmost node PurchaseOrder, right-click, and select Show Properties View (if this view is not already shown).
    3. Scroll the Properties view to find the Model twisty. Underneath is the Feature Delegation property. Set that property to Virtual.
    4. Set Feature Delegation in PurchaseOrder.genmodel


Step D: Customize the Generator to Enable Boolean Flags

  1. Set the Boolean Flags Field generator model property in the PurchaseOrder generator model.
    1. Open the PurchaseOrder.genmodel file available in the model folder of the project imported in step B (if not already open).
    2. Select the topmost node PurchaseOrder, right-click, and select Show Properties View (if this view is not already shown).
    3. Scroll the Properties view to find the Model Feature Defaults twisty. Underneath is the Boolean Flags Field property. Set that property to flags.
    4. Set Boolean Flags Field in PurchaseOrder.genmodel


Step E: Generate and Examine the Model Code

  1. Generate the model code from the genmodel file.
    1. Open the PurchaseOrder.genmodel file available in the model folder of the project imported in step B (if not already open).
    2. Select the topmost node PurchaseOrder, right-click, and select Generate Model Code.
    3. The code should be compiled automatically as it is generated, and should recompile whenever it is changed. If you have disabled automatic building in the workbench preferences, you can initiate compilation manually by selecting Build All from the Project menu.
    4. Generate the model code

  2. Analyze the PersonImpl.java source file.
    1. Open the PersonImpl.java file available in the org.emf.tutorial.advanced.po package.
    2. Notice that an array field (eVirtualValues) and associated index field (eVirtualIndexBits0) were generated to store the values of non-primitive features.
    3. Notice a bit field (flags) was generated to represent the values of boolean attributes.
    4. Analyze PersonImpl

  3. Analyze the CustomerImpl.java source file.
    1. Open the CustomerImpl.java file available in the org.emf.tutorial.advanced.po package.
    2. Notice that no field was generated for the purchaseOrders reference. The accessor for the purchaseOrders reference gets/sets the value at a specific index (maintained in the index field in PersonImpl) in the array field inherited from PersonImpl.
    3. Notice purchaseOrders reference

    4. Notice that no field was generated for the vip attribute, but instead there is a static constant bit index (VIP_EFLAG). The accessors for the vip attribute get and set the corresponding bit in the bit field inherited from PersonImpl.
    5. Notice vip attribute


Summary

You experimented with memory-related EMF code generator options and witnessed the effect of such options on the generated code.