From a371fad368c4d697b2906079bfbe8059269ed362 Mon Sep 17 00:00:00 2001 From: Carl Shapiro Date: Sun, 23 Jan 2011 15:58:31 -0800 Subject: [PATCH] Replace collect with clear for the SoftReference policy. The garbage collector is invoked with a parameter that changes the SoftReference clearing policy. This parameter is normally false, meaning the garbage collector will attempt to preserve some softly-reachable referents of SoftReference instances. When true, the garbage collector will treat SoftReference instances as WeakReference instances and always clearly referent fields with softly-reachable referents. The code refers to this action as collecting soft references which is misleading. The change to the garbage collector policy has an effect on the referent field of SoftReference instances and any SoftReference instance which is unreachable is subject collection like any other object. With this change we now use the description clearing soft refernces to describe the policy. Bug: 3381480 Change-Id: Ie179514e68d4621237b08658c1c55811a49f1210 --- vm/alloc/Alloc.c | 4 ++-- vm/alloc/Alloc.h | 7 +++++-- vm/alloc/Heap.c | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/vm/alloc/Alloc.c b/vm/alloc/Alloc.c index 3f954426f..629dc452c 100644 --- a/vm/alloc/Alloc.c +++ b/vm/alloc/Alloc.c @@ -295,14 +295,14 @@ void dvmReleaseTrackedAlloc(Object* obj, Thread* self) /* * Explicitly initiate garbage collection. */ -void dvmCollectGarbage(bool collectSoftReferences) +void dvmCollectGarbage(bool clearSoftReferences) { if (gDvm.disableExplicitGc) { return; } dvmLockHeap(); dvmWaitForConcurrentGcToComplete(); - dvmCollectGarbageInternal(collectSoftReferences, GC_EXPLICIT); + dvmCollectGarbageInternal(clearSoftReferences, GC_EXPLICIT); dvmUnlockHeap(); } diff --git a/vm/alloc/Alloc.h b/vm/alloc/Alloc.h index 804e40e1d..eba53df7e 100644 --- a/vm/alloc/Alloc.h +++ b/vm/alloc/Alloc.h @@ -155,9 +155,12 @@ void dvmSetTargetHeapUtilization(float newTarget); /* * Initiate garbage collection. * - * This usually happens automatically, but can also be caused by Runtime.gc(). + * This usually happens automatically, but can also be caused by + * Runtime.gc(). If clearSoftReferences is true, the garbage + * collector will not attempt to preserve any softly-reachable + * SoftReference referents. */ -void dvmCollectGarbage(bool collectSoftRefs); +void dvmCollectGarbage(bool clearSoftReferences); /* * Returns a count of the direct instances of a class. diff --git a/vm/alloc/Heap.c b/vm/alloc/Heap.c index 3c130bb84..456fe50ff 100644 --- a/vm/alloc/Heap.c +++ b/vm/alloc/Heap.c @@ -216,7 +216,7 @@ Object *dvmGetNextHeapWorkerObject(HeapWorkerOperation *op) /* Do a full garbage collection, which may grow the * heap as a side-effect if the live set is large. */ -static void gcForMalloc(bool collectSoftReferences) +static void gcForMalloc(bool clearSoftReferences) { if (gDvm.allocProf.enabled) { Thread* self = dvmThreadSelf(); @@ -227,9 +227,9 @@ static void gcForMalloc(bool collectSoftReferences) } /* This may adjust the soft limit as a side-effect. */ - LOGD_HEAP("dvmMalloc initiating GC%s\n", - collectSoftReferences ? "(collect SoftReferences)" : ""); - dvmCollectGarbageInternal(collectSoftReferences, GC_FOR_MALLOC); + LOGD_HEAP("dvmMalloc initiating GC%s", + clearSoftReferences ? "(clear SoftReferences)" : ""); + dvmCollectGarbageInternal(clearSoftReferences, GC_FOR_MALLOC); } /* Try as hard as possible to allocate some memory. -- 2.11.0