diff options
author | Dimitry Ivanov <dimitry@google.com> | 2016-07-29 13:25:33 -0700 |
---|---|---|
committer | Dimitry Ivanov <dimitry@google.com> | 2016-07-29 14:05:39 -0700 |
commit | 65707b696a59f28b3980c78bdb4b049231610e64 (patch) | |
tree | 31fcb0e09dbe033dbd8fb82c6c304ad362d5a2ea /linker/linker_allocator.cpp | |
parent | 4bc6eea83e127a50d4763f067486ec79ed4e61a7 (diff) |
Improvements to initialization of linker_allocator
Make linker_allocator independent of the order of global constructors.
Bug: http://b/30483811
Change-Id: I18a323175661b8e1c9e398f2d6112f7a08d2cceb
Test: boot the device with I3ac91758a1a043146c65f2ae0f36fcfbe372c30f
Diffstat (limited to 'linker/linker_allocator.cpp')
-rw-r--r-- | linker/linker_allocator.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/linker/linker_allocator.cpp b/linker/linker_allocator.cpp index 7deddea4a..dc6dfc151 100644 --- a/linker/linker_allocator.cpp +++ b/linker/linker_allocator.cpp @@ -70,8 +70,8 @@ static inline uint16_t log2(size_t number) { return result; } -LinkerSmallObjectAllocator::LinkerSmallObjectAllocator() - : type_(0), block_size_(0), free_pages_cnt_(0), free_blocks_list_(nullptr) {} +LinkerSmallObjectAllocator::LinkerSmallObjectAllocator(uint32_t type, size_t block_size) + : type_(type), block_size_(block_size), free_pages_cnt_(0), free_blocks_list_(nullptr) {} void* LinkerSmallObjectAllocator::alloc() { CHECK(block_size_ != 0); @@ -159,11 +159,6 @@ void LinkerSmallObjectAllocator::free(void* ptr) { } } -void LinkerSmallObjectAllocator::init(uint32_t type, size_t block_size) { - type_ = type; - block_size_ = block_size; -} - linker_vector_t::iterator LinkerSmallObjectAllocator::find_page_record(void* ptr) { void* addr = reinterpret_cast<void*>(PAGE_START(reinterpret_cast<uintptr_t>(ptr))); small_object_page_record boundary; @@ -221,11 +216,20 @@ void LinkerSmallObjectAllocator::alloc_page() { } -LinkerMemoryAllocator::LinkerMemoryAllocator() { +void LinkerMemoryAllocator::initialize_allocators() { + if (allocators_ != nullptr) { + return; + } + + LinkerSmallObjectAllocator* allocators = + reinterpret_cast<LinkerSmallObjectAllocator*>(allocators_buf_); + for (size_t i = 0; i < kSmallObjectAllocatorsCount; ++i) { uint32_t type = i + kSmallObjectMinSizeLog2; - allocators_[i].init(type, 1 << type); + new (allocators + i) LinkerSmallObjectAllocator(type, 1 << type); } + + allocators_ = allocators; } void* LinkerMemoryAllocator::alloc_mmap(size_t size) { @@ -336,5 +340,6 @@ LinkerSmallObjectAllocator* LinkerMemoryAllocator::get_small_object_allocator(ui __libc_fatal("invalid type: %u", type); } + initialize_allocators(); return &allocators_[type - kSmallObjectMinSizeLog2]; } |