Automated Construction of Memory Diagrams for ...

3 downloads 0 Views 853KB Size Report
Apr 16, 2010 - Andrew R. Dalton and William Kreahling. {adalton, wkreahling}@wcu.edu. Department of Mathematics and Computer Science. Western ...
Automated Construction of Memory Diagrams for Program Comprehension Andrew R. Dalton and William Kreahling {adalton, wkreahling}@wcu.edu Department of Mathematics and Computer Science Western Carolina University

April 16, 2010 ACM Southeast Conference

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

1 / 24

Presentation Roadmap

1

Introduction

2

System Overview

3

Toolkit Components

4

Examples

5

Conclusions and Questions

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

2 / 24

Introduction

Problems OO systems are complex Primitives vs references Instance vs class variables Instance vs class methods

Observation Visualizations help UML Memory diagrams

Creating visualizations by hand can be tedious

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

3 / 24

Introduction (cont’d) Example ClassName ClassName private primitive 3

staticMethod()

private static reference

instanceMethod()

Idea A toolkit for automating the construction of memory diagrams will will help both students and instructors take advantage of memory diagrams as an aid to program comprehension. Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

4 / 24

Contributions

Memory Diagramming Toolkit Java API Memory diagramming language (MDL) MDL to GXL translator GXL to MDL translator GXL to GraphViz DOT translator

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

5 / 24

Presentation Roadmap

1

Introduction

2

System Overview

3

Toolkit Components

4

Examples

5

Conclusions and Questions

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

6 / 24

Design Desiderata

Goals Enable creation of diagrams from correct programs Enable creation of incorrect diagrams Enable filtering of irrelevant details Enable cyclic diagram revision

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

7 / 24

System Architecture

Toolkit Components Running Java Program

Java API

GXL2DOT

DOT File

GraphViz Dot

GXL File MDL File

MDL2GXL

GXL2MDL

Image

User

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

8 / 24

Presentation Roadmap

1

Introduction

2

System Overview

3

Toolkit Components

4

Examples

5

Conclusions and Questions

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

9 / 24

Java API Enables analysis of graph rooted at an object Uses reflection to recursively identify

Running Java Program

Classes Methods Fields Values

Java API

GXL File

Generates a GXL document Example 1 2 3 4 5

Map root = new HashMap(); root.put("Age", new Integer(18)); ... ObjectGraph graph = new ObjectGraph(root); graph.generateGxl(new File("mapGraph.gxl"));

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

10 / 24

Memory Diagramming Language (MDL) Example 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

class Object { public String toString(); } class String extends Object { ... } class char[] extends Object { ... } class Person extends Object { primitive private static int personCount = 1; public static int getNumPeople(); public String getName(); public int getAge(); } object person instanceof Person { primitive private int age = 18; reference private String name = personName; } object personName instanceof String { reference private char[] value = charArray; } object charArray instanceof char[] { primitive public final int length = 3; primitive private char value[0] = ’J’; primitive private char value[1] = ’i’; primitive private char value[2] = ’m’; }

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

11 / 24

MDL To GXL Translator

Uses compiler tools to scan and parse MDL files Builds an AST corresponding to the structure of the MDL file Applies the Visitor design pattern to traverse the AST and translate each element to GXL

Andrew R. Dalton, Western Carolina University

User

Running Java Program

MDL File

MDL2GXL

Java API

GXL File

Automated Construction of Memory Diagrams

12 / 24

GXL To MDL Translator

Uses Java GXL library to load GXL document Traverses GXL graph and translates it to an in-memory model of the program Applies the Visitor design pattern to traverse the model and translate it to MDL

GXL File

GXL2MDL

MDL2GXL

MDL File User

Enables user to perform cyclic revisions to graphs

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

13 / 24

GXL To Dot Translator

Translates GXL files to GraphViz Dot files Enables filtering Classes Methods Objects Fields

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

14 / 24

GXL To Dot Translator (cont’d)

Like the GXL to MDL translator, loads GXL and builds a model Applies a different visitor to translate the model to Dot GraphViz Dot parses the Dot file and produces an image file

Andrew R. Dalton, Western Carolina University

GXL File

GXL2DOT

Image

Other Toolkit Components

DOT File

GraphViz Dot

Automated Construction of Memory Diagrams

15 / 24

Presentation Roadmap

1

Introduction

2

System Overview

3

Toolkit Components

4

Examples

5

Conclusions and Questions

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

16 / 24

Strings

String::toUpperCase() String::substring(int) String::toLowerCase() String::length() String::trim() String::intern()

String int count 3 char[] value

char[] int length

length

3

Object::toString() char [0] W

char [1] C

Andrew R. Dalton, Western Carolina University

char [2] U

array

Automated Construction of Memory Diagrams

17 / 24

Enumerations

Direction Direction EAST

Direction ordinal() name()

EAST

Direction NORTH Direction SOUTH

NORTH

values() valueOf(String)

Direction WEST

SOUTH

   

WEST

Direction

Direction

int ordinal

int ordinal

int ordinal

2

3

0

Direction int ordinal 1

String name

String name

String name

String name

...

...

...

...

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

18 / 24

Linked List contains(Object) clear() add(Object) get(int) add(int, Object) set(int, Object) size() remove(Object) indexOf(Object)

LinkedList int size 4 LinkedList$ListNode head LinkedList$ListNode tail

LinkedList$ListNode Object element

LinkedList$ListNode next

LinkedList this$0

LinkedList$ListNode Object element

LinkedList$ListNode next

Integer

LinkedList this$0

LinkedList$ListNode

int value

Object element

LinkedList$ListNode next

LinkedList this$0

0

Integer intValue()

int value

LinkedList$ListNode Object element

LinkedList$ListNode next

LinkedList this$0

1

Integer int value

LinkedList$ListNode Object element

LinkedList$ListNode next

LinkedList this$0

2

Integer int value 3

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

19 / 24

Incorrect (By Design)

getValue() setValue(Integer) toString()

int Integer value 27

int    

MDL Code 1 2 3 4 5 6

class Object { public String toString(); } class int extends Object { public Integer getValue(); public void setValue(Integer value); } object object0 instanceof int { primitive private Integer value = 27; }

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

20 / 24

Presentation Roadmap

1

Introduction

2

System Overview

3

Toolkit Components

4

Examples

5

Conclusions and Questions

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

21 / 24

Conclusions Contribution: Memory Diagramming Toolkit Java API Memory diagramming language (MDL) MDL to GXL translator GXL to MDL translator GXL to GraphViz DOT translator Enables Creation of diagrams from correct programs Creation of incorrect diagrams Filtering of irrelevant details Cyclic diagram revision

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

22 / 24

Future Directions

More student use and feedback Enhance selection GUI to enable element highlighting Expand approach to other OO languages

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

23 / 24

Automated Construction of Memory Diagrams for Program Comprehension Andrew R. Dalton and William Kreahling {adalton, wkreahling}@wcu.edu Department of Mathematics and Computer Science Western Carolina University

April 16, 2010 ACM Southeast Conference

Questions?

Andrew R. Dalton, Western Carolina University

Automated Construction of Memory Diagrams

24 / 24

Suggest Documents