summaryrefslogtreecommitdiffstats
path: root/vm/alloc
diff options
context:
space:
mode:
authorHiroshi Yamauchi <yamauchi@google.com>2013-07-15 14:20:41 -0700
committerBrian Carlstrom <bdc@google.com>2013-07-31 01:14:03 -0700
commit478976606f43c8095c829a5b78d79ff50b4c43ef (patch)
treeb6df4e8f16e5da889cdc727c555b2361ec1a4875 /vm/alloc
parentabbd2ea62e490d60a0bf680e7b110a53a8c910ed (diff)
downloadandroid_dalvik-478976606f43c8095c829a5b78d79ff50b4c43ef.tar.gz
android_dalvik-478976606f43c8095c829a5b78d79ff50b4c43ef.tar.bz2
android_dalvik-478976606f43c8095c829a5b78d79ff50b4c43ef.zip
Show size/alloc/free per Dalvik heap space in dumpsys
Add the heap size/alloc/free stats to the Dalvik heap space breakdown section in dumpsys meminfo. Also, now the zygote heap has a distict ashmem region name. Bug: 9532137 Bug: 8266259 (cherry picked from commit 3edfe0b32753309ad7dcccd894239cb0a8aefb85) Change-Id: I9b32727e4211f571a5205b6b7281958514d245d4
Diffstat (limited to 'vm/alloc')
-rw-r--r--vm/alloc/HeapSource.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/vm/alloc/HeapSource.cpp b/vm/alloc/HeapSource.cpp
index 4d03da1f2..2c0a47489 100644
--- a/vm/alloc/HeapSource.cpp
+++ b/vm/alloc/HeapSource.cpp
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <sys/mman.h>
#include <errno.h>
+#include <cutils/ashmem.h>
#define SIZE_MAX UINT_MAX // TODO: get SIZE_MAX from stdint.h
@@ -384,6 +385,36 @@ static bool addInitialHeap(HeapSource *hs, mspace msp, size_t maximumSize)
}
/*
+ * A helper for addNewHeap(). Remap the new heap so that it will have
+ * a separate ashmem region with possibly a different name, etc. In
+ * practice, this is used to give the app heap a separate ashmem
+ * region from the zygote heap's.
+ */
+static bool remapNewHeap(HeapSource* hs, Heap* newHeap)
+{
+ char* newHeapBase = newHeap->base;
+ size_t rem_size = hs->heapBase + hs->heapLength - newHeapBase;
+ munmap(newHeapBase, rem_size);
+ int fd = ashmem_create_region("dalvik-heap", rem_size);
+ if (fd == -1) {
+ ALOGE("Unable to create an ashmem region for the new heap");
+ return false;
+ }
+ void* addr = mmap(newHeapBase, rem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ int ret = close(fd);
+ if (addr == MAP_FAILED) {
+ ALOGE("Unable to map an ashmem region for the new heap");
+ return false;
+ }
+ if (ret == -1) {
+ ALOGE("Unable to close fd for the ashmem region for the new heap");
+ munmap(newHeapBase, rem_size);
+ return false;
+ }
+ return true;
+}
+
+/*
* Adds an additional heap to the heap source. Returns false if there
* are too many heaps or insufficient free space to add another heap.
*/
@@ -421,6 +452,9 @@ static bool addNewHeap(HeapSource *hs)
heap.base = base;
heap.limit = heap.base + heap.maximumSize;
heap.brk = heap.base + morecoreStart;
+ if (!remapNewHeap(hs, &heap)) {
+ return false;
+ }
heap.msp = createMspace(base, morecoreStart, hs->minFree);
if (heap.msp == NULL) {
return false;
@@ -575,7 +609,7 @@ GcHeap* dvmHeapSourceStartup(size_t startSize, size_t maximumSize,
* among the heaps managed by the garbage collector.
*/
length = ALIGN_UP_TO_PAGE_SIZE(maximumSize);
- base = dvmAllocRegion(length, PROT_NONE, "dalvik-heap");
+ base = dvmAllocRegion(length, PROT_NONE, gDvm.zygote ? "dalvik-zygote" : "dalvik-heap");
if (base == NULL) {
return NULL;
}