summaryrefslogtreecommitdiffstats
path: root/vm/alloc
diff options
context:
space:
mode:
authorWei Wang <wangw@codeaurora.org>2013-01-23 15:17:39 -0800
committerSteve Kondik <shade@chemlab.org>2013-07-25 20:52:30 -0700
commit692e1ca87effa2be064094572900f13d15d4f48a (patch)
treee0e79d41ed0538dde9a23f53652d8bf1f4a6fdd0 /vm/alloc
parentbe687ce31418b5f88bdcebafd9e42c6e1d3b1d2f (diff)
downloadandroid_dalvik-692e1ca87effa2be064094572900f13d15d4f48a.tar.gz
android_dalvik-692e1ca87effa2be064094572900f13d15d4f48a.tar.bz2
android_dalvik-692e1ca87effa2be064094572900f13d15d4f48a.zip
GC triggering performance optimizations
Copy the correct starting heap size at process init. Interfaces to set GC/managed heap parameters. Change-Id: I454b1985a3225d7dbdea9c5d4e6f0c9f5e24352e
Diffstat (limited to 'vm/alloc')
-rw-r--r--vm/alloc/Alloc.h20
-rw-r--r--vm/alloc/HeapSource.cpp71
2 files changed, 83 insertions, 8 deletions
diff --git a/vm/alloc/Alloc.h b/vm/alloc/Alloc.h
index efee1bde3..4bcd45834 100644
--- a/vm/alloc/Alloc.h
+++ b/vm/alloc/Alloc.h
@@ -117,6 +117,26 @@ float dvmGetTargetHeapUtilization(void);
void dvmSetTargetHeapUtilization(float newTarget);
/*
+ * Sets HEAP_MIN_FREE
+ */
+void dvmSetTargetHeapMinFree(size_t size);
+
+/*
+ * Gets HEAP_MIN_FREE
+ */
+int dvmGetTargetHeapMinFree();
+
+/*
+ * Sets CONCURRENT_START
+ */
+void dvmSetTargetHeapConcurrentStart(size_t size);
+
+/*
+ * Gets CONCURRENT_START
+ */
+int dvmGetTargetHeapConcurrentStart();
+
+/*
* Initiate garbage collection.
*
* This usually happens automatically, but can also be caused by
diff --git a/vm/alloc/HeapSource.cpp b/vm/alloc/HeapSource.cpp
index 93cdd2fd7..f6c2464bc 100644
--- a/vm/alloc/HeapSource.cpp
+++ b/vm/alloc/HeapSource.cpp
@@ -43,12 +43,14 @@ static void trimHeaps();
/* Start a concurrent collection when free memory falls under this
* many bytes.
*/
-#define CONCURRENT_START (128 << 10)
+#define CONCURRENT_START_DEFAULT (128 << 10)
+
+static unsigned int concurrentStart = CONCURRENT_START_DEFAULT;
/* The next GC will not be concurrent when free memory after a GC is
* under this many bytes.
*/
-#define CONCURRENT_MIN_FREE (CONCURRENT_START + (128 << 10))
+#define CONCURRENT_MIN_FREE (concurrentStart + (128 << 10))
#define HS_BOILERPLATE() \
do { \
@@ -408,9 +410,9 @@ static bool addNewHeap(HeapSource *hs)
overhead, hs->maximumSize);
return false;
}
- size_t morecoreStart = SYSTEM_PAGE_SIZE;
+ size_t morecoreStart = MAX(SYSTEM_PAGE_SIZE, gDvm.heapStartingSize);
heap.maximumSize = hs->growthLimit - overhead;
- heap.concurrentStartBytes = hs->minFree - CONCURRENT_START;
+ heap.concurrentStartBytes = hs->minFree - concurrentStart;
heap.base = base;
heap.limit = heap.base + heap.maximumSize;
heap.brk = heap.base + morecoreStart;
@@ -611,8 +613,8 @@ GcHeap* dvmHeapSourceStartup(size_t startSize, size_t maximumSize,
if (hs->maxFree > hs->maximumSize) {
hs->maxFree = hs->maximumSize;
}
- if (hs->minFree < CONCURRENT_START) {
- hs->minFree = CONCURRENT_START;
+ if (hs->minFree < concurrentStart) {
+ hs->minFree = concurrentStart;
} else if (hs->minFree > hs->maxFree) {
hs->minFree = hs->maxFree;
}
@@ -649,6 +651,13 @@ fail:
bool dvmHeapSourceStartupAfterZygote()
{
+ //For each new application forked, we need to reset softLimit and
+ //concurrentStartBytes to be the correct expected value, not the one
+ //inherit from Zygote
+ HeapSource* hs = gHs;
+
+ hs->softLimit=SIZE_MAX;
+ hs->heaps[0].concurrentStartBytes = mspace_footprint(hs->heaps[0].msp) - concurrentStart;
return gDvm.concurrentMarkSweep ? gcDaemonStartup() : true;
}
@@ -1226,8 +1235,9 @@ static void setIdealFootprint(size_t max)
static void snapIdealFootprint()
{
HS_BOILERPLATE();
+ HeapSource *hs = gHs;
- setIdealFootprint(getSoftFootprint(true));
+ setIdealFootprint(getSoftFootprint(true) + hs->minFree);
}
/*
@@ -1269,6 +1279,48 @@ void dvmSetTargetHeapUtilization(float newTarget)
}
/*
+ * Sets TargetHeapMinFree
+ */
+void dvmSetTargetHeapMinFree(size_t size)
+{
+ HS_BOILERPLATE();
+ gHs->minFree = size;
+ LOGD_HEAP("dvmSetTargetHeapIdealFree %d", gHs->minFree );
+}
+
+/*
+ * Gets TargetHeapMinFree
+ */
+int dvmGetTargetHeapMinFree()
+{
+ HS_BOILERPLATE();
+ LOGD_HEAP("dvmGetTargetHeapIdealFree %d", gHs->minFree );
+ return gHs->minFree;
+}
+
+
+/*
+ * Sets concurrentStart
+ */
+void dvmSetTargetHeapConcurrentStart(size_t size)
+{
+ concurrentStart = size;
+ LOGD_HEAP("dvmSetTargetHeapConcurrentStart %d", size );
+}
+
+/*
+ * Gets concurrentStart
+ */
+int dvmGetTargetHeapConcurrentStart()
+{
+ HS_BOILERPLATE();
+ LOGD_HEAP("dvmGetTargetHeapConcurrentStart %d", concurrentStart );
+ return concurrentStart;
+}
+
+
+
+/*
* Given the size of a live set, returns the ideal heap size given
* the current target utilization and MIN/MAX values.
*/
@@ -1327,7 +1379,10 @@ void dvmHeapSourceGrowForUtilization()
/* Not enough free memory to allow a concurrent GC. */
heap->concurrentStartBytes = SIZE_MAX;
} else {
- heap->concurrentStartBytes = freeBytes - CONCURRENT_START;
+ //For small footprint, we keep the min percentage to start
+ //concurrent GC; for big footprint, we keep the absolute value
+ //of free to start concurrent GC
+ heap->concurrentStartBytes = freeBytes - MIN(freeBytes * (float)(0.2), concurrentStart);
}
}