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

ClassInstance

public class ClassInstance extends Instance

Fields Summary
private byte[]
mFieldValues
Constructors Summary
public ClassInstance(long id, StackTrace stack, long classId)

        mId = id;
        mStack = stack;
        mClassId = classId;
    
Methods Summary
public java.lang.StringdescribeReferenceTo(long referent)

        ClassObj isa = mHeap.mState.findClass(mClassId);
        int[] types = isa.mFieldTypes;
        String[] fieldNames = isa.mFieldNames;
        ByteArrayInputStream bais = new ByteArrayInputStream(mFieldValues);
        DataInputStream dis = new DataInputStream(bais);
        final int N = types.length;
        StringBuilder result = new StringBuilder("Referenced in field(s):");
        int numReferences = 0;
        
        /*
         * Spin through the list of fields, add info about the field
         * references to the output text.
         */
        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();
                    }
                    
                    if (id == referent) {
                        numReferences++;
                        result.append("\n    ");
                        result.append(fieldNames[i]);
                    }
                } else {
                    dis.skipBytes(size);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        /*
         *  TODO:  perform a similar loop over the static fields of isa
         */

        if (numReferences == 0) {
            return super.describeReferenceTo(referent);
        }
        
        return result.toString();
    
public final intgetSize()

        ClassObj isa = mHeap.mState.findClass(mClassId);
        
        return isa.getSize();
    
public final java.lang.StringgetTypeName()

        ClassObj theClass = mHeap.mState.findClass(mClassId);
        
        return theClass.mClassName;
    
public final voidloadFieldData(java.io.DataInputStream in, int numBytes)

        mFieldValues = new byte[numBytes];
        in.readFully(mFieldValues);
    
private voidresolve(State state, ClassObj isa, int[] types, byte[] values)

        ByteArrayInputStream bais = new ByteArrayInputStream(values);
        DataInputStream dis = new DataInputStream(bais);
        final int N = types.length;

        /*
         * Spin through the list of fields, find all object references,
         * and list ourselves as a reference holder.
         */
        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.addParent(this);
                        }
                    } else {
                        dis.skipBytes(size);
                    }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    
public voidresolveReferences(State state)

        ClassObj isa = mHeap.mState.findClass(mClassId);

        resolve(state, isa, isa.mStaticFieldTypes, isa.mStaticFieldValues);
        resolve(state, isa, isa.mFieldTypes, mFieldValues);
    
public final java.lang.StringtoString()

        return String.format("%s@0x%08x", getTypeName(), mId);
    
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);
        }

        State state = mHeap.mState;
        ClassObj isa = state.findClass(mClassId);
        int[] types = isa.mFieldTypes;
        ByteArrayInputStream bais = new ByteArrayInputStream(mFieldValues);
        DataInputStream dis = new DataInputStream(bais);
        final int N = types.length;
        
        /*
         * Spin through the list of fields, find all object references,
         * and list ourselves as a reference holder.
         */
        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();
        }