FileDocCategorySizeDatePackage
ClassObj.javaAPI DocAndroid 1.5 API7261Wed May 06 22:41:02 BST 2009com.android.hit

ClassObj

public class ClassObj extends Instance implements Comparable

Fields Summary
String
mClassName
long
mSuperclassId
String[]
mFieldNames
int[]
mFieldTypes
String[]
mStaticFieldNames
int[]
mStaticFieldTypes
byte[]
mStaticFieldValues
ArrayList
mInstances
Set
mSubclasses
int
mSize
Constructors Summary
public ClassObj(long id, StackTrace stack, String className)


           
        mId = id;
        mStack = stack;
        mClassName = className;
    
Methods Summary
public final voidaddInstance(Instance instance)

        mInstances.add(instance);
    
public final voidaddSubclass(com.android.hit.ClassObj subclass)

        mSubclasses.add(subclass);
    
public final intcompareTo(com.android.hit.ClassObj o)

        return mClassName.compareTo(o.mClassName);
    
public final voiddump()

        System.out.println("+----------  ClassObj dump for: " + mClassName);

        System.out.println("+-----  Static fields");
        
        for (int i = 0; i < mStaticFieldNames.length; i++) {
            System.out.println(mStaticFieldNames[i] + ": " 
                + mStaticFieldTypes[i]);
        }

        System.out.println("+-----  Instance fields");
        
        for (int i = 0; i < mFieldNames.length; i++) {
            System.out.println(mFieldNames[i] + ": " + mFieldTypes[i]);
        }
    
public final voiddumpSubclasses()

        for (ClassObj subclass: mSubclasses) {
            System.out.println("     " + subclass.mClassName);
        }
    
public final booleanequals(java.lang.Object o)

        if (! (o instanceof ClassObj)) {
            return false;
        }
        
        return 0 == compareTo((ClassObj) o);
    
public final java.lang.StringgetTypeName()

        return "class " + mClassName;
    
public final voidresolveReferences(State state)

        ByteArrayInputStream bais =
            new ByteArrayInputStream(mStaticFieldValues);
        DataInputStream dis = new DataInputStream(bais);
        int[] types = mStaticFieldTypes;
        final int N = types.length;
        
        /*
         * Spin through the list of static fields, find all object references,
         * and list ourselves as a reference holder.  Also add them to
         * the list of root objects.
         */
        try {
            for (int i = 0; i < N; i++) {
                int type = types[i];
                int size = Types.getTypeSize(type);
                
                if (type == Types.OBJECT) {
                    long id;
                    
                    if (size == 4) {
                        id = dis.readInt();
                    } else {
                        id = dis.readLong();
                    }
                    
                    RootObj root = new RootObj(RootType.JAVA_STATIC, id);
                    
                    if (id == 0) {
                        root.mComment = String.format(
                            "Static field %s:%s null",
                                mClassName,
                                mStaticFieldNames[i]);
                    } else {
                        Instance instance = state.findReference(id);
                        
                        instance.addParent(this);
                        
                        root.mComment = String.format(
                            "Static field %s:%s %s [%s] 0x%08x",
                                mClassName,
                                mStaticFieldNames[i],
                                instance.getTypeName(),
                                instance.mHeap.mName,
                                id);
                    }

                    mHeap.addRoot(root);
                } else {
                    dis.skipBytes(size);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

        //  Lastly, add ourself as a subclass of our superclass
        if (mSuperclassId != 0) {
            ClassObj superclass = state.findClass(mSuperclassId);
            
            superclass.addSubclass(this);
        }
    
public final voidsetFieldNames(java.lang.String[] names)

        mFieldNames = names;
    
public final voidsetFieldTypes(int[] types)

        mFieldTypes = types;
    
public final voidsetStaticFieldNames(java.lang.String[] names)

        mStaticFieldNames = names;
    
public final voidsetStaticFieldTypes(int[] types)

        mStaticFieldTypes = types;
    
public final voidsetStaticFieldValues(byte[] values)

        mStaticFieldValues = values;
    
public final voidsetSuperclassId(long id)

        mSuperclassId = id;
    
public final java.lang.StringtoString()

        return mClassName.replace('/", '.");
    
public final voidvisit(java.util.Set resultSet, Filter filter)

        if (resultSet.contains(this)) {
            return;
        }
        
        if (filter != null) {
            if (filter.accept(this)) {
                resultSet.add(this);
            }
        } else {
            resultSet.add(this);
        }
        
        ByteArrayInputStream bais =
            new ByteArrayInputStream(mStaticFieldValues);
        DataInputStream dis = new DataInputStream(bais);
        int[] types = mStaticFieldTypes;
        final int N = types.length;
        State state = mHeap.mState;
        
        /*
         * Spin through the list of static fields, find all object references,
         * and visit them.
         */
        try {
            for (int i = 0; i < N; i++) {
                int type = types[i];
                int size = Types.getTypeSize(type);
                
                if (type == Types.OBJECT) {
                    long id;
                    
                    if (size == 4) {
                        id = dis.readInt();
                    } else {
                        id = dis.readLong();
                    }
                    
                    Instance instance = state.findReference(id);
                    
                    if (instance != null) {
                        instance.visit(resultSet, filter);
                    }
                } else {
                    dis.skipBytes(size);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }