Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 2 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 3 | #include "space.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 4 | |
| 5 | #include <sys/mman.h> |
| 6 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 7 | #include "UniquePtr.h" |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 8 | #include "file.h" |
| 9 | #include "image.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 10 | #include "logging.h" |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 11 | #include "os.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 12 | #include "utils.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 13 | |
| 14 | namespace art { |
| 15 | |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 16 | Space* Space::Create(const std::string& name, size_t initial_size, size_t maximum_size, size_t growth_size, byte* requested_base) { |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 17 | UniquePtr<Space> space(new Space(name)); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 18 | bool success = space->Init(initial_size, maximum_size, growth_size, requested_base); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 19 | if (!success) { |
| 20 | return NULL; |
| 21 | } else { |
| 22 | return space.release(); |
| 23 | } |
| 24 | } |
| 25 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 26 | Space* Space::CreateFromImage(const std::string& image_file_name) { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 27 | CHECK(image_file_name != NULL); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 28 | UniquePtr<Space> space(new Space(image_file_name)); |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 29 | bool success = space->InitFromImage(image_file_name); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 30 | if (!success) { |
| 31 | return NULL; |
| 32 | } else { |
| 33 | return space.release(); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | Space::~Space() {} |
| 38 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 39 | void* Space::CreateMallocSpace(void* base, |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 40 | size_t initial_size, |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 41 | size_t maximum_size) { |
| 42 | errno = 0; |
| 43 | bool is_locked = false; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 44 | size_t commit_size = initial_size / 2; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 45 | void* msp = create_contiguous_mspace_with_base(commit_size, maximum_size, |
| 46 | is_locked, base); |
| 47 | if (msp != NULL) { |
| 48 | // Do not permit the heap grow past the starting size without our |
| 49 | // intervention. |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 50 | mspace_set_max_allowed_footprint(msp, initial_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 51 | } else { |
| 52 | // There is no guarantee that errno has meaning when the call |
| 53 | // fails, but it often does. |
| 54 | PLOG(ERROR) << "create_contiguous_mspace_with_base failed"; |
| 55 | } |
| 56 | return msp; |
| 57 | } |
| 58 | |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 59 | bool Space::Init(size_t initial_size, size_t maximum_size, size_t growth_size, byte* requested_base) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 60 | VLOG(startup) << "Space::Init entering " << name_ |
| 61 | << " initial_size=" << initial_size |
| 62 | << " maximum_size=" << maximum_size |
| 63 | << " growth_size=" << growth_size |
| 64 | << " requested_base=" << reinterpret_cast<void*>(requested_base); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 65 | if (initial_size > growth_size) { |
| 66 | LOG(ERROR) << "Failed to create space with initial size > growth size (" |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 67 | << initial_size << ">" << growth_size << "): " << name_; |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 68 | return false; |
| 69 | } |
| 70 | if (growth_size > maximum_size) { |
| 71 | LOG(ERROR) << "Failed to create space with growth size > maximum size (" |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 72 | << growth_size << ">" << maximum_size << "): " << name_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 73 | return false; |
| 74 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 75 | size_t length = RoundUp(maximum_size, kPageSize); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 76 | int prot = PROT_READ | PROT_WRITE; |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame^] | 77 | UniquePtr<MemMap> mem_map(MemMap::MapAnonymous(name_.c_str(), requested_base, length, prot)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 78 | if (mem_map.get() == NULL) { |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 79 | LOG(WARNING) << "Failed to allocate " << length << " bytes for space: " << name_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 80 | return false; |
| 81 | } |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 82 | InitFromMemMap(mem_map.release()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 83 | maximum_size_ = maximum_size; |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 84 | size_t growth_length = RoundUp(growth_size, kPageSize); |
| 85 | growth_size_ = growth_size; |
| 86 | growth_limit_ = base_ + growth_length; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 87 | mspace_ = CreateMallocSpace(base_, initial_size, maximum_size); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 88 | if (mspace_ == NULL) { |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 89 | LOG(WARNING) << "Failed to create mspace for space: " << name_; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 90 | return false; |
| 91 | } |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 92 | VLOG(startup) << "Space::Init exiting"; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 93 | return true; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 96 | void Space::InitFromMemMap(MemMap* mem_map) { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 97 | mem_map_.reset(mem_map); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 98 | base_ = mem_map_->GetAddress(); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 99 | limit_ = base_ + mem_map->GetLength(); |
| 100 | } |
| 101 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 102 | bool Space::InitFromImage(const std::string& image_file_name) { |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 103 | Runtime* runtime = Runtime::Current(); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 104 | VLOG(startup) << "Space::InitFromImage entering" |
| 105 | << " image_file_name=" << image_file_name; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 106 | UniquePtr<File> file(OS::OpenFile(image_file_name.c_str(), false)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 107 | if (file.get() == NULL) { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 108 | LOG(WARNING) << "Failed to open " << image_file_name; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 109 | return false; |
| 110 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 111 | ImageHeader image_header; |
| 112 | bool success = file->ReadFully(&image_header, sizeof(image_header)); |
| 113 | if (!success || !image_header.IsValid()) { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 114 | LOG(WARNING) << "Invalid image header " << image_file_name; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 115 | return false; |
| 116 | } |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame^] | 117 | UniquePtr<MemMap> map(MemMap::MapFileAtAddress(image_header.GetImageBaseAddr(), |
| 118 | file->Length(), |
| 119 | // TODO: selectively PROT_EXEC stubs |
| 120 | PROT_READ | PROT_WRITE | PROT_EXEC, |
| 121 | MAP_PRIVATE | MAP_FIXED, |
| 122 | file->Fd(), |
| 123 | 0)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 124 | if (map.get() == NULL) { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 125 | LOG(WARNING) << "Failed to map " << image_file_name; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 126 | return false; |
| 127 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 128 | CHECK_EQ(image_header.GetImageBaseAddr(), map->GetAddress()); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 129 | image_header_ = reinterpret_cast<ImageHeader*>(map->GetAddress()); |
| 130 | DCHECK_EQ(0, memcmp(&image_header, image_header_, sizeof(ImageHeader))); |
| 131 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 132 | Object* jni_stub_array = image_header.GetImageRoot(ImageHeader::kJniStubArray); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 133 | runtime->SetJniDlsymLookupStub(down_cast<ByteArray*>(jni_stub_array)); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 134 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 135 | Object* ame_stub_array = image_header.GetImageRoot(ImageHeader::kAbstractMethodErrorStubArray); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 136 | runtime->SetAbstractMethodErrorStubArray(down_cast<ByteArray*>(ame_stub_array)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 137 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 138 | Object* resolution_stub_array = image_header.GetImageRoot(ImageHeader::kInstanceResolutionStubArray); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 139 | runtime->SetResolutionStubArray( |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 140 | down_cast<ByteArray*>(resolution_stub_array), Runtime::kInstanceMethod); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 141 | resolution_stub_array = image_header.GetImageRoot(ImageHeader::kStaticResolutionStubArray); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 142 | runtime->SetResolutionStubArray( |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 143 | down_cast<ByteArray*>(resolution_stub_array), Runtime::kStaticMethod); |
| 144 | resolution_stub_array = image_header.GetImageRoot(ImageHeader::kUnknownMethodResolutionStubArray); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 145 | runtime->SetResolutionStubArray( |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 146 | down_cast<ByteArray*>(resolution_stub_array), Runtime::kUnknownMethod); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 147 | |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 148 | Object* callee_save_method = image_header.GetImageRoot(ImageHeader::kCalleeSaveMethod); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 149 | runtime->SetCalleeSaveMethod(down_cast<Method*>(callee_save_method), Runtime::kSaveAll); |
| 150 | callee_save_method = image_header.GetImageRoot(ImageHeader::kRefsOnlySaveMethod); |
| 151 | runtime->SetCalleeSaveMethod(down_cast<Method*>(callee_save_method), Runtime::kRefsOnly); |
| 152 | callee_save_method = image_header.GetImageRoot(ImageHeader::kRefsAndArgsSaveMethod); |
| 153 | runtime->SetCalleeSaveMethod(down_cast<Method*>(callee_save_method), Runtime::kRefsAndArgs); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 154 | |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 155 | InitFromMemMap(map.release()); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 156 | growth_limit_ = limit_; |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 157 | VLOG(startup) << "Space::InitFromImage exiting"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 161 | Object* Space::AllocWithoutGrowth(size_t num_bytes) { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 162 | DCHECK(mspace_ != NULL); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 163 | return reinterpret_cast<Object*>(mspace_calloc(mspace_, 1, num_bytes)); |
| 164 | } |
| 165 | |
| 166 | Object* Space::AllocWithGrowth(size_t num_bytes) { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 167 | DCHECK(mspace_ != NULL); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 168 | // Grow as much as possible within the mspace. |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 169 | size_t max_allowed = growth_size_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 170 | mspace_set_max_allowed_footprint(mspace_, max_allowed); |
| 171 | // Try the allocation. |
| 172 | void* ptr = AllocWithoutGrowth(num_bytes); |
| 173 | // Shrink back down as small as possible. |
| 174 | size_t footprint = mspace_footprint(mspace_); |
| 175 | mspace_set_max_allowed_footprint(mspace_, footprint); |
| 176 | // Return the new allocation or NULL. |
| 177 | return reinterpret_cast<Object*>(ptr); |
| 178 | } |
| 179 | |
| 180 | size_t Space::Free(void* ptr) { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 181 | DCHECK(mspace_ != NULL); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 182 | DCHECK(ptr != NULL); |
| 183 | size_t num_bytes = mspace_usable_size(mspace_, ptr); |
| 184 | mspace_free(mspace_, ptr); |
| 185 | return num_bytes; |
| 186 | } |
| 187 | |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 188 | size_t Space::FreeList(size_t num_ptrs, void** ptrs) { |
| 189 | DCHECK(mspace_ != NULL); |
| 190 | DCHECK(ptrs != NULL); |
| 191 | void* merged = ptrs[0]; |
| 192 | size_t num_bytes = 0; |
| 193 | for (size_t i = 1; i < num_ptrs; i++) { |
| 194 | num_bytes += mspace_usable_size(mspace_, ptrs[i]); |
| 195 | if (mspace_merge_objects(mspace_, merged, ptrs[i]) == NULL) { |
| 196 | mspace_free(mspace_, merged); |
| 197 | merged = ptrs[i]; |
| 198 | } |
| 199 | } |
| 200 | CHECK(merged != NULL); |
| 201 | mspace_free(mspace_, merged); |
| 202 | return num_bytes; |
| 203 | } |
| 204 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 205 | size_t Space::AllocationSize(const Object* obj) { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 206 | DCHECK(mspace_ != NULL); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 207 | return mspace_usable_size(mspace_, obj) + kChunkOverhead; |
| 208 | } |
| 209 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 210 | void Space::DontNeed(void* start, void* end, void* num_bytes) { |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 211 | start = (void*)RoundUp((uintptr_t)start, kPageSize); |
| 212 | end = (void*)RoundDown((uintptr_t)end, kPageSize); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 213 | if (start >= end) { |
| 214 | return; |
| 215 | } |
| 216 | size_t length = reinterpret_cast<byte*>(end) - reinterpret_cast<byte*>(start); |
| 217 | int result = madvise(start, length, MADV_DONTNEED); |
| 218 | if (result == -1) { |
| 219 | PLOG(WARNING) << "madvise failed"; |
| 220 | } else { |
| 221 | *reinterpret_cast<size_t*>(num_bytes) += length; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void Space::Trim() { |
| 226 | CHECK(mspace_ != NULL); |
| 227 | mspace_trim(mspace_, 0); |
| 228 | size_t num_bytes_released = 0; |
| 229 | mspace_walk_free_pages(mspace_, DontNeed, &num_bytes_released); |
| 230 | } |
| 231 | |
Elliott Hughes | 6a5bd49 | 2011-10-28 14:33:57 -0700 | [diff] [blame] | 232 | void Space::Walk(void(*callback)(const void*, size_t, const void*, size_t, void*), void* arg) { |
| 233 | if (mspace_ != NULL) { |
| 234 | mspace_walk_heap(mspace_, callback, arg); |
| 235 | } |
| 236 | } |
| 237 | |
Shih-wei Liao | 7f1caab | 2011-10-06 12:11:04 -0700 | [diff] [blame] | 238 | size_t Space::GetMaxAllowedFootprint() { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 239 | DCHECK(mspace_ != NULL); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 240 | return mspace_max_allowed_footprint(mspace_); |
| 241 | } |
| 242 | |
Elliott Hughes | 6a5bd49 | 2011-10-28 14:33:57 -0700 | [diff] [blame] | 243 | void Space::SetMaxAllowedFootprint(size_t limit) { |
Shih-wei Liao | 7f1caab | 2011-10-06 12:11:04 -0700 | [diff] [blame] | 244 | DCHECK(mspace_ != NULL); |
| 245 | |
| 246 | // Compare against the actual footprint, rather than the |
| 247 | // max_allowed, because the heap may not have grown all the |
| 248 | // way to the allowed size yet. |
| 249 | // |
| 250 | size_t current_space_size = mspace_footprint(mspace_); |
| 251 | if (limit < current_space_size) { |
| 252 | // Don't let the space grow any more. |
| 253 | mspace_set_max_allowed_footprint(mspace_, current_space_size); |
| 254 | } else { |
| 255 | // Let the heap grow to the requested limit. |
| 256 | mspace_set_max_allowed_footprint(mspace_, limit); |
| 257 | } |
| 258 | } |
| 259 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 260 | void Space::Grow(size_t new_size) { |
Elliott Hughes | 53b6131 | 2011-08-12 18:28:20 -0700 | [diff] [blame] | 261 | UNIMPLEMENTED(FATAL); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | } // namespace art |