Header file clean up.

Remove runtime.h from object.h.
Move TypeStaticIf to its own header file to avoid bringing utils.h into
allocator.h.
Move Array::DataOffset into -inl.h as it now has a utils.h dependency.
Fix include issues arising from this.

Change-Id: I4605b1aa4ff5f8dc15706a0132e15df03c7c8ba0
diff --git a/runtime/base/allocator.cc b/runtime/base/allocator.cc
index 64cdbbf..f67616e 100644
--- a/runtime/base/allocator.cc
+++ b/runtime/base/allocator.cc
@@ -25,10 +25,6 @@
 
 namespace art {
 
-Atomic<uint64_t> TrackedAllocators::bytes_used_[kAllocatorTagCount];
-Atomic<uint64_t> TrackedAllocators::max_bytes_used_[kAllocatorTagCount];
-Atomic<uint64_t> TrackedAllocators::total_bytes_used_[kAllocatorTagCount];
-
 class MallocAllocator FINAL : public Allocator {
  public:
   explicit MallocAllocator() {}
@@ -76,13 +72,19 @@
   return &g_noop_allocator;
 }
 
-void TrackedAllocators::Dump(std::ostream& os) {
+namespace TrackedAllocators {
+
+Atomic<size_t> g_bytes_used[kAllocatorTagCount];
+volatile size_t g_max_bytes_used[kAllocatorTagCount];
+Atomic<uint64_t> g_total_bytes_used[kAllocatorTagCount];
+
+void Dump(std::ostream& os) {
   if (kEnableTrackingAllocator) {
     os << "Dumping native memory usage\n";
     for (size_t i = 0; i < kAllocatorTagCount; ++i) {
-      uint64_t bytes_used = bytes_used_[i].LoadRelaxed();
-      uint64_t max_bytes_used = max_bytes_used_[i].LoadRelaxed();
-      uint64_t total_bytes_used = total_bytes_used_[i].LoadRelaxed();
+      uint64_t bytes_used = g_bytes_used[i].LoadRelaxed();
+      uint64_t max_bytes_used = g_max_bytes_used[i];
+      uint64_t total_bytes_used = g_total_bytes_used[i].LoadRelaxed();
       if (total_bytes_used != 0) {
         os << static_cast<AllocatorTag>(i) << " active=" << bytes_used << " max="
            << max_bytes_used << " total=" << total_bytes_used << "\n";
@@ -91,4 +93,6 @@
   }
 }
 
+}  // namespace TrackedAllocators
+
 }  // namespace art
diff --git a/runtime/base/allocator.h b/runtime/base/allocator.h
index 2c3e966..95dd407 100644
--- a/runtime/base/allocator.h
+++ b/runtime/base/allocator.h
@@ -22,7 +22,7 @@
 #include "atomic.h"
 #include "base/macros.h"
 #include "base/mutex.h"
-#include "utils.h"
+#include "base/type_static_if.h"
 
 namespace art {
 
@@ -71,26 +71,35 @@
 };
 std::ostream& operator<<(std::ostream& os, const AllocatorTag& tag);
 
-class TrackedAllocators {
- public:
-  static bool Add(uint32_t tag, AtomicInteger* bytes_used);
-  static void Dump(std::ostream& os);
-  static void RegisterAllocation(AllocatorTag tag, uint64_t bytes) {
-    total_bytes_used_[tag].FetchAndAddSequentiallyConsistent(bytes);
-    uint64_t new_bytes = bytes_used_[tag].FetchAndAddSequentiallyConsistent(bytes) + bytes;
-    max_bytes_used_[tag].StoreRelaxed(std::max(max_bytes_used_[tag].LoadRelaxed(), new_bytes));
-  }
-  static void RegisterFree(AllocatorTag tag, uint64_t bytes) {
-    bytes_used_[tag].FetchAndSubSequentiallyConsistent(bytes);
-  }
+namespace TrackedAllocators {
 
- private:
-  static Atomic<uint64_t> bytes_used_[kAllocatorTagCount];
-  static Atomic<uint64_t> max_bytes_used_[kAllocatorTagCount];
-  static Atomic<uint64_t> total_bytes_used_[kAllocatorTagCount];
-};
+// Running count of number of bytes used for this kind of allocation. Increased by allocations,
+// decreased by deallocations.
+extern Atomic<size_t> g_bytes_used[kAllocatorTagCount];
 
-// Tracking allocator, tracks how much memory is used.
+// Largest value of bytes used seen.
+extern volatile size_t g_max_bytes_used[kAllocatorTagCount];
+
+// Total number of bytes allocated of this kind.
+extern Atomic<uint64_t> g_total_bytes_used[kAllocatorTagCount];
+
+void Dump(std::ostream& os);
+
+inline void RegisterAllocation(AllocatorTag tag, size_t bytes) {
+  g_total_bytes_used[tag].FetchAndAddSequentiallyConsistent(bytes);
+  size_t new_bytes = g_bytes_used[tag].FetchAndAddSequentiallyConsistent(bytes) + bytes;
+  if (g_max_bytes_used[tag] < new_bytes) {
+    g_max_bytes_used[tag] = new_bytes;
+  }
+}
+
+inline void RegisterFree(AllocatorTag tag, size_t bytes) {
+  g_bytes_used[tag].FetchAndSubSequentiallyConsistent(bytes);
+}
+
+}  // namespace TrackedAllocators
+
+// Tracking allocator for use with STL types, tracks how much memory is used.
 template<class T, AllocatorTag kTag>
 class TrackingAllocatorImpl {
  public:
@@ -132,7 +141,7 @@
     free(p);
   }
 
-  static AllocatorTag GetTag() {
+  static constexpr AllocatorTag GetTag() {
     return kTag;
   }
 };
diff --git a/runtime/base/type_static_if.h b/runtime/base/type_static_if.h
new file mode 100644
index 0000000..a74d79a
--- /dev/null
+++ b/runtime/base/type_static_if.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014 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_TYPE_STATIC_IF_H_
+#define ART_RUNTIME_BASE_TYPE_STATIC_IF_H_
+
+// A static if which determines whether to return type A or B based on the condition boolean.
+template <bool condition, typename A, typename B>
+struct TypeStaticIf {
+  typedef A type;
+};
+
+// Specialization to handle the false case.
+template <typename A, typename B>
+struct TypeStaticIf<false, A,  B> {
+  typedef B type;
+};
+
+#endif  // ART_RUNTIME_BASE_TYPE_STATIC_IF_H_