Home | History | Annotate | Download | only in alloc

Lines Matching full:heap

26 #include "alloc/Heap.h"
40 /* How long to wait after a GC before performing a heap trim
62 struct Heap {
67 /* The largest size that this heap is allowed to grow to.
87 * The lowest address of this heap, inclusive.
92 * The highest address of this heap, exclusive.
97 * If the heap has an mspace, the current high water mark in
104 /* Target ideal heap utilization ratio; range 1..HEAP_UTILIZATION_MAX
108 /* The starting heap size.
112 /* The largest that the heap source as a whole is allowed to grow.
117 * The largest size we permit the heap to grow. This value allows
118 * the user to limit the heap growth below the maximum size. This
122 * heap.
126 /* The desired max size of the heap source as a whole.
131 * active heap before a GC is forced. This is used to "shrink" the
132 * heap in lieu of actual compaction.
138 * when the heap size is below the maximum size or growth limit.
144 * when the heap size is below the maximum size or growth limit.
148 /* The heaps; heaps[0] is always the active heap,
151 Heap heaps[HEAP_SOURCE_MAX_HEAP_COUNT];
203 * Returns true iff a soft limit is in effect for the active heap.
209 * if there is more than one heap. If there is only one
210 * heap, a non-SIZE_MAX softLimit should always be the same
218 * allocated from the active heap before a GC is forced.
231 * is false, don't count the heap at index 0.
251 * Returns the heap that <ptr> could have come from, or NULL
252 * if it could not have come from any heap.
254 static Heap *ptr2heap(const HeapSource *hs, const void *ptr)
260 const Heap *const heap = &hs->heaps[i];
262 if ((const char *)ptr >= heap->base && (const char *)ptr < heap->limit) {
263 return (Heap *)heap;
273 * us a much more accurate picture of heap utilization than
278 static void countAllocation(Heap *heap, const void *ptr)
280 assert(heap->bytesAllocated < mspace_footprint(heap->msp));
282 heap->bytesAllocated += mspace_usable_size(ptr) +
284 heap->objectsAllocated++;
288 assert(heap->bytesAllocated < mspace_footprint(heap->msp));
291 static void countFree(Heap *heap, const void *ptr, size_t *numBytes)
295 if (delta < heap->bytesAllocated) {
296 heap->bytesAllocated -= delta;
298 heap->bytesAllocated = 0;
302 if (heap->objectsAllocated > 0) {
303 heap->objectsAllocated--;
321 // Do not allow morecore requests to succeed beyond the starting size of the heap.
330 * Service request from DlMalloc to increase heap size.
334 Heap* heap = NULL;
337 heap = &gHs->heaps[i];
341 if (heap == NULL) {
342 ALOGE("Failed to find heap for mspace %p", mspace);
345 char* original_brk = heap->brk;
351 assert(new_brk <= heap->limit);
355 assert(original_brk + increment > heap->base);
362 heap->brk = new_brk;
369 * Add the initial heap. Returns false if the initial heap was
370 * already added to the heap source.
390 * A helper for addNewHeap(). Remap the new heap so that it will have
392 * practice, this is used to give the app heap a separate ashmem
393 * region from the zygote heap's.
395 static bool remapNewHeap(HeapSource* hs, Heap* newHeap)
400 int fd = ashmem_create_region("dalvik-heap", rem_size);
402 ALOGE("Unable to create an ashmem region for the new heap");
408 ALOGE("Unable to map an ashmem region for the new heap");
412 ALOGE("Unable to close fd for the ashmem region for the new heap");
420 * Adds an additional heap to the heap source. Returns false if there
421 * are too many heaps or insufficient free space to add another heap.
425 Heap heap;
435 memset(&heap, 0, sizeof(heap));
438 * Heap storage comes from a common virtual memory reservation.
439 * The new heap will start on the page after the old heap.
452 heap.maximumSize = hs->growthLimit - overhead;
453 heap.concurrentStartBytes = hs->minFree - CONCURRENT_START;
454 heap.base = base;
455 heap.limit = heap.base + heap.maximumSize;
456 heap.brk = heap.base + morecoreStart;
457 if (!remapNewHeap(hs, &heap)) {
460 heap.msp = createMspace(base, morecoreStart, hs->minFree);
461 if (heap.msp == NULL) {
465 /* Don't let the soon-to-be-old heap grow any further.
471 /* Put the new heap in the list, at heaps[0].
475 hs->heaps[0] = heap;
496 /* Timed out waiting for a GC request, schedule a heap trim. */
503 // Many JDWP requests cause allocation. We can't take the heap lock and wait to
506 // heap lock itself, leading to deadlock. http://b/8191824.
557 * heap is perfectly full of the smallest object.
588 * Initializes the heap source; must be called before any other
590 * allocated from the heap source.
604 ALOGE("Bad heap size parameters (start=%zd, max=%zd, limit=%zd)",
614 base = dvmAllocRegion(length, PROT_NONE, gDvm.zygote ? "dalvik-zygote" : "dalvik-heap");
620 * a heap source.
629 LOGE_HEAP("Can't allocate heap descriptor");
635 LOGE_HEAP("Can't allocate heap source");
668 LOGE_HEAP("Can't add initial heap");
704 * first time. We create a heap for all future zygote process allocations,
705 * in an attempt to avoid touching pages in the zygote heap. (This would
721 /* Create a new heap for post-fork zygote allocations. We only
724 ALOGV("Splitting out new zygote heap");
778 Heap *const heap = &hs->heaps[i];
779 void *heap_brk = heap->brk;
787 * Returns the requested value. If the per-heap stats are requested, fill
790 * Caller must hold the heap lock.
803 Heap *const heap = &hs->heaps[i];
807 value = heap->brk - heap->base;
808 assert(value == mspace_footprint(heap->msp));
811 value = mspace_footprint_limit(heap->msp);
814 value = heap->bytesAllocated;
817 value = heap->objectsAllocated;
889 /* heap[0] is never immune */
923 Heap* heap = hs2heap(hs);
924 if (heap->bytesAllocated + n > hs->softLimit) {
927 * if the heap is full.
941 ptr = mspace_malloc(heap->msp, n);
966 ptr = mspace_calloc(heap->msp, 1, n);
972 countAllocation(heap, ptr);
983 if (heap->bytesAllocated > heap->concurrentStartBytes) {
996 static void* heapAllocAndGrow(HeapSource *hs, Heap *heap, size_t n)
1001 size_t max = heap->maximumSize;
1003 mspace_set_footprint_limit(heap->msp, max);
1009 mspace_set_footprint_limit(heap->msp,
1010 mspace_footprint(heap->msp));
1023 Heap* heap = hs2heap(hs);
1046 /* We're not soft-limited. Grow the heap to satisfy the request.
1049 ptr = heapAllocAndGrow(hs, heap, n);
1080 Heap* heap = ptr2heap(gHs, *ptrs);
1082 if (heap != NULL) {
1083 mspace msp = heap->msp;
1085 // much. For heap[0] -- the 'active heap' -- we call
1088 if (heap == gHs->heaps) {
1092 assert(ptr2heap(gHs, ptrs[i]) == heap);
1093 countFree(heap, ptrs[i], &numBytes);
1098 // This is not an 'active heap'. Only do the accounting.
1101 assert(ptr2heap(gHs, ptrs[i]) == heap);
1102 countFree(heap, ptrs[i], &numBytes);
1110 * Returns true iff <ptr> is in the heap source.
1120 * Returns true iff <ptr> was allocated from the heap source.
1139 Heap *heap = ptr2heap(hs, obj);
1140 if (heap != NULL) {
1141 /* If the object is not in the active heap, we assume that
1144 return heap != hs->heaps;
1147 /* The pointer is outside of any known heap, or we are not
1161 Heap* heap = ptr2heap(gHs, ptr);
1162 if (heap != NULL) {
1169 * Returns the number of bytes that the heap source has allocated
1172 * Caller must hold the heap lock.
1188 * Returns the current maximum size of the heap source respecting any
1199 * maximum heap size.
1216 * current heap. When a soft limit is in effect, this is effectively
1218 * the current heap).
1234 * Gets the maximum number of bytes that the heap source is allowed
1248 * footprint of the active heap.
1253 * max_allowed, because the heap may not have grown all the
1259 /* Don't let the heap grow any more, and impose a soft limit.
1264 /* Let the heap grow to the requested max, and remove any
1273 * Sets the maximum number of bytes that the heap source is allowed
1284 LOGI_HEAP("Clamp target GC heap from %zd.%03zdMB to %u.%03uMB",
1290 /* Convert max into a size that applies to the active heap.
1316 * Gets the current ideal heap utilization, represented as a number
1329 * Sets the new ideal heap utilization, represented as a number
1349 ALOGV("Set heap target utilization to %zd/%d (%f)",
1354 * Given the size of a live set, returns the ideal heap size given
1360 * ideal heap size based on the size of the live set.
1376 * Given the current contents of the active heap, increase the allowed
1377 * heap footprint to match the target utilization ratio. This
1385 Heap* heap = hs2heap(hs);
1388 * ideal heap size based on the size of the live set.
1389 * Note that only the active heap plays any part in this.
1394 * the current heap.
1396 size_t currentHeapUsed = heap->bytesAllocated;
1401 * If the target heap size would exceed the max, setIdealFootprint()
1410 heap->concurrentStartBytes = SIZE_MAX;
1412 heap->concurrentStartBytes = freeBytes - CONCURRENT_START;
1423 * TODO: move this somewhere else, especially the native heap part.
1454 Heap *heap = &hs->heaps[i];
1457 mspace_trim(heap->msp, 0);
1460 mspace_inspect_all(heap->msp, releasePagesInRange, &heapBytes);
1463 /* Same for the native heap. */
1473 * Walks over the heap source and passes every allocated and
1488 callback(NULL, NULL, 0, arg); // Indicate end of a heap.
1493 * Gets the number of heaps available in the heap source.
1495 * Caller must hold the heap lock, because gHs caches a field