summaryrefslogtreecommitdiffstats
path: root/runtime/runtime.cc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2013-12-16 11:54:42 -0800
committerMathieu Chartier <mathieuc@google.com>2014-01-08 14:16:12 -0800
commite6da9af8dfe0a3e3fbc2be700554f6478380e7b9 (patch)
tree127a0565fce79f05d82d0ff242fbbffa6e2bc6b3 /runtime/runtime.cc
parent977d409b959497eecc44a35cff16115d0f04ccab (diff)
downloadart-e6da9af8dfe0a3e3fbc2be700554f6478380e7b9.zip
art-e6da9af8dfe0a3e3fbc2be700554f6478380e7b9.tar.gz
art-e6da9af8dfe0a3e3fbc2be700554f6478380e7b9.tar.bz2
Background compaction support.
When the process state changes to a state which does not perceives jank, we copy from the main free-list backed allocation space to the bump pointer space and enable the semispace allocator. When we transition back to foreground, we copy back to a free-list backed space. Create a seperate non-moving space which only holds non-movable objects. This enables us to quickly wipe the current alloc space (DlMalloc / RosAlloc) when we transition to background. Added multiple alloc space support to the sticky mark sweep GC. Added a -XX:BackgroundGC option which lets you specify which GC to use for background apps. Passing in -XX:BackgroundGC=SS makes the heap compact the heap for apps which do not perceive jank. Results: Simple background foreground test: 0. Reboot phone, unlock. 1. Open browser, click on home. 2. Open calculator, click on home. 3. Open calendar, click on home. 4. Open camera, click on home. 5. Open clock, click on home. 6. adb shell dumpsys meminfo PSS Normal ART: Sample 1: 88468 kB: Dalvik 3188 kB: Dalvik Other Sample 2: 81125 kB: Dalvik 3080 kB: Dalvik Other PSS Dalvik: Total PSS by category: Sample 1: 81033 kB: Dalvik 27787 kB: Dalvik Other Sample 2: 81901 kB: Dalvik 28869 kB: Dalvik Other PSS ART + Background Compaction: Sample 1: 71014 kB: Dalvik 1412 kB: Dalvik Other Sample 2: 73859 kB: Dalvik 1400 kB: Dalvik Other Dalvik other reduction can be explained by less deep allocation stacks / less live bitmaps / less dirty cards. TODO improvements: Recycle mem-maps which are unused in the current state. Not hardcode 64 MB capacity of non movable space (avoid returning linear alloc nightmares). Figure out ways to deal with low virtual address memory problems. Bug: 8981901 Change-Id: Ib235d03f45548ffc08a06b8ae57bf5bada49d6f3
Diffstat (limited to 'runtime/runtime.cc')
-rw-r--r--runtime/runtime.cc48
1 files changed, 35 insertions, 13 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 5a28b2d..91d9b94 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -356,6 +356,25 @@ void Runtime::SweepSystemWeaks(RootVisitor* visitor, void* arg) {
GetJavaVM()->SweepJniWeakGlobals(visitor, arg);
}
+static gc::CollectorType ParseCollectorType(const std::string& option) {
+ std::vector<std::string> gc_options;
+ Split(option, ',', gc_options);
+ gc::CollectorType collector_type = gc::kCollectorTypeNone;
+ for (size_t i = 0; i < gc_options.size(); ++i) {
+ if (gc_options[i] == "MS" || gc_options[i] == "nonconcurrent") {
+ collector_type = gc::kCollectorTypeMS;
+ } else if (gc_options[i] == "CMS" || gc_options[i] == "concurrent") {
+ collector_type = gc::kCollectorTypeCMS;
+ } else if (gc_options[i] == "SS") {
+ collector_type = gc::kCollectorTypeSS;
+ } else {
+ LOG(WARNING) << "Ignoring unknown -Xgc option: " << gc_options[i];
+ return gc::kCollectorTypeNone;
+ }
+ }
+ return collector_type;
+}
+
Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) {
UniquePtr<ParsedOptions> parsed(new ParsedOptions());
const char* boot_class_path_string = getenv("BOOTCLASSPATH");
@@ -381,6 +400,9 @@ Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, b
parsed->conc_gc_threads_ = 0;
// Default is CMS which is Sticky + Partial + Full CMS GC.
parsed->collector_type_ = gc::kCollectorTypeCMS;
+ // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
+ // parsing options.
+ parsed->background_collector_type_ = gc::kCollectorTypeNone;
parsed->stack_size_ = 0; // 0 means default.
parsed->max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
parsed->low_memory_mode_ = false;
@@ -570,18 +592,15 @@ Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, b
} else if (option == "-Xint") {
parsed->interpreter_only_ = true;
} else if (StartsWith(option, "-Xgc:")) {
- std::vector<std::string> gc_options;
- Split(option.substr(strlen("-Xgc:")), ',', gc_options);
- for (size_t i = 0; i < gc_options.size(); ++i) {
- if (gc_options[i] == "MS" || gc_options[i] == "nonconcurrent") {
- parsed->collector_type_ = gc::kCollectorTypeMS;
- } else if (gc_options[i] == "CMS" || gc_options[i] == "concurrent") {
- parsed->collector_type_ = gc::kCollectorTypeCMS;
- } else if (gc_options[i] == "SS") {
- parsed->collector_type_ = gc::kCollectorTypeSS;
- } else {
- LOG(WARNING) << "Ignoring unknown -Xgc option: " << gc_options[i];
- }
+ gc::CollectorType collector_type = ParseCollectorType(option.substr(strlen("-Xgc:")));
+ if (collector_type != gc::kCollectorTypeNone) {
+ parsed->collector_type_ = collector_type;
+ }
+ } else if (StartsWith(option, "-XX:BackgroundGC=")) {
+ gc::CollectorType collector_type = ParseCollectorType(
+ option.substr(strlen("-XX:BackgroundGC=")));
+ if (collector_type != gc::kCollectorTypeNone) {
+ parsed->background_collector_type_ = collector_type;
}
} else if (option == "-XX:+DisableExplicitGC") {
parsed->is_explicit_gc_disabled_ = true;
@@ -708,7 +727,9 @@ Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, b
if (parsed->heap_growth_limit_ == 0) {
parsed->heap_growth_limit_ = parsed->heap_maximum_size_;
}
-
+ if (parsed->background_collector_type_ == gc::kCollectorTypeNone) {
+ parsed->background_collector_type_ = parsed->collector_type_;
+ }
return parsed.release();
}
@@ -957,6 +978,7 @@ bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
options->heap_maximum_size_,
options->image_,
options->collector_type_,
+ options->background_collector_type_,
options->parallel_gc_threads_,
options->conc_gc_threads_,
options->low_memory_mode_,