| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/heap/spaces.h" | 5 #include "src/heap/spaces.h" |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 9 #include "src/base/platform/semaphore.h" | 9 #include "src/base/platform/semaphore.h" |
| 10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 if (!heap()->CanExpandOldGeneration(size)) return false; | 1222 if (!heap()->CanExpandOldGeneration(size)) return false; |
| 1223 | 1223 |
| 1224 Page* p = heap()->memory_allocator()->AllocatePage(size, this, executable()); | 1224 Page* p = heap()->memory_allocator()->AllocatePage(size, this, executable()); |
| 1225 if (p == nullptr) return false; | 1225 if (p == nullptr) return false; |
| 1226 | 1226 |
| 1227 AccountCommitted(static_cast<intptr_t>(p->size())); | 1227 AccountCommitted(static_cast<intptr_t>(p->size())); |
| 1228 | 1228 |
| 1229 // Pages created during bootstrapping may contain immortal immovable objects. | 1229 // Pages created during bootstrapping may contain immortal immovable objects. |
| 1230 if (!heap()->deserialization_complete()) p->MarkNeverEvacuate(); | 1230 if (!heap()->deserialization_complete()) p->MarkNeverEvacuate(); |
| 1231 | 1231 |
| 1232 // When incremental marking was activated, old space pages are allocated |
| 1233 // black. |
| 1234 if (heap()->incremental_marking()->black_allocation() && |
| 1235 identity() == OLD_SPACE) { |
| 1236 p->markbits()->SetAllBits(); |
| 1237 p->SetFlag(Page::BLACK_PAGE); |
| 1238 if (FLAG_trace_incremental_marking) { |
| 1239 PrintIsolate(heap()->isolate(), "Added black page %p\n", |
| 1240 static_cast<void*>(p)); |
| 1241 } |
| 1242 } |
| 1243 |
| 1232 DCHECK(Capacity() <= heap()->MaxOldGenerationSize()); | 1244 DCHECK(Capacity() <= heap()->MaxOldGenerationSize()); |
| 1233 | 1245 |
| 1234 p->InsertAfter(anchor_.prev_page()); | 1246 p->InsertAfter(anchor_.prev_page()); |
| 1235 | 1247 |
| 1236 return true; | 1248 return true; |
| 1237 } | 1249 } |
| 1238 | 1250 |
| 1239 | 1251 |
| 1240 int PagedSpace::CountTotalPages() { | 1252 int PagedSpace::CountTotalPages() { |
| 1241 int count = 0; | 1253 int count = 0; |
| 1242 for (Page* page : *this) { | 1254 for (Page* page : *this) { |
| 1243 count++; | 1255 count++; |
| 1244 USE(page); | 1256 USE(page); |
| 1245 } | 1257 } |
| 1246 return count; | 1258 return count; |
| 1247 } | 1259 } |
| 1248 | 1260 |
| 1249 | 1261 |
| 1250 void PagedSpace::ResetFreeListStatistics() { | 1262 void PagedSpace::ResetFreeListStatistics() { |
| 1251 for (Page* page : *this) { | 1263 for (Page* page : *this) { |
| 1252 page->ResetFreeListStatistics(); | 1264 page->ResetFreeListStatistics(); |
| 1253 } | 1265 } |
| 1254 } | 1266 } |
| 1255 | 1267 |
| 1256 void PagedSpace::SetAllocationInfo(Address top, Address limit) { | |
| 1257 SetTopAndLimit(top, limit); | |
| 1258 if (top != nullptr && top != limit && | |
| 1259 heap()->incremental_marking()->black_allocation()) { | |
| 1260 Page* page = Page::FromAddress(top); | |
| 1261 page->markbits()->SetRange(page->AddressToMarkbitIndex(top), | |
| 1262 page->AddressToMarkbitIndex(limit)); | |
| 1263 page->IncrementLiveBytes(static_cast<int>(limit - top)); | |
| 1264 } | |
| 1265 } | |
| 1266 | |
| 1267 void PagedSpace::MarkAllocationInfoBlack() { | |
| 1268 DCHECK(heap()->incremental_marking()->black_allocation()); | |
| 1269 Address current_top = top(); | |
| 1270 Address current_limit = limit(); | |
| 1271 if (current_top != nullptr && current_top != current_limit) { | |
| 1272 Page* page = Page::FromAddress(current_top); | |
| 1273 page->markbits()->SetRange(page->AddressToMarkbitIndex(current_top), | |
| 1274 page->AddressToMarkbitIndex(current_limit)); | |
| 1275 page->IncrementLiveBytes(static_cast<int>(current_limit - current_top)); | |
| 1276 } | |
| 1277 } | |
| 1278 | |
| 1279 // Empty space allocation info, returning unused area to free list. | |
| 1280 void PagedSpace::EmptyAllocationInfo() { | |
| 1281 // Mark the old linear allocation area with a free space map so it can be | |
| 1282 // skipped when scanning the heap. | |
| 1283 Address current_top = top(); | |
| 1284 Address current_limit = limit(); | |
| 1285 if (current_top == nullptr) { | |
| 1286 DCHECK(current_limit == nullptr); | |
| 1287 return; | |
| 1288 } | |
| 1289 int old_linear_size = static_cast<int>(current_limit - current_top); | |
| 1290 SetTopAndLimit(NULL, NULL); | |
| 1291 if (current_top != current_limit && | |
| 1292 heap()->incremental_marking()->black_allocation()) { | |
| 1293 Page* page = Page::FromAddress(current_top); | |
| 1294 page->markbits()->ClearRange(page->AddressToMarkbitIndex(current_top), | |
| 1295 page->AddressToMarkbitIndex(current_limit)); | |
| 1296 page->IncrementLiveBytes(-static_cast<int>(current_limit - current_top)); | |
| 1297 } | |
| 1298 Free(current_top, old_linear_size); | |
| 1299 } | |
| 1300 | 1268 |
| 1301 void PagedSpace::IncreaseCapacity(int size) { | 1269 void PagedSpace::IncreaseCapacity(int size) { |
| 1302 accounting_stats_.ExpandSpace(size); | 1270 accounting_stats_.ExpandSpace(size); |
| 1303 } | 1271 } |
| 1304 | 1272 |
| 1305 void PagedSpace::ReleasePage(Page* page) { | 1273 void PagedSpace::ReleasePage(Page* page) { |
| 1306 DCHECK_EQ(page->LiveBytes(), 0); | 1274 DCHECK_EQ(page->LiveBytes(), 0); |
| 1307 DCHECK_EQ(AreaSize(), page->area_size()); | 1275 DCHECK_EQ(AreaSize(), page->area_size()); |
| 1308 DCHECK_EQ(page->owner(), this); | 1276 DCHECK_EQ(page->owner(), this); |
| 1309 | 1277 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 | 1324 |
| 1357 // Perform space-specific object verification. | 1325 // Perform space-specific object verification. |
| 1358 VerifyObject(object); | 1326 VerifyObject(object); |
| 1359 | 1327 |
| 1360 // The object itself should look OK. | 1328 // The object itself should look OK. |
| 1361 object->ObjectVerify(); | 1329 object->ObjectVerify(); |
| 1362 | 1330 |
| 1363 // All the interior pointers should be contained in the heap. | 1331 // All the interior pointers should be contained in the heap. |
| 1364 int size = object->Size(); | 1332 int size = object->Size(); |
| 1365 object->IterateBody(map->instance_type(), size, visitor); | 1333 object->IterateBody(map->instance_type(), size, visitor); |
| 1366 if (Marking::IsBlack(ObjectMarking::MarkBitFrom(object))) { | 1334 if (!page->IsFlagSet(Page::BLACK_PAGE) && |
| 1335 Marking::IsBlack(ObjectMarking::MarkBitFrom(object))) { |
| 1367 black_size += size; | 1336 black_size += size; |
| 1368 } | 1337 } |
| 1369 | 1338 |
| 1370 CHECK(object->address() + size <= top); | 1339 CHECK(object->address() + size <= top); |
| 1371 end_of_previous_object = object->address() + size; | 1340 end_of_previous_object = object->address() + size; |
| 1372 } | 1341 } |
| 1373 CHECK_LE(black_size, page->LiveBytes()); | 1342 CHECK_LE(black_size, page->LiveBytes()); |
| 1374 } | 1343 } |
| 1375 CHECK(allocation_pointer_found_in_space); | 1344 CHECK(allocation_pointer_found_in_space); |
| 1376 } | 1345 } |
| (...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 DCHECK(0 < size_in_bytes); | 2422 DCHECK(0 < size_in_bytes); |
| 2454 DCHECK(size_in_bytes <= kMaxBlockSize); | 2423 DCHECK(size_in_bytes <= kMaxBlockSize); |
| 2455 DCHECK(IsAligned(size_in_bytes, kPointerSize)); | 2424 DCHECK(IsAligned(size_in_bytes, kPointerSize)); |
| 2456 // Don't free list allocate if there is linear space available. | 2425 // Don't free list allocate if there is linear space available. |
| 2457 DCHECK(owner_->limit() - owner_->top() < size_in_bytes); | 2426 DCHECK(owner_->limit() - owner_->top() < size_in_bytes); |
| 2458 | 2427 |
| 2459 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); | 2428 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); |
| 2460 // Mark the old linear allocation area with a free space map so it can be | 2429 // Mark the old linear allocation area with a free space map so it can be |
| 2461 // skipped when scanning the heap. This also puts it back in the free list | 2430 // skipped when scanning the heap. This also puts it back in the free list |
| 2462 // if it is big enough. | 2431 // if it is big enough. |
| 2463 owner_->EmptyAllocationInfo(); | 2432 owner_->Free(owner_->top(), old_linear_size); |
| 2433 owner_->SetTopAndLimit(nullptr, nullptr); |
| 2464 | 2434 |
| 2465 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - | 2435 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - |
| 2466 old_linear_size); | 2436 old_linear_size); |
| 2467 | 2437 |
| 2468 int new_node_size = 0; | 2438 int new_node_size = 0; |
| 2469 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); | 2439 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
| 2470 if (new_node == nullptr) return nullptr; | 2440 if (new_node == nullptr) return nullptr; |
| 2471 | 2441 |
| 2472 int bytes_left = new_node_size - size_in_bytes; | 2442 int bytes_left = new_node_size - size_in_bytes; |
| 2473 DCHECK(bytes_left >= 0); | 2443 DCHECK(bytes_left >= 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2487 const int kThreshold = IncrementalMarking::kAllocatedThreshold; | 2457 const int kThreshold = IncrementalMarking::kAllocatedThreshold; |
| 2488 | 2458 |
| 2489 // Memory in the linear allocation area is counted as allocated. We may free | 2459 // Memory in the linear allocation area is counted as allocated. We may free |
| 2490 // a little of this again immediately - see below. | 2460 // a little of this again immediately - see below. |
| 2491 owner_->Allocate(new_node_size); | 2461 owner_->Allocate(new_node_size); |
| 2492 | 2462 |
| 2493 if (owner_->heap()->inline_allocation_disabled()) { | 2463 if (owner_->heap()->inline_allocation_disabled()) { |
| 2494 // Keep the linear allocation area empty if requested to do so, just | 2464 // Keep the linear allocation area empty if requested to do so, just |
| 2495 // return area back to the free list instead. | 2465 // return area back to the free list instead. |
| 2496 owner_->Free(new_node->address() + size_in_bytes, bytes_left); | 2466 owner_->Free(new_node->address() + size_in_bytes, bytes_left); |
| 2497 owner_->SetAllocationInfo(new_node->address() + size_in_bytes, | 2467 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, |
| 2498 new_node->address() + size_in_bytes); | 2468 new_node->address() + size_in_bytes); |
| 2499 } else if (bytes_left > kThreshold && | 2469 } else if (bytes_left > kThreshold && |
| 2500 owner_->heap()->incremental_marking()->IsMarkingIncomplete() && | 2470 owner_->heap()->incremental_marking()->IsMarkingIncomplete() && |
| 2501 FLAG_incremental_marking) { | 2471 FLAG_incremental_marking) { |
| 2502 int linear_size = owner_->RoundSizeDownToObjectAlignment(kThreshold); | 2472 int linear_size = owner_->RoundSizeDownToObjectAlignment(kThreshold); |
| 2503 // We don't want to give too large linear areas to the allocator while | 2473 // We don't want to give too large linear areas to the allocator while |
| 2504 // incremental marking is going on, because we won't check again whether | 2474 // incremental marking is going on, because we won't check again whether |
| 2505 // we want to do another increment until the linear area is used up. | 2475 // we want to do another increment until the linear area is used up. |
| 2506 owner_->Free(new_node->address() + size_in_bytes + linear_size, | 2476 owner_->Free(new_node->address() + size_in_bytes + linear_size, |
| 2507 new_node_size - size_in_bytes - linear_size); | 2477 new_node_size - size_in_bytes - linear_size); |
| 2508 owner_->SetAllocationInfo( | 2478 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, |
| 2509 new_node->address() + size_in_bytes, | 2479 new_node->address() + size_in_bytes + linear_size); |
| 2510 new_node->address() + size_in_bytes + linear_size); | |
| 2511 } else { | 2480 } else { |
| 2512 DCHECK(bytes_left >= 0); | 2481 DCHECK(bytes_left >= 0); |
| 2513 // Normally we give the rest of the node to the allocator as its new | 2482 // Normally we give the rest of the node to the allocator as its new |
| 2514 // linear allocation area. | 2483 // linear allocation area. |
| 2515 owner_->SetAllocationInfo(new_node->address() + size_in_bytes, | 2484 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, |
| 2516 new_node->address() + new_node_size); | 2485 new_node->address() + new_node_size); |
| 2517 } | 2486 } |
| 2518 | 2487 |
| 2519 owner_->AllocationStep(new_node->address(), size_in_bytes); | 2488 owner_->AllocationStep(new_node->address(), size_in_bytes); |
| 2520 | 2489 |
| 2521 return new_node; | 2490 return new_node; |
| 2522 } | 2491 } |
| 2523 | 2492 |
| 2524 intptr_t FreeList::EvictFreeListItems(Page* page) { | 2493 intptr_t FreeList::EvictFreeListItems(Page* page) { |
| 2525 intptr_t sum = 0; | 2494 intptr_t sum = 0; |
| 2526 page->ForAllFreeListCategories( | 2495 page->ForAllFreeListCategories( |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2896 if (Heap::ShouldZapGarbage()) { | 2865 if (Heap::ShouldZapGarbage()) { |
| 2897 // Make the object consistent so the heap can be verified in OldSpaceStep. | 2866 // Make the object consistent so the heap can be verified in OldSpaceStep. |
| 2898 // We only need to do this in debug builds or if verify_heap is on. | 2867 // We only need to do this in debug builds or if verify_heap is on. |
| 2899 reinterpret_cast<Object**>(object->address())[0] = | 2868 reinterpret_cast<Object**>(object->address())[0] = |
| 2900 heap()->fixed_array_map(); | 2869 heap()->fixed_array_map(); |
| 2901 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 2870 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); |
| 2902 } | 2871 } |
| 2903 | 2872 |
| 2904 heap()->incremental_marking()->OldSpaceStep(object_size); | 2873 heap()->incremental_marking()->OldSpaceStep(object_size); |
| 2905 AllocationStep(object->address(), object_size); | 2874 AllocationStep(object->address(), object_size); |
| 2906 | |
| 2907 if (heap()->incremental_marking()->black_allocation()) { | |
| 2908 Marking::MarkBlack(ObjectMarking::MarkBitFrom(object)); | |
| 2909 MemoryChunk::IncrementLiveBytesFromGC(object, object_size); | |
| 2910 } | |
| 2911 return object; | 2875 return object; |
| 2912 } | 2876 } |
| 2913 | 2877 |
| 2914 | 2878 |
| 2915 size_t LargeObjectSpace::CommittedPhysicalMemory() { | 2879 size_t LargeObjectSpace::CommittedPhysicalMemory() { |
| 2916 // On a platform that provides lazy committing of memory, we over-account | 2880 // On a platform that provides lazy committing of memory, we over-account |
| 2917 // the actually committed memory. There is no easy way right now to support | 2881 // the actually committed memory. There is no easy way right now to support |
| 2918 // precise accounting of committed memory in large object space. | 2882 // precise accounting of committed memory in large object space. |
| 2919 return CommittedMemory(); | 2883 return CommittedMemory(); |
| 2920 } | 2884 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3134 object->ShortPrint(); | 3098 object->ShortPrint(); |
| 3135 PrintF("\n"); | 3099 PrintF("\n"); |
| 3136 } | 3100 } |
| 3137 printf(" --------------------------------------\n"); | 3101 printf(" --------------------------------------\n"); |
| 3138 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3102 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3139 } | 3103 } |
| 3140 | 3104 |
| 3141 #endif // DEBUG | 3105 #endif // DEBUG |
| 3142 } // namespace internal | 3106 } // namespace internal |
| 3143 } // namespace v8 | 3107 } // namespace v8 |
| OLD | NEW |