blob: 7b1a421f4ad631ea64b29fe8c7a2ed0ab0f2db2d [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070016
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -070017#include "dlmalloc_space-inl.h"
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070018
Ian Rogers1d54e732013-05-02 21:10:01 -070019#include "gc/accounting/card_table.h"
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070020#include "gc/accounting/space_bitmap-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070021#include "gc/heap.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070022#include "mirror/class-inl.h"
Mathieu Chartier0f72e412013-09-06 16:40:01 -070023#include "mirror/object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "runtime.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "thread.h"
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070026#include "thread_list.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070027#include "utils.h"
Ian Rogers6fac4472014-02-25 17:01:10 -080028#include "valgrind_malloc_space-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070029
Carl Shapiro69759ea2011-07-21 18:13:35 -070030namespace art {
Ian Rogers1d54e732013-05-02 21:10:01 -070031namespace gc {
32namespace space {
Ian Rogers30fab402012-01-23 15:43:46 -080033
Ian Rogers6fac4472014-02-25 17:01:10 -080034static constexpr bool kPrefetchDuringDlMallocFreeList = true;
35
Andreas Gamped7576322014-10-24 22:13:45 -070036DlMallocSpace::DlMallocSpace(MemMap* mem_map, size_t initial_size, const std::string& name,
37 void* mspace, uint8_t* begin, uint8_t* end, uint8_t* limit,
38 size_t growth_limit, bool can_move_objects, size_t starting_size)
Mathieu Chartier31f44142014-04-08 14:40:03 -070039 : MallocSpace(name, mem_map, begin, end, limit, growth_limit, true, can_move_objects,
40 starting_size, initial_size),
41 mspace_(mspace) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -070042 CHECK(mspace != nullptr);
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070043}
44
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080045DlMallocSpace* DlMallocSpace::CreateFromMemMap(MemMap* mem_map, const std::string& name,
Mathieu Chartier661974a2014-01-09 11:23:53 -080046 size_t starting_size, size_t initial_size,
Mathieu Chartier31f44142014-04-08 14:40:03 -070047 size_t growth_limit, size_t capacity,
48 bool can_move_objects) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080049 DCHECK(mem_map != nullptr);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -070050 void* mspace = CreateMspace(mem_map->Begin(), starting_size, initial_size);
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080051 if (mspace == nullptr) {
Ian Rogers30fab402012-01-23 15:43:46 -080052 LOG(ERROR) << "Failed to initialize mspace for alloc space (" << name << ")";
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080053 return nullptr;
Ian Rogers30fab402012-01-23 15:43:46 -080054 }
55
lzang1385de732014-02-21 14:15:01 +080056 // Protect memory beyond the starting size. morecore will add r/w permissions when necessory
Ian Rogers13735952014-10-08 12:43:28 -070057 uint8_t* end = mem_map->Begin() + starting_size;
lzang1385de732014-02-21 14:15:01 +080058 if (capacity - starting_size > 0) {
59 CHECK_MEMORY_CALL(mprotect, (end, capacity - starting_size, PROT_NONE), name);
Ian Rogers30fab402012-01-23 15:43:46 -080060 }
61
62 // Everything is set so record in immutable structure and leave
Ian Rogers13735952014-10-08 12:43:28 -070063 uint8_t* begin = mem_map->Begin();
Mathieu Chartierda44d772014-04-01 15:01:46 -070064 if (Runtime::Current()->RunningOnValgrind()) {
Andreas Gamped7576322014-10-24 22:13:45 -070065 return new ValgrindMallocSpace<DlMallocSpace, kDefaultValgrindRedZoneBytes, true, false>(
66 mem_map, initial_size, name, mspace, begin, end, begin + capacity, growth_limit,
Mathieu Chartier31f44142014-04-08 14:40:03 -070067 can_move_objects, starting_size);
Ian Rogers1d54e732013-05-02 21:10:01 -070068 } else {
Andreas Gamped7576322014-10-24 22:13:45 -070069 return new DlMallocSpace(mem_map, initial_size, name, mspace, begin, end, begin + capacity,
70 growth_limit, can_move_objects, starting_size);
Ian Rogers1d54e732013-05-02 21:10:01 -070071 }
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080072}
73
Mathieu Chartier31f44142014-04-08 14:40:03 -070074DlMallocSpace* DlMallocSpace::Create(const std::string& name, size_t initial_size,
Ian Rogers13735952014-10-08 12:43:28 -070075 size_t growth_limit, size_t capacity, uint8_t* requested_begin,
Mathieu Chartier31f44142014-04-08 14:40:03 -070076 bool can_move_objects) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080077 uint64_t start_time = 0;
78 if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) {
79 start_time = NanoTime();
80 LOG(INFO) << "DlMallocSpace::Create entering " << name
81 << " initial_size=" << PrettySize(initial_size)
82 << " growth_limit=" << PrettySize(growth_limit)
83 << " capacity=" << PrettySize(capacity)
84 << " requested_begin=" << reinterpret_cast<void*>(requested_begin);
85 }
86
87 // Memory we promise to dlmalloc before it asks for morecore.
88 // Note: making this value large means that large allocations are unlikely to succeed as dlmalloc
89 // will ask for this memory from sys_alloc which will fail as the footprint (this value plus the
90 // size of the large allocation) will be greater than the footprint limit.
91 size_t starting_size = kPageSize;
92 MemMap* mem_map = CreateMemMap(name, starting_size, &initial_size, &growth_limit, &capacity,
93 requested_begin);
94 if (mem_map == nullptr) {
95 LOG(ERROR) << "Failed to create mem map for alloc space (" << name << ") of size "
96 << PrettySize(capacity);
97 return nullptr;
98 }
99 DlMallocSpace* space = CreateFromMemMap(mem_map, name, starting_size, initial_size,
Mathieu Chartier31f44142014-04-08 14:40:03 -0700100 growth_limit, capacity, can_move_objects);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700101 // We start out with only the initial size possibly containing objects.
Ian Rogers30fab402012-01-23 15:43:46 -0800102 if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) {
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700103 LOG(INFO) << "DlMallocSpace::Create exiting (" << PrettyDuration(NanoTime() - start_time)
Ian Rogers3bb17a62012-01-27 23:56:44 -0800104 << " ) " << *space;
Ian Rogers30fab402012-01-23 15:43:46 -0800105 }
106 return space;
Carl Shapiro69759ea2011-07-21 18:13:35 -0700107}
108
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700109void* DlMallocSpace::CreateMspace(void* begin, size_t morecore_start, size_t initial_size) {
Ian Rogers30fab402012-01-23 15:43:46 -0800110 // clear errno to allow PLOG on error
Carl Shapiro69759ea2011-07-21 18:13:35 -0700111 errno = 0;
Ian Rogers3bb17a62012-01-27 23:56:44 -0800112 // create mspace using our backing storage starting at begin and with a footprint of
113 // morecore_start. Don't use an internal dlmalloc lock (as we already hold heap lock). When
114 // morecore_start bytes of memory is exhaused morecore will be called.
115 void* msp = create_mspace_with_base(begin, morecore_start, false /*locked*/);
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800116 if (msp != nullptr) {
Ian Rogers30fab402012-01-23 15:43:46 -0800117 // Do not allow morecore requests to succeed beyond the initial size of the heap
Ian Rogers3bb17a62012-01-27 23:56:44 -0800118 mspace_set_footprint_limit(msp, initial_size);
Carl Shapiro69759ea2011-07-21 18:13:35 -0700119 } else {
Ian Rogers30fab402012-01-23 15:43:46 -0800120 PLOG(ERROR) << "create_mspace_with_base failed";
Carl Shapiro69759ea2011-07-21 18:13:35 -0700121 }
122 return msp;
123}
124
Ian Rogers6fac4472014-02-25 17:01:10 -0800125mirror::Object* DlMallocSpace::AllocWithGrowth(Thread* self, size_t num_bytes,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700126 size_t* bytes_allocated, size_t* usable_size,
127 size_t* bytes_tl_bulk_allocated) {
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700128 mirror::Object* result;
129 {
130 MutexLock mu(self, lock_);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700131 // Grow as much as possible within the space.
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700132 size_t max_allowed = Capacity();
133 mspace_set_footprint_limit(mspace_, max_allowed);
134 // Try the allocation.
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700135 result = AllocWithoutGrowthLocked(self, num_bytes, bytes_allocated, usable_size,
136 bytes_tl_bulk_allocated);
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700137 // Shrink back down as small as possible.
138 size_t footprint = mspace_footprint(mspace_);
139 mspace_set_footprint_limit(mspace_, footprint);
jeffhaoc1160702011-10-27 15:48:45 -0700140 }
Mathieu Chartier661974a2014-01-09 11:23:53 -0800141 if (result != nullptr) {
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700142 // Zero freshly allocated memory, done while not holding the space's lock.
143 memset(result, 0, num_bytes);
Mathieu Chartier661974a2014-01-09 11:23:53 -0800144 // Check that the result is contained in the space.
145 CHECK(!kDebugSpaces || Contains(result));
Hiroshi Yamauchi50b29282013-07-30 13:58:37 -0700146 }
Ian Rogers30fab402012-01-23 15:43:46 -0800147 return result;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700148}
149
Andreas Gamped7576322014-10-24 22:13:45 -0700150MallocSpace* DlMallocSpace::CreateInstance(MemMap* mem_map, const std::string& name,
Ian Rogers13735952014-10-08 12:43:28 -0700151 void* allocator, uint8_t* begin, uint8_t* end,
152 uint8_t* limit, size_t growth_limit,
Mathieu Chartier31f44142014-04-08 14:40:03 -0700153 bool can_move_objects) {
Andreas Gamped7576322014-10-24 22:13:45 -0700154 if (Runtime::Current()->RunningOnValgrind()) {
155 return new ValgrindMallocSpace<DlMallocSpace, kDefaultValgrindRedZoneBytes, true, false>(
156 mem_map, initial_size_, name, allocator, begin, end, limit, growth_limit,
157 can_move_objects, starting_size_);
158 } else {
159 return new DlMallocSpace(mem_map, initial_size_, name, allocator, begin, end, limit,
160 growth_limit, can_move_objects, starting_size_);
161 }
Mathieu Chartier0f72e412013-09-06 16:40:01 -0700162}
163
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800164size_t DlMallocSpace::Free(Thread* self, mirror::Object* ptr) {
Ian Rogers50b35e22012-10-04 10:09:15 -0700165 MutexLock mu(self, lock_);
Mathieu Chartier8e9a1492012-10-04 12:25:40 -0700166 if (kDebugSpaces) {
Mathieu Chartier661974a2014-01-09 11:23:53 -0800167 CHECK(ptr != nullptr);
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700168 CHECK(Contains(ptr)) << "Free (" << ptr << ") not in bounds of heap " << *this;
169 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800170 const size_t bytes_freed = AllocationSizeNonvirtual(ptr, nullptr);
Mathieu Chartier0f72e412013-09-06 16:40:01 -0700171 if (kRecentFreeCount > 0) {
172 RegisterRecentFree(ptr);
173 }
Ian Rogers30fab402012-01-23 15:43:46 -0800174 mspace_free(mspace_, ptr);
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700175 return bytes_freed;
Ian Rogers30fab402012-01-23 15:43:46 -0800176}
177
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178size_t DlMallocSpace::FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700179 DCHECK(ptrs != nullptr);
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800180
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700181 // Don't need the lock to calculate the size of the freed pointers.
182 size_t bytes_freed = 0;
183 for (size_t i = 0; i < num_ptrs; i++) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 mirror::Object* ptr = ptrs[i];
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800185 const size_t look_ahead = 8;
186 if (kPrefetchDuringDlMallocFreeList && i + look_ahead < num_ptrs) {
187 // The head of chunk for the allocation is sizeof(size_t) behind the allocation.
188 __builtin_prefetch(reinterpret_cast<char*>(ptrs[i + look_ahead]) - sizeof(size_t));
189 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800190 bytes_freed += AllocationSizeNonvirtual(ptr, nullptr);
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700191 }
192
Mathieu Chartier0f72e412013-09-06 16:40:01 -0700193 if (kRecentFreeCount > 0) {
194 MutexLock mu(self, lock_);
195 for (size_t i = 0; i < num_ptrs; i++) {
196 RegisterRecentFree(ptrs[i]);
197 }
198 }
199
Mathieu Chartier8e9a1492012-10-04 12:25:40 -0700200 if (kDebugSpaces) {
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700201 size_t num_broken_ptrs = 0;
202 for (size_t i = 0; i < num_ptrs; i++) {
203 if (!Contains(ptrs[i])) {
204 num_broken_ptrs++;
205 LOG(ERROR) << "FreeList[" << i << "] (" << ptrs[i] << ") not in bounds of heap " << *this;
206 } else {
207 size_t size = mspace_usable_size(ptrs[i]);
208 memset(ptrs[i], 0xEF, size);
209 }
Ian Rogers30fab402012-01-23 15:43:46 -0800210 }
Mathieu Chartier2fde5332012-09-14 14:51:54 -0700211 CHECK_EQ(num_broken_ptrs, 0u);
Ian Rogers30fab402012-01-23 15:43:46 -0800212 }
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800213
214 {
215 MutexLock mu(self, lock_);
Mathieu Chartierd22d5482012-11-06 17:14:12 -0800216 mspace_bulk_free(mspace_, reinterpret_cast<void**>(ptrs), num_ptrs);
217 return bytes_freed;
218 }
Ian Rogers30fab402012-01-23 15:43:46 -0800219}
220
Ian Rogers48931882013-01-22 14:35:16 -0800221size_t DlMallocSpace::Trim() {
Ian Rogers50b35e22012-10-04 10:09:15 -0700222 MutexLock mu(Thread::Current(), lock_);
Elliott Hughes9eebd3b2012-06-08 13:56:31 -0700223 // Trim to release memory at the end of the space.
224 mspace_trim(mspace_, 0);
225 // Visit space looking for page-sized holes to advise the kernel we don't need.
Ian Rogers48931882013-01-22 14:35:16 -0800226 size_t reclaimed = 0;
Ian Rogers1d54e732013-05-02 21:10:01 -0700227 mspace_inspect_all(mspace_, DlmallocMadviseCallback, &reclaimed);
Ian Rogers48931882013-01-22 14:35:16 -0800228 return reclaimed;
Elliott Hughes9eebd3b2012-06-08 13:56:31 -0700229}
Ian Rogers30fab402012-01-23 15:43:46 -0800230
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700231void DlMallocSpace::Walk(void(*callback)(void *start, void *end, size_t num_bytes, void* callback_arg),
Ian Rogers30fab402012-01-23 15:43:46 -0800232 void* arg) {
Ian Rogers50b35e22012-10-04 10:09:15 -0700233 MutexLock mu(Thread::Current(), lock_);
Ian Rogers30fab402012-01-23 15:43:46 -0800234 mspace_inspect_all(mspace_, callback, arg);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700235 callback(nullptr, nullptr, 0, arg); // Indicate end of a space.
Ian Rogers30fab402012-01-23 15:43:46 -0800236}
237
Hiroshi Yamauchi09b07a92013-07-15 13:17:06 -0700238size_t DlMallocSpace::GetFootprint() {
239 MutexLock mu(Thread::Current(), lock_);
240 return mspace_footprint(mspace_);
241}
242
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700243size_t DlMallocSpace::GetFootprintLimit() {
Ian Rogers50b35e22012-10-04 10:09:15 -0700244 MutexLock mu(Thread::Current(), lock_);
Ian Rogers30fab402012-01-23 15:43:46 -0800245 return mspace_footprint_limit(mspace_);
246}
247
Mathieu Chartier1c23e1e2012-10-12 14:14:11 -0700248void DlMallocSpace::SetFootprintLimit(size_t new_size) {
Ian Rogers50b35e22012-10-04 10:09:15 -0700249 MutexLock mu(Thread::Current(), lock_);
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700250 VLOG(heap) << "DlMallocSpace::SetFootprintLimit " << PrettySize(new_size);
Ian Rogers30fab402012-01-23 15:43:46 -0800251 // Compare against the actual footprint, rather than the Size(), because the heap may not have
252 // grown all the way to the allowed size yet.
Ian Rogers30fab402012-01-23 15:43:46 -0800253 size_t current_space_size = mspace_footprint(mspace_);
254 if (new_size < current_space_size) {
255 // Don't let the space grow any more.
256 new_size = current_space_size;
257 }
258 mspace_set_footprint_limit(mspace_, new_size);
259}
260
Hiroshi Yamauchibe031ff2013-10-08 16:42:37 -0700261uint64_t DlMallocSpace::GetBytesAllocated() {
Hiroshi Yamauchi4ce1f002013-11-18 14:49:09 -0800262 MutexLock mu(Thread::Current(), lock_);
263 size_t bytes_allocated = 0;
264 mspace_inspect_all(mspace_, DlmallocBytesAllocatedCallback, &bytes_allocated);
265 return bytes_allocated;
Hiroshi Yamauchibe031ff2013-10-08 16:42:37 -0700266}
267
268uint64_t DlMallocSpace::GetObjectsAllocated() {
Hiroshi Yamauchi4ce1f002013-11-18 14:49:09 -0800269 MutexLock mu(Thread::Current(), lock_);
270 size_t objects_allocated = 0;
271 mspace_inspect_all(mspace_, DlmallocObjectsAllocatedCallback, &objects_allocated);
272 return objects_allocated;
Hiroshi Yamauchibe031ff2013-10-08 16:42:37 -0700273}
274
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800275void DlMallocSpace::Clear() {
Mathieu Chartier31f44142014-04-08 14:40:03 -0700276 size_t footprint_limit = GetFootprintLimit();
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800277 madvise(GetMemMap()->Begin(), GetMemMap()->Size(), MADV_DONTNEED);
Mathieu Chartier31f44142014-04-08 14:40:03 -0700278 live_bitmap_->Clear();
279 mark_bitmap_->Clear();
Ian Rogersbe2a1df2014-07-10 00:56:36 -0700280 SetEnd(Begin() + starting_size_);
Mathieu Chartier31f44142014-04-08 14:40:03 -0700281 mspace_ = CreateMspace(mem_map_->Begin(), starting_size_, initial_size_);
282 SetFootprintLimit(footprint_limit);
Mathieu Chartier15d34022014-02-26 17:16:38 -0800283}
284
Hiroshi Yamauchicf58d4a2013-09-26 14:21:22 -0700285#ifndef NDEBUG
286void DlMallocSpace::CheckMoreCoreForPrecondition() {
287 lock_.AssertHeld(Thread::Current());
288}
289#endif
290
Hiroshi Yamauchi654dd482014-07-09 12:54:32 -0700291static void MSpaceChunkCallback(void* start, void* end, size_t used_bytes, void* arg) {
292 size_t chunk_size = reinterpret_cast<uint8_t*>(end) - reinterpret_cast<uint8_t*>(start);
293 if (used_bytes < chunk_size) {
294 size_t chunk_free_bytes = chunk_size - used_bytes;
295 size_t& max_contiguous_allocation = *reinterpret_cast<size_t*>(arg);
296 max_contiguous_allocation = std::max(max_contiguous_allocation, chunk_free_bytes);
297 }
298}
299
300void DlMallocSpace::LogFragmentationAllocFailure(std::ostream& os, size_t failed_alloc_bytes) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700301 UNUSED(failed_alloc_bytes);
Hiroshi Yamauchi654dd482014-07-09 12:54:32 -0700302 Thread* self = Thread::Current();
303 size_t max_contiguous_allocation = 0;
304 // To allow the Walk/InspectAll() to exclusively-lock the mutator
305 // lock, temporarily release the shared access to the mutator
306 // lock here by transitioning to the suspended state.
307 Locks::mutator_lock_->AssertSharedHeld(self);
308 self->TransitionFromRunnableToSuspended(kSuspended);
309 Walk(MSpaceChunkCallback, &max_contiguous_allocation);
310 self->TransitionFromSuspendedToRunnable();
311 Locks::mutator_lock_->AssertSharedHeld(self);
312 os << "; failed due to fragmentation (largest possible contiguous allocation "
313 << max_contiguous_allocation << " bytes)";
314}
315
Ian Rogers1d54e732013-05-02 21:10:01 -0700316} // namespace space
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800317
318namespace allocator {
319
320// Implement the dlmalloc morecore callback.
321void* ArtDlMallocMoreCore(void* mspace, intptr_t increment) {
322 Heap* heap = Runtime::Current()->GetHeap();
323 ::art::gc::space::DlMallocSpace* dlmalloc_space = heap->GetDlMallocSpace();
324 // Support for multiple DlMalloc provided by a slow path.
325 if (UNLIKELY(dlmalloc_space == nullptr || dlmalloc_space->GetMspace() != mspace)) {
326 dlmalloc_space = nullptr;
327 for (space::ContinuousSpace* space : heap->GetContinuousSpaces()) {
328 if (space->IsDlMallocSpace()) {
329 ::art::gc::space::DlMallocSpace* cur_dlmalloc_space = space->AsDlMallocSpace();
330 if (cur_dlmalloc_space->GetMspace() == mspace) {
331 dlmalloc_space = cur_dlmalloc_space;
332 break;
333 }
334 }
335 }
336 CHECK(dlmalloc_space != nullptr) << "Couldn't find DlmMallocSpace with mspace=" << mspace;
337 }
338 return dlmalloc_space->MoreCore(increment);
339}
340
341} // namespace allocator
342
Ian Rogers1d54e732013-05-02 21:10:01 -0700343} // namespace gc
Carl Shapiro69759ea2011-07-21 18:13:35 -0700344} // namespace art