summaryrefslogtreecommitdiffstats
path: root/runtime/base/allocator.h
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2014-10-08 11:47:24 -0700
committerIan Rogers <irogers@google.com>2014-10-08 11:57:59 -0700
commit7e70b002c4552347ed1af8c002a0e13f08864f20 (patch)
tree79d5ee5444a5be70130d9a75dd51831c4b15687b /runtime/base/allocator.h
parentedc34c88b8f8abd04f9c4668787403608cf0b2d4 (diff)
downloadandroid_art-7e70b002c4552347ed1af8c002a0e13f08864f20.tar.gz
android_art-7e70b002c4552347ed1af8c002a0e13f08864f20.tar.bz2
android_art-7e70b002c4552347ed1af8c002a0e13f08864f20.zip
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
Diffstat (limited to 'runtime/base/allocator.h')
-rw-r--r--runtime/base/allocator.h47
1 files changed, 28 insertions, 19 deletions
diff --git a/runtime/base/allocator.h b/runtime/base/allocator.h
index 2c3e966d32..95dd407924 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 @@ enum AllocatorTag {
};
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 {
+
+// 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];
+
+// 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;
}
+}
- private:
- static Atomic<uint64_t> bytes_used_[kAllocatorTagCount];
- static Atomic<uint64_t> max_bytes_used_[kAllocatorTagCount];
- static Atomic<uint64_t> total_bytes_used_[kAllocatorTagCount];
-};
+inline void RegisterFree(AllocatorTag tag, size_t bytes) {
+ g_bytes_used[tag].FetchAndSubSequentiallyConsistent(bytes);
+}
+
+} // namespace TrackedAllocators
-// Tracking allocator, tracks how much memory is used.
+// 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 @@ class TrackingAllocatorImpl {
free(p);
}
- static AllocatorTag GetTag() {
+ static constexpr AllocatorTag GetTag() {
return kTag;
}
};