700 likes | 840 Views
Role-Based Exploration of Object-Oriented Programs. Brian Demsky and Martin Rinard MIT Laboratory for Computer Science . Research Goal. Help developers discover and understand Different states of objects in computation Relationships between objects in different states
E N D
Role-Based Explorationof Object-Oriented Programs Brian Demsky and Martin Rinard MIT Laboratory for Computer Science
Research Goal Help developers discover and understand • Different states of objects in computation • Relationships between objects in different states • How states and actions interact • How objects change state in response to program actions • Assumptions that program actions make on the states of accessed objects
Basic Approach • Automatically examine execution of program • Extract information about states and actions • Graphically and interactively present information
Outline • Challenges • Example • Roles and Object States • Extracted Information • Presenting Information to Developer • Extensions and Customization • Experience • Related Work • Conclusion
Challenges Given a program, automatically infer an appropriate set of abstract object states for that program Relate the object states to important structural and functional properties of the program Present this information to the developer
Role Separation Predicates • Set of predicates (role separation predicates) • Evaluate predicates on each object • Objects with the same values for the predicates are in the same state • We call each state a role • We say that an object plays its role
Role Separation Predicates:Set of Predicates ra rb rc State o1 o2 o3 o4 o5 Objects P1(o1)=T P2(o1)=T P3(o1)=T P1(o2)=F P2(o2)=T P3(o2)=T P1(o3)=F P2(o3)=T P3(o3)=T P1(o4)=T P2(o4)=F P3(o4)=T P1(o5)=T P2(o5)=F P3(o5)=T
Choosing Predicates • Each predicate should capture some aspect of some conceptual role that an object might play • One obvious category of predicates Predicates that capture the class of the object • How do we select other predicates? • Examine common information representation strategies • Select predicates that capture the distinctions that these patterns are designed to represent
Example Developer Salesperson salesperson developer manages manages Employee
Properties • Interesting invariants: • Only an employee who is a salesperson should make a sale • Only an employee who is a developer should check code in to the code base • How can we tell a salesperson from a developer?
Developer Developer developer developer Employee Employee SalesPerson SalesPerson SalesPerson salesperson salesperson salesperson Employee Employee Employee Examples of Employees Playing Developer and Salesperson Roles
SalesPerson SalesPerson SalesPerson salesperson salesperson salesperson Employee Employee Employee Examples of Employees Playing Developer and Salesperson Roles Developer developer Employee Developer developer Employee
Examples of Employees Playing Developer and Salesperson Roles SalesPerson Developer salesperson developer Employee Employee SalesPerson salesperson Employee Developer SalesPerson developer salesperson Employee Employee
Solution Heap Alias Predicates: Captures whether a given field of a given class points to object in question Formal Predicate: Pc.f(o) is true if o has a reference from the f field of an instance of class c Example: PDeveloper.developer(o) is true if o is a developer
Role Changes Developer Developer SalesPerson SalesPerson • Employees can migrate through careers • Roles can capture these changes of an object’s referencing state and of the functional constraints placed on the object developer salesperson developer salesperson Employee Employee Employee
More Properties • Property: Only managers are sent to management training seminars • How can we identify managers?
Employee Employee Employee manages manages manages Vector of Developer & SalesPerson Vector of Developer & SalesPerson Vector of Developer & SalesPerson Instances of an Employee Playing Managing and Non-managing Roles Employee Employee Employee
Instances of an Employee Playing Managing and Non-managing Roles Employee Employee Employee manages Employee Vector of Developer & SalesPerson Employee Employee manages manages Vector of Developer & SalesPerson Vector of Developer & SalesPerson
Solution Non-null field predicates: Capture what references an object has to other objects Formal Predicates: Pg(o) is true if o has the non-null field g, false otherwise Example: Pmanages(o) is true if o is a manager
Role Separation Criteria For each class c: Pc(o) = object o has class c For each class and field pair <c,f>: Pc.f(o) = there is a reference to o from the field f of an instance of c For each field g: Pg(o) = object o has a non-null field g For key local and global variables v: Pv(o) = object o is reachable from v For each fields f,g: Pf,g(o) = object o has the cyclic path o.f.g=o For key methods m and parameters n: Pm,n(o)= object o has been parameter n of method m
Role developer Employee w/manages Class: Employee Heap Aliases: Developer.developer, Non-null Fields: manages Role Description PEmployee(o) =T PDeveloper.developer(o)=T Pmanages(o) = T Developer.developer manages
Dynamic Role Inference • Instrument execution of the program • Run program to generate a trace of heap operations • Dynamically compute • Roles that each object plays • Transitions between roles • Roles of methods’ parameters
When Do We Evaluate Roles? • Goal: Evaluate roles when objects have consistent states • Objects are likely to have consistent states at method entry and exit points • By default our tool evaluates the roles of objects at method boundaries • The developer can modify this default policy
Role Naming Heuristic manages Vector w/ elementData • The role name assigned to this role description is: manages Vectorw/ elementData • manages refers to the heap alias to the object • Vector is the class name of the object • elementData refers to the non-null field of the object • The tool allows the developer to manually provide more descriptive names for a role, and we have done so in some cases to improve readability elementData manages Class: java.lang.Vector
Role Transition Diagram Initial Employee developer Employee salesperson Employee this arg of Developer.<init> this arg of SalesPerson.<init> this arg of assignEmployees developer Employee w/ manages this arg of assignEmployees this arg of SalesPerson.<init> salesperson Employee w/ manages developer & salesperson Employee restructureCompany this arg of assignEmployees developer & salesperson w/ manages
Role Transition Diagram Initial Employee developer Employee salesperson Employee this arg of Developer.<init> this arg of SalesPerson.<init> this arg of assignEmployees developer Employee w/ manages this arg of assignEmployees this arg of SalesPerson.<init> salesperson Employee w/ manages developer & salesperson Employee restructureCompany this arg of assignEmployees developer & salesperson w/ manages
Enhanced Method Interfaces • Our tool can generate an enhanced method interface which includes: • the roles of the parameters • the role changes that the method performs • We believe developers will find this sort of information useful for understanding • assumptions that methods make • effects of a method on objects it accesses
Enhanced Method Interface Developer.<init>(Developer, Employee) Calling Context: (InitialDeveloper, InitialEmployee) Return Context: (Developer, developer Employee) Role Changes: InitialDeveloper -> Developer InitialEmployee -> developer Employee
Role Relationship Diagram developer Employee developer developer developer Employee w/ manages developer & salesperson Employee w/ manages Developer developer developer developer & salesperson Employee
Role Relationship Diagram developer Employee developer developer developer & salesperson Employee w/ manages developer Employee w/ manages Developer developer developer developer & salesperson Employee
Interactive Support • Our tool uses a graphical web-based interface to communicate inferred properties • The tool presents: • Role transition diagrams for each class • A role relationship diagram • Links from the diagrams to the appropriate • role descriptions • enhanced method interfaces
Role Relationship Diagram developer Employee developer developer developer Employee w/ manages developer & salesperson Employee w/ manages Developer developer developer developer & salesperson Employee
Role Relationship Diagram developer Employee developer developer developer Employee w/ manages developer Employee w/ manages developer & salesperson Employee w/ manages Developer developer developer developer & salesperson Employee
Role developer Employee w/manages satisfies Class: Employee Heap Aliases: Developer.developer Non-null Fields: manages Role Description manages Developer.developer
Role developer Employee w/manages satisfies Class: Employee Heap Aliases: Developer.developer Non-null Fields: manages Role Description Employee manages Developer.developer
Role Transition Diagram Initial Employee developer Employee salesperson Employee this arg of Developer.<init> this arg of SalesPerson.<init> this arg of assignEmployees developer Employee w/ manages this arg of assignEmployees this arg of SalesPerson.<init> salesperson Employee w/ manages developer & salesperson Employee restructureCompany this arg of assignEmployees developer & salesperson w/ manages
Role Transition Diagram Initial Employee developer Employee salesperson Employee this arg of Developer.<init> this arg of SalesPerson.<init> this arg of assignEmployees developer Employee w/ manages this arg of assignEmployees this arg of SalesPerson.<init> salesperson Employee w/ manages salesperson Employee w/ manages developer & salesperson Employee restructureCompany this arg of assignEmployees developer & salesperson w/ manages
Role salesperson Employee w/manages satisfies Class: Employee Heap Aliases: SalesPerson.salesperson Non-null Fields: manages Role Description manages SalesPerson.salesperson
Role Subspaces • Different activities require exploration at varying levels of detail • The developer may initially need very coarse information then later explore certain aspects in greater detail • The developer may coarsen aspects of objects orthogonal to the developer’s current interest • Role subspaces provide a means to manage role separation predicates • Developers specify a role subspace by specifying a subset of role separation criteria • Multiple role subspaces can be used simultaneously
Role Subspaces PEmployee(o) Pmanages(o) PDeveloper.developer(o) PSalesPerson.salesperson(o) Role Subspace { Class: Employee Non-null Fields: manages } . . .
Role Transition Diagram InitialEmployee this arg of assignEmployee Employee w/ manages
Multiple Object Data Structures Employee manages Vector Array Developer Developer SalesPerson Developer
Multiple Object Data Structures Employee manages Developer Developer SalesPerson Developer
Customization • Our web-based interface allows the developer to control the analysis. The developer can: • Define multiple role subspaces • View projections of role transition diagrams and role relationship diagrams onto the defined role subspaces • Declare methods atomic to hide internal role changes • Declare a set of methods to be considered in the method invocation history of objects
Experience • We used our tool on a variety of different applications: • JhttpServer – a simple web server • Jess – an expert system shell • Direct-To – an air-traffic control tool
Role Transition Diagram for Socket Initial Socket Socket ServerSocket Socket w/ address ServerSocket w/fd Garbage Socket w/fd bound ServerSocket Socket w/o output Socket w/ input listening ServerSocket Socket w/o fd Socket w/ output