diff options
Diffstat (limited to 'vm/alloc/Heap.cpp')
-rw-r--r-- | vm/alloc/Heap.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/vm/alloc/Heap.cpp b/vm/alloc/Heap.cpp index 1d06dfec0..65b33105d 100644 --- a/vm/alloc/Heap.cpp +++ b/vm/alloc/Heap.cpp @@ -31,6 +31,11 @@ #include <limits.h> #include <errno.h> +#ifdef LOG_NDDEBUG +#undef LOG_NDDEBUG +#define LOG_NDDEBUG 0 +#endif + static const GcSpec kGcForMallocSpec = { true, /* isPartial */ false, /* isConcurrent */ @@ -215,17 +220,13 @@ static void *tryMalloc(size_t size) * lock, wait for the GC to complete, and retrying allocating. */ dvmWaitForConcurrentGcToComplete(); - ptr = dvmHeapSourceAlloc(size); - if (ptr != NULL) { - return ptr; - } + } else { + /* + * Try a foreground GC since a concurrent GC is not currently running. + */ + gcForMalloc(false); } - /* - * Another failure. Our thread was starved or there may be too - * many live objects. Try a foreground GC. This will have no - * effect if the concurrent GC is already running. - */ - gcForMalloc(false); + ptr = dvmHeapSourceAlloc(size); if (ptr != NULL) { return ptr; @@ -713,8 +714,9 @@ void dvmCollectGarbageInternal(const GcSpec* spec) * suspend when the GC thread calls dvmUnlockHeap before dvmResumeAllThreads, * but there's no risk of deadlock.) */ -void dvmWaitForConcurrentGcToComplete() +bool dvmWaitForConcurrentGcToComplete() { + bool waited = gDvm.gcHeap->gcRunning; Thread *self = dvmThreadSelf(); assert(self != NULL); u4 start = dvmGetRelativeTimeMsec(); @@ -724,5 +726,8 @@ void dvmWaitForConcurrentGcToComplete() dvmChangeStatus(self, oldStatus); } u4 end = dvmGetRelativeTimeMsec(); - ALOGD("WAIT_FOR_CONCURRENT_GC blocked %ums", end - start); + if (end - start > 0) { + ALOGD("WAIT_FOR_CONCURRENT_GC blocked %ums", end - start); + } + return waited; } |