OSDN Git Service

Ensure that an explicit GC request initiates a GC.
authorCarl Shapiro <cshapiro@google.com>
Sat, 18 Sep 2010 00:10:48 +0000 (17:10 -0700)
committerCarl Shapiro <cshapiro@google.com>
Sat, 18 Sep 2010 00:10:48 +0000 (17:10 -0700)
Previously, if a concurrent GC was in-flight when an explicit GC was
requested a warning would be logged about a recursive GC attempt.  Now,
the requesting thread will block until the GC is inactive and afterward
initiate its foreground collection.

Change-Id: Ibc4cef83315ffe7ccf822a32beb4cce5b1c816bd

vm/alloc/Alloc.c

index 02955bc..4dcd91c 100644 (file)
@@ -295,9 +295,10 @@ void dvmReleaseTrackedAlloc(Object* obj, Thread* self)
 void dvmCollectGarbage(bool collectSoftReferences)
 {
     dvmLockHeap();
-
+    while (gDvm.gcHeap->gcRunning) {
+        dvmWaitForConcurrentGcToComplete();
+    }
     dvmCollectGarbageInternal(collectSoftReferences, GC_EXPLICIT);
-
     dvmUnlockHeap();
 }