Chromium Code Reviews

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

Issue 1265443003: remove recursion from NewSpace::AllocateRaw* (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: EnsureAllocation now guarantees that bump-pointer will succeed Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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/v8.h" 5 #include "src/v8.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/mark-compact.h" 10 #include "src/heap/mark-compact.h"
(...skipping 1449 matching lines...)
1460 1460
1461 int remaining_in_page = static_cast<int>(limit - top); 1461 int remaining_in_page = static_cast<int>(limit - top);
1462 heap()->CreateFillerObjectAt(top, remaining_in_page); 1462 heap()->CreateFillerObjectAt(top, remaining_in_page);
1463 pages_used_++; 1463 pages_used_++;
1464 UpdateAllocationInfo(); 1464 UpdateAllocationInfo();
1465 1465
1466 return true; 1466 return true;
1467 } 1467 }
1468 1468
1469 1469
1470 AllocationResult NewSpace::SlowAllocateRaw(int size_in_bytes, 1470 bool NewSpace::EnsureAllocation(int size_in_bytes,
1471 AllocationAlignment alignment) { 1471 AllocationAlignment alignment) {
1472 Address old_top = allocation_info_.top(); 1472 Address old_top = allocation_info_.top();
1473 Address high = to_space_.page_high(); 1473 Address high = to_space_.page_high();
1474 if (old_top + size_in_bytes >= high) {
Hannes Payer (out of office) 2015/07/31 07:50:52 We should compare against aligned_size_in_bytes he
ofrobots 2015/07/31 13:47:38 Done.
1475 // Not enough room in the page, try to allocate a new one.
1476 if (!AddFreshPage()) {
1477 return false;
1478 }
1479
1480 // Do a step for the bytes allocated on the last page.
1481 int bytes_allocated = static_cast<int>(old_top - top_on_previous_step_);
1482 heap()->incremental_marking()->Step(bytes_allocated,
1483 IncrementalMarking::GC_VIA_STACK_GUARD);
1484 top_on_previous_step_ = to_space_.page_low();
Hannes Payer (out of office) 2015/07/31 07:50:52 to_space_.page_low() should be the same as allocat
ofrobots 2015/07/31 13:47:38 Done.
1485
1486 old_top = allocation_info_.top();
Hannes Payer (out of office) 2015/07/31 07:50:52 Since we got a new top here, we have to recalculat
ofrobots 2015/07/31 13:47:39 Done.
1487 high = to_space_.page_high();
1488 }
1489
1490 DCHECK(old_top + size_in_bytes < high);
1491
1474 if (allocation_info_.limit() < high) { 1492 if (allocation_info_.limit() < high) {
1475 int alignment_size = Heap::GetFillToAlign(old_top, alignment); 1493 int alignment_size = Heap::GetFillToAlign(old_top, alignment);
1476 int aligned_size_in_bytes = size_in_bytes + alignment_size; 1494 int aligned_size_in_bytes = size_in_bytes + alignment_size;
1477 1495
1478 // Either the limit has been lowered because linear allocation was disabled 1496 // Either the limit has been lowered because linear allocation was disabled
1479 // or because incremental marking wants to get a chance to do a step. Set 1497 // or because incremental marking wants to get a chance to do a step. Set
1480 // the new limit accordingly. 1498 // the new limit accordingly.
1481 Address new_top = old_top + aligned_size_in_bytes; 1499 Address new_top = old_top + aligned_size_in_bytes;
1482 int bytes_allocated = static_cast<int>(new_top - top_on_previous_step_); 1500 int bytes_allocated = static_cast<int>(new_top - top_on_previous_step_);
1483 heap()->incremental_marking()->Step(bytes_allocated, 1501 heap()->incremental_marking()->Step(bytes_allocated,
1484 IncrementalMarking::GC_VIA_STACK_GUARD); 1502 IncrementalMarking::GC_VIA_STACK_GUARD);
1485 UpdateInlineAllocationLimit(aligned_size_in_bytes); 1503 UpdateInlineAllocationLimit(aligned_size_in_bytes);
1486 top_on_previous_step_ = new_top; 1504 top_on_previous_step_ = new_top;
1487 if (alignment == kWordAligned) return AllocateRawUnaligned(size_in_bytes);
1488 return AllocateRawAligned(size_in_bytes, alignment);
1489 } else if (AddFreshPage()) {
1490 // Switched to new page. Try allocating again.
1491 int bytes_allocated = static_cast<int>(old_top - top_on_previous_step_);
1492 heap()->incremental_marking()->Step(bytes_allocated,
1493 IncrementalMarking::GC_VIA_STACK_GUARD);
1494 top_on_previous_step_ = to_space_.page_low();
1495 if (alignment == kWordAligned) return AllocateRawUnaligned(size_in_bytes);
1496 return AllocateRawAligned(size_in_bytes, alignment);
1497 } else {
1498 return AllocationResult::Retry();
1499 } 1505 }
1506 return true;
1500 } 1507 }
1501 1508
1502 1509
1503 #ifdef VERIFY_HEAP 1510 #ifdef VERIFY_HEAP
1504 // We do not use the SemiSpaceIterator because verification doesn't assume 1511 // We do not use the SemiSpaceIterator because verification doesn't assume
1505 // that it works (it depends on the invariants we are checking). 1512 // that it works (it depends on the invariants we are checking).
1506 void NewSpace::Verify() { 1513 void NewSpace::Verify() {
1507 // The allocation pointer should be in the space or at the very end. 1514 // The allocation pointer should be in the space or at the very end.
1508 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); 1515 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
1509 1516
(...skipping 1631 matching lines...)
3141 object->ShortPrint(); 3148 object->ShortPrint();
3142 PrintF("\n"); 3149 PrintF("\n");
3143 } 3150 }
3144 printf(" --------------------------------------\n"); 3151 printf(" --------------------------------------\n");
3145 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 3152 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
3146 } 3153 }
3147 3154
3148 #endif // DEBUG 3155 #endif // DEBUG
3149 } // namespace internal 3156 } // namespace internal
3150 } // namespace v8 3157 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.h ('k') | src/heap/spaces-inl.h » ('j') | src/heap/spaces-inl.h » ('J')

Powered by Google App Engine