1 / 1

Towards A Light-Weight Tool for Locating Unintentional Object Retention in Java Programs

Motivation. Objectives. Code Weaving in AspectJ. Build a light-weight tool for Identifying the suspected classes of loitering objects, and further. locating unintended object references in the source code.

Télécharger la présentation

Towards A Light-Weight Tool for Locating Unintentional Object Retention in Java Programs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Motivation Objectives Code Weaving in AspectJ • Build a light-weight tool for • Identifying the suspected classes of loitering objects, and further. • locating unintended object references in the source code. • Even with automatic garbage collector, memory leaks do occur in Java programs in the form of loitering objects. • Such loitering objects can be hard to locate and fix in a complex Java program. • Current tools for diagnosing Java memory leaks address this problem mostly by digging information buried in JVM heap. This approach is weak at • assisting programmer to establish strong hypothesis about loitering objects. • providing effective clues to where in the source code these loitering objects are retained. Key Ideas Tool Components • Object life monitoring aspect • calculates D/C ratio • Reference logging aspect • tracks unintended references • Reference pattern analysis tool • extracts suspicious reference patterns The object Destruction/Creation ratio of a class is a good indicator for identifying loitering objects. A log of reference assignments that keeps track of all the references linking to the suspected objects will enable us to locate where those unintentional references are set. AspectJ’s code weaving facility provides a good basis for building a light-weight tool for the tasks above. A Flawed Implementation of Queue with Loitering Objects Execution Flow head public class TestQueue {publicstaticvoid main(String[] args) { Queue myQueue = new Queue(); for (int i=1; i<=100; i++) myQueue.enqueue(new Integer(i)); for (int i=1; i<=90; i++) System.out.println(myQueue.dequeue()); } } public class Queue { ... public Object dequeue() { QueueNode tmp = head; head = tmp.getNextNode(); tmp.setNextNode(null); return tmp.getContainedObject(); } } Test Program QN1 ---------------- QN prev QN next Object elem QN2 ---------------- QN prev QN next Object elem QN3 ---------------- QN prev QN next Object elem Major Steps ...... What is a Memory Leak in Java To locate unintended object references: • Weave in the object life monitoring aspect into the target application. Run the application for a period of time in order to calculate the D/C ratio value for selected application classes. • Identify some the suspected classes based on the D/C statistics, and then weave in the reference logging aspect on objects of those chosen classes. • Likewise, run the application for a period of time to log all references linking to the objects of suspected classes. • Analyze the reference log and extract reference patterns that look suspicious. • Use the reference patterns and precise source code location information to locate the code causing unintended references. object A object B object C myQueue = new Queue();…myQueue.enqueue(..);myQueue.enqueue(..);… head QN1 ---------------- QN prev QN next Object elem QN2 ---------------- QN prev QN next Object elem QN3 ---------------- QN prev QN next Object elem ...... object A object B object C myObj = myQueue.dequeue(); missing code:head.setPreviousNode(null); myObj head QN1 ---------------- QN prev QN next Object elem QN2 ---------------- QN prev QN next Object elem QN3 ---------------- QN prev QN next Object elem ...... Live Object Loitering Object object A object B object C myObj = myQueue.dequeue(); Object field Intended Ref. myObj Unintended Ref. class : testCases.QueueNode reference count : 110 class statistics : testCases.Queue : 2 testCases.QueueNode : 108 field statistics : QueueNode testCases.QueueNode.next : 9 QueueNode testCases.QueueNode.prev : 99 QueueNode testCases.Queue.headNode : 1 QueueNode testCases.Queue.tailNode : 1 location statistics : Queue.java:22 : 1 Queue.java:46 : 1 QueueNode.java:42 : 9 QueueNode.java:16 : 99 Reference Statistics from the Log testCases.Queue : 0/1 = 0.0% testCases.QueueNode : 0/100 = 0.0% Destruction/Creation Ratio crosscutting concern class class Reference Pattern Extraction suspected class Reference Count:: 99Field: prevLocation: QueueNode.java, line 16 Reference Count:: 1Field: headNodeLocation: Queue.java, line 22 Work Ahead testCases.QueueNode • Investigate enhancements to the scope of AspectJ’s join points. • AspectJ does not pick out join points of array-element access. • Develop a visual interface for the reference analysis tool. testCases.Queue where (pointcut) weaving do what (advice) Reference Count:: 9Field: nextLocation: QueueNode.java, line 42 aspect Reference Count:: 1Field: tailNodeLocation: Queue.java, line 46 Towards A Light-Weight Tool for Locating Unintentional Object Retention in Java Programs Chin-Hung ChienFoxconn Electronics Inc.richard.chien@foxconn.com Kung Chen and Ju-Bing ChenDept. of Computer ScienceNational Chengchi Universitychenk@cs.nccu.edu.twg9405@cs.nccu.edu.tw Unreachable garbage Reachable but not Live loitering objects Reachable and Live Root Set

More Related