Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "space.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 18 | |
| 19 | #include <sys/mman.h> |
| 20 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 21 | #include "UniquePtr.h" |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 22 | #include "dlmalloc.h" |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 23 | #include "file.h" |
| 24 | #include "image.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 25 | #include "logging.h" |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 26 | #include "os.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 27 | #include "utils.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 31 | #ifndef NDEBUG |
| 32 | #define DEBUG_SPACES 1 |
| 33 | #endif |
| 34 | |
| 35 | #define CHECK_MEMORY_CALL(call, args, what) \ |
| 36 | do { \ |
| 37 | int rc = call args; \ |
| 38 | if (UNLIKELY(rc != 0)) { \ |
| 39 | errno = rc; \ |
| 40 | PLOG(FATAL) << # call << " failed for " << what; \ |
| 41 | } \ |
| 42 | } while (false) |
| 43 | |
| 44 | AllocSpace* Space::CreateAllocSpace(const std::string& name, size_t initial_size, |
| 45 | size_t growth_limit, size_t capacity, |
| 46 | byte* requested_begin) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 47 | // Memory we promise to dlmalloc before it asks for morecore. |
| 48 | // Note: making this value large means that large allocations are unlikely to succeed as dlmalloc |
| 49 | // will ask for this memory from sys_alloc which will fail as the footprint (this value plus the |
| 50 | // size of the large allocation) will be greater than the footprint limit. |
| 51 | size_t starting_size = kPageSize; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 52 | uint64_t start_time = 0; |
| 53 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
| 54 | start_time = NanoTime(); |
| 55 | VLOG(startup) << "Space::CreateAllocSpace entering " << name |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 56 | << " initial_size=" << PrettySize(initial_size) |
| 57 | << " growth_limit=" << PrettySize(growth_limit) |
| 58 | << " capacity=" << PrettySize(capacity) |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 59 | << " requested_begin=" << reinterpret_cast<void*>(requested_begin); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 60 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 61 | |
| 62 | // Sanity check arguments |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 63 | if (starting_size > initial_size) { |
| 64 | initial_size = starting_size; |
| 65 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 66 | if (initial_size > growth_limit) { |
| 67 | LOG(ERROR) << "Failed to create alloc space (" << name << ") where the initial size (" |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 68 | << PrettySize(initial_size) << ") is larger than its capacity (" |
| 69 | << PrettySize(growth_limit) << ")"; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 70 | return NULL; |
| 71 | } |
| 72 | if (growth_limit > capacity) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 73 | LOG(ERROR) << "Failed to create alloc space (" << name << ") where the growth limit capacity (" |
| 74 | << PrettySize(growth_limit) << ") is larger than the capacity (" |
| 75 | << PrettySize(capacity) << ")"; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | // Page align growth limit and capacity which will be used to manage mmapped storage |
| 80 | growth_limit = RoundUp(growth_limit, kPageSize); |
| 81 | capacity = RoundUp(capacity, kPageSize); |
| 82 | |
| 83 | UniquePtr<MemMap> mem_map(MemMap::MapAnonymous(name.c_str(), requested_begin, |
| 84 | capacity, PROT_READ | PROT_WRITE)); |
| 85 | if (mem_map.get() == NULL) { |
| 86 | LOG(ERROR) << "Failed to allocate pages for alloc space (" << name << ") of size " |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 87 | << PrettySize(capacity); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 88 | return NULL; |
| 89 | } |
| 90 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 91 | void* mspace = AllocSpace::CreateMallocSpace(mem_map->Begin(), starting_size, initial_size); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 92 | if (mspace == NULL) { |
| 93 | LOG(ERROR) << "Failed to initialize mspace for alloc space (" << name << ")"; |
| 94 | return NULL; |
| 95 | } |
| 96 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 97 | // Protect memory beyond the initial size. |
| 98 | byte* end = mem_map->Begin() + starting_size; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 99 | if (capacity - initial_size > 0) { |
| 100 | CHECK_MEMORY_CALL(mprotect, (end, capacity - initial_size, PROT_NONE), name); |
| 101 | } |
| 102 | |
| 103 | // Everything is set so record in immutable structure and leave |
| 104 | AllocSpace* space = new AllocSpace(name, mem_map.release(), mspace, end, growth_limit); |
| 105 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 106 | LOG(INFO) << "Space::CreateAllocSpace exiting (" << PrettyDuration(NanoTime() - start_time) |
| 107 | << " ) " << *space; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 108 | } |
| 109 | return space; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 112 | void* AllocSpace::CreateMallocSpace(void* begin, size_t morecore_start, size_t initial_size) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 113 | // clear errno to allow PLOG on error |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 114 | errno = 0; |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 115 | // create mspace using our backing storage starting at begin and with a footprint of |
| 116 | // morecore_start. Don't use an internal dlmalloc lock (as we already hold heap lock). When |
| 117 | // morecore_start bytes of memory is exhaused morecore will be called. |
| 118 | void* msp = create_mspace_with_base(begin, morecore_start, false /*locked*/); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 119 | if (msp != NULL) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 120 | // Do not allow morecore requests to succeed beyond the initial size of the heap |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 121 | mspace_set_footprint_limit(msp, initial_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 122 | } else { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 123 | PLOG(ERROR) << "create_mspace_with_base failed"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 124 | } |
| 125 | return msp; |
| 126 | } |
| 127 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 128 | Object* AllocSpace::AllocWithoutGrowth(size_t num_bytes) { |
| 129 | Object* result = reinterpret_cast<Object*>(mspace_calloc(mspace_, 1, num_bytes)); |
| 130 | #if DEBUG_SPACES |
| 131 | if (result != NULL) { |
| 132 | CHECK(Contains(result)) << "Allocation (" << reinterpret_cast<void*>(result) |
| 133 | << ") not in bounds of heap " << *this; |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 134 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 135 | #endif |
| 136 | return result; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 139 | Object* AllocSpace::AllocWithGrowth(size_t num_bytes) { |
| 140 | // Grow as much as possible within the mspace. |
| 141 | size_t max_allowed = Capacity(); |
| 142 | mspace_set_footprint_limit(mspace_, max_allowed); |
| 143 | // Try the allocation. |
| 144 | void* ptr = AllocWithoutGrowth(num_bytes); |
| 145 | // Shrink back down as small as possible. |
| 146 | size_t footprint = mspace_footprint(mspace_); |
| 147 | mspace_set_footprint_limit(mspace_, footprint); |
| 148 | // Return the new allocation or NULL. |
| 149 | Object* result = reinterpret_cast<Object*>(ptr); |
| 150 | CHECK(result == NULL || Contains(result)); |
| 151 | return result; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 154 | void AllocSpace::Free(Object* ptr) { |
| 155 | #if DEBUG_SPACES |
| 156 | CHECK(ptr != NULL); |
| 157 | CHECK(Contains(ptr)) << "Free (" << ptr << ") not in bounds of heap " << *this; |
| 158 | #endif |
| 159 | mspace_free(mspace_, ptr); |
| 160 | } |
| 161 | |
| 162 | void AllocSpace::FreeList(size_t num_ptrs, Object** ptrs) { |
| 163 | #if DEBUG_SPACES |
| 164 | CHECK(ptrs != NULL); |
| 165 | size_t num_broken_ptrs = 0; |
| 166 | for (size_t i = 0; i < num_ptrs; i++) { |
| 167 | if(!Contains(ptrs[i])) { |
| 168 | num_broken_ptrs++; |
| 169 | LOG(ERROR) << "FreeList[" << i << "] (" << ptrs[i] << ") not in bounds of heap " << *this; |
| 170 | } |
| 171 | } |
| 172 | CHECK_EQ(num_broken_ptrs, 0u); |
| 173 | #endif |
| 174 | mspace_bulk_free(mspace_, reinterpret_cast<void**>(ptrs), num_ptrs); |
| 175 | } |
| 176 | |
| 177 | // Callback from dlmalloc when it needs to increase the footprint |
| 178 | extern "C" void* art_heap_morecore(void* mspace, intptr_t increment) { |
| 179 | AllocSpace* space = Heap::GetAllocSpace(); |
| 180 | if (LIKELY(space->GetMspace() == mspace)) { |
| 181 | return space->MoreCore(increment); |
| 182 | } else { |
| 183 | // Exhaustively search alloc spaces |
| 184 | const std::vector<Space*>& spaces = Heap::GetSpaces(); |
| 185 | for (size_t i = 0; i < spaces.size(); i++) { |
| 186 | if (spaces[i]->IsAllocSpace()) { |
| 187 | AllocSpace* space = spaces[i]->AsAllocSpace(); |
| 188 | if (mspace == space->GetMspace()) { |
| 189 | return space->MoreCore(increment); |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | LOG(FATAL) << "Unexpected call to art_heap_morecore. mspace: " << mspace |
| 194 | << " increment: " << increment; |
| 195 | return NULL; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | void* AllocSpace::MoreCore(intptr_t increment) { |
| 200 | byte* original_end = end_; |
| 201 | if (increment != 0) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 202 | VLOG(heap) << "AllocSpace::MoreCore " << PrettySize(increment); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 203 | byte* new_end = original_end + increment; |
| 204 | if (increment > 0) { |
| 205 | #if DEBUG_SPACES |
| 206 | // Should never be asked to increase the allocation beyond the capacity of the space. Enforced |
| 207 | // by mspace_set_footprint_limit. |
| 208 | CHECK_LE(new_end, Begin() + Capacity()); |
| 209 | #endif |
| 210 | CHECK_MEMORY_CALL(mprotect, (original_end, increment, PROT_READ | PROT_WRITE), GetSpaceName()); |
| 211 | } else { |
| 212 | #if DEBUG_SPACES |
| 213 | // Should never be asked for negative footprint (ie before begin) |
| 214 | CHECK_GT(original_end + increment, Begin()); |
| 215 | #endif |
| 216 | // Advise we don't need the pages and protect them |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 217 | // TODO: by removing permissions to the pages we may be causing TLB shoot-down which can be |
| 218 | // expensive (note the same isn't true for giving permissions to a page as the protected |
| 219 | // page shouldn't be in a TLB). We should investigate performance impact of just |
| 220 | // removing ignoring the memory protection change here and in Space::CreateAllocSpace. It's |
| 221 | // likely just a useful debug feature. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 222 | size_t size = -increment; |
| 223 | CHECK_MEMORY_CALL(madvise, (new_end, size, MADV_DONTNEED), GetSpaceName()); |
| 224 | CHECK_MEMORY_CALL(mprotect, (new_end, size, PROT_NONE), GetSpaceName()); |
| 225 | } |
| 226 | // Update end_ |
| 227 | end_ = new_end; |
| 228 | } |
| 229 | return original_end; |
| 230 | } |
| 231 | |
| 232 | size_t AllocSpace::AllocationSize(const Object* obj) { |
| 233 | return mspace_usable_size(const_cast<void*>(reinterpret_cast<const void*>(obj))) + kChunkOverhead; |
| 234 | } |
| 235 | |
| 236 | // Call back from mspace_inspect_all returning the start and end of chunks and the bytes used, |
| 237 | // if used_bytes is 0 then it indicates the range isn't in use and we madvise to the system that |
| 238 | // we don't need it |
| 239 | static void DontNeed(void* start, void* end, size_t used_bytes, void* num_bytes) { |
| 240 | if (used_bytes == 0) { |
| 241 | start = reinterpret_cast<void*>(RoundUp((uintptr_t)start, kPageSize)); |
| 242 | end = reinterpret_cast<void*>(RoundDown((uintptr_t)end, kPageSize)); |
| 243 | if (end > start) { |
| 244 | // We have a page aligned region to madvise on |
| 245 | size_t length = reinterpret_cast<byte*>(end) - reinterpret_cast<byte*>(start); |
| 246 | CHECK_MEMORY_CALL(madvise, (start, length, MADV_DONTNEED), "trim"); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | void AllocSpace::Trim() { |
| 252 | // Trim to release memory at the end of the space |
| 253 | mspace_trim(mspace_, 0); |
| 254 | // Visit space looking for page size holes to advise we don't need |
| 255 | size_t num_bytes_released = 0; |
| 256 | mspace_inspect_all(mspace_, DontNeed, &num_bytes_released); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | void AllocSpace::Walk(void(*callback)(void *start, void *end, size_t num_bytes, void* callback_arg), |
| 261 | void* arg) { |
| 262 | mspace_inspect_all(mspace_, callback, arg); |
| 263 | } |
| 264 | |
| 265 | size_t AllocSpace::GetFootprintLimit() { |
| 266 | return mspace_footprint_limit(mspace_); |
| 267 | } |
| 268 | |
| 269 | void AllocSpace::SetFootprintLimit(size_t new_size) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 270 | VLOG(heap) << "AllocSpace::SetFootprintLimit " << PrettySize(new_size); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 271 | // Compare against the actual footprint, rather than the Size(), because the heap may not have |
| 272 | // grown all the way to the allowed size yet. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 273 | size_t current_space_size = mspace_footprint(mspace_); |
| 274 | if (new_size < current_space_size) { |
| 275 | // Don't let the space grow any more. |
| 276 | new_size = current_space_size; |
| 277 | } |
| 278 | mspace_set_footprint_limit(mspace_, new_size); |
| 279 | } |
| 280 | |
| 281 | ImageSpace* Space::CreateImageSpace(const std::string& image_file_name) { |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 282 | CHECK(!image_file_name.empty()); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 283 | |
| 284 | uint64_t start_time = 0; |
| 285 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
| 286 | start_time = NanoTime(); |
| 287 | LOG(INFO) << "Space::CreateImageSpace entering" << " image_file_name=" << image_file_name; |
| 288 | } |
| 289 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 290 | UniquePtr<File> file(OS::OpenFile(image_file_name.c_str(), false)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 291 | if (file.get() == NULL) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 292 | LOG(ERROR) << "Failed to open " << image_file_name; |
| 293 | return NULL; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 294 | } |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 295 | ImageHeader image_header; |
| 296 | bool success = file->ReadFully(&image_header, sizeof(image_header)); |
| 297 | if (!success || !image_header.IsValid()) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 298 | LOG(ERROR) << "Invalid image header " << image_file_name; |
| 299 | return NULL; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 300 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 301 | UniquePtr<MemMap> map(MemMap::MapFileAtAddress(image_header.GetImageBegin(), |
Brian Carlstrom | 8952189 | 2011-12-07 22:05:07 -0800 | [diff] [blame] | 302 | file->Length(), |
| 303 | // TODO: selectively PROT_EXEC stubs |
| 304 | PROT_READ | PROT_WRITE | PROT_EXEC, |
| 305 | MAP_PRIVATE | MAP_FIXED, |
| 306 | file->Fd(), |
| 307 | 0)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 308 | if (map.get() == NULL) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 309 | LOG(ERROR) << "Failed to map " << image_file_name; |
| 310 | return NULL; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 311 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 312 | CHECK_EQ(image_header.GetImageBegin(), map->Begin()); |
| 313 | DCHECK_EQ(0, memcmp(&image_header, map->Begin(), sizeof(ImageHeader))); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 314 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 315 | Runtime* runtime = Runtime::Current(); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 316 | Object* jni_stub_array = image_header.GetImageRoot(ImageHeader::kJniStubArray); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 317 | runtime->SetJniDlsymLookupStub(down_cast<ByteArray*>(jni_stub_array)); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 318 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 319 | Object* ame_stub_array = image_header.GetImageRoot(ImageHeader::kAbstractMethodErrorStubArray); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 320 | runtime->SetAbstractMethodErrorStubArray(down_cast<ByteArray*>(ame_stub_array)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 321 | |
Ian Rogers | fb6adba | 2012-03-04 21:51:51 -0800 | [diff] [blame] | 322 | Object* resolution_stub_array = |
| 323 | image_header.GetImageRoot(ImageHeader::kStaticResolutionStubArray); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 324 | runtime->SetResolutionStubArray( |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 325 | down_cast<ByteArray*>(resolution_stub_array), Runtime::kStaticMethod); |
| 326 | resolution_stub_array = image_header.GetImageRoot(ImageHeader::kUnknownMethodResolutionStubArray); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 327 | runtime->SetResolutionStubArray( |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 328 | down_cast<ByteArray*>(resolution_stub_array), Runtime::kUnknownMethod); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 329 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 330 | Object* resolution_method = image_header.GetImageRoot(ImageHeader::kResolutionMethod); |
| 331 | runtime->SetResolutionMethod(down_cast<Method*>(resolution_method)); |
| 332 | |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 333 | Object* callee_save_method = image_header.GetImageRoot(ImageHeader::kCalleeSaveMethod); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 334 | runtime->SetCalleeSaveMethod(down_cast<Method*>(callee_save_method), Runtime::kSaveAll); |
| 335 | callee_save_method = image_header.GetImageRoot(ImageHeader::kRefsOnlySaveMethod); |
| 336 | runtime->SetCalleeSaveMethod(down_cast<Method*>(callee_save_method), Runtime::kRefsOnly); |
| 337 | callee_save_method = image_header.GetImageRoot(ImageHeader::kRefsAndArgsSaveMethod); |
| 338 | runtime->SetCalleeSaveMethod(down_cast<Method*>(callee_save_method), Runtime::kRefsAndArgs); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 339 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 340 | ImageSpace* space = new ImageSpace(image_file_name, map.release()); |
| 341 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 342 | LOG(INFO) << "Space::CreateImageSpace exiting (" << PrettyDuration(NanoTime() - start_time) |
| 343 | << ") " << *space; |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 344 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 345 | return space; |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 348 | void ImageSpace::RecordImageAllocations(HeapBitmap* live_bitmap) const { |
| 349 | uint64_t start_time = 0; |
| 350 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
| 351 | LOG(INFO) << "ImageSpace::RecordImageAllocations entering"; |
| 352 | start_time = NanoTime(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 353 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 354 | DCHECK(!Runtime::Current()->IsStarted()); |
| 355 | CHECK(live_bitmap != NULL); |
| 356 | byte* current = Begin() + RoundUp(sizeof(ImageHeader), kObjectAlignment); |
| 357 | byte* end = End(); |
| 358 | while (current < end) { |
| 359 | DCHECK_ALIGNED(current, kObjectAlignment); |
| 360 | const Object* obj = reinterpret_cast<const Object*>(current); |
| 361 | live_bitmap->Set(obj); |
| 362 | current += RoundUp(obj->SizeOf(), kObjectAlignment); |
| 363 | } |
| 364 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 365 | LOG(INFO) << "ImageSpace::RecordImageAllocations exiting (" |
| 366 | << PrettyDuration(NanoTime() - start_time) << ")"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 370 | std::ostream& operator<<(std::ostream& os, const Space& space) { |
| 371 | os << (space.IsImageSpace() ? "Image" : "Alloc") << "Space[" |
| 372 | << "begin=" << reinterpret_cast<void*>(space.Begin()) |
| 373 | << ",end=" << reinterpret_cast<void*>(space.End()) |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 374 | << ",size=" << PrettySize(space.Size()) << ",capacity=" << PrettySize(space.Capacity()) |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 375 | << ",name=\"" << space.GetSpaceName() << "\"]"; |
| 376 | return os; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | } // namespace art |