dynamic analysis and visualizing of data structures in java programs presented by sokhom pheng...

34
Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February 9 th 2005

Upload: randall-evans

Post on 17-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

Dynamic Analysis and Visualizing of Data

Structures in Java Programs

Presented by Sokhom Pheng(Supervisor: Clark Verbrugge)

McGill UniversityFebruary 9th 2005

Page 2: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

2

Outline

Motivation Brief overview of *J Requirements for data structure (DS)

analysis Some algorithms for analysis Issues Future works

Page 3: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

3

Motivation

Visual understanding of data structure in java programs

Help understand code without looking at source code

Dynamic analysis

Page 4: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

4

Brief Overview of *J

Developed by Bruno Dufour in the sable lab

Java Application *J Analyzer

Data Structure Analyzer

*J Agent(JVMPI)

trace file

Page 5: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

5

Why isn’t *J enough for DS Analysis? JVMPI doesn’t provide all info

Missing references of objects Missing info on actual values for primitive

Important for accessing arrays Does not track objects

Page 6: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

6

Requirements for Data Structures Analysis Need to simulate the whole program

execution Keep track of the JVM stacks

Follow JVM design (VM Spec) Invocation stack for each thread Stack frame for each method

Execution stack to contain operand objects

Keep track of actual values (even of primitives) for array indices

Page 7: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

7

Represent Data Structures in Memory Object, method and class has unique ID and

entity (originally implemented in *J) ObjectEntity: ID, name, type, size, … MethodEntity: signature, name, class entity, … ClassEntity: name, number of methods/interfaces,

… Recreate objects and their references to each

other by executing bytecodes found in the trace Eg. putfield obj1 obj2

Page 8: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

8

Algorithm for DS Analysis

Goal: identifying data structures Started with identifying “tree”, “dag” and

“cycle” detected by DFS

tree dag cycle

Page 9: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

9

Algorithm for DS Analysis (con’d) Other way to identify DS

Combinatorial topology Shape represented by set of equations

Reference Shape Graph (RSG)1

Node represent memory location having similar reference patterns

1 A new Dependence Test Based on Shape Analysis for Pointer-Based Codes, Navarro, Corbera, Asenjo, Tineo, Plata, Zapata, LCPC 2004

Page 10: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

10

RSG Example

Page 11: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

11

Advantage over Static Analysispublic class BinaryTree { ...

public static void main(String[] args) {...tree.left = tree.right;tree.right = new Node(...);

... } ...}

class Node { ... }

Static Analysis

tree

dagdagdag

Page 12: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

12

Advantage over Static Analysis (con’d)From JOlden benchmark: BiSort

After 62 modifications

Page 13: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

13

Advantage over Static Analysis (con’d)From JOlden benchmark: BiSort

After 63 modifications

Page 14: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

14

Data Gathering Issues

Start up code JVMPI doesn’t start with JVM

Lack of array indices Primitive values from I/O

Native methods

Page 15: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

15

Potential Solutions

Look only at application code Ignore arrays for now

Page 16: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

16

Analysis Problems

Multiple entry points

tree dag

cycle

obj1 obj2

obj3

obj5

obj4

obj6

Sol’n: Look at all entry points individually

obj7

obj8

Page 17: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

17

Analysis Problems (con’d)

Garbage objects Induce multiple entry points Dead nodes not trivially distinguished from live

ones

obj1 obj2

obj3 obj4

Garbage Node

Page 18: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

18

Sol’n for Garbage Problem

Root set Exclude garbage objects not yet deleted by

garbage collector

Static fields, live variables and live methods parameters

obj2

obj1 obj1

obj2

obj1

Page 19: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

19

Example of Entry Points

public class Foo { static bar = new Bar();

public static void main(String[] args) {Foo foo = new Foo();foo.foo1(new Bar());...

}

public void foo1(Bar b) {Foo f = new Foo();...

}}class Bar { ... }

Root set

{bar}

{bar, foo}

{bar, foo}

{bar, foo, b, f}

{bar}

Page 20: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

20

DS Configuration Options

Self loop Why do they exist? Effect: makes everything cyclic

Page 21: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

21

DS Configuration Options (con’d) Doubly-connected DS

Effect: makes everything cyclic Not every edge is doubly-connected

Page 22: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

22

Gathering Other Useful Info

Encode “age” of modification How a DS evolves over time

Amount of garbage being carried “Drag” effect

Page 23: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

23

Drag Effect

From JOlden benchmark: Barnes-Hut

After 58 modifications

Page 24: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

24

Legend / Encoding

≤ 1000 byte codes

≤ 100 byte codes

≤ 10 byte codes

≤ 10000 byte codes

≤ 100000 byte codes

≤ 1000000 byte codes

> 1000000 byte codes

Age of node

New node

Cycle

DAG

Tree

obj1 Garbage

Page 25: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

25

Example

From JOlden benchmark: Barnes-Hut

After 13 modifications

Page 26: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

26

Garbage Option

Option to show garbage objects or not

Page 27: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

27

Representing Entry Points

Different shapes and colours for entry point depending on type of DS

Page 28: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

28

Drawing Tool

Dot / Graphviz Generates snapshots

Page 29: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

29

Drawing Issue

Drawing of one graph has no relation to drawing of the next Dot try to be optimal Jumps all over the place

Page 30: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

30

Drawing Issue Example

Page 31: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

31

Possible Solutions

Tom Sawyer Software (currently investigating) Incremental drawing

Hack into Dot’s source code Add “inter-frames” between snapshots

Page 32: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

32

Small Complete Example

Page 33: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

33

Future Works

Deal with arrays and unknown info Draw approximate graph

Handle start up code / native methods Investigate other drawing tools Add other analyses

RSG from LCPC paper Topological approach (set of equations)

Calculate “drags” for garbage objects Analyze more and more complex programs

Page 34: Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February

February 9th 2005 Dynamic Analysis and Visualizing of Data Structures in Java Programs

34

Thank You!