ART: Add support for runtime debug checks

Add support for runtime-switchable debug flags. These flags are only
enabled in debug mode, and a constexpr false in release mode. This
allows to distinguish fast from slow checks, for example.

To simplify usage, two macros should be used. DECLARE_RUNTIME_DEBUG_FLAG
defines a static class member or constexpr as the flag. DEFINE_RUNTIME_DEBUG_FLAG
defines the static storage and registers it, if needed. See the
documentation in logging.h.

As is, runtime checks are disabled by default. Pass -XX:SlowDebug=true
to enable them on startup.

Add logging_test. Fix up tests and scripts to enable slow debug checks.

Bug: 35644369
Test: m test-art-host
Change-Id: Icc1cb0bb921d863514c55abef794c5c96f8af801
diff --git a/tools/art b/tools/art
index 0bc08f0..2e5df91 100644
--- a/tools/art
+++ b/tools/art
@@ -24,6 +24,7 @@
 LIBART=libart.so
 JIT_PROFILE="no"
 VERBOSE="no"
+EXTRA_OPTIONS=""
 
 # Follow all sym links to get the program name.
 if [ z"$BASH_SOURCE" != z ]; then
@@ -147,6 +148,8 @@
     ;& # Fallthrough
   --debug)
     LIBART="libartd.so"
+    # Expect that debug mode wants all checks.
+    EXTRA_OPTIONS="${EXTRA_OPTIONS} -XX:SlowDebug=true"
     ;;
   --gdb)
     LIBART="libartd.so"
@@ -203,7 +206,6 @@
 
 LIBDIR="$(find_libdir $ART_BINARY_PATH)"
 LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
-EXTRA_OPTIONS=""
 
 # If ANDROID_DATA is the system ANDROID_DATA or is not set, use our own,
 # and ensure we delete it at the end.
diff --git a/tools/run-jdwp-tests.sh b/tools/run-jdwp-tests.sh
index f742767..225fb39 100755
--- a/tools/run-jdwp-tests.sh
+++ b/tools/run-jdwp-tests.sh
@@ -154,7 +154,7 @@
 if [[ $debug == "yes" ]]; then
   art="$art -d"
   art_debugee="$art_debugee -d"
-  vm_args="$vm_args --vm-arg -XXlib:libartd.so"
+  vm_args="$vm_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
 fi
 if [[ $verbose == "yes" ]]; then
   # Enable JDWP logs in the debuggee.
diff --git a/tools/run-libcore-tests.sh b/tools/run-libcore-tests.sh
index 8b3df3a..6dcc23a 100755
--- a/tools/run-libcore-tests.sh
+++ b/tools/run-libcore-tests.sh
@@ -127,7 +127,7 @@
   elif [[ "$1" == "--debug" ]]; then
     # Remove the --debug from the arguments.
     vogar_args=${vogar_args/$1}
-    vogar_args="$vogar_args --vm-arg -XXlib:libartd.so"
+    vogar_args="$vogar_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
     debug=true
     shift
   elif [[ "$1" == "-Xgc:gcstress" ]]; then