Loading core/java/android/app/ActivityThread.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -6224,6 +6224,12 @@ public final class ActivityThread extends ClientTransactionHandler { Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) { for (PropertyInvalidatedCache pic : PropertyInvalidatedCache.getActiveCaches()) { pic.clear(); } } ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); final int N = callbacks.size(); final int N = callbacks.size(); Loading core/java/android/app/PropertyInvalidatedCache.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -27,11 +27,13 @@ import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; import java.util.HashMap; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; import java.util.Random; import java.util.Random; import java.util.WeakHashMap; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong; /** /** Loading Loading @@ -197,6 +199,14 @@ public abstract class PropertyInvalidatedCache<Query, Result> { @GuardedBy("sCorkLock") @GuardedBy("sCorkLock") private static final HashMap<String, Integer> sCorks = new HashMap<>(); private static final HashMap<String, Integer> sCorks = new HashMap<>(); /** * Weakly references all cache objects in the current process, allowing us to iterate over * them all for purposes like issuing debug dumps and reacting to memory pressure. */ @GuardedBy("sCorkLock") private static final WeakHashMap<PropertyInvalidatedCache, Void> sCaches = new WeakHashMap<>(); private final Object mLock = new Object(); private final Object mLock = new Object(); /** /** Loading Loading @@ -241,6 +251,9 @@ public abstract class PropertyInvalidatedCache<Query, Result> { return size() > maxEntries; return size() > maxEntries; } } }; }; synchronized (sCorkLock) { sCaches.put(this, null); } } } /** /** Loading @@ -248,6 +261,9 @@ public abstract class PropertyInvalidatedCache<Query, Result> { */ */ public final void clear() { public final void clear() { synchronized (mLock) { synchronized (mLock) { if (DEBUG) { Log.d(TAG, "clearing cache for " + mPropertyName); } mCache.clear(); mCache.clear(); } } } } Loading Loading @@ -710,4 +726,13 @@ public abstract class PropertyInvalidatedCache<Query, Result> { Log.d(TAG, "disabling all caches in the process"); Log.d(TAG, "disabling all caches in the process"); sEnabled = false; sEnabled = false; } } /** * Return a list of caches alive at the current time. */ public static ArrayList<PropertyInvalidatedCache> getActiveCaches() { synchronized (sCorkLock) { return new ArrayList<PropertyInvalidatedCache>(sCaches.keySet()); } } } } Loading
core/java/android/app/ActivityThread.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -6224,6 +6224,12 @@ public final class ActivityThread extends ClientTransactionHandler { Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "trimMemory"); if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level); if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) { for (PropertyInvalidatedCache pic : PropertyInvalidatedCache.getActiveCaches()) { pic.clear(); } } ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(true, null); final int N = callbacks.size(); final int N = callbacks.size(); Loading
core/java/android/app/PropertyInvalidatedCache.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -27,11 +27,13 @@ import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; import java.util.HashMap; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; import java.util.Random; import java.util.Random; import java.util.WeakHashMap; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong; /** /** Loading Loading @@ -197,6 +199,14 @@ public abstract class PropertyInvalidatedCache<Query, Result> { @GuardedBy("sCorkLock") @GuardedBy("sCorkLock") private static final HashMap<String, Integer> sCorks = new HashMap<>(); private static final HashMap<String, Integer> sCorks = new HashMap<>(); /** * Weakly references all cache objects in the current process, allowing us to iterate over * them all for purposes like issuing debug dumps and reacting to memory pressure. */ @GuardedBy("sCorkLock") private static final WeakHashMap<PropertyInvalidatedCache, Void> sCaches = new WeakHashMap<>(); private final Object mLock = new Object(); private final Object mLock = new Object(); /** /** Loading Loading @@ -241,6 +251,9 @@ public abstract class PropertyInvalidatedCache<Query, Result> { return size() > maxEntries; return size() > maxEntries; } } }; }; synchronized (sCorkLock) { sCaches.put(this, null); } } } /** /** Loading @@ -248,6 +261,9 @@ public abstract class PropertyInvalidatedCache<Query, Result> { */ */ public final void clear() { public final void clear() { synchronized (mLock) { synchronized (mLock) { if (DEBUG) { Log.d(TAG, "clearing cache for " + mPropertyName); } mCache.clear(); mCache.clear(); } } } } Loading Loading @@ -710,4 +726,13 @@ public abstract class PropertyInvalidatedCache<Query, Result> { Log.d(TAG, "disabling all caches in the process"); Log.d(TAG, "disabling all caches in the process"); sEnabled = false; sEnabled = false; } } /** * Return a list of caches alive at the current time. */ public static ArrayList<PropertyInvalidatedCache> getActiveCaches() { synchronized (sCorkLock) { return new ArrayList<PropertyInvalidatedCache>(sCaches.keySet()); } } } }