Hiroshi Yamauchi | 7cb7bbc | 2013-11-18 17:27:37 -0800 | [diff] [blame] | 1 | |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include "rosalloc_space.h" |
| 19 | |
| 20 | #include "rosalloc_space-inl.h" |
| 21 | #include "gc/accounting/card_table.h" |
| 22 | #include "gc/heap.h" |
| 23 | #include "mirror/class-inl.h" |
| 24 | #include "mirror/object-inl.h" |
| 25 | #include "runtime.h" |
| 26 | #include "thread.h" |
| 27 | #include "thread_list.h" |
| 28 | #include "utils.h" |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 29 | #include "valgrind_malloc_space-inl.h" |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | namespace gc { |
| 33 | namespace space { |
| 34 | |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 35 | static constexpr bool kPrefetchDuringRosAllocFreeList = true; |
| 36 | |
| 37 | template class ValgrindMallocSpace<RosAllocSpace, allocator::RosAlloc*>; |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 38 | |
| 39 | RosAllocSpace::RosAllocSpace(const std::string& name, MemMap* mem_map, |
| 40 | art::gc::allocator::RosAlloc* rosalloc, byte* begin, byte* end, |
| 41 | byte* limit, size_t growth_limit) |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 42 | : MallocSpace(name, mem_map, begin, end, limit, growth_limit), rosalloc_(rosalloc) { |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 43 | CHECK(rosalloc != NULL); |
| 44 | } |
| 45 | |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 46 | RosAllocSpace* RosAllocSpace::CreateFromMemMap(MemMap* mem_map, const std::string& name, |
Ian Rogers | a55cf41 | 2014-02-27 00:31:26 -0800 | [diff] [blame] | 47 | size_t starting_size, size_t initial_size, |
| 48 | size_t growth_limit, size_t capacity, |
| 49 | bool low_memory_mode) { |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 50 | DCHECK(mem_map != nullptr); |
| 51 | allocator::RosAlloc* rosalloc = CreateRosAlloc(mem_map->Begin(), starting_size, initial_size, |
Hiroshi Yamauchi | 26d69ff | 2014-02-27 11:27:10 -0800 | [diff] [blame] | 52 | capacity, low_memory_mode); |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 53 | if (rosalloc == NULL) { |
| 54 | LOG(ERROR) << "Failed to initialize rosalloc for alloc space (" << name << ")"; |
| 55 | return NULL; |
| 56 | } |
| 57 | |
lzang1 | 385de73 | 2014-02-21 14:15:01 +0800 | [diff] [blame] | 58 | // Protect memory beyond the starting size. MoreCore will add r/w permissions when necessory |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 59 | byte* end = mem_map->Begin() + starting_size; |
lzang1 | 385de73 | 2014-02-21 14:15:01 +0800 | [diff] [blame] | 60 | if (capacity - starting_size > 0) { |
| 61 | CHECK_MEMORY_CALL(mprotect, (end, capacity - starting_size, PROT_NONE), name); |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | // Everything is set so record in immutable structure and leave |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 65 | byte* begin = mem_map->Begin(); |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 66 | // TODO: Fix RosAllocSpace to support valgrind. There is currently some issues with |
| 67 | // AllocationSize caused by redzones. b/12944686 |
Mathieu Chartier | 36bf216 | 2014-03-20 15:40:37 -0700 | [diff] [blame] | 68 | if (false && Runtime::Current()->GetHeap()->RunningOnValgrind()) { |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 69 | return new ValgrindMallocSpace<RosAllocSpace, allocator::RosAlloc*>( |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 70 | name, mem_map, rosalloc, begin, end, begin + capacity, growth_limit, initial_size); |
| 71 | } else { |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 72 | return new RosAllocSpace(name, mem_map, rosalloc, begin, end, begin + capacity, growth_limit); |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 73 | } |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 76 | RosAllocSpace::~RosAllocSpace() { |
| 77 | delete rosalloc_; |
| 78 | } |
| 79 | |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 80 | RosAllocSpace* RosAllocSpace::Create(const std::string& name, size_t initial_size, |
Ian Rogers | a55cf41 | 2014-02-27 00:31:26 -0800 | [diff] [blame] | 81 | size_t growth_limit, size_t capacity, byte* requested_begin, |
| 82 | bool low_memory_mode) { |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 83 | uint64_t start_time = 0; |
| 84 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
| 85 | start_time = NanoTime(); |
| 86 | VLOG(startup) << "RosAllocSpace::Create entering " << name |
| 87 | << " initial_size=" << PrettySize(initial_size) |
| 88 | << " growth_limit=" << PrettySize(growth_limit) |
| 89 | << " capacity=" << PrettySize(capacity) |
| 90 | << " requested_begin=" << reinterpret_cast<void*>(requested_begin); |
| 91 | } |
| 92 | |
| 93 | // Memory we promise to rosalloc before it asks for morecore. |
| 94 | // Note: making this value large means that large allocations are unlikely to succeed as rosalloc |
| 95 | // will ask for this memory from sys_alloc which will fail as the footprint (this value plus the |
| 96 | // size of the large allocation) will be greater than the footprint limit. |
Hiroshi Yamauchi | 5ccd498 | 2014-03-11 12:19:04 -0700 | [diff] [blame] | 97 | size_t starting_size = Heap::kDefaultStartingSize; |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 98 | MemMap* mem_map = CreateMemMap(name, starting_size, &initial_size, &growth_limit, &capacity, |
| 99 | requested_begin); |
| 100 | if (mem_map == NULL) { |
| 101 | LOG(ERROR) << "Failed to create mem map for alloc space (" << name << ") of size " |
| 102 | << PrettySize(capacity); |
| 103 | return NULL; |
| 104 | } |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 105 | |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 106 | RosAllocSpace* space = CreateFromMemMap(mem_map, name, starting_size, initial_size, |
| 107 | growth_limit, capacity, low_memory_mode); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 108 | // We start out with only the initial size possibly containing objects. |
| 109 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
| 110 | LOG(INFO) << "RosAllocSpace::Create exiting (" << PrettyDuration(NanoTime() - start_time) |
| 111 | << " ) " << *space; |
| 112 | } |
| 113 | return space; |
| 114 | } |
| 115 | |
Hiroshi Yamauchi | 573f7d2 | 2013-12-17 11:54:23 -0800 | [diff] [blame] | 116 | allocator::RosAlloc* RosAllocSpace::CreateRosAlloc(void* begin, size_t morecore_start, size_t initial_size, |
Hiroshi Yamauchi | 26d69ff | 2014-02-27 11:27:10 -0800 | [diff] [blame] | 117 | size_t maximum_size, bool low_memory_mode) { |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 118 | // clear errno to allow PLOG on error |
| 119 | errno = 0; |
| 120 | // create rosalloc using our backing storage starting at begin and |
| 121 | // with a footprint of morecore_start. When morecore_start bytes of |
| 122 | // memory is exhaused morecore will be called. |
Hiroshi Yamauchi | 573f7d2 | 2013-12-17 11:54:23 -0800 | [diff] [blame] | 123 | allocator::RosAlloc* rosalloc = new art::gc::allocator::RosAlloc( |
Hiroshi Yamauchi | 26d69ff | 2014-02-27 11:27:10 -0800 | [diff] [blame] | 124 | begin, morecore_start, maximum_size, |
Hiroshi Yamauchi | 573f7d2 | 2013-12-17 11:54:23 -0800 | [diff] [blame] | 125 | low_memory_mode ? |
| 126 | art::gc::allocator::RosAlloc::kPageReleaseModeAll : |
| 127 | art::gc::allocator::RosAlloc::kPageReleaseModeSizeAndEnd); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 128 | if (rosalloc != NULL) { |
| 129 | rosalloc->SetFootprintLimit(initial_size); |
| 130 | } else { |
| 131 | PLOG(ERROR) << "RosAlloc::Create failed"; |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 132 | } |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 133 | return rosalloc; |
| 134 | } |
| 135 | |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 136 | mirror::Object* RosAllocSpace::AllocWithGrowth(Thread* self, size_t num_bytes, |
| 137 | size_t* bytes_allocated, size_t* usable_size) { |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 138 | mirror::Object* result; |
| 139 | { |
| 140 | MutexLock mu(self, lock_); |
| 141 | // Grow as much as possible within the space. |
| 142 | size_t max_allowed = Capacity(); |
| 143 | rosalloc_->SetFootprintLimit(max_allowed); |
| 144 | // Try the allocation. |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 145 | result = AllocCommon(self, num_bytes, bytes_allocated, usable_size); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 146 | // Shrink back down as small as possible. |
| 147 | size_t footprint = rosalloc_->Footprint(); |
| 148 | rosalloc_->SetFootprintLimit(footprint); |
| 149 | } |
| 150 | // Note RosAlloc zeroes memory internally. |
| 151 | // Return the new allocation or NULL. |
| 152 | CHECK(!kDebugSpaces || result == NULL || Contains(result)); |
| 153 | return result; |
| 154 | } |
| 155 | |
| 156 | MallocSpace* RosAllocSpace::CreateInstance(const std::string& name, MemMap* mem_map, void* allocator, |
| 157 | byte* begin, byte* end, byte* limit, size_t growth_limit) { |
| 158 | return new RosAllocSpace(name, mem_map, reinterpret_cast<allocator::RosAlloc*>(allocator), |
| 159 | begin, end, limit, growth_limit); |
| 160 | } |
| 161 | |
| 162 | size_t RosAllocSpace::Free(Thread* self, mirror::Object* ptr) { |
| 163 | if (kDebugSpaces) { |
| 164 | CHECK(ptr != NULL); |
| 165 | CHECK(Contains(ptr)) << "Free (" << ptr << ") not in bounds of heap " << *this; |
| 166 | } |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 167 | const size_t bytes_freed = AllocationSizeNonvirtual(ptr, nullptr); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 168 | if (kRecentFreeCount > 0) { |
| 169 | MutexLock mu(self, lock_); |
| 170 | RegisterRecentFree(ptr); |
| 171 | } |
| 172 | rosalloc_->Free(self, ptr); |
| 173 | return bytes_freed; |
| 174 | } |
| 175 | |
| 176 | size_t RosAllocSpace::FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) { |
| 177 | DCHECK(ptrs != NULL); |
| 178 | |
| 179 | // Don't need the lock to calculate the size of the freed pointers. |
| 180 | size_t bytes_freed = 0; |
| 181 | for (size_t i = 0; i < num_ptrs; i++) { |
| 182 | mirror::Object* ptr = ptrs[i]; |
| 183 | const size_t look_ahead = 8; |
| 184 | if (kPrefetchDuringRosAllocFreeList && i + look_ahead < num_ptrs) { |
| 185 | __builtin_prefetch(reinterpret_cast<char*>(ptrs[i + look_ahead])); |
| 186 | } |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 187 | bytes_freed += AllocationSizeNonvirtual(ptr, nullptr); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | if (kRecentFreeCount > 0) { |
| 191 | MutexLock mu(self, lock_); |
| 192 | for (size_t i = 0; i < num_ptrs; i++) { |
| 193 | RegisterRecentFree(ptrs[i]); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if (kDebugSpaces) { |
| 198 | size_t num_broken_ptrs = 0; |
| 199 | for (size_t i = 0; i < num_ptrs; i++) { |
| 200 | if (!Contains(ptrs[i])) { |
| 201 | num_broken_ptrs++; |
| 202 | LOG(ERROR) << "FreeList[" << i << "] (" << ptrs[i] << ") not in bounds of heap " << *this; |
| 203 | } else { |
| 204 | size_t size = rosalloc_->UsableSize(ptrs[i]); |
| 205 | memset(ptrs[i], 0xEF, size); |
| 206 | } |
| 207 | } |
| 208 | CHECK_EQ(num_broken_ptrs, 0u); |
| 209 | } |
| 210 | |
| 211 | rosalloc_->BulkFree(self, reinterpret_cast<void**>(ptrs), num_ptrs); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 212 | return bytes_freed; |
| 213 | } |
| 214 | |
| 215 | // Callback from rosalloc when it needs to increase the footprint |
| 216 | extern "C" void* art_heap_rosalloc_morecore(allocator::RosAlloc* rosalloc, intptr_t increment) { |
| 217 | Heap* heap = Runtime::Current()->GetHeap(); |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 218 | RosAllocSpace* rosalloc_space = heap->GetRosAllocSpace(); |
| 219 | DCHECK(rosalloc_space != nullptr); |
| 220 | DCHECK_EQ(rosalloc_space->GetRosAlloc(), rosalloc); |
| 221 | return rosalloc_space->MoreCore(increment); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 224 | size_t RosAllocSpace::Trim() { |
Hiroshi Yamauchi | 573f7d2 | 2013-12-17 11:54:23 -0800 | [diff] [blame] | 225 | { |
| 226 | MutexLock mu(Thread::Current(), lock_); |
| 227 | // Trim to release memory at the end of the space. |
| 228 | rosalloc_->Trim(); |
| 229 | } |
| 230 | // Attempt to release pages if it does not release all empty pages. |
| 231 | if (!rosalloc_->DoesReleaseAllPages()) { |
| 232 | VLOG(heap) << "RosAllocSpace::Trim() "; |
| 233 | size_t reclaimed = 0; |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 234 | InspectAllRosAlloc(DlmallocMadviseCallback, &reclaimed, false); |
Hiroshi Yamauchi | 573f7d2 | 2013-12-17 11:54:23 -0800 | [diff] [blame] | 235 | return reclaimed; |
| 236 | } |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | void RosAllocSpace::Walk(void(*callback)(void *start, void *end, size_t num_bytes, void* callback_arg), |
| 241 | void* arg) { |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 242 | InspectAllRosAlloc(callback, arg, true); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | size_t RosAllocSpace::GetFootprint() { |
| 246 | MutexLock mu(Thread::Current(), lock_); |
| 247 | return rosalloc_->Footprint(); |
| 248 | } |
| 249 | |
| 250 | size_t RosAllocSpace::GetFootprintLimit() { |
| 251 | MutexLock mu(Thread::Current(), lock_); |
| 252 | return rosalloc_->FootprintLimit(); |
| 253 | } |
| 254 | |
| 255 | void RosAllocSpace::SetFootprintLimit(size_t new_size) { |
| 256 | MutexLock mu(Thread::Current(), lock_); |
| 257 | VLOG(heap) << "RosAllocSpace::SetFootprintLimit " << PrettySize(new_size); |
| 258 | // Compare against the actual footprint, rather than the Size(), because the heap may not have |
| 259 | // grown all the way to the allowed size yet. |
| 260 | size_t current_space_size = rosalloc_->Footprint(); |
| 261 | if (new_size < current_space_size) { |
| 262 | // Don't let the space grow any more. |
| 263 | new_size = current_space_size; |
| 264 | } |
| 265 | rosalloc_->SetFootprintLimit(new_size); |
| 266 | } |
| 267 | |
| 268 | uint64_t RosAllocSpace::GetBytesAllocated() { |
Hiroshi Yamauchi | 4ce1f00 | 2013-11-18 14:49:09 -0800 | [diff] [blame] | 269 | size_t bytes_allocated = 0; |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 270 | InspectAllRosAlloc(art::gc::allocator::RosAlloc::BytesAllocatedCallback, &bytes_allocated, false); |
Hiroshi Yamauchi | 4ce1f00 | 2013-11-18 14:49:09 -0800 | [diff] [blame] | 271 | return bytes_allocated; |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | uint64_t RosAllocSpace::GetObjectsAllocated() { |
Hiroshi Yamauchi | 4ce1f00 | 2013-11-18 14:49:09 -0800 | [diff] [blame] | 275 | size_t objects_allocated = 0; |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 276 | InspectAllRosAlloc(art::gc::allocator::RosAlloc::ObjectsAllocatedCallback, &objects_allocated, false); |
Hiroshi Yamauchi | 4ce1f00 | 2013-11-18 14:49:09 -0800 | [diff] [blame] | 277 | return objects_allocated; |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 280 | void RosAllocSpace::InspectAllRosAllocWithSuspendAll( |
| 281 | void (*callback)(void *start, void *end, size_t num_bytes, void* callback_arg), |
| 282 | void* arg, bool do_null_callback_at_end) NO_THREAD_SAFETY_ANALYSIS { |
| 283 | // TODO: NO_THREAD_SAFETY_ANALYSIS. |
| 284 | Thread* self = Thread::Current(); |
| 285 | ThreadList* tl = Runtime::Current()->GetThreadList(); |
| 286 | tl->SuspendAll(); |
| 287 | { |
| 288 | MutexLock mu(self, *Locks::runtime_shutdown_lock_); |
| 289 | MutexLock mu2(self, *Locks::thread_list_lock_); |
| 290 | rosalloc_->InspectAll(callback, arg); |
| 291 | if (do_null_callback_at_end) { |
| 292 | callback(NULL, NULL, 0, arg); // Indicate end of a space. |
| 293 | } |
| 294 | } |
| 295 | tl->ResumeAll(); |
| 296 | } |
| 297 | |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 298 | void RosAllocSpace::InspectAllRosAlloc(void (*callback)(void *start, void *end, size_t num_bytes, void* callback_arg), |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 299 | void* arg, bool do_null_callback_at_end) NO_THREAD_SAFETY_ANALYSIS { |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 300 | // TODO: NO_THREAD_SAFETY_ANALYSIS. |
| 301 | Thread* self = Thread::Current(); |
| 302 | if (Locks::mutator_lock_->IsExclusiveHeld(self)) { |
| 303 | // The mutators are already suspended. For example, a call path |
| 304 | // from SignalCatcher::HandleSigQuit(). |
| 305 | rosalloc_->InspectAll(callback, arg); |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 306 | if (do_null_callback_at_end) { |
| 307 | callback(NULL, NULL, 0, arg); // Indicate end of a space. |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 308 | } |
Hiroshi Yamauchi | 1cd53db | 2014-03-28 15:26:48 -0700 | [diff] [blame] | 309 | } else if (Locks::mutator_lock_->IsSharedHeld(self)) { |
| 310 | // The mutators are not suspended yet and we have a shared access |
| 311 | // to the mutator lock. Temporarily release the shared access by |
| 312 | // transitioning to the suspend state, and suspend the mutators. |
| 313 | self->TransitionFromRunnableToSuspended(kSuspended); |
| 314 | InspectAllRosAllocWithSuspendAll(callback, arg, do_null_callback_at_end); |
| 315 | self->TransitionFromSuspendedToRunnable(); |
| 316 | Locks::mutator_lock_->AssertSharedHeld(self); |
| 317 | } else { |
| 318 | // The mutators are not suspended yet. Suspend the mutators. |
| 319 | InspectAllRosAllocWithSuspendAll(callback, arg, do_null_callback_at_end); |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | void RosAllocSpace::RevokeThreadLocalBuffers(Thread* thread) { |
| 324 | rosalloc_->RevokeThreadLocalRuns(thread); |
| 325 | } |
| 326 | |
| 327 | void RosAllocSpace::RevokeAllThreadLocalBuffers() { |
| 328 | rosalloc_->RevokeAllThreadLocalRuns(); |
| 329 | } |
| 330 | |
Hiroshi Yamauchi | c93c530 | 2014-03-20 16:15:37 -0700 | [diff] [blame] | 331 | void RosAllocSpace::AssertAllThreadLocalBuffersAreRevoked() { |
| 332 | if (kIsDebugBuild) { |
| 333 | rosalloc_->AssertAllThreadLocalRunsAreRevoked(); |
| 334 | } |
| 335 | } |
| 336 | |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 337 | void RosAllocSpace::Clear() { |
| 338 | madvise(GetMemMap()->Begin(), GetMemMap()->Size(), MADV_DONTNEED); |
| 339 | GetLiveBitmap()->Clear(); |
| 340 | GetMarkBitmap()->Clear(); |
| 341 | } |
| 342 | |
Mathieu Chartier | 15d3402 | 2014-02-26 17:16:38 -0800 | [diff] [blame] | 343 | void RosAllocSpace::Reset() { |
| 344 | // TODO: Delete and create new mspace here. |
| 345 | } |
| 346 | |
Hiroshi Yamauchi | cf58d4a | 2013-09-26 14:21:22 -0700 | [diff] [blame] | 347 | } // namespace space |
| 348 | } // namespace gc |
| 349 | } // namespace art |