FileDocCategorySizeDatePackage
BaseHeapPanel.javaAPI DocAndroid 1.5 API6016Wed May 06 22:41:08 BST 2009com.android.ddmuilib

BaseHeapPanel

public abstract class BaseHeapPanel extends TablePanel
Base Panel for heap panels.

Fields Summary
protected byte[]
mProcessedHeapData
store the processed heap segment, so that we don't recompute Image for nothing
private Map
mHeapMap
Constructors Summary
Methods Summary
protected org.eclipse.swt.graphics.ImageDatacreateLinearHeapImage(byte[] pixData, int h, org.eclipse.swt.graphics.PaletteData palette)
Creates a linear image of the heap data.

param
pixData
param
h
param
palette
return

        int w = pixData.length / h;
        if (pixData.length % h != 0) {
            w++;
        }

        // Create the heap image.
        ImageData id = new ImageData(w, h, 8, palette);

        int x = 0;
        int y = 0;
        for (byte b : pixData) {
            if (b >= 0) {
                id.setPixel(x, y, b);
            }

            y++;
            if (y >= h) {
                y = 0;
                x++;
            }
        }

        return id;
    
private voiddoSerializeHeapData(java.util.Collection heapData)
Processes and serialize the heapData.

The resulting serialized array is {@link #mProcessedHeapData}.

the resulting map is {@link #mHeapMap}.

param
heapData the collection of {@link HeapSegment} that forms the heap data.

        mHeapMap = new TreeMap<Integer, ArrayList<HeapSegmentElement>>();

        Iterator<HeapSegment> iterator;
        ByteArrayOutputStream out;

        out = new ByteArrayOutputStream(4 * 1024);

        iterator = heapData.iterator();
        while (iterator.hasNext()) {
            HeapSegment hs = iterator.next();

            HeapSegmentElement e = null;
            while (true) {
                int v;

                e = hs.getNextElement(null);
                if (e == null) {
                    break;
                }
                
                if (e.getSolidity() == HeapSegmentElement.SOLIDITY_FREE) {
                    v = 1;
                } else {
                    v = e.getKind() + 2;
                }
                
                // put the element in the map
                ArrayList<HeapSegmentElement> elementList = mHeapMap.get(v);
                if (elementList == null) {
                    elementList = new ArrayList<HeapSegmentElement>();
                    mHeapMap.put(v, elementList);
                }
                elementList.add(e);


                int len = e.getLength() / 8;
                while (len > 0) {
                    out.write(v);
                    --len;
                }
            }
        }
        mProcessedHeapData = out.toByteArray();
        
        // sort the segment element in the heap info.
        Collection<ArrayList<HeapSegmentElement>> elementLists = mHeapMap.values();
        for (ArrayList<HeapSegmentElement> elementList : elementLists) {
            Collections.sort(elementList);
        }
    
protected byte[]getSerializedData()
Returns the serialized heap data

        return mProcessedHeapData;
    
protected booleanserializeHeapData(com.android.ddmlib.ClientData.HeapData heapData)
Serialize the heap data into an array. The resulting array is available through getSerializedData().

param
heapData The heap data to serialize
return
true if the data changed.

        Collection<HeapSegment> heapSegments;

        // Atomically get and clear the heap data.
        synchronized (heapData) {
            // get the segments
            heapSegments = heapData.getHeapSegments();
            
            
            if (heapSegments != null) {
                // if they are not null, we never processed them.
                // Before we process then, we drop them from the HeapData
                heapData.clearHeapData();

                // process them into a linear byte[]
                doSerializeHeapData(heapSegments);
                heapData.setProcessedHeapData(mProcessedHeapData);
                heapData.setProcessedHeapMap(mHeapMap);
                
            } else {
                // the heap segments are null. Let see if the heapData contains a 
                // list that is already processed.
                
                byte[] pixData = heapData.getProcessedHeapData();
                
                // and compare it to the one we currently have in the panel.
                if (pixData == mProcessedHeapData) {
                    // looks like its the same
                    return false;
                } else {
                    mProcessedHeapData = pixData;
                }
                
                Map<Integer, ArrayList<HeapSegmentElement>> heapMap =
                    heapData.getProcessedHeapMap();
                mHeapMap = heapMap;
            }
        }

        return true;