blob: bc4414daabf0953eca688ed618d30d5368c2d49a [file] [log] [blame]
Hiroshi Yamauchi7cb7bbc2013-11-18 17:27:37 -08001
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -07002/*
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
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070018#include "rosalloc_space-inl.h"
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070019
Ian Rogerscf7f1912014-10-22 22:06:39 -070020#define ATRACE_TAG ATRACE_TAG_DALVIK
21#include "cutils/trace.h"
22
Vladimir Marko80afd022015-05-19 18:08:00 +010023#include "base/time_utils.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070024#include "gc/accounting/card_table.h"
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070025#include "gc/accounting/space_bitmap-inl.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070026#include "gc/heap.h"
27#include "mirror/class-inl.h"
28#include "mirror/object-inl.h"
29#include "runtime.h"
30#include "thread.h"
31#include "thread_list.h"
32#include "utils.h"
Ian Rogers6fac4472014-02-25 17:01:10 -080033#include "valgrind_malloc_space-inl.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070034
35namespace art {
36namespace gc {
37namespace space {
38
Mathieu Chartier73d1e172014-04-11 17:53:48 -070039static constexpr bool kPrefetchDuringRosAllocFreeList = false;
Mathieu Chartier8585bad2014-04-11 17:53:48 -070040static constexpr size_t kPrefetchLookAhead = 8;
41// Use this only for verification, it is not safe to use since the class of the object may have
42// been freed.
43static constexpr bool kVerifyFreedBytes = false;
Ian Rogers6fac4472014-02-25 17:01:10 -080044
Mathieu Chartier31f44142014-04-08 14:40:03 -070045// TODO: Fix
46// template class ValgrindMallocSpace<RosAllocSpace, allocator::RosAlloc*>;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070047
Andreas Gamped7576322014-10-24 22:13:45 -070048RosAllocSpace::RosAllocSpace(MemMap* mem_map, size_t initial_size, const std::string& name,
Ian Rogers13735952014-10-08 12:43:28 -070049 art::gc::allocator::RosAlloc* rosalloc, uint8_t* begin, uint8_t* end,
50 uint8_t* limit, size_t growth_limit, bool can_move_objects,
Andreas Gamped7576322014-10-24 22:13:45 -070051 size_t starting_size, bool low_memory_mode)
Mathieu Chartier31f44142014-04-08 14:40:03 -070052 : MallocSpace(name, mem_map, begin, end, limit, growth_limit, true, can_move_objects,
53 starting_size, initial_size),
54 rosalloc_(rosalloc), low_memory_mode_(low_memory_mode) {
55 CHECK(rosalloc != nullptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070056}
57
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080058RosAllocSpace* RosAllocSpace::CreateFromMemMap(MemMap* mem_map, const std::string& name,
Ian Rogersa55cf412014-02-27 00:31:26 -080059 size_t starting_size, size_t initial_size,
60 size_t growth_limit, size_t capacity,
Mathieu Chartier31f44142014-04-08 14:40:03 -070061 bool low_memory_mode, bool can_move_objects) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080062 DCHECK(mem_map != nullptr);
Andreas Gamped7576322014-10-24 22:13:45 -070063
64 bool running_on_valgrind = Runtime::Current()->RunningOnValgrind();
65
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080066 allocator::RosAlloc* rosalloc = CreateRosAlloc(mem_map->Begin(), starting_size, initial_size,
Andreas Gamped7576322014-10-24 22:13:45 -070067 capacity, low_memory_mode, running_on_valgrind);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070068 if (rosalloc == nullptr) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080069 LOG(ERROR) << "Failed to initialize rosalloc for alloc space (" << name << ")";
Mathieu Chartier2cebb242015-04-21 16:50:40 -070070 return nullptr;
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080071 }
72
lzang1385de732014-02-21 14:15:01 +080073 // Protect memory beyond the starting size. MoreCore will add r/w permissions when necessory
Ian Rogers13735952014-10-08 12:43:28 -070074 uint8_t* end = mem_map->Begin() + starting_size;
lzang1385de732014-02-21 14:15:01 +080075 if (capacity - starting_size > 0) {
76 CHECK_MEMORY_CALL(mprotect, (end, capacity - starting_size, PROT_NONE), name);
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080077 }
78
79 // Everything is set so record in immutable structure and leave
Ian Rogers13735952014-10-08 12:43:28 -070080 uint8_t* begin = mem_map->Begin();
Mathieu Chartier661974a2014-01-09 11:23:53 -080081 // TODO: Fix RosAllocSpace to support valgrind. There is currently some issues with
82 // AllocationSize caused by redzones. b/12944686
Andreas Gamped7576322014-10-24 22:13:45 -070083 if (running_on_valgrind) {
84 return new ValgrindMallocSpace<RosAllocSpace, kDefaultValgrindRedZoneBytes, false, true>(
85 mem_map, initial_size, name, rosalloc, begin, end, begin + capacity, growth_limit,
86 can_move_objects, starting_size, low_memory_mode);
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080087 } else {
Andreas Gamped7576322014-10-24 22:13:45 -070088 return new RosAllocSpace(mem_map, initial_size, name, rosalloc, begin, end, begin + capacity,
89 growth_limit, can_move_objects, starting_size, low_memory_mode);
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080090 }
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080091}
92
Mathieu Chartier661974a2014-01-09 11:23:53 -080093RosAllocSpace::~RosAllocSpace() {
94 delete rosalloc_;
95}
96
Ian Rogers6fac4472014-02-25 17:01:10 -080097RosAllocSpace* RosAllocSpace::Create(const std::string& name, size_t initial_size,
Ian Rogers13735952014-10-08 12:43:28 -070098 size_t growth_limit, size_t capacity, uint8_t* requested_begin,
Mathieu Chartier31f44142014-04-08 14:40:03 -070099 bool low_memory_mode, bool can_move_objects) {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700100 uint64_t start_time = 0;
101 if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) {
102 start_time = NanoTime();
103 VLOG(startup) << "RosAllocSpace::Create entering " << name
104 << " initial_size=" << PrettySize(initial_size)
105 << " growth_limit=" << PrettySize(growth_limit)
106 << " capacity=" << PrettySize(capacity)
107 << " requested_begin=" << reinterpret_cast<void*>(requested_begin);
108 }
109
110 // Memory we promise to rosalloc before it asks for morecore.
111 // Note: making this value large means that large allocations are unlikely to succeed as rosalloc
112 // will ask for this memory from sys_alloc which will fail as the footprint (this value plus the
113 // size of the large allocation) will be greater than the footprint limit.
Hiroshi Yamauchi5ccd4982014-03-11 12:19:04 -0700114 size_t starting_size = Heap::kDefaultStartingSize;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700115 MemMap* mem_map = CreateMemMap(name, starting_size, &initial_size, &growth_limit, &capacity,
116 requested_begin);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700117 if (mem_map == nullptr) {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700118 LOG(ERROR) << "Failed to create mem map for alloc space (" << name << ") of size "
119 << PrettySize(capacity);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700120 return nullptr;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700121 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700122
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800123 RosAllocSpace* space = CreateFromMemMap(mem_map, name, starting_size, initial_size,
Mathieu Chartier31f44142014-04-08 14:40:03 -0700124 growth_limit, capacity, low_memory_mode,
125 can_move_objects);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700126 // We start out with only the initial size possibly containing objects.
127 if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) {
128 LOG(INFO) << "RosAllocSpace::Create exiting (" << PrettyDuration(NanoTime() - start_time)
129 << " ) " << *space;
130 }
131 return space;
132}
133
Mathieu Chartier31f44142014-04-08 14:40:03 -0700134allocator::RosAlloc* RosAllocSpace::CreateRosAlloc(void* begin, size_t morecore_start,
135 size_t initial_size,
Andreas Gamped7576322014-10-24 22:13:45 -0700136 size_t maximum_size, bool low_memory_mode,
137 bool running_on_valgrind) {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700138 // clear errno to allow PLOG on error
139 errno = 0;
140 // create rosalloc using our backing storage starting at begin and
141 // with a footprint of morecore_start. When morecore_start bytes of
142 // memory is exhaused morecore will be called.
Hiroshi Yamauchi573f7d22013-12-17 11:54:23 -0800143 allocator::RosAlloc* rosalloc = new art::gc::allocator::RosAlloc(
Hiroshi Yamauchi26d69ff2014-02-27 11:27:10 -0800144 begin, morecore_start, maximum_size,
Hiroshi Yamauchi573f7d22013-12-17 11:54:23 -0800145 low_memory_mode ?
146 art::gc::allocator::RosAlloc::kPageReleaseModeAll :
Andreas Gamped7576322014-10-24 22:13:45 -0700147 art::gc::allocator::RosAlloc::kPageReleaseModeSizeAndEnd,
148 running_on_valgrind);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700149 if (rosalloc != nullptr) {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700150 rosalloc->SetFootprintLimit(initial_size);
151 } else {
152 PLOG(ERROR) << "RosAlloc::Create failed";
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800153 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700154 return rosalloc;
155}
156
Ian Rogers6fac4472014-02-25 17:01:10 -0800157mirror::Object* RosAllocSpace::AllocWithGrowth(Thread* self, size_t num_bytes,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700158 size_t* bytes_allocated, size_t* usable_size,
159 size_t* bytes_tl_bulk_allocated) {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700160 mirror::Object* result;
161 {
162 MutexLock mu(self, lock_);
163 // Grow as much as possible within the space.
164 size_t max_allowed = Capacity();
165 rosalloc_->SetFootprintLimit(max_allowed);
166 // Try the allocation.
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700167 result = AllocCommon(self, num_bytes, bytes_allocated, usable_size,
168 bytes_tl_bulk_allocated);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700169 // Shrink back down as small as possible.
170 size_t footprint = rosalloc_->Footprint();
171 rosalloc_->SetFootprintLimit(footprint);
172 }
173 // Note RosAlloc zeroes memory internally.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700174 // Return the new allocation or null.
Mathieu Chartier0651d412014-04-29 14:37:57 -0700175 CHECK(!kDebugSpaces || result == nullptr || Contains(result));
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700176 return result;
177}
178
Andreas Gamped7576322014-10-24 22:13:45 -0700179MallocSpace* RosAllocSpace::CreateInstance(MemMap* mem_map, const std::string& name,
180 void* allocator, uint8_t* begin, uint8_t* end,
181 uint8_t* limit, size_t growth_limit,
Mathieu Chartier31f44142014-04-08 14:40:03 -0700182 bool can_move_objects) {
Andreas Gamped7576322014-10-24 22:13:45 -0700183 if (Runtime::Current()->RunningOnValgrind()) {
184 return new ValgrindMallocSpace<RosAllocSpace, kDefaultValgrindRedZoneBytes, false, true>(
185 mem_map, initial_size_, name, reinterpret_cast<allocator::RosAlloc*>(allocator), begin, end,
186 limit, growth_limit, can_move_objects, starting_size_, low_memory_mode_);
187 } else {
188 return new RosAllocSpace(mem_map, initial_size_, name,
189 reinterpret_cast<allocator::RosAlloc*>(allocator), begin, end, limit,
190 growth_limit, can_move_objects, starting_size_, low_memory_mode_);
191 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700192}
193
194size_t RosAllocSpace::Free(Thread* self, mirror::Object* ptr) {
195 if (kDebugSpaces) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700196 CHECK(ptr != nullptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700197 CHECK(Contains(ptr)) << "Free (" << ptr << ") not in bounds of heap " << *this;
198 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700199 if (kRecentFreeCount > 0) {
200 MutexLock mu(self, lock_);
201 RegisterRecentFree(ptr);
202 }
Mathieu Chartier8585bad2014-04-11 17:53:48 -0700203 return rosalloc_->Free(self, ptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700204}
205
206size_t RosAllocSpace::FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) {
Mathieu Chartier8585bad2014-04-11 17:53:48 -0700207 DCHECK(ptrs != nullptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700208
Mathieu Chartier8585bad2014-04-11 17:53:48 -0700209 size_t verify_bytes = 0;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700210 for (size_t i = 0; i < num_ptrs; i++) {
Mathieu Chartier8585bad2014-04-11 17:53:48 -0700211 if (kPrefetchDuringRosAllocFreeList && i + kPrefetchLookAhead < num_ptrs) {
212 __builtin_prefetch(reinterpret_cast<char*>(ptrs[i + kPrefetchLookAhead]));
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700213 }
Mathieu Chartier8585bad2014-04-11 17:53:48 -0700214 if (kVerifyFreedBytes) {
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700215 verify_bytes += AllocationSizeNonvirtual<true>(ptrs[i], nullptr);
Mathieu Chartier8585bad2014-04-11 17:53:48 -0700216 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700217 }
218
219 if (kRecentFreeCount > 0) {
220 MutexLock mu(self, lock_);
221 for (size_t i = 0; i < num_ptrs; i++) {
222 RegisterRecentFree(ptrs[i]);
223 }
224 }
225
226 if (kDebugSpaces) {
227 size_t num_broken_ptrs = 0;
228 for (size_t i = 0; i < num_ptrs; i++) {
229 if (!Contains(ptrs[i])) {
230 num_broken_ptrs++;
231 LOG(ERROR) << "FreeList[" << i << "] (" << ptrs[i] << ") not in bounds of heap " << *this;
232 } else {
233 size_t size = rosalloc_->UsableSize(ptrs[i]);
234 memset(ptrs[i], 0xEF, size);
235 }
236 }
237 CHECK_EQ(num_broken_ptrs, 0u);
238 }
239
Mathieu Chartier8585bad2014-04-11 17:53:48 -0700240 const size_t bytes_freed = rosalloc_->BulkFree(self, reinterpret_cast<void**>(ptrs), num_ptrs);
241 if (kVerifyFreedBytes) {
242 CHECK_EQ(verify_bytes, bytes_freed);
243 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700244 return bytes_freed;
245}
246
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700247size_t RosAllocSpace::Trim() {
Hiroshi Yamauchid9a88de2014-04-07 13:52:31 -0700248 VLOG(heap) << "RosAllocSpace::Trim() ";
Hiroshi Yamauchi573f7d22013-12-17 11:54:23 -0800249 {
250 MutexLock mu(Thread::Current(), lock_);
251 // Trim to release memory at the end of the space.
252 rosalloc_->Trim();
253 }
254 // Attempt to release pages if it does not release all empty pages.
255 if (!rosalloc_->DoesReleaseAllPages()) {
Hiroshi Yamauchid9a88de2014-04-07 13:52:31 -0700256 return rosalloc_->ReleasePages();
Hiroshi Yamauchi573f7d22013-12-17 11:54:23 -0800257 }
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700258 return 0;
259}
260
261void RosAllocSpace::Walk(void(*callback)(void *start, void *end, size_t num_bytes, void* callback_arg),
262 void* arg) {
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700263 InspectAllRosAlloc(callback, arg, true);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700264}
265
266size_t RosAllocSpace::GetFootprint() {
267 MutexLock mu(Thread::Current(), lock_);
268 return rosalloc_->Footprint();
269}
270
271size_t RosAllocSpace::GetFootprintLimit() {
272 MutexLock mu(Thread::Current(), lock_);
273 return rosalloc_->FootprintLimit();
274}
275
276void RosAllocSpace::SetFootprintLimit(size_t new_size) {
277 MutexLock mu(Thread::Current(), lock_);
278 VLOG(heap) << "RosAllocSpace::SetFootprintLimit " << PrettySize(new_size);
279 // Compare against the actual footprint, rather than the Size(), because the heap may not have
280 // grown all the way to the allowed size yet.
281 size_t current_space_size = rosalloc_->Footprint();
282 if (new_size < current_space_size) {
283 // Don't let the space grow any more.
284 new_size = current_space_size;
285 }
286 rosalloc_->SetFootprintLimit(new_size);
287}
288
289uint64_t RosAllocSpace::GetBytesAllocated() {
Hiroshi Yamauchi4ce1f002013-11-18 14:49:09 -0800290 size_t bytes_allocated = 0;
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700291 InspectAllRosAlloc(art::gc::allocator::RosAlloc::BytesAllocatedCallback, &bytes_allocated, false);
Hiroshi Yamauchi4ce1f002013-11-18 14:49:09 -0800292 return bytes_allocated;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700293}
294
295uint64_t RosAllocSpace::GetObjectsAllocated() {
Hiroshi Yamauchi4ce1f002013-11-18 14:49:09 -0800296 size_t objects_allocated = 0;
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700297 InspectAllRosAlloc(art::gc::allocator::RosAlloc::ObjectsAllocatedCallback, &objects_allocated, false);
Hiroshi Yamauchi4ce1f002013-11-18 14:49:09 -0800298 return objects_allocated;
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700299}
300
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700301void RosAllocSpace::InspectAllRosAllocWithSuspendAll(
302 void (*callback)(void *start, void *end, size_t num_bytes, void* callback_arg),
303 void* arg, bool do_null_callback_at_end) NO_THREAD_SAFETY_ANALYSIS {
304 // TODO: NO_THREAD_SAFETY_ANALYSIS.
305 Thread* self = Thread::Current();
306 ThreadList* tl = Runtime::Current()->GetThreadList();
Mathieu Chartierbf9fc582015-03-13 17:21:25 -0700307 tl->SuspendAll(__FUNCTION__);
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700308 {
309 MutexLock mu(self, *Locks::runtime_shutdown_lock_);
310 MutexLock mu2(self, *Locks::thread_list_lock_);
311 rosalloc_->InspectAll(callback, arg);
312 if (do_null_callback_at_end) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700313 callback(nullptr, nullptr, 0, arg); // Indicate end of a space.
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700314 }
315 }
316 tl->ResumeAll();
317}
318
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700319void RosAllocSpace::InspectAllRosAlloc(void (*callback)(void *start, void *end, size_t num_bytes, void* callback_arg),
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700320 void* arg, bool do_null_callback_at_end) NO_THREAD_SAFETY_ANALYSIS {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700321 // TODO: NO_THREAD_SAFETY_ANALYSIS.
322 Thread* self = Thread::Current();
323 if (Locks::mutator_lock_->IsExclusiveHeld(self)) {
324 // The mutators are already suspended. For example, a call path
325 // from SignalCatcher::HandleSigQuit().
326 rosalloc_->InspectAll(callback, arg);
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700327 if (do_null_callback_at_end) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700328 callback(nullptr, nullptr, 0, arg); // Indicate end of a space.
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700329 }
Hiroshi Yamauchi1cd53db2014-03-28 15:26:48 -0700330 } else if (Locks::mutator_lock_->IsSharedHeld(self)) {
331 // The mutators are not suspended yet and we have a shared access
332 // to the mutator lock. Temporarily release the shared access by
333 // transitioning to the suspend state, and suspend the mutators.
334 self->TransitionFromRunnableToSuspended(kSuspended);
335 InspectAllRosAllocWithSuspendAll(callback, arg, do_null_callback_at_end);
336 self->TransitionFromSuspendedToRunnable();
337 Locks::mutator_lock_->AssertSharedHeld(self);
338 } else {
339 // The mutators are not suspended yet. Suspend the mutators.
340 InspectAllRosAllocWithSuspendAll(callback, arg, do_null_callback_at_end);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700341 }
342}
343
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700344size_t RosAllocSpace::RevokeThreadLocalBuffers(Thread* thread) {
345 return rosalloc_->RevokeThreadLocalRuns(thread);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700346}
347
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700348size_t RosAllocSpace::RevokeAllThreadLocalBuffers() {
349 return rosalloc_->RevokeAllThreadLocalRuns();
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700350}
351
Ian Rogers68d8b422014-07-17 11:09:10 -0700352void RosAllocSpace::AssertThreadLocalBuffersAreRevoked(Thread* thread) {
353 if (kIsDebugBuild) {
354 rosalloc_->AssertThreadLocalRunsAreRevoked(thread);
355 }
356}
357
Hiroshi Yamauchic93c5302014-03-20 16:15:37 -0700358void RosAllocSpace::AssertAllThreadLocalBuffersAreRevoked() {
359 if (kIsDebugBuild) {
360 rosalloc_->AssertAllThreadLocalRunsAreRevoked();
361 }
362}
363
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800364void RosAllocSpace::Clear() {
Mathieu Chartier31f44142014-04-08 14:40:03 -0700365 size_t footprint_limit = GetFootprintLimit();
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800366 madvise(GetMemMap()->Begin(), GetMemMap()->Size(), MADV_DONTNEED);
Mathieu Chartier31f44142014-04-08 14:40:03 -0700367 live_bitmap_->Clear();
368 mark_bitmap_->Clear();
Ian Rogersbe2a1df2014-07-10 00:56:36 -0700369 SetEnd(begin_ + starting_size_);
Mathieu Chartier31f44142014-04-08 14:40:03 -0700370 delete rosalloc_;
Hiroshi Yamauchi94c41df2014-12-18 21:19:24 -0800371 rosalloc_ = CreateRosAlloc(mem_map_->Begin(), starting_size_, initial_size_,
372 NonGrowthLimitCapacity(), low_memory_mode_,
373 Runtime::Current()->RunningOnValgrind());
Mathieu Chartier31f44142014-04-08 14:40:03 -0700374 SetFootprintLimit(footprint_limit);
Mathieu Chartier15d34022014-02-26 17:16:38 -0800375}
376
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700377} // namespace space
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800378
379namespace allocator {
380
381// Callback from rosalloc when it needs to increase the footprint.
382void* ArtRosAllocMoreCore(allocator::RosAlloc* rosalloc, intptr_t increment) {
383 Heap* heap = Runtime::Current()->GetHeap();
384 art::gc::space::RosAllocSpace* rosalloc_space = heap->GetRosAllocSpace(rosalloc);
385 DCHECK(rosalloc_space != nullptr);
386 DCHECK_EQ(rosalloc_space->GetRosAlloc(), rosalloc);
387 return rosalloc_space->MoreCore(increment);
388}
389
390} // namespace allocator
391
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700392} // namespace gc
393} // namespace art