diff options
author | 2017-12-07 13:37:10 -0800 | |
---|---|---|
committer | 2017-12-07 16:26:11 -0800 | |
commit | dcc528d2c7d5ac2cc075d4c965fdf702421d0f43 (patch) | |
tree | e070070248facaf4c23f0ceb4a713de29b681462 | |
parent | 57943810cfc789da890d73621741729da5feaaf8 (diff) |
ART: Move runtime-debug flags to own files
To reduce the need for base/logging.h and separate out concerns.
Test: m
Change-Id: Ib373357325c6e622f608ada341594c3bea2fce2e
-rw-r--r-- | runtime/Android.bp | 1 | ||||
-rw-r--r-- | runtime/art_method.h | 2 | ||||
-rw-r--r-- | runtime/base/logging.cc | 49 | ||||
-rw-r--r-- | runtime/base/logging.h | 37 | ||||
-rw-r--r-- | runtime/base/logging_test.cc | 1 | ||||
-rw-r--r-- | runtime/base/runtime_debug.cc | 74 | ||||
-rw-r--r-- | runtime/base/runtime_debug.h | 61 | ||||
-rw-r--r-- | runtime/common_runtime_test.cc | 1 | ||||
-rw-r--r-- | runtime/gc/heap.h | 2 | ||||
-rw-r--r-- | runtime/jit/jit.cc | 1 | ||||
-rw-r--r-- | runtime/native/dalvik_system_ZygoteHooks.cc | 1 | ||||
-rw-r--r-- | runtime/native_stack_dump.cc | 1 | ||||
-rw-r--r-- | runtime/read_barrier.h | 2 | ||||
-rw-r--r-- | runtime/thread-inl.h | 1 | ||||
-rw-r--r-- | test/004-JniTest/jni_test.cc | 1 |
15 files changed, 146 insertions, 89 deletions
diff --git a/runtime/Android.bp b/runtime/Android.bp index a136ccb9d0..6477347a6e 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -39,6 +39,7 @@ cc_defaults { "base/hex_dump.cc", "base/logging.cc", "base/mutex.cc", + "base/runtime_debug.cc", "base/safe_copy.cc", "base/scoped_arena_allocator.cc", "base/scoped_flock.cc", diff --git a/runtime/art_method.h b/runtime/art_method.h index 4718150400..2c23c99dae 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -25,8 +25,8 @@ #include "base/casts.h" #include "base/enums.h" #include "base/iteration_range.h" -#include "base/logging.h" // For RUNTIME_DEBUG_FLAG. #include "base/macros.h" +#include "base/runtime_debug.h" #include "dex_file.h" #include "dex_instruction_iterator.h" #include "gc_root.h" diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc index 4776357fdf..26106eef2f 100644 --- a/runtime/base/logging.cc +++ b/runtime/base/logging.cc @@ -34,55 +34,6 @@ namespace art { -// We test here that the runtime-debug-checks are actually a no-op constexpr false in release -// builds, as we can't check that in gtests (which are always debug). - -#ifdef NDEBUG -namespace { -DECLARE_RUNTIME_DEBUG_FLAG(kTestForConstexpr); -static_assert(!kTestForConstexpr, "Issue with DECLARE_RUNTIME_DEBUG_FLAG in NDEBUG."); -} -#endif - -// Implementation of runtime debug flags. This should be compile-time optimized away in release -// builds. -namespace { -bool gSlowEnabled = false; // Default for slow flags is "off." - -// Use a function with a static to ensure our vector storage doesn't have initialization order -// issues. -std::vector<bool*>& GetFlagPtrs() { - static std::vector<bool*> g_flag_ptrs; - return g_flag_ptrs; -} - -bool RegisterRuntimeDebugFlagImpl(bool* flag_ptr) { - GetFlagPtrs().push_back(flag_ptr); - return gSlowEnabled; -} - -void SetRuntimeDebugFlagsEnabledImpl(bool enabled) { - gSlowEnabled = enabled; - for (bool* flag_ptr : GetFlagPtrs()) { - *flag_ptr = enabled; - } -} - -} // namespace - -bool RegisterRuntimeDebugFlag(bool* flag_ptr) { - if (kIsDebugBuild) { - return RegisterRuntimeDebugFlagImpl(flag_ptr); - } - return false; -} - -void SetRuntimeDebugFlagsEnabled(bool enabled) { - if (kIsDebugBuild) { - SetRuntimeDebugFlagsEnabledImpl(enabled); - } -} - LogVerbosity gLogVerbosity; std::atomic<unsigned int> gAborting(0); diff --git a/runtime/base/logging.h b/runtime/base/logging.h index 5703b3c746..981fbbfba4 100644 --- a/runtime/base/logging.h +++ b/runtime/base/logging.h @@ -63,43 +63,6 @@ struct LogVerbosity { // Global log verbosity setting, initialized by InitLogging. extern LogVerbosity gLogVerbosity; -// Runtime debug flags are flags that have a runtime component, that is, their value can be changed. -// This is meant to implement fast vs slow debug builds, in that certain debug flags can be turned -// on and off. To that effect, expose two macros to help implement and globally drive these flags: -// -// In the header, declare a (class) flag like this: -// -// class C { -// DECLARE_RUNTIME_DEBUG_FLAG(kFlag); -// }; -// -// This will declare a flag kFlag that is a constexpr false in release builds, and a static field -// in debug builds. Usage is than uniform as C::kFlag. -// -// In the cc file, define the flag like this: -// -// DEFINE_RUNTIME_DEBUG_FLAG(C, kFlag); -// -// This will define the static storage, as necessary, and register the flag with the runtime -// infrastructure to toggle the value. - -#ifdef NDEBUG -#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ - static constexpr bool x = false; -// Note: the static_assert in the following only works for public flags. Fix this when we cross -// the line at some point. -#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ - static_assert(!C::x, "Unexpected enabled flag in release build"); -#else -#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ - static bool x; -#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ - bool C::x = RegisterRuntimeDebugFlag(&C::x); -#endif // NDEBUG - -bool RegisterRuntimeDebugFlag(bool* runtime_debug_flag); -void SetRuntimeDebugFlagsEnabled(bool enabled); - // 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive // aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown // makes forward progress. diff --git a/runtime/base/logging_test.cc b/runtime/base/logging_test.cc index d380b9eccc..404e080b03 100644 --- a/runtime/base/logging_test.cc +++ b/runtime/base/logging_test.cc @@ -22,6 +22,7 @@ #include "base/bit_utils.h" #include "base/macros.h" #include "common_runtime_test.h" +#include "runtime_debug.h" namespace art { diff --git a/runtime/base/runtime_debug.cc b/runtime/base/runtime_debug.cc new file mode 100644 index 0000000000..4f8a8ec9c6 --- /dev/null +++ b/runtime/base/runtime_debug.cc @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "runtime_debug.h" + +#include <vector> + +#include "globals.h" + +namespace art { + +// We test here that the runtime-debug-checks are actually a no-op constexpr false in release +// builds, as we can't check that in gtests (which are always debug). + +#ifdef NDEBUG +namespace { +DECLARE_RUNTIME_DEBUG_FLAG(kTestForConstexpr); +static_assert(!kTestForConstexpr, "Issue with DECLARE_RUNTIME_DEBUG_FLAG in NDEBUG."); +} +#endif + +// Implementation of runtime debug flags. This should be compile-time optimized away in release +// builds. +namespace { +bool gSlowEnabled = false; // Default for slow flags is "off." + +// Use a function with a static to ensure our vector storage doesn't have initialization order +// issues. +std::vector<bool*>& GetFlagPtrs() { + static std::vector<bool*> g_flag_ptrs; + return g_flag_ptrs; +} + +bool RegisterRuntimeDebugFlagImpl(bool* flag_ptr) { + GetFlagPtrs().push_back(flag_ptr); + return gSlowEnabled; +} + +void SetRuntimeDebugFlagsEnabledImpl(bool enabled) { + gSlowEnabled = enabled; + for (bool* flag_ptr : GetFlagPtrs()) { + *flag_ptr = enabled; + } +} + +} // namespace + +bool RegisterRuntimeDebugFlag(bool* flag_ptr) { + if (kIsDebugBuild) { + return RegisterRuntimeDebugFlagImpl(flag_ptr); + } + return false; +} + +void SetRuntimeDebugFlagsEnabled(bool enabled) { + if (kIsDebugBuild) { + SetRuntimeDebugFlagsEnabledImpl(enabled); + } +} + +} // namespace art diff --git a/runtime/base/runtime_debug.h b/runtime/base/runtime_debug.h new file mode 100644 index 0000000000..89a0361fa7 --- /dev/null +++ b/runtime/base/runtime_debug.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_BASE_RUNTIME_DEBUG_H_ +#define ART_RUNTIME_BASE_RUNTIME_DEBUG_H_ + +namespace art { + +// Runtime debug flags are flags that have a runtime component, that is, their value can be changed. +// This is meant to implement fast vs slow debug builds, in that certain debug flags can be turned +// on and off. To that effect, expose two macros to help implement and globally drive these flags: +// +// In the header, declare a (class) flag like this: +// +// class C { +// DECLARE_RUNTIME_DEBUG_FLAG(kFlag); +// }; +// +// This will declare a flag kFlag that is a constexpr false in release builds, and a static field +// in debug builds. Usage is than uniform as C::kFlag. +// +// In the cc file, define the flag like this: +// +// DEFINE_RUNTIME_DEBUG_FLAG(C, kFlag); +// +// This will define the static storage, as necessary, and register the flag with the runtime +// infrastructure to toggle the value. + +#ifdef NDEBUG +#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ + static constexpr bool x = false; +// Note: the static_assert in the following only works for public flags. Fix this when we cross +// the line at some point. +#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ + static_assert(!C::x, "Unexpected enabled flag in release build"); +#else +#define DECLARE_RUNTIME_DEBUG_FLAG(x) \ + static bool x; +#define DEFINE_RUNTIME_DEBUG_FLAG(C, x) \ + bool C::x = RegisterRuntimeDebugFlag(&C::x); +#endif // NDEBUG + +bool RegisterRuntimeDebugFlag(bool* runtime_debug_flag); +void SetRuntimeDebugFlagsEnabled(bool enabled); + +} // namespace art + +#endif // ART_RUNTIME_BASE_RUNTIME_DEBUG_H_ diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index ef1647caf3..6db4d92708 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -30,6 +30,7 @@ #include "base/file_utils.h" #include "base/logging.h" #include "base/macros.h" +#include "base/runtime_debug.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h index 10bae7114e..bb21b7cf00 100644 --- a/runtime/gc/heap.h +++ b/runtime/gc/heap.h @@ -27,9 +27,9 @@ #include "allocator_type.h" #include "arch/instruction_set.h" #include "atomic.h" -#include "base/logging.h" // For DECLARE_RUNTIME_DEBUG_FLAG. #include "base/macros.h" #include "base/mutex.h" +#include "base/runtime_debug.h" #include "base/time_utils.h" #include "gc/collector/gc_type.h" #include "gc/collector/iteration.h" diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index a6aa9167eb..783d05df34 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -22,6 +22,7 @@ #include "base/enums.h" #include "base/logging.h" // For VLOG. #include "base/memory_tool.h" +#include "base/runtime_debug.h" #include "debugger.h" #include "entrypoints/runtime_asm_entrypoints.h" #include "interpreter/interpreter.h" diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc index bdbb80bd58..fd80aaeaf7 100644 --- a/runtime/native/dalvik_system_ZygoteHooks.cc +++ b/runtime/native/dalvik_system_ZygoteHooks.cc @@ -25,6 +25,7 @@ #include "art_method-inl.h" #include "base/macros.h" #include "base/mutex.h" +#include "base/runtime_debug.h" #include "debugger.h" #include "java_vm_ext.h" #include "jit/jit.h" diff --git a/runtime/native_stack_dump.cc b/runtime/native_stack_dump.cc index f166714b79..841506bce3 100644 --- a/runtime/native_stack_dump.cc +++ b/runtime/native_stack_dump.cc @@ -41,6 +41,7 @@ #include "arch/instruction_set.h" #include "base/file_utils.h" +#include "base/logging.h" // For gAborting. #include "base/memory_tool.h" #include "base/mutex.h" #include "base/unix_file/fd_file.h" diff --git a/runtime/read_barrier.h b/runtime/read_barrier.h index ce2cb0e568..e8df2ad4ce 100644 --- a/runtime/read_barrier.h +++ b/runtime/read_barrier.h @@ -19,9 +19,9 @@ #include <android-base/logging.h> -#include "base/logging.h" // For DECLARE_RUNTIME_DEBUG_FLAG. #include "base/macros.h" #include "base/mutex.h" +#include "base/runtime_debug.h" #include "gc_root.h" #include "jni.h" #include "mirror/object_reference.h" diff --git a/runtime/thread-inl.h b/runtime/thread-inl.h index b5a962691b..9d08531b69 100644 --- a/runtime/thread-inl.h +++ b/runtime/thread-inl.h @@ -20,6 +20,7 @@ #include "thread.h" #include "base/casts.h" +#include "base/logging.h" // For gAborting. #include "base/mutex-inl.h" #include "base/time_utils.h" #include "jni_env_ext.h" diff --git a/test/004-JniTest/jni_test.cc b/test/004-JniTest/jni_test.cc index eb14d48a8d..4561895509 100644 --- a/test/004-JniTest/jni_test.cc +++ b/test/004-JniTest/jni_test.cc @@ -23,6 +23,7 @@ #include <android-base/logging.h> #include "art_method-inl.h" +#include "base/runtime_debug.h" #include "jni.h" namespace art { |