diff options
author | Ian Rogers <irogers@google.com> | 2014-10-08 19:56:27 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-10-08 19:56:27 +0000 |
commit | 5bf66fd9e6541d6386235b584d0a3f0c0dc06370 (patch) | |
tree | c4a8a163d1802eee8b8ec5a5e7385535a3a8d8e3 | |
parent | 35d013f642be175b3baf78cd28582aebe9beb69a (diff) | |
parent | 175b2732f7e55a07094c30aa08d946189b4af97e (diff) | |
download | android_art-5bf66fd9e6541d6386235b584d0a3f0c0dc06370.tar.gz android_art-5bf66fd9e6541d6386235b584d0a3f0c0dc06370.tar.bz2 android_art-5bf66fd9e6541d6386235b584d0a3f0c0dc06370.zip |
am 175b2732: Merge "Header file clean up."
* commit '175b2732f7e55a07094c30aa08d946189b4af97e':
Header file clean up.
-rw-r--r-- | compiler/dex/quick/arm/int_arm.cc | 2 | ||||
-rw-r--r-- | compiler/dex/quick/arm64/int_arm64.cc | 2 | ||||
-rw-r--r-- | compiler/dex/quick/mips/int_mips.cc | 2 | ||||
-rwxr-xr-x | compiler/dex/quick/x86/int_x86.cc | 2 | ||||
-rwxr-xr-x | compiler/dex/quick/x86/target_x86.cc | 2 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_arm.cc | 2 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86.cc | 2 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86_64.cc | 2 | ||||
-rw-r--r-- | runtime/base/allocator.cc | 20 | ||||
-rw-r--r-- | runtime/base/allocator.h | 47 | ||||
-rw-r--r-- | runtime/base/type_static_if.h | 32 | ||||
-rw-r--r-- | runtime/mirror/array-inl.h | 8 | ||||
-rw-r--r-- | runtime/mirror/array.h | 8 | ||||
-rw-r--r-- | runtime/mirror/class_loader.h | 2 | ||||
-rw-r--r-- | runtime/mirror/object.h | 1 | ||||
-rw-r--r-- | runtime/mirror/object_array-inl.h | 1 | ||||
-rw-r--r-- | runtime/utils.h | 24 |
17 files changed, 91 insertions, 68 deletions
diff --git a/compiler/dex/quick/arm/int_arm.cc b/compiler/dex/quick/arm/int_arm.cc index bf09446438..eb80b4e9e2 100644 --- a/compiler/dex/quick/arm/int_arm.cc +++ b/compiler/dex/quick/arm/int_arm.cc @@ -21,7 +21,7 @@ #include "dex/quick/mir_to_lir-inl.h" #include "dex/reg_storage_eq.h" #include "entrypoints/quick/quick_entrypoints.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" namespace art { diff --git a/compiler/dex/quick/arm64/int_arm64.cc b/compiler/dex/quick/arm64/int_arm64.cc index 8ce0afd94b..b1c06148da 100644 --- a/compiler/dex/quick/arm64/int_arm64.cc +++ b/compiler/dex/quick/arm64/int_arm64.cc @@ -21,7 +21,7 @@ #include "dex/quick/mir_to_lir-inl.h" #include "dex/reg_storage_eq.h" #include "entrypoints/quick/quick_entrypoints.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" #include "utils.h" namespace art { diff --git a/compiler/dex/quick/mips/int_mips.cc b/compiler/dex/quick/mips/int_mips.cc index 95c1262cda..30aa611f9f 100644 --- a/compiler/dex/quick/mips/int_mips.cc +++ b/compiler/dex/quick/mips/int_mips.cc @@ -21,7 +21,7 @@ #include "dex/reg_storage_eq.h" #include "entrypoints/quick/quick_entrypoints.h" #include "mips_lir.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" namespace art { diff --git a/compiler/dex/quick/x86/int_x86.cc b/compiler/dex/quick/x86/int_x86.cc index 8638204878..0902f3cfa2 100755 --- a/compiler/dex/quick/x86/int_x86.cc +++ b/compiler/dex/quick/x86/int_x86.cc @@ -20,7 +20,7 @@ #include "dex/quick/mir_to_lir-inl.h" #include "dex/reg_storage_eq.h" #include "mirror/art_method.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" #include "x86_lir.h" namespace art { diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc index 9aeaf6057e..2ef4c218c3 100755 --- a/compiler/dex/quick/x86/target_x86.cc +++ b/compiler/dex/quick/x86/target_x86.cc @@ -23,7 +23,7 @@ #include "dex/compiler_internals.h" #include "dex/quick/mir_to_lir-inl.h" #include "dex/reg_storage_eq.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" #include "mirror/art_method.h" #include "mirror/string.h" #include "oat.h" diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc index d116905903..a68837eb7c 100644 --- a/compiler/optimizing/code_generator_arm.cc +++ b/compiler/optimizing/code_generator_arm.cc @@ -18,7 +18,7 @@ #include "entrypoints/quick/quick_entrypoints.h" #include "gc/accounting/card_table.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" #include "mirror/art_method.h" #include "mirror/class.h" #include "thread.h" diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index 328fc93ca8..ec82dd3aee 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -18,7 +18,7 @@ #include "entrypoints/quick/quick_entrypoints.h" #include "gc/accounting/card_table.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" #include "mirror/art_method.h" #include "mirror/class.h" #include "thread.h" diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index 5d04ca688f..f5437a17cb 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -18,7 +18,7 @@ #include "entrypoints/quick/quick_entrypoints.h" #include "gc/accounting/card_table.h" -#include "mirror/array.h" +#include "mirror/array-inl.h" #include "mirror/art_method.h" #include "mirror/class.h" #include "mirror/object_reference.h" diff --git a/runtime/base/allocator.cc b/runtime/base/allocator.cc index 64cdbbf2d7..f67616ef0d 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 @@ Allocator* Allocator::GetNoopAllocator() { 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 @@ void TrackedAllocators::Dump(std::ostream& os) { } } +} // namespace TrackedAllocators + } // namespace art 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; } }; diff --git a/runtime/base/type_static_if.h b/runtime/base/type_static_if.h new file mode 100644 index 0000000000..a74d79a665 --- /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_ diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h index 6582226dd5..13b5a8ba27 100644 --- a/runtime/mirror/array-inl.h +++ b/runtime/mirror/array-inl.h @@ -45,6 +45,14 @@ inline size_t Array::SizeOf() { return header_size + data_size; } +inline MemberOffset Array::DataOffset(size_t component_size) { + DCHECK(IsPowerOfTwo(component_size)) << component_size; + size_t data_offset = RoundUp(OFFSETOF_MEMBER(Array, first_element_), component_size); + DCHECK_EQ(RoundUp(data_offset, component_size), data_offset) + << "Array data offset isn't aligned with component size"; + return MemberOffset(data_offset); +} + template<VerifyObjectFlags kVerifyFlags> inline bool Array::CheckIsValidIndex(int32_t index) { if (UNLIKELY(static_cast<uint32_t>(index) >= diff --git a/runtime/mirror/array.h b/runtime/mirror/array.h index 521d7e7fea..12bec8974e 100644 --- a/runtime/mirror/array.h +++ b/runtime/mirror/array.h @@ -64,13 +64,7 @@ class MANAGED Array : public Object { return OFFSET_OF_OBJECT_MEMBER(Array, length_); } - static MemberOffset DataOffset(size_t component_size) { - DCHECK(IsPowerOfTwo(component_size)) << component_size; - size_t data_offset = RoundUp(OFFSETOF_MEMBER(Array, first_element_), component_size); - DCHECK_EQ(RoundUp(data_offset, component_size), data_offset) - << "Array data offset isn't aligned with component size"; - return MemberOffset(data_offset); - } + static MemberOffset DataOffset(size_t component_size); void* GetRawData(size_t component_size, int32_t index) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { diff --git a/runtime/mirror/class_loader.h b/runtime/mirror/class_loader.h index ff2ad89230..b10a296f18 100644 --- a/runtime/mirror/class_loader.h +++ b/runtime/mirror/class_loader.h @@ -17,7 +17,7 @@ #ifndef ART_RUNTIME_MIRROR_CLASS_LOADER_H_ #define ART_RUNTIME_MIRROR_CLASS_LOADER_H_ -#include "mirror/object.h" +#include "object.h" namespace art { diff --git a/runtime/mirror/object.h b/runtime/mirror/object.h index 6cd230b533..b68aef9c7f 100644 --- a/runtime/mirror/object.h +++ b/runtime/mirror/object.h @@ -19,7 +19,6 @@ #include "object_reference.h" #include "offsets.h" -#include "runtime.h" #include "verify_object.h" namespace art { diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h index 0ca44f8a3e..fbc4f4a675 100644 --- a/runtime/mirror/object_array-inl.h +++ b/runtime/mirror/object_array-inl.h @@ -19,6 +19,7 @@ #include "object_array.h" +#include "array-inl.h" #include "base/stringprintf.h" #include "gc/heap.h" #include "mirror/art_field.h" diff --git a/runtime/utils.h b/runtime/utils.h index 3f2d829b68..4fcd380a8d 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -145,18 +145,6 @@ static inline uint32_t High32Bits(uint64_t value) { return static_cast<uint32_t>(value >> 32); } -// 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; -}; - // Type identity. template <typename T> struct TypeIdentity { @@ -199,18 +187,6 @@ static inline T* AlignUp(T* x, uintptr_t n) { return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uintptr_t>(x), n)); } -// Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., -// figure 3-3, page 48, where the function is called clp2. -static inline uint32_t RoundUpToPowerOfTwo(uint32_t x) { - x = x - 1; - x = x | (x >> 1); - x = x | (x >> 2); - x = x | (x >> 4); - x = x | (x >> 8); - x = x | (x >> 16); - return x + 1; -} - template<typename T> static constexpr int CLZ(T x) { return (sizeof(T) == sizeof(uint32_t)) |