summaryrefslogtreecommitdiffstats
path: root/vm/alloc
diff options
context:
space:
mode:
authorIliyan Malchev <malchev@google.com>2012-02-16 11:23:36 -0800
committerIliyan Malchev <malchev@google.com>2012-02-16 11:30:09 -0800
commitb74e7190e86d559712747e5cdb31a0d390b7af7d (patch)
tree7ac5eb198a63b938d42b74f43988bf5b73c8de11 /vm/alloc
parent5bac60aaafca855f68e1f8b5527d4a4b7897f234 (diff)
downloadandroid_dalvik-b74e7190e86d559712747e5cdb31a0d390b7af7d.tar.gz
android_dalvik-b74e7190e86d559712747e5cdb31a0d390b7af7d.tar.bz2
android_dalvik-b74e7190e86d559712747e5cdb31a0d390b7af7d.zip
Replace malloc() followed by memset() to zero with calloc()
Bionic's calloc() is smart enough to not zero out memory if it gets that memory from an anonyous mmap. Thus, if we use malloc for large allocations, we cause unnecessary memory duplication by following the malloc() with a memset(). An even better approach would be to replace the known large calloc() calls with dvmAllocRegion() allocation. Change-Id: Id308f541c9a040d5929bf991b6c2bfdefb823c3c
Diffstat (limited to 'vm/alloc')
-rw-r--r--vm/alloc/Copying.cpp9
-rw-r--r--vm/alloc/HeapSource.cpp6
2 files changed, 5 insertions, 10 deletions
diff --git a/vm/alloc/Copying.cpp b/vm/alloc/Copying.cpp
index 49c676052..ad5b8fc94 100644
--- a/vm/alloc/Copying.cpp
+++ b/vm/alloc/Copying.cpp
@@ -444,9 +444,8 @@ GcHeap *dvmHeapSourceStartup(size_t startSize, size_t absoluteMaxSize)
assert(startSize <= absoluteMaxSize);
- heapSource = malloc(sizeof(*heapSource));
+ heapSource = calloc(1, sizeof(*heapSource));
assert(heapSource != NULL);
- memset(heapSource, 0, sizeof(*heapSource));
heapSource->minimumSize = alignUp(startSize, BLOCK_SIZE);
heapSource->maximumSize = alignUp(absoluteMaxSize, BLOCK_SIZE);
@@ -475,9 +474,8 @@ GcHeap *dvmHeapSourceStartup(size_t startSize, size_t absoluteMaxSize)
/* Byte indicating space residence or free status of block. */
{
size_t size = sizeof(heapSource->blockSpace[0]);
- heapSource->blockSpace = malloc(heapSource->totalBlocks*size);
+ heapSource->blockSpace = calloc(1, heapSource->totalBlocks*size);
assert(heapSource->blockSpace != NULL);
- memset(heapSource->blockSpace, 0, heapSource->totalBlocks*size);
}
dvmHeapBitmapInit(&heapSource->allocBits,
@@ -489,9 +487,8 @@ GcHeap *dvmHeapSourceStartup(size_t startSize, size_t absoluteMaxSize)
heapSource->allocPtr = allocateBlocks(heapSource, 1);
heapSource->allocLimit = heapSource->allocPtr + BLOCK_SIZE;
- gcHeap = malloc(sizeof(*gcHeap));
+ gcHeap = calloc(1, sizeof(*gcHeap));
assert(gcHeap != NULL);
- memset(gcHeap, 0, sizeof(*gcHeap));
gcHeap->heapSource = heapSource;
return gcHeap;
diff --git a/vm/alloc/HeapSource.cpp b/vm/alloc/HeapSource.cpp
index c0ad07df5..f051b4df6 100644
--- a/vm/alloc/HeapSource.cpp
+++ b/vm/alloc/HeapSource.cpp
@@ -535,20 +535,18 @@ GcHeap* dvmHeapSourceStartup(size_t startSize, size_t maximumSize,
goto fail;
}
- gcHeap = (GcHeap *)malloc(sizeof(*gcHeap));
+ gcHeap = (GcHeap *)calloc(1, sizeof(*gcHeap));
if (gcHeap == NULL) {
LOGE_HEAP("Can't allocate heap descriptor");
goto fail;
}
- memset(gcHeap, 0, sizeof(*gcHeap));
- hs = (HeapSource *)malloc(sizeof(*hs));
+ hs = (HeapSource *)calloc(1, sizeof(*hs));
if (hs == NULL) {
LOGE_HEAP("Can't allocate heap source");
free(gcHeap);
goto fail;
}
- memset(hs, 0, sizeof(*hs));
hs->targetUtilization = DEFAULT_HEAP_UTILIZATION;
hs->startSize = startSize;