Add a compile-time constant bool equivalent to !defined(NDEBUG).

This makes some code slightly less awkward.

Change-Id: Iafd359dd0baa65510ed9510a7d93ee01605f51e4
diff --git a/src/class_linker.cc b/src/class_linker.cc
index 0f7ccad..a6668a3 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -556,10 +556,7 @@
                                   int oat_fd,
                                   const std::string& oat_cache_filename) {
   std::string dex2oat_string(GetAndroidRoot());
-  dex2oat_string += "/bin/dex2oat";
-#ifndef NDEBUG
-  dex2oat_string += 'd';
-#endif
+  dex2oat_string += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat");
   const char* dex2oat = dex2oat_string.c_str();
 
   const char* class_path = Runtime::Current()->GetClassPathString().c_str();
@@ -2227,12 +2224,7 @@
   klass->SetStatus(Class::kStatusInitialized);
 
   // sanity checks
-#ifndef NDEBUG
-  bool debug = true;
-#else
-  bool debug = false;
-#endif
-  if (debug) {
+  if (kIsDebugBuild) {
     CHECK(klass->GetIFields() == NULL);
     CheckProxyConstructor(klass->GetDirectMethod(0));
     for (size_t i = 0; i < num_virtual_methods; ++i) {
diff --git a/src/compiler.cc b/src/compiler.cc
index 4d39cd7..6618dea 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -256,11 +256,7 @@
 
   // Bad things happen if we pull in the libartd-compiler to a libart dex2oat or vice versa,
   // because we end up with both libart and libartd in the same address space!
-#ifndef NDEBUG
-  const char* suffix = "d";
-#else
-  const char* suffix = "";
-#endif
+  const char* suffix = (kIsDebugBuild ? "d" : "");
 
   // Work out the filename for the compiler library.
 #if !defined(ART_USE_LLVM_COMPILER)
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index 0098f02..f2696e3 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -477,13 +477,8 @@
   int thread_count = 2;
   bool support_debugging = false;
   InstructionSet instruction_set = kThumb2;
-#ifndef NDEBUG
-  bool dump_stats = true;
-  bool dump_timings = true;
-#else
-  bool dump_stats = false;
-  bool dump_timings = false;
-#endif
+  bool dump_stats = kIsDebugBuild;
+  bool dump_timings = kIsDebugBuild;
 
   for (int i = 0; i < argc; i++) {
     const StringPiece option(argv[i]);
diff --git a/src/dex_verifier.h b/src/dex_verifier.h
index eaae42c..ee36f53 100644
--- a/src/dex_verifier.h
+++ b/src/dex_verifier.h
@@ -53,11 +53,7 @@
  * changes to the verifier (to make sure we're not skipping over stuff). The only reason not to do
  * it is that it slightly increases the time required to perform verification.
  */
-#ifndef NDEBUG
-# define DEAD_CODE_SCAN  true
-#else
-# define DEAD_CODE_SCAN  false
-#endif
+#define DEAD_CODE_SCAN kIsDebugBuild
 
 /*
  * RegType holds information about the "type" of data held in a register.
diff --git a/src/globals.h b/src/globals.h
index 4ec6dcb..35a2113 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -53,6 +53,13 @@
 // compile-time constant so the compiler can generate better code.
 const int kPageSize = 4096;
 
+// Whether or not this is a debug build. Useful in conditionals where NDEBUG isn't.
+#if defined(NDEBUG)
+const bool kIsDebugBuild = false;
+#else
+const bool kIsDebugBuild = true;
+#endif
+
 }  // namespace art
 
 #endif  // ART_SRC_GLOBALS_H_
diff --git a/src/heap.cc b/src/heap.cc
index d847682..f351b72 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -62,10 +62,7 @@
   std::vector<char*> arg_vector;
 
   std::string dex2oat_string(GetAndroidRoot());
-  dex2oat_string += "/bin/dex2oat";
-#ifndef NDEBUG
-  dex2oat_string += 'd';
-#endif
+  dex2oat_string += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat");
   const char* dex2oat = dex2oat_string.c_str();
   arg_vector.push_back(strdup(dex2oat));
 
diff --git a/src/mutex.cc b/src/mutex.cc
index b3cf946..5a9df17 100644
--- a/src/mutex.cc
+++ b/src/mutex.cc
@@ -27,8 +27,10 @@
 
 namespace art {
 
-#if !defined(NDBEUG)
 static inline void CheckSafeToLockOrUnlock(MutexRank rank, bool is_locking) {
+  if (!kIsDebugBuild) {
+    return;
+  }
   if (rank == -1) {
     return;
   }
@@ -37,20 +39,16 @@
     self->CheckSafeToLockOrUnlock(rank, is_locking);
   }
 }
-#else
-static inline void CheckSafeToLockOrUnlock(MutexRank, bool) {}
-#endif
 
-#if !defined(NDEBUG)
 static inline void CheckSafeToWait(MutexRank rank) {
+  if (!kIsDebugBuild) {
+    return;
+  }
   Thread* self = Thread::Current();
   if (self != NULL) {
     self->CheckSafeToWait(rank);
   }
 }
-#else
-static inline void CheckSafeToWait(MutexRank) {}
-#endif
 
 Mutex::Mutex(const char* name, MutexRank rank) : name_(name), rank_(rank) {
   // Like Java, we use recursive mutexes.
diff --git a/src/object.h b/src/object.h
index 4e3e850..cfea1c9 100644
--- a/src/object.h
+++ b/src/object.h
@@ -2333,8 +2333,10 @@
   return GetField32(OFFSET_OF_OBJECT_MEMBER(Method, method_dex_index_), false);
 }
 
-#if !defined(NDEBUG)
 inline void Method::AssertPcIsWithinCode(uintptr_t pc) const {
+  if (!kIsDebugBuild) {
+    return;
+  }
   if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) {
     return;
   }
@@ -2348,9 +2350,6 @@
       << " code=" << GetCode()
       << " size=" << GetCodeSize();
 }
-#else
-inline void Method::AssertPcIsWithinCode(uintptr_t) const {}
-#endif
 
 inline String* Class::GetName() const {
   return GetFieldObject<String*>(OFFSET_OF_OBJECT_MEMBER(Class, name_), false);
diff --git a/src/runtime.cc b/src/runtime.cc
index d2e8e07..4156bb3 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -280,13 +280,8 @@
   if (class_path_string != NULL) {
     parsed->class_path_string_ = class_path_string;
   }
-#ifdef NDEBUG
-  // -Xcheck:jni is off by default for regular builds...
-  parsed->check_jni_ = false;
-#else
-  // ...but on by default in debug builds.
-  parsed->check_jni_ = true;
-#endif
+  // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
+  parsed->check_jni_ = kIsDebugBuild;
 
   parsed->heap_initial_size_ = Heap::kInitialSize;
   parsed->heap_maximum_size_ = Heap::kMaximumSize;
@@ -435,10 +430,11 @@
     } else if (StartsWith(option, "-Xlockprofthreshold:")) {
       parsed->lock_profiling_threshold_ = ParseIntegerOrDie(option);
     } else if (StartsWith(option, "-Xstacktracefile:")) {
-// always show stack traces in debug builds
-#ifdef NDEBUG
-      parsed->stack_trace_file_ = option.substr(strlen("-Xstacktracefile:"));
-#endif
+      if (kIsDebugBuild) {
+        // Ignore the zygote and always show stack traces in debug builds.
+      } else {
+        parsed->stack_trace_file_ = option.substr(strlen("-Xstacktracefile:"));
+      }
     } else if (option == "sensitiveThread") {
       parsed->hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(options[i].second);
     } else if (option == "vfprintf") {
@@ -476,11 +472,7 @@
   }
 
   LOG(INFO) << "Build type: "
-#ifndef NDEBUG
-            << "debug"
-#else
-            << "optimized"
-#endif
+            << (kIsDebugBuild ? "debug" : "optimized")
             << "; CheckJNI: " << (parsed->check_jni_ ? "on" : "off");
 
   return parsed.release();