com.ibm.dtfj.analyzer.util
Class WorkHeap

java.lang.Object
  extended by com.ibm.dtfj.analyzer.util.WorkHeap
All Implemented Interfaces:
ObjectObserver

public class WorkHeap
extends java.lang.Object
implements ObjectObserver

Define a container to hold a subset of the objects reachable from the the Runtime. In essence we tell this class what objects we care about by passing iterators. We can then do operations on this heap to find the set of reachable objects etc.


Field Summary
static int DEFAULT_GRAIN
          The default to be used to define the expected object grain - minimum object size
 
Constructor Summary
WorkHeap()
          Build an heap with default grain and unlimited size
WorkHeap(ClassDirectory dir)
          Build a heap with default grain and unlimited size using the given class directory.
WorkHeap(int grain)
          Build an empty heap with the given grain (object address granularity)
WorkHeap(int grain, long size)
          Build an empty heap with the given grain (object address granularity) and maximum size.
 
Method Summary
 void buildReferenceTables(ObjectIterator objs)
          Build the set of references and referenced-by indexes for the reachable objects
 void checkReferenceCounts(ObjectIterator objs)
          Assume that the set of references and referenced-by indexes for the reachable objects re complete and then test them for accuracy
 void clear()
          Clear all mark and reference information
 void clearMarks()
          Clear all mark information
 void clearReferences()
          Clear all reference information
static int countMarkedObjects(ObjectIterator itr, ObjectMarkSet marks)
          Count the total marked objects by iterating over the set and observing the given set of marks.
 long countMarks()
          Count the number of marked objects
 ObjectMarkSet getActualMarks()
          Get the set of marked objects.
 ClassDirectory getDirectory()
          Get the class directory used to find classes.
 int getGrain()
          Get the object granularity.
 ObjectMarkSet getMarks()
          Get the set of marked objects.
 void markDeep(ObjectIterator objs)
          Mark the set of objects identified by the given iterator and everything that those objects reach.
 ObjectMarkSet markOnReferenceCount(int limit, boolean above)
          Look at all the objects in the heap and mark them based on how many objects they reference.
 ObjectMarkSet markOnReferencedByCount(int limit, boolean above)
          Look at all the objects in the heap and mark them based on how many objects they are referenced by.
static ObjectMarkSet markReferences(ObjectIterator itr, ClassDirectory dir, int grain)
          This is a convenience method designed to be used as part of a marking scheme.
 void markRefsFrom(ObjectIterator objs)
          Mark the set of objects identified by the given iterator.
 ObjectMarkSet markRoots()
          Look at all the objects in the heap and mark any that have no references to them - the assumed set of root objects.
 void markShallow(ObjectIterator objs)
          Mark the objects identified by the given iterator.
 void processObject(java.lang.Object context, com.ibm.dtfj.java.JavaObject obj)
          (non-Javadoc)
 void reportReferences(ObjectIterator objs, IAnalysisReport report)
          Assuming that the set of references and referenced-by indexes for the reachable objects are complete show the reference trees for the iterated objects.
 void setDirectory(ClassDirectory dir)
          Set the class directory used to find classes.
 java.lang.String toString()
          (non-Javadoc)
static long totalObjectSize(ObjectIterator itr)
          Count the total size of the objects in the iterator.
 void unmarkShallow(ObjectIterator objs)
          Unmark the objects identified by the given iterator.
 void visitIfClassIsMarked(ObjectIterator objs, ObjectObserver obs, boolean mark)
          Iterate over the objects in the iterator and call the observer for any of them which are instances of a class which is marked.
 void visitIfClassLoaderIsMarked(ObjectIterator objs, ObjectObserver obs, boolean mark)
          Iterate over the objects in the iterator and call the observer for any of them which are instances of a class which was loaded by a loader that is marked.
 void visitIfReferencesMarkedObject(ObjectIterator objs, ObjectObserver obs, boolean mark)
          Iterate over the objects in the iterator and call the observer if any of them reference an object which is already marked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_GRAIN

public static final int DEFAULT_GRAIN
The default to be used to define the expected object grain - minimum object size

See Also:
Constant Field Values
Constructor Detail

WorkHeap

public WorkHeap()
Build an heap with default grain and unlimited size


WorkHeap

public WorkHeap(ClassDirectory dir)
Build a heap with default grain and unlimited size using the given class directory.

Parameters:
dir - the directory to use when getting class scanners

WorkHeap

public WorkHeap(int grain)
Build an empty heap with the given grain (object address granularity)

Parameters:
grain - the addressing granularity

WorkHeap

public WorkHeap(int grain,
                long size)
Build an empty heap with the given grain (object address granularity) and maximum size.

Parameters:
grain - the addressing granularity
size - the largest address
Method Detail

markReferences

public static ObjectMarkSet markReferences(ObjectIterator itr,
                                           ClassDirectory dir,
                                           int grain)
This is a convenience method designed to be used as part of a marking scheme. For each of the objects in the iterator we visit the immediately referenced objects and mark them. The resulting MarkSet thus shows the objects which are referenced by a given set of objects. By using the resulting MarkSet to constrain the objects returned from the iterator we can thus trace the entire referenced set of objects in multiple phases. Note that this is not the same as a deep marking by visiting the referenced objects and then visiting the references they make etc. For that see the mark or markRefsFrom methods.

Parameters:
itr - an iterator defining the objects to mark
dir - an optional class directory or null
grain - the object granularity
Returns:
the resulting mark set

countMarkedObjects

public static int countMarkedObjects(ObjectIterator itr,
                                     ObjectMarkSet marks)
Count the total marked objects by iterating over the set and observing the given set of marks. Note that the result is the AND of the objects known to the iterator and the objects marked in the set. Hence it is not the same as the count operation on either the iterator or the MarkSet.

Parameters:
itr - the set of objects
marks - the marks
Returns:
the number of marked objects

totalObjectSize

public static long totalObjectSize(ObjectIterator itr)
Count the total size of the objects in the iterator.

Parameters:
itr - the set of objects
Returns:
the total size the objects

setDirectory

public void setDirectory(ClassDirectory dir)
Set the class directory used to find classes.

Parameters:
dir - the class directory to use

getDirectory

public ClassDirectory getDirectory()
Get the class directory used to find classes.

Returns:
the class directory in use

getGrain

public int getGrain()
Get the object granularity.

Returns:
object granularity

clearMarks

public void clearMarks()
Clear all mark information


clearReferences

public void clearReferences()
Clear all reference information


clear

public void clear()
Clear all mark and reference information


markShallow

public void markShallow(ObjectIterator objs)
Mark the objects identified by the given iterator. Note that we don't mark the objects which they in turn reference.

Parameters:
objs - an iterator over the set of objects

unmarkShallow

public void unmarkShallow(ObjectIterator objs)
Unmark the objects identified by the given iterator. Note that we don't mark the objects which they in turn reference.

Parameters:
objs - an iterator over the set of objects

visitIfReferencesMarkedObject

public void visitIfReferencesMarkedObject(ObjectIterator objs,
                                          ObjectObserver obs,
                                          boolean mark)
Iterate over the objects in the iterator and call the observer if any of them reference an object which is already marked. If the mark flag is set we also mark the object we have just found.

Parameters:
objs - an iterator over the set of objects
obs - an observer to call with objects that we have identified
mark - if true then mark the newly found object

visitIfClassIsMarked

public void visitIfClassIsMarked(ObjectIterator objs,
                                 ObjectObserver obs,
                                 boolean mark)
Iterate over the objects in the iterator and call the observer for any of them which are instances of a class which is marked.

Parameters:
objs - an iterator over the set of objects
obs - an observer to call with objects that we have identified
mark - if true then mark the newly found object

visitIfClassLoaderIsMarked

public void visitIfClassLoaderIsMarked(ObjectIterator objs,
                                       ObjectObserver obs,
                                       boolean mark)
Iterate over the objects in the iterator and call the observer for any of them which are instances of a class which was loaded by a loader that is marked.

Parameters:
objs - an iterator over the set of objects
obs - an observer to call with objects that we have identified
mark - if true then mark the newly found object

markDeep

public void markDeep(ObjectIterator objs)
Mark the set of objects identified by the given iterator and everything that those objects reach.

Parameters:
objs - an iterator over the set of objects

markRefsFrom

public void markRefsFrom(ObjectIterator objs)
Mark the set of objects identified by the given iterator. The iterator is treated as the root set and we mark all references from it.

Parameters:
objs - an iterator over the set of objects

getActualMarks

public ObjectMarkSet getActualMarks()
Get the set of marked objects. Note that a reference to the set is returned and so future operations on the heap WILL affect the returned set. This should only be used when the memory penalty of a copy (getMarks) is excessive.

Returns:
the mark set identifying the marked objects

getMarks

public ObjectMarkSet getMarks()
Get the set of marked objects. Note that a copy of the set is returned and so future operations on the heap will NOT affect this returned set.

Returns:
the mark set identifying the marked objects

buildReferenceTables

public void buildReferenceTables(ObjectIterator objs)
Build the set of references and referenced-by indexes for the reachable objects

Parameters:
objs - an iterator over the set of objects

checkReferenceCounts

public void checkReferenceCounts(ObjectIterator objs)
Assume that the set of references and referenced-by indexes for the reachable objects re complete and then test them for accuracy

Parameters:
objs - an iterator over the set of objects

reportReferences

public void reportReferences(ObjectIterator objs,
                             IAnalysisReport report)
Assuming that the set of references and referenced-by indexes for the reachable objects are complete show the reference trees for the iterated objects.

Parameters:
objs - an iterator over the set of objects
report - the report to get the information

markRoots

public ObjectMarkSet markRoots()
Look at all the objects in the heap and mark any that have no references to them - the assumed set of root objects. Return the resulting set of marks.

Returns:
a set of marks relating to unreferenced objects

markOnReferenceCount

public ObjectMarkSet markOnReferenceCount(int limit,
                                          boolean above)
Look at all the objects in the heap and mark them based on how many objects they reference. The limit parameter is the target number of references made by the objectand the flag determines if the marking is done if >limit or <=limit.

Parameters:
limit - the desired number of references
above - if true mark objects with more than limit references else mark objects with less than or equal to the number of refs.
Returns:
a set of marks relating to unreferenced objects

markOnReferencedByCount

public ObjectMarkSet markOnReferencedByCount(int limit,
                                             boolean above)
Look at all the objects in the heap and mark them based on how many objects they are referenced by. The limit parameter is the target number of references made to the object and the flag determines if the marking is done if >limit or <=limit.

Parameters:
limit - the desired number of references
above - if true mark objects with more than limit references else mark objects with less than or equal to the number of refs.
Returns:
a set of marks relating to unreferenced objects

processObject

public void processObject(java.lang.Object context,
                          com.ibm.dtfj.java.JavaObject obj)
(non-Javadoc)

Specified by:
processObject in interface ObjectObserver
Parameters:
context - the context - possibly the object heap
obj - the object itself
See Also:
ObjectObserver.processObject( Object, com.ibm.dtfj.java.JavaObject)

countMarks

public long countMarks()
Count the number of marked objects

Returns:
number of marked objects

toString

public java.lang.String toString()
(non-Javadoc)

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


© Copyright IBM Corp. 2007, 2008 All Rights Reserved. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.