340 likes | 621 Views
Dynamic Analysis and Visualizing of Data Structures in Java Programs. Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill University February 9 th 2005. Outline. Motivation Brief overview of *J Requirements for data structure (DS) analysis Some algorithms for analysis Issues
E N D
Dynamic Analysis and Visualizing of Data Structures in Java Programs Presented by Sokhom Pheng (Supervisor: Clark Verbrugge) McGill UniversityFebruary 9th 2005
Outline • Motivation • Brief overview of *J • Requirements for data structure (DS) analysis • Some algorithms for analysis • Issues • Future works Dynamic Analysis and Visualizing of Data Structures in Java Programs
Motivation • Visual understanding of data structure in java programs • Help understand code without looking at source code • Dynamic analysis Dynamic Analysis and Visualizing of Data Structures in Java Programs
Brief Overview of *J • Developed by Bruno Dufour in the sable lab *J Analyzer Java Application trace file *J Agent(JVMPI) Data Structure Analyzer Dynamic Analysis and Visualizing of Data Structures in Java Programs
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 Dynamic Analysis and Visualizing of Data Structures in Java Programs
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 Dynamic Analysis and Visualizing of Data Structures in Java Programs
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 Dynamic Analysis and Visualizing of Data Structures in Java Programs
Algorithm for DS Analysis • Goal: identifying data structures • Started with identifying “tree”, “dag” and “cycle” detected by DFS cycle tree dag Dynamic Analysis and Visualizing of Data Structures in Java Programs
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 Dynamic Analysis and Visualizing of Data Structures in Java Programs
RSG Example Dynamic Analysis and Visualizing of Data Structures in Java Programs
Advantage over Static Analysis Static Analysis public class BinaryTree { ... public static void main(String[] args) { ... tree.left = tree.right; tree.right = new Node(...); ... } ...} class Node { ... } tree dag dag dag Dynamic Analysis and Visualizing of Data Structures in Java Programs
Advantage over Static Analysis (con’d) From JOlden benchmark: BiSort After 62 modifications Dynamic Analysis and Visualizing of Data Structures in Java Programs
Advantage over Static Analysis (con’d) From JOlden benchmark: BiSort After 63 modifications Dynamic Analysis and Visualizing of Data Structures in Java Programs
Data Gathering Issues • Start up code • JVMPI doesn’t start with JVM • Lack of array indices • Primitive values from I/O • Native methods Dynamic Analysis and Visualizing of Data Structures in Java Programs
Potential Solutions • Look only at application code • Ignore arrays for now Dynamic Analysis and Visualizing of Data Structures in Java Programs
Analysis Problems • Multiple entry points obj1 obj2 tree dag obj3 obj4 cycle obj5 obj7 obj6 obj8 Sol’n: Look at all entry points individually Dynamic Analysis and Visualizing of Data Structures in Java Programs
Analysis Problems (con’d) • Garbage objects • Induce multiple entry points • Dead nodes not trivially distinguished from live ones obj2 obj1 Garbage Node obj4 obj3 Dynamic Analysis and Visualizing of Data Structures in Java Programs
Sol’n for Garbage Problem • Root set • Exclude garbage objects not yet deleted by garbage collector • Static fields, live variables and live methods parameters obj1 obj1 obj1 obj2 obj2 Dynamic Analysis and Visualizing of Data Structures in Java Programs
Example of Entry Points Root set 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 { ... } {bar} {bar, foo} {bar, foo} {bar} {bar, foo, b, f} Dynamic Analysis and Visualizing of Data Structures in Java Programs
DS Configuration Options • Self loop • Why do they exist? • Effect: makes everything cyclic Dynamic Analysis and Visualizing of Data Structures in Java Programs
DS Configuration Options (con’d) • Doubly-connected DS • Effect: makes everything cyclic • Not every edge is doubly-connected Dynamic Analysis and Visualizing of Data Structures in Java Programs
Gathering Other Useful Info • Encode “age” of modification • How a DS evolves over time • Amount of garbage being carried • “Drag” effect Dynamic Analysis and Visualizing of Data Structures in Java Programs
Drag Effect From JOlden benchmark: Barnes-Hut After 58 modifications Dynamic Analysis and Visualizing of Data Structures in Java Programs
Legend / Encoding Age of node New node ≤ 10 byte codes ≤ 100 byte codes Cycle ≤ 1000 byte codes DAG ≤ 10000 byte codes Tree ≤ 100000 byte codes obj1 Garbage ≤ 1000000 byte codes >1000000 byte codes Dynamic Analysis and Visualizing of Data Structures in Java Programs
Example From JOlden benchmark: Barnes-Hut After 13 modifications Dynamic Analysis and Visualizing of Data Structures in Java Programs
Garbage Option • Option to show garbage objects or not Dynamic Analysis and Visualizing of Data Structures in Java Programs
Representing Entry Points • Different shapes and colours for entry point depending on type of DS Dynamic Analysis and Visualizing of Data Structures in Java Programs
Drawing Tool • Dot / Graphviz • Generates snapshots Dynamic Analysis and Visualizing of Data Structures in Java Programs
Drawing Issue • Drawing of one graph has no relation to drawing of the next • Dot try to be optimal • Jumps all over the place Dynamic Analysis and Visualizing of Data Structures in Java Programs
Drawing Issue Example Dynamic Analysis and Visualizing of Data Structures in Java Programs
Possible Solutions • Tom Sawyer Software (currently investigating) • Incremental drawing • Hack into Dot’s source code • Add “inter-frames” between snapshots Dynamic Analysis and Visualizing of Data Structures in Java Programs
Small Complete Example Dynamic Analysis and Visualizing of Data Structures in Java Programs
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 Dynamic Analysis and Visualizing of Data Structures in Java Programs
Thank You! Dynamic Analysis and Visualizing of Data Structures in Java Programs