Merge "Replace generic GC type flag with a specific Generational CC flag."
am: 77ad6aee15

Change-Id: I44675d5fb088cebc01f75f7a176f42cd06d4f007
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 815b963..7c69c33 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -222,8 +222,15 @@
 
 // Namespace for Android Runtime flags applied during boot time.
 static const char* RUNTIME_NATIVE_BOOT_NAMESPACE = "runtime_native_boot";
-// Feature flag name for Garbage Collector type.
-static const char* GCTYPE = "gctype";
+// Feature flag name to enable/disable generational garbage collection in ART's
+// Concurrent Copying (CC) garbage collector.
+static const char* ENABLE_GENERATIONAL_CC = "enable_generational_cc";
+// Runtime option enabling generational garbage collection in ART's Concurrent
+// Copying (CC) garbage collector.
+static const char* kGenerationalCCRuntimeOption = "-Xgc:generational_cc";
+// Runtime option disabling generational garbage collection in ART's Concurrent
+// Copying (CC) garbage collector.
+static const char* kNoGenerationalCCRuntimeOption = "-Xgc:nogenerational_cc";
 
 static AndroidRuntime* gCurRuntime = NULL;
 
@@ -775,17 +782,21 @@
       addOption("-XX:LowMemoryMode");
     }
 
-    std::string gc_type_override =
-            server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE,
-                                                                 GCTYPE,
-                                                                 /*default_value=*/ "");
-    std::string gc_type_override_temp;
-    if (gc_type_override.empty()) {
-        parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
-    } else {
-        // Copy the string so it doesn't go out of scope since addOption does not make a copy.
-        gc_type_override_temp = "-Xgc:" + gc_type_override;
-        addOption(gc_type_override_temp.c_str());
+    /*
+     * Garbage-collection related options.
+     */
+    parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
+
+    // If it set, honor the "enable_generational_cc" device configuration;
+    // otherwise, let the runtime use its default behavior.
+    std::string enable_generational_cc =
+        server_configurable_flags::GetServerConfigurableFlag(RUNTIME_NATIVE_BOOT_NAMESPACE,
+                                                             ENABLE_GENERATIONAL_CC,
+                                                             /*default_value=*/ "");
+    if (enable_generational_cc == "true") {
+        addOption(kGenerationalCCRuntimeOption);
+    } else if (enable_generational_cc == "false") {
+        addOption(kNoGenerationalCCRuntimeOption);
     }
 
     parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
diff --git a/core/jni/runtime_native_boot-flags-test.sh b/core/jni/runtime_native_boot-flags-test.sh
index 66e18bb..01f37f0 100755
--- a/core/jni/runtime_native_boot-flags-test.sh
+++ b/core/jni/runtime_native_boot-flags-test.sh
@@ -172,12 +172,14 @@
   done
 }
 
-# test_android_runtime_flag FLAG VALUE
-# ------------------------------------
-# Test device configuration FLAG with VALUE.
+# test_android_runtime_flag FLAG VALUE GC_RUNTIME_OPTION
+# ------------------------------------------------------
+# Test device configuration FLAG with VALUE. Check that GC_RUNTIME_OPTION is
+# passed as GC Runtime option by the zygote.
 function test_android_runtime_flag {
   local flag=$1
   local value=$2
+  local gc_runtime_option=$3
 
   # Persistent system property (set after a reboot) associated with the device
   # configuration flag.
@@ -196,21 +198,21 @@
   local context="Flag set, before reboot"
   check_device_config_flag "$context" "$flag" "$value"
   check_system_property "$context" "$prop" "$value"
-  check_no_zygote_gc_runtime_option "$context" "$value"
+  check_no_zygote_gc_runtime_option "$context" "$gc_runtime_option"
 
   # Reboot device for the flag value to take effect.
   reboot_and_wait_for_device
   context="Flag set, after 1st reboot"
   check_device_config_flag "$context" "$flag" "$value"
   check_system_property "$context" "$prop" "$value"
-  check_zygote_gc_runtime_option "$context" "$value"
+  check_zygote_gc_runtime_option "$context" "$gc_runtime_option"
 
   # Reboot device a second time and check that the state has persisted.
   reboot_and_wait_for_device
   context="Flag set, after 2nd reboot"
   check_device_config_flag "$context" "$flag" "$value"
   check_system_property "$context" "$prop" "$value"
-  check_zygote_gc_runtime_option "$context" "$value"
+  check_zygote_gc_runtime_option "$context" "$gc_runtime_option"
 
   say "Unsetting device configuration flag..."
   adb shell device_config delete "$namespace" "$flag" >/dev/null
@@ -222,7 +224,7 @@
   context="Flag unset, after 3rd reboot"
   check_no_device_config_flag "$context" "$flag"
   check_no_system_property "$context" "$prop"
-  check_no_zygote_gc_runtime_option "$context" "$value"
+  check_no_zygote_gc_runtime_option "$context" "$gc_runtime_option"
 }
 
 # Enumerate Zygote processes.
@@ -232,9 +234,9 @@
   (zygote32_64|zygote64_32) zygotes="zygote zygote64";;
 esac
 
-# Test "gctype" flag values.
-test_android_runtime_flag gctype nogenerational_cc
-test_android_runtime_flag gctype generational_cc
+# Test "enable_generational_cc" flag values.
+test_android_runtime_flag enable_generational_cc false nogenerational_cc
+test_android_runtime_flag enable_generational_cc true generational_cc
 
 if [[ "$exit_status" -eq 0 ]]; then
   banner "All tests passed."