The reference VM - AutoUnfold ubrvm

From OO Lab
Revision as of 17:00, 2 December 2011 by RyanYang (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A Special Reference VM - Autounfold

In this tutorial, a special type of UBRVM called AutoUnfold? is introduced. A normal reference VM such as Laserline or Orbit_Orgehead needs to be clicked to unfold its pointer contents.

However, while visualizing some cases, particularly Java's arrays, this basic feature cannot meet a user's normal expectation of visualization. Unlike C,C++ array, a Java array is an array of references. For example, when your declare a Java array and you need to initialize the elements somewhere in the code.

   RGB[][] colour = new RGB[w][h];
       for(int j=0;j<w;j++){
           for(int i=0;i<h;i++){
               double r = (double)(Math.random());
               double g = (double)(Math.random());
               double b = (double)(Math.random());
               colour[i][j] = new RGB(r,g,b);
           }
       }

Using composite VM such as ball_laser can have the following weird results.

Array of references in Java

So, xDIVA implements a special reference VM called autounfold_ubrvm. An autounfold reference VM when created will unfold its content automatically. Imaging that a click to the reference VM is automatically performed by xDIVA.

Besides the click is automated, Autounfold_ubrvm positions the unfolded VM at the same position as autounfold_ubrvm. For example, let a reference VM called P and let its pointed content be visualized as a VM Q. When Q is created, Q will be positioned at the location of P. In fact, P is actually a cube which is invisible and slightly larger than Q so that Q is surrounded by P.

Any mouse events performed on Q will be intercepted by P first. Next, once P processes the mouse event, P will propagate the event to Q. For example, it is possible to connect some message to P's _vm_clickmsg and some other message to Q's _vm_clickmsg. These two messages will all be handled.

Example RGB.java

In this tutorial, we will demonstrate how to use autounfold_ubrvm by RGB.java. Please open the RGB.java and set the break point at the place shown as follows:

RGBjava.jpg

1.Run xDIVA, and visualize the array "colour"

When mapping dialog pops up, select ball_laser to visualize the reference.

RGB-1.jpg

In xDIVA, a grey ball is shown. Click to unfold the reference. Another mapping dialog will pop up.

RGB-2.jpg

2. Click on the |+| beside the array to unfold the array compound structure. A sub mapping dialog pops up as follows. Please follow the screen shot to make the connection. Please look at the type of colour[i][j]. Their types are all of "ref" type. In this mapping, we assign an autounfold ubrvm for each elements of the colour.

At the end of xMappingTree, we use a container called 2Darray_ubvm. 2Darray_ubvm is a container that layout the child elements into a 2D array. To use this container, you need to give the rows and columns, which are the dimenions of the array. By default, they are set to 0,0 and will cause assert false for now if you do not set them properly.

RGB-3.jpg

Please remember to give the dimension of the array to the 2Darray_ubvm by open its port attributes as follows: In the figure, we set the rows and columns port attributes to 2,2

RGB-5.jpg

3. Press OK and another mapping dialog pops up because the autounfold reference VM is created and it immediately unfold its value, which is an RGB object. Please complete the following connections. Remember to press the Apply all once you have completed the mappings. We want the mapping to apply automatically to every colour[i][j].

RGB-6.jpg

4. Once the OK is pressed, the result is shown as

RGB-7.jpg

Personal tools