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

ArrayInstance

public class ArrayInstance extends Instance

Fields Summary
private int
mType
private int
mNumEntries
private byte[]
mData
Constructors Summary
public ArrayInstance(long id, StackTrace stack, int type, int numEntries, byte[] data)

        mId = id;
        mStack = stack;
        mType = type;
        mNumEntries = numEntries;
        mData = data;
    
Methods Summary
public java.lang.StringdescribeReferenceTo(long referent)

        //  If this isn't an object array then we can't refer to an object
        if (mType != Types.OBJECT) {
            return super.describeReferenceTo(referent);
        }
        
        int idSize = Types.getTypeSize(mType);
        final int N = mNumEntries;
        int numRefs = 0;
        StringBuilder result = new StringBuilder("Elements [");
        ByteArrayInputStream bais = new ByteArrayInputStream(mData);
        DataInputStream dis = new DataInputStream(bais);
        
        /*
         * Spin through all the objects and build up a string describing
         * all of the array elements that refer to the target object.
         */
        for (int i = 0; i < N; i++) {
            long id;
            
            try {
                if (idSize == 4) {
                    id = dis.readInt();
                } else {
                    id = dis.readLong();
                }
                
                if (id == referent) {
                    numRefs++;
                    
                    if (numRefs > 1) {
                        result.append(", ");
                    }
                    
                    result.append(i);
                }
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
        }
        
        if (numRefs == 0) {
            return super.describeReferenceTo(referent);
        }

        result.append("]");
        
        return result.toString();
    
public final intgetSize()

        return mData.length;
    
public final java.lang.StringgetTypeName()

        return Types.getTypeName(mType) + "[" + mNumEntries + "]";
    
public final voidresolveReferences(State state)

        if (mType != Types.OBJECT) {
            return;
        }
        
        /*
         * mData holds a stream of object instance ids
         * Spin through them all and list ourselves as a reference holder.
         */
        int idSize = Types.getTypeSize(mType);
        final int N = mNumEntries;
        
        ByteArrayInputStream bais = new ByteArrayInputStream(mData);
        DataInputStream dis = new DataInputStream(bais);
        
        for (int i = 0; i < N; i++) {
            long id;

            try {
                if (idSize == 4) {
                    id = dis.readInt();
                } else {
                    id = dis.readLong();
                }

                Instance instance = state.findReference(id);
                
                if (instance != null) {
                    instance.addParent(this);
                }
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
        }
    
public final java.lang.StringtoString()

        return String.format("%s@0x08x", getTypeName(), mId);
    
public final voidvisit(java.util.Set resultSet, Filter filter)

        //  If we're in the set then we and our children have been visited
        if (resultSet.contains(this)) {
            return;
        }
        
        if (null != filter) {
            if (filter.accept(this)) {
                resultSet.add(this);
            }
        } else {
            resultSet.add(this);
        }

        if (mType != Types.OBJECT) {
            return;
        }
        
        /*
         * mData holds a stream of object instance ids
         * Spin through them all and visit them
         */
        int idSize = Types.getTypeSize(mType);
        final int N = mNumEntries;
        
        ByteArrayInputStream bais = new ByteArrayInputStream(mData);
        DataInputStream dis = new DataInputStream(bais);
        State state = mHeap.mState;
        
        for (int i = 0; i < N; i++) {
            long id;
            
            try {
                if (idSize == 4) {
                    id = dis.readInt();
                } else {
                    id = dis.readLong();
                }
                
                Instance instance = state.findReference(id);
                
                if (instance != null) {
                    instance.visit(resultSet, filter);
                }
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
        }