From 72b16f0ad0a4f0f81c0db4a24ecd6629348950e0 Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Tue, 19 Feb 2019 18:09:58 +0000 Subject: [PATCH] Replace generic GC type flag with a specific Generational CC flag. The "gctype" device configuration flag (from the "runtime_native_boot" namespace) was a string passed verbatim as an argument to the runtime option "-Xgc". It was too generic, conveyed no typing information, and was error-prone (there was no control over what was passed from the server to the zygote, and then to the runtime). This change replaces "gctype" with a specific, Boolean "enable_generational_cc" flag. This new flag better reflects the nature of the experiment to be conducted (either enable or disable generational garbage collection in ART's concurrent copying collector). Test: core/jni/runtime_native_boot-flags-test.sh Bug: 72446017 Bug: 120794191 Bug: 123754583 Change-Id: I30a73171c0dc3c7bc891c4f164eed0ba42b0f420 --- core/jni/AndroidRuntime.cpp | 37 +++++++++++++++++++----------- core/jni/runtime_native_boot-flags-test.sh | 22 ++++++++++-------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index c45900c098b3..ce2e35351beb 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -232,8 +232,15 @@ extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env); // 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; @@ -785,17 +792,21 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) 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 66e18bb19c44..01f37f07e5ca 100755 --- a/core/jni/runtime_native_boot-flags-test.sh +++ b/core/jni/runtime_native_boot-flags-test.sh @@ -172,12 +172,14 @@ function check_no_zygote_gc_runtime_option { 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 @@ function test_android_runtime_flag { 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 @@ function test_android_runtime_flag { 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 @@ case $(adb shell getprop ro.zygote) in (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." -- 2.11.0