diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-10-14 15:01:24 -0700 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-10-14 15:43:21 -0700 |
commit | 6e88ef6b604a7a945a466784580c42e6554c1289 (patch) | |
tree | 1e296564787b51514cf2eca5b732647c1a82912e /runtime/mem_map.cc | |
parent | 58e51f38e2304a08aa9ec380383e0b3614f96a96 (diff) | |
download | art-6e88ef6b604a7a945a466784580c42e6554c1289.tar.gz art-6e88ef6b604a7a945a466784580c42e6554c1289.tar.bz2 art-6e88ef6b604a7a945a466784580c42e6554c1289.zip |
Change MemMap::maps_ to not be global variable
Runtime.exit() was causing globals to get destructed at the same time
that another thread was using it for allocating a new mem map.
Bug: 17962201
Change-Id: I400cb7b8141d858f3c08a6fe59a02838c04c6962
Diffstat (limited to 'runtime/mem_map.cc')
-rw-r--r-- | runtime/mem_map.cc | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc index 231e9e56b0..3144ce1643 100644 --- a/runtime/mem_map.cc +++ b/runtime/mem_map.cc @@ -70,7 +70,7 @@ std::ostream& operator<<(std::ostream& os, const MemMap::Maps& mem_maps) { return os; } -MemMap::Maps MemMap::maps_; +MemMap::Maps* MemMap::maps_ = nullptr; #if USE_ART_LOW_4G_ALLOCATOR // Handling mem_map in 32b address range for 64b architectures that do not support MAP_32BIT. @@ -457,11 +457,12 @@ MemMap::~MemMap() { // Remove it from maps_. MutexLock mu(Thread::Current(), *Locks::mem_maps_lock_); bool found = false; - for (auto it = maps_.lower_bound(base_begin_), end = maps_.end(); + DCHECK(maps_ != nullptr); + for (auto it = maps_->lower_bound(base_begin_), end = maps_->end(); it != end && it->first == base_begin_; ++it) { if (it->second == this) { found = true; - maps_.erase(it); + maps_->erase(it); break; } } @@ -483,7 +484,8 @@ MemMap::MemMap(const std::string& name, uint8_t* begin, size_t size, void* base_ // Add it to maps_. MutexLock mu(Thread::Current(), *Locks::mem_maps_lock_); - maps_.insert(std::pair<void*, MemMap*>(base_begin_, this)); + DCHECK(maps_ != nullptr); + maps_->insert(std::make_pair(base_begin_, this)); } } @@ -614,7 +616,7 @@ void MemMap::DumpMapsLocked(std::ostream& os) { bool MemMap::HasMemMap(MemMap* map) { void* base_begin = map->BaseBegin(); - for (auto it = maps_.lower_bound(base_begin), end = maps_.end(); + for (auto it = maps_->lower_bound(base_begin), end = maps_->end(); it != end && it->first == base_begin; ++it) { if (it->second == map) { return true; @@ -626,7 +628,8 @@ bool MemMap::HasMemMap(MemMap* map) { MemMap* MemMap::GetLargestMemMapAt(void* address) { size_t largest_size = 0; MemMap* largest_map = nullptr; - for (auto it = maps_.lower_bound(address), end = maps_.end(); + DCHECK(maps_ != nullptr); + for (auto it = maps_->lower_bound(address), end = maps_->end(); it != end && it->first == address; ++it) { MemMap* map = it->second; CHECK(map != nullptr); @@ -638,6 +641,20 @@ MemMap* MemMap::GetLargestMemMapAt(void* address) { return largest_map; } +void MemMap::Init() { + MutexLock mu(Thread::Current(), *Locks::mem_maps_lock_); + if (maps_ == nullptr) { + // dex2oat calls MemMap::Init twice since its needed before the runtime is created. + maps_ = new Maps; + } +} + +void MemMap::Shutdown() { + MutexLock mu(Thread::Current(), *Locks::mem_maps_lock_); + delete maps_; + maps_ = nullptr; +} + std::ostream& operator<<(std::ostream& os, const MemMap& mem_map) { os << StringPrintf("[MemMap: %p-%p prot=0x%x %s]", mem_map.BaseBegin(), mem_map.BaseEnd(), mem_map.GetProtect(), |