Express (Distributed operating systems), v8.0 > Troubleshoot and support > Analyzing application server Java system dumps with the IBM Monitoring and Diagnostic Tools for Java - Dump Analyzer > Write a new analysis module or script > Write and running a new analysis module


ObjectIterator and filtering

As previously noted there are various utility classes designed to simplify the process of iterating through a set of objects returned in a basic java.util.Iterator. The DTFJIterator is intended to handle CorruptData objects and the SortedIterator is designed to ensure that elements are returned in a well defined order. In order to allow various forms of complex analysis of large heaps we also provide a set of iterators that allow heap objects to be subset in a variety of ways. The basic iterator is com.ibm.dtfj.analyzer.util.ObjectIterator and it can be built using the static factory methods on that class. The iterator can be built to iterate over all the objects in a Heap or a Runtime (all the heaps). By default it will actually return no objects ! This is deliberate although initially confusing; either a filter needs to be added to accept some objects or the default accept state needs to be set true.

// Do some population analysis on all the objects in a runtime ObjectIterator itrAll = ObjectIterator.build(getContext().getCurrentJavaRuntime()); itrAll.setDefaultAcceptState(true); // accept all objects PopulationCounter ctr = new PopulationCounter(this); ctr.analyzeAndReport("All objects",itrAll,report);

If we now add a simple filter we can do some analysis of just a subset of the objects in the heap.

// Do some population analysis on objects of class starting java/lang/ref/SoftRef ObjectIterator itrAll = ObjectIterator.build(getContext().getCurrentJavaRuntime()); itrAll.setDefaultAcceptState(false); // reject everything unless accepted by a filter itrAll.addFilter(new ClassAccept("java/lang/ref/SoftRef*",true)); // match name including superclasses PopulationCounter ctr = new PopulationCounter(this); ctr.analyzeAndReport("All SoftReference objects",itrAll,report);


Filters

There are various forms of filter that can be added to an ObjectIterator and there may be multiple filters. All the possible filters are defined in the package com.ibm.dtfj.analyzer.util.filter. When handling multiple filters an object is accepted if any filter accepts it and no filter rejects it. For each filtering attribute there are three filter classes and hence for filtering on class name we have

The *Accept and *Reject filters are simply derived from the *Filter classes. The attributes which can currently be filtered are as follows.

The first four need little explanation in that they are simply filtering on different aspects of the object being examined; its class, its address, its size and whether or not it is an array. The final one; the MarkedFilter allows filtering to be done on the basis of information which is not necessarily held in the object itself. As mentioned previously it is possible to combine the various filters and thus we can extend the previous example to accept objects which extend SoftReference, are larger than some given size and are in a given region of the heap.

// Show all objects of class starting java/lang/ref/SoftRef ObjectIterator itrAll = ObjectIterator.build(getContext().getCurrentJavaRuntime()); itrAll.setDefaultAcceptState(false); itrAll.addFilter(new ClassAccept("java/lang/ref/SoftReference",true)); itrAll.addFilter(new SizeAccept(100,1000)); itrAll.addFilter(new AddressAccept(0x800000,0x830200)); PopulationCounter ctr = new PopulationCounter(this); ctr.analyzeAndReport("Some SoftReference objects",itrAll,report);

Use combinations of filters it is possible to subset the objects in a variety of ways with the intention of then doing further analysis on the resulting set. When analyzing out of memory conditions it is often necessary to do more than simply subset the heap by examining object properties. We need to consider the references between objects and build sets based on those references. To facilitate that form of analysis we have a WorkHeap class. In essence it is designed to mimic the sort of operations that the garbage collector undertakes on the real heap so that we can start with a set of objects (defined by an ObjectIterator and some set of filters) and then mark the objects which are referenced from that set. We can then take the resulting MarkSet and perform boolean operations against previously created MarkSet objects and hence build up very complex forms of analysis. The WorkHeap class is defined in package com.ibm.dtfj.analyzer.util ( javadoc).

+

Search Tips   |   Advanced Search