com.ibm.dtfj.analyzer.util
Class ClassScanner

java.lang.Object
  extended by com.ibm.dtfj.analyzer.util.ClassScanner

public class ClassScanner
extends java.lang.Object

A class that simplifies the process of getting the contents of object fields. The field descriptors of the class are cached and thus instances of the class can be rapidly scanned. In particular it is possible to visit all the object references made by an instance and this can optionally include the references made by superclasses.


Constructor Summary
ClassScanner(com.ibm.dtfj.java.JavaClass cls)
          Build a scanner on the given JavaClass.
 
Method Summary
 com.ibm.dtfj.java.JavaField getField(java.lang.String name, boolean includeSuperclass)
          Return the field with the given name and optionally search the superclass
 int getIntegerField(com.ibm.dtfj.java.JavaObject obj, java.lang.String name, boolean includeSuperclass)
          Get the content of an integer field.
 com.ibm.dtfj.java.JavaClass getJavaClass()
          Get the java class that this scanner describes
 long getLongField(com.ibm.dtfj.java.JavaObject obj, java.lang.String name, boolean includeSuperclass)
          Get the content of a long field
 java.lang.String getName()
          Get the class name that this Scanner operates on.
 com.ibm.dtfj.java.JavaField[] getObjectInstanceFields(boolean includeSuperclass)
          Get the set of primitive instance fields defined on this class and optionally include the superclass chain.
 com.ibm.dtfj.java.JavaField[] getPrimitiveInstanceFields(boolean includeSuperclass)
          Get the set of primitive instance fields defined on this class and optionally include the superclass chain.
 boolean hasFinalizer()
          Does this class define a finalizer
 boolean isPrimitiveType(java.lang.String type)
          Return true if the given type is primitive (boolean, byte, short etc.)
 boolean isSubclassOf(com.ibm.dtfj.java.JavaClass c)
          Is the class represented by this scanner a subclass of the given class - if so return true else false.
 java.lang.String toString()
          (non-Javadoc)
 void visitReferences(com.ibm.dtfj.java.JavaObject obj, ObjectObserver obs, java.lang.Object context)
          Visit all the references from the given object which must match the class of this scanner.
 void visitReferencesFast(com.ibm.dtfj.java.JavaObject obj, ObjectObserver obs, java.lang.Object context)
          Visit all the references from the given object which must match the class of this scanner.
 void visitStaticReferences(ObjectObserver obs, java.lang.Object context)
          Trace the static fields and build roots if the root set is non null
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassScanner

public ClassScanner(com.ibm.dtfj.java.JavaClass cls)
Build a scanner on the given JavaClass. This scanner can then be used to scan the fields of instances of this class.

Parameters:
cls -
Method Detail

getJavaClass

public com.ibm.dtfj.java.JavaClass getJavaClass()
Get the java class that this scanner describes

Returns:
the java class

isPrimitiveType

public boolean isPrimitiveType(java.lang.String type)
Return true if the given type is primitive (boolean, byte, short etc.)

Parameters:
type - the type name
Returns:
true if primitive else false

hasFinalizer

public boolean hasFinalizer()
Does this class define a finalizer

Returns:
true if it does

getName

public java.lang.String getName()
Get the class name that this Scanner operates on.

Returns:
class name

visitReferences

public void visitReferences(com.ibm.dtfj.java.JavaObject obj,
                            ObjectObserver obs,
                            java.lang.Object context)
Visit all the references from the given object which must match the class of this scanner. This method will check this precondition and throw an exception if not met. The check can be avoided by invoking visitReferencesFast(JavaObject obj, ObjectObserver obs, Object context)

Parameters:
obj - the object to scan for references
obs - the observer to pass the references to
context - a context which will be passed to the object processing routine

visitReferencesFast

public void visitReferencesFast(com.ibm.dtfj.java.JavaObject obj,
                                ObjectObserver obs,
                                java.lang.Object context)
Visit all the references from the given object which must match the class of this scanner. This method will not check the precondition but may fail later if it is not met. It is specifically designed for the case where the invoking code knows it has the correct ClassScanner for the object and wants to avoid the cost of the check. (See visitReferences(JavaObject obj, ObjectObserver obs, Object context))

Parameters:
obj - the object to scan for references
obs - the observer to pass the references to
context - a context which will be passed to the object processing routine

visitStaticReferences

public void visitStaticReferences(ObjectObserver obs,
                                  java.lang.Object context)
Trace the static fields and build roots if the root set is non null

Parameters:
obs - the observer to pass the references to
context - a context which will be passed to the object processing routine

getPrimitiveInstanceFields

public com.ibm.dtfj.java.JavaField[] getPrimitiveInstanceFields(boolean includeSuperclass)
Get the set of primitive instance fields defined on this class and optionally include the superclass chain.

Parameters:
includeSuperclass - should we look for a superclass field ?
Returns:
the fields from this class and optionally the superclasses ordered superclass first

getObjectInstanceFields

public com.ibm.dtfj.java.JavaField[] getObjectInstanceFields(boolean includeSuperclass)
Get the set of primitive instance fields defined on this class and optionally include the superclass chain.

Parameters:
includeSuperclass - should we look for a superclass field ?
Returns:
the fields from this class and optionally the superclasses ordered superclass first

getField

public com.ibm.dtfj.java.JavaField getField(java.lang.String name,
                                            boolean includeSuperclass)
Return the field with the given name and optionally search the superclass

Parameters:
name -
includeSuperclass -
Returns:
the field

getIntegerField

public int getIntegerField(com.ibm.dtfj.java.JavaObject obj,
                           java.lang.String name,
                           boolean includeSuperclass)
                    throws com.ibm.dtfj.image.CorruptDataException,
                           com.ibm.dtfj.image.MemoryAccessException
Get the content of an integer field. This is a convenience method which just calls getField and then getInt on the resulting field. All the resulting exceptions are thrown by this method.

Parameters:
obj - the object to get the field content from
name - the field name to get
includeSuperclass - should we look for a superclass field ?
Returns:
the field value
Throws:
com.ibm.dtfj.image.MemoryAccessException
com.ibm.dtfj.image.CorruptDataException

getLongField

public long getLongField(com.ibm.dtfj.java.JavaObject obj,
                         java.lang.String name,
                         boolean includeSuperclass)
                  throws com.ibm.dtfj.image.CorruptDataException,
                         com.ibm.dtfj.image.MemoryAccessException
Get the content of a long field

Parameters:
obj - the object to get the field content from
name - the field name to get
includeSuperclass - should we look for a superclass field ?
Returns:
the field value
Throws:
com.ibm.dtfj.image.MemoryAccessException
com.ibm.dtfj.image.CorruptDataException

isSubclassOf

public boolean isSubclassOf(com.ibm.dtfj.java.JavaClass c)
Is the class represented by this scanner a subclass of the given class - if so return true else false.

Parameters:
c - the class to test
Returns:
true if this is a subclass of the given class

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.