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