diff options
| author | 2013-11-22 22:51:13 +0000 | |
|---|---|---|
| committer | 2013-11-22 22:51:13 +0000 | |
| commit | f566f383e47e4bba18591fbd14d202d3ec606ab0 (patch) | |
| tree | b821b8a46f757828e10176c454e588e4b1794cb2 | |
| parent | 4137f4828a6a7c48aa1b161cecb82e1e0880aa16 (diff) | |
| parent | 3c2856e939f3daa7a95a1f8cb70f47e7a621db3c (diff) | |
Merge "Inline RosAlloc::Alloc()." into dalvik-dev
| -rw-r--r-- | runtime/gc/allocator/rosalloc-inl.h | 45 | ||||
| -rw-r--r-- | runtime/gc/allocator/rosalloc.cc | 57 | ||||
| -rw-r--r-- | runtime/gc/allocator/rosalloc.h | 9 | ||||
| -rw-r--r-- | runtime/gc/space/rosalloc_space-inl.h | 1 |
4 files changed, 76 insertions, 36 deletions
diff --git a/runtime/gc/allocator/rosalloc-inl.h b/runtime/gc/allocator/rosalloc-inl.h new file mode 100644 index 0000000000..f395314a4d --- /dev/null +++ b/runtime/gc/allocator/rosalloc-inl.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2013 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_GC_ALLOCATOR_ROSALLOC_INL_H_ +#define ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_ + +#include "rosalloc.h" + +namespace art { +namespace gc { +namespace allocator { + +inline ALWAYS_INLINE void* RosAlloc::Alloc(Thread* self, size_t size, size_t* bytes_allocated) { + if (UNLIKELY(size > kLargeSizeThreshold)) { + return AllocLargeObject(self, size, bytes_allocated); + } + void* m = AllocFromRun(self, size, bytes_allocated); + // Check if the returned memory is really all zero. + if (kCheckZeroMemory && m != NULL) { + byte* bytes = reinterpret_cast<byte*>(m); + for (size_t i = 0; i < size; ++i) { + DCHECK_EQ(bytes[i], 0); + } + } + return m; +} + +} // namespace allocator +} // namespace gc +} // namespace art + +#endif // ART_RUNTIME_GC_ALLOCATOR_ROSALLOC_INL_H_ diff --git a/runtime/gc/allocator/rosalloc.cc b/runtime/gc/allocator/rosalloc.cc index 9e65894895..3030fa7fec 100644 --- a/runtime/gc/allocator/rosalloc.cc +++ b/runtime/gc/allocator/rosalloc.cc @@ -27,11 +27,6 @@ namespace art { namespace gc { namespace allocator { -// If true, log verbose details of operations. -static const bool kTraceRosAlloc = false; -// If true, check that the returned memory is actually zero. -static const bool kCheckZeroMemory = kIsDebugBuild; - extern "C" void* art_heap_rosalloc_morecore(RosAlloc* rosalloc, intptr_t increment); size_t RosAlloc::bracketSizes[kNumOfSizeBrackets]; @@ -401,44 +396,34 @@ void RosAlloc::FreePages(Thread* self, void* ptr) { } } -void* RosAlloc::Alloc(Thread* self, size_t size, size_t* bytes_allocated) { - if (UNLIKELY(size > kLargeSizeThreshold)) { - size_t num_pages = RoundUp(size, kPageSize) / kPageSize; - void* r; - { - MutexLock mu(self, lock_); - r = AllocPages(self, num_pages, kPageMapLargeObject); - } - if (bytes_allocated != NULL) { - *bytes_allocated = num_pages * kPageSize; - } - if (kTraceRosAlloc) { - if (r != NULL) { - LOG(INFO) << "RosAlloc::Alloc() : (large obj) 0x" << std::hex << reinterpret_cast<intptr_t>(r) - << "-0x" << (reinterpret_cast<intptr_t>(r) + num_pages * kPageSize) - << "(" << std::dec << (num_pages * kPageSize) << ")"; - } else { - LOG(INFO) << "RosAlloc::Alloc() : (large obj) NULL"; - } - } - // Check if the returned memory is really all zero. - if (kCheckZeroMemory && r != NULL) { - byte* bytes = reinterpret_cast<byte*>(r); - for (size_t i = 0; i < size; ++i) { - DCHECK_EQ(bytes[i], 0); - } +void* RosAlloc::AllocLargeObject(Thread* self, size_t size, size_t* bytes_allocated) { + DCHECK(size > kLargeSizeThreshold); + size_t num_pages = RoundUp(size, kPageSize) / kPageSize; + void* r; + { + MutexLock mu(self, lock_); + r = AllocPages(self, num_pages, kPageMapLargeObject); + } + if (bytes_allocated != NULL) { + *bytes_allocated = num_pages * kPageSize; + } + if (kTraceRosAlloc) { + if (r != NULL) { + LOG(INFO) << "RosAlloc::AllocLargeObject() : 0x" << std::hex << reinterpret_cast<intptr_t>(r) + << "-0x" << (reinterpret_cast<intptr_t>(r) + num_pages * kPageSize) + << "(" << std::dec << (num_pages * kPageSize) << ")"; + } else { + LOG(INFO) << "RosAlloc::AllocLargeObject() : NULL"; } - return r; } - void* m = AllocFromRun(self, size, bytes_allocated); // Check if the returned memory is really all zero. - if (kCheckZeroMemory && m != NULL) { - byte* bytes = reinterpret_cast<byte*>(m); + if (kCheckZeroMemory && r != NULL) { + byte* bytes = reinterpret_cast<byte*>(r); for (size_t i = 0; i < size; ++i) { DCHECK_EQ(bytes[i], 0); } } - return m; + return r; } void RosAlloc::FreeInternal(Thread* self, void* ptr) { diff --git a/runtime/gc/allocator/rosalloc.h b/runtime/gc/allocator/rosalloc.h index c81306ffd5..d5b6de1637 100644 --- a/runtime/gc/allocator/rosalloc.h +++ b/runtime/gc/allocator/rosalloc.h @@ -345,6 +345,12 @@ class RosAlloc { // runs for the rest. static const size_t kMaxThreadLocalSizeBracketIdx = 10; + // If true, check that the returned memory is actually zero. + static constexpr bool kCheckZeroMemory = kIsDebugBuild; + + // If true, log verbose details of operations. + static constexpr bool kTraceRosAlloc = false; + struct hash_run { size_t operator()(const RosAlloc::Run* r) const { return reinterpret_cast<size_t>(r); @@ -429,6 +435,9 @@ class RosAlloc { // The internal of non-bulk Free(). void FreeInternal(Thread* self, void* ptr) LOCKS_EXCLUDED(lock_); + // Allocates large objects. + void* AllocLargeObject(Thread* self, size_t size, size_t* bytes_allocated) LOCKS_EXCLUDED(lock_); + public: RosAlloc(void* base, size_t capacity); void* Alloc(Thread* self, size_t size, size_t* bytes_allocated) diff --git a/runtime/gc/space/rosalloc_space-inl.h b/runtime/gc/space/rosalloc_space-inl.h index 0fe5dd7a95..5de4265dc2 100644 --- a/runtime/gc/space/rosalloc_space-inl.h +++ b/runtime/gc/space/rosalloc_space-inl.h @@ -17,6 +17,7 @@ #ifndef ART_RUNTIME_GC_SPACE_ROSALLOC_SPACE_INL_H_ #define ART_RUNTIME_GC_SPACE_ROSALLOC_SPACE_INL_H_ +#include "gc/allocator/rosalloc-inl.h" #include "rosalloc_space.h" #include "thread.h" |