FileDocCategorySizeDatePackage
AbstractMemorySpy.javaAPI DocAndroid 1.5 API4243Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.platform

AbstractMemorySpy

public abstract class AbstractMemorySpy extends Object implements IMemorySpy
Abstract implementation for the OS memory spies.

Fields Summary
protected Map
memoryInUse
protected Map
refToShadow
protected ReferenceQueue
notifyQueue
Constructors Summary
public AbstractMemorySpy()

        super();
    
Methods Summary
public voidalloc(PlatformAddress address)

        AddressWrapper wrapper = new AddressWrapper(address);
        synchronized (this) {
            memoryInUse.put(wrapper.shadow, wrapper);
            refToShadow.put(wrapper.wrAddress, wrapper.shadow);
        }
    
public voidautoFree(PlatformAddress address)

        AddressWrapper wrapper;
        synchronized (this) {
            wrapper = memoryInUse.get(address);
        }
        if (wrapper != null) {
            wrapper.autoFree = true;
        }
    
public booleanfree(PlatformAddress address)

        AddressWrapper wrapper;
        synchronized (this) {
            wrapper = memoryInUse.remove(address);
            // BEGIN android-added
            if (wrapper != null) {
                refToShadow.remove(wrapper.wrAddress);
            }
            // END android-added
        }
        if (wrapper == null) {
            // Attempt to free memory we didn't alloc
            System.err
                    .println("Memory Spy! Fixed attempt to free memory that was not allocated " + address); //$NON-NLS-1$
        }
        return wrapper != null;
    
protected voidorphanedMemory(java.lang.ref.Reference ref)

        AddressWrapper wrapper;
        // BEGIN android-changed
        // copied from newer version of harmony
        synchronized (this) {
            PlatformAddress shadow = refToShadow.remove(ref);
            wrapper = memoryInUse.get(shadow);
            if (wrapper != null) {
                // There is a leak if we were not auto-freeing this memory.
                if (!wrapper.autoFree) {
                    System.err
                            .println("Memory Spy! Fixed memory leak by freeing " + wrapper.shadow); //$NON-NLS-1$
                }
                wrapper.shadow.free();
            }
        }
        ref.clear();
        // END android-changed
    
public voidrangeCheck(PlatformAddress address, int offset, int length)

        // Do nothing