From: Ian Rogers Date: Tue, 28 Aug 2012 22:54:19 +0000 (-0700) Subject: Revert "Revert "Trim pre-Zygote fork, fix under-estimate of heap limit."" X-Git-Tag: android-x86-4.4-r1~168^2~18^2~34 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=2f30ef57;p=android-x86%2Fdalvik.git Revert "Revert "Trim pre-Zygote fork, fix under-estimate of heap limit."" This reverts commit 4c7e27186d87ccd40646fd4f514dc982ff5b40b1. --- diff --git a/vm/alloc/HeapSource.cpp b/vm/alloc/HeapSource.cpp index c62cde1b4..cd2f4df2d 100644 --- a/vm/alloc/HeapSource.cpp +++ b/vm/alloc/HeapSource.cpp @@ -639,6 +639,9 @@ bool dvmHeapSourceStartupBeforeFork() assert(gDvm.zygote); if (!gDvm.newZygoteHeapAllocated) { + /* Ensure heaps are trimmed to minimize footprint pre-fork. + */ + trimHeaps(); /* Create a new heap for post-fork zygote allocations. We only * try once, even if it fails. */ @@ -686,6 +689,25 @@ void *dvmHeapSourceGetBase() } /* + * Returns a high water mark, between base and limit all objects must have been + * allocated. + */ +void *dvmHeapSourceGetLimit() +{ + HeapSource *hs = gHs; + void *max_brk = hs->heaps[0].brk; + +#ifndef NDEBUG + for (size_t i = 1; i < hs->numHeaps; i++) { + Heap *const heap = &hs->heaps[i]; + void *heap_brk = heap->brk; + assert (max_brk > heap_brk); + } +#endif + return max_brk; +} + +/* * Returns the requested value. If the per-heap stats are requested, fill * them as well. * @@ -706,7 +728,8 @@ size_t dvmHeapSourceGetValue(HeapSourceValueSpec spec, size_t perHeapStats[], switch (spec) { case HS_FOOTPRINT: - value = mspace_footprint(heap->msp); + value = heap->brk - heap->base; + assert(value == mspace_footprint(heap->msp)); break; case HS_ALLOWED_FOOTPRINT: value = mspace_footprint_limit(heap->msp); @@ -979,7 +1002,7 @@ bool dvmHeapSourceContainsAddress(const void *ptr) { HS_BOILERPLATE(); - return (dvmHeapBitmapCoversAddress(&gHs->liveBits, ptr)); + return (dvmHeapSourceGetBase() <= ptr) && (ptr <= dvmHeapSourceGetLimit()); } /* diff --git a/vm/alloc/HeapSource.h b/vm/alloc/HeapSource.h index 4bd11cde5..e1f682075 100644 --- a/vm/alloc/HeapSource.h +++ b/vm/alloc/HeapSource.h @@ -92,6 +92,12 @@ HeapBitmap *dvmHeapSourceGetMarkBits(void); void *dvmHeapSourceGetBase(void); /* + * Returns a high water mark, between base and limit all objects must have been + * allocated. + */ +void *dvmHeapSourceGetLimit(void); + +/* * Returns the requested value. If the per-heap stats are requested, fill * them as well. */ diff --git a/vm/alloc/MarkSweep.cpp b/vm/alloc/MarkSweep.cpp index d4f4669ba..268d88085 100644 --- a/vm/alloc/MarkSweep.cpp +++ b/vm/alloc/MarkSweep.cpp @@ -560,7 +560,7 @@ static void scanGrayObjects(GcMarkContext *ctx) footprint = dvmHeapSourceGetValue(HS_FOOTPRINT, NULL, 0); base = &h->cardTableBase[0]; - limit = dvmCardFromAddr((u1 *)dvmHeapSourceGetBase() + footprint); + limit = dvmCardFromAddr((u1 *)dvmHeapSourceGetLimit()); assert(limit <= &h->cardTableBase[h->cardTableLength]); ptr = base;