Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/heap/spaces.cc

Issue 1364303002: [heap] Fix PagedSpace::SizeOfObjects calling from within FreeList::Allocate (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: CHECK -> DCHECK Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/full-codegen/full-codegen.h" 9 #include "src/full-codegen/full-codegen.h"
10 #include "src/heap/slots-buffer.h" 10 #include "src/heap/slots-buffer.h"
(...skipping 2368 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 DCHECK(size_in_bytes <= kMaxBlockSize); 2379 DCHECK(size_in_bytes <= kMaxBlockSize);
2380 DCHECK(IsAligned(size_in_bytes, kPointerSize)); 2380 DCHECK(IsAligned(size_in_bytes, kPointerSize));
2381 // Don't free list allocate if there is linear space available. 2381 // Don't free list allocate if there is linear space available.
2382 DCHECK(owner_->limit() - owner_->top() < size_in_bytes); 2382 DCHECK(owner_->limit() - owner_->top() < size_in_bytes);
2383 2383
2384 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); 2384 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top());
2385 // Mark the old linear allocation area with a free space map so it can be 2385 // Mark the old linear allocation area with a free space map so it can be
2386 // skipped when scanning the heap. This also puts it back in the free list 2386 // skipped when scanning the heap. This also puts it back in the free list
2387 // if it is big enough. 2387 // if it is big enough.
2388 owner_->Free(owner_->top(), old_linear_size); 2388 owner_->Free(owner_->top(), old_linear_size);
2389 owner_->SetTopAndLimit(nullptr, nullptr);
2389 2390
2390 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - 2391 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes -
2391 old_linear_size); 2392 old_linear_size);
2392 2393
2393 int new_node_size = 0; 2394 int new_node_size = 0;
2394 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); 2395 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size);
2395 if (new_node == NULL) { 2396 if (new_node == nullptr) return nullptr;
2396 owner_->SetTopAndLimit(NULL, NULL);
2397 return NULL;
2398 }
2399 2397
2400 int bytes_left = new_node_size - size_in_bytes; 2398 int bytes_left = new_node_size - size_in_bytes;
2401 DCHECK(bytes_left >= 0); 2399 DCHECK(bytes_left >= 0);
2402 2400
2403 #ifdef DEBUG 2401 #ifdef DEBUG
2404 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { 2402 for (int i = 0; i < size_in_bytes / kPointerSize; i++) {
2405 reinterpret_cast<Object**>(new_node->address())[i] = 2403 reinterpret_cast<Object**>(new_node->address())[i] =
2406 Smi::FromInt(kCodeZapValue); 2404 Smi::FromInt(kCodeZapValue);
2407 } 2405 }
2408 #endif 2406 #endif
(...skipping 23 matching lines...) Expand all
2432 // we want to do another increment until the linear area is used up. 2430 // we want to do another increment until the linear area is used up.
2433 owner_->Free(new_node->address() + size_in_bytes + linear_size, 2431 owner_->Free(new_node->address() + size_in_bytes + linear_size,
2434 new_node_size - size_in_bytes - linear_size); 2432 new_node_size - size_in_bytes - linear_size);
2435 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, 2433 owner_->SetTopAndLimit(new_node->address() + size_in_bytes,
2436 new_node->address() + size_in_bytes + linear_size); 2434 new_node->address() + size_in_bytes + linear_size);
2437 } else if (bytes_left > 0) { 2435 } else if (bytes_left > 0) {
2438 // Normally we give the rest of the node to the allocator as its new 2436 // Normally we give the rest of the node to the allocator as its new
2439 // linear allocation area. 2437 // linear allocation area.
2440 owner_->SetTopAndLimit(new_node->address() + size_in_bytes, 2438 owner_->SetTopAndLimit(new_node->address() + size_in_bytes,
2441 new_node->address() + new_node_size); 2439 new_node->address() + new_node_size);
2442 } else {
2443 // TODO(gc) Try not freeing linear allocation region when bytes_left
2444 // are zero.
2445 owner_->SetTopAndLimit(NULL, NULL);
2446 } 2440 }
2447 2441
2448 return new_node; 2442 return new_node;
2449 } 2443 }
2450 2444
2451 2445
2452 intptr_t FreeList::EvictFreeListItems(Page* p) { 2446 intptr_t FreeList::EvictFreeListItems(Page* p) {
2453 intptr_t sum = huge_list_.EvictFreeListItemsInList(p); 2447 intptr_t sum = huge_list_.EvictFreeListItemsInList(p);
2454 p->set_available_in_huge_free_list(0); 2448 p->set_available_in_huge_free_list(0);
2455 2449
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 2540
2547 // Clear the free list before a full GC---it will be rebuilt afterward. 2541 // Clear the free list before a full GC---it will be rebuilt afterward.
2548 free_list_.Reset(); 2542 free_list_.Reset();
2549 } 2543 }
2550 2544
2551 2545
2552 intptr_t PagedSpace::SizeOfObjects() { 2546 intptr_t PagedSpace::SizeOfObjects() {
2553 DCHECK(!FLAG_concurrent_sweeping || 2547 DCHECK(!FLAG_concurrent_sweeping ||
2554 heap()->mark_compact_collector()->sweeping_in_progress() || 2548 heap()->mark_compact_collector()->sweeping_in_progress() ||
2555 (unswept_free_bytes_ == 0)); 2549 (unswept_free_bytes_ == 0));
2556 return Size() - unswept_free_bytes_ - (limit() - top()); 2550 const intptr_t size = Size() - unswept_free_bytes_ - (limit() - top());
2551 DCHECK_GE(size, 0);
2552 USE(size);
2553 return size;
2557 } 2554 }
2558 2555
2559 2556
2560 // After we have booted, we have created a map which represents free space 2557 // After we have booted, we have created a map which represents free space
2561 // on the heap. If there was already a free list then the elements on it 2558 // on the heap. If there was already a free list then the elements on it
2562 // were created with the wrong FreeSpaceMap (normally NULL), so we need to 2559 // were created with the wrong FreeSpaceMap (normally NULL), so we need to
2563 // fix them. 2560 // fix them.
2564 void PagedSpace::RepairFreeListsAfterDeserialization() { 2561 void PagedSpace::RepairFreeListsAfterDeserialization() {
2565 free_list_.RepairLists(heap()); 2562 free_list_.RepairLists(heap());
2566 // Each page may have a small free space that is not tracked by a free list. 2563 // Each page may have a small free space that is not tracked by a free list.
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 object->ShortPrint(); 3141 object->ShortPrint();
3145 PrintF("\n"); 3142 PrintF("\n");
3146 } 3143 }
3147 printf(" --------------------------------------\n"); 3144 printf(" --------------------------------------\n");
3148 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3145 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3149 } 3146 }
3150 3147
3151 #endif // DEBUG 3148 #endif // DEBUG
3152 } // namespace internal 3149 } // namespace internal
3153 } // namespace v8 3150 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698