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/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...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int filler_size = Heap::GetFillToAlign(old_top, alignment); |
| 1475 int aligned_size_in_bytes = size_in_bytes + filler_size; |
| 1476 |
| 1477 if (old_top + aligned_size_in_bytes >= high) { |
| 1478 // Not enough room in the page, try to allocate a new one. |
| 1479 if (!AddFreshPage()) { |
| 1480 return false; |
| 1481 } |
| 1482 |
| 1483 // Do a step for the bytes allocated on the last page. |
| 1484 int bytes_allocated = static_cast<int>(old_top - top_on_previous_step_); |
| 1485 heap()->incremental_marking()->Step(bytes_allocated, |
| 1486 IncrementalMarking::GC_VIA_STACK_GUARD); |
| 1487 old_top = allocation_info_.top(); |
| 1488 top_on_previous_step_ = old_top; |
| 1489 |
| 1490 high = to_space_.page_high(); |
| 1491 filler_size = Heap::GetFillToAlign(old_top, alignment); |
| 1492 aligned_size_in_bytes = size_in_bytes + filler_size; |
| 1493 } |
| 1494 |
| 1495 DCHECK(old_top + aligned_size_in_bytes < high); |
| 1496 |
1474 if (allocation_info_.limit() < high) { | 1497 if (allocation_info_.limit() < high) { |
1475 int alignment_size = Heap::GetFillToAlign(old_top, alignment); | |
1476 int aligned_size_in_bytes = size_in_bytes + alignment_size; | |
1477 | |
1478 // Either the limit has been lowered because linear allocation was disabled | 1498 // 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 | 1499 // or because incremental marking wants to get a chance to do a step. Set |
1480 // the new limit accordingly. | 1500 // the new limit accordingly. |
1481 Address new_top = old_top + aligned_size_in_bytes; | 1501 Address new_top = old_top + aligned_size_in_bytes; |
1482 int bytes_allocated = static_cast<int>(new_top - top_on_previous_step_); | 1502 int bytes_allocated = static_cast<int>(new_top - top_on_previous_step_); |
1483 heap()->incremental_marking()->Step(bytes_allocated, | 1503 heap()->incremental_marking()->Step(bytes_allocated, |
1484 IncrementalMarking::GC_VIA_STACK_GUARD); | 1504 IncrementalMarking::GC_VIA_STACK_GUARD); |
1485 UpdateInlineAllocationLimit(aligned_size_in_bytes); | 1505 UpdateInlineAllocationLimit(aligned_size_in_bytes); |
1486 top_on_previous_step_ = new_top; | 1506 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 } | 1507 } |
| 1508 return true; |
1500 } | 1509 } |
1501 | 1510 |
1502 | 1511 |
1503 #ifdef VERIFY_HEAP | 1512 #ifdef VERIFY_HEAP |
1504 // We do not use the SemiSpaceIterator because verification doesn't assume | 1513 // We do not use the SemiSpaceIterator because verification doesn't assume |
1505 // that it works (it depends on the invariants we are checking). | 1514 // that it works (it depends on the invariants we are checking). |
1506 void NewSpace::Verify() { | 1515 void NewSpace::Verify() { |
1507 // The allocation pointer should be in the space or at the very end. | 1516 // The allocation pointer should be in the space or at the very end. |
1508 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1517 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
1509 | 1518 |
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3141 object->ShortPrint(); | 3150 object->ShortPrint(); |
3142 PrintF("\n"); | 3151 PrintF("\n"); |
3143 } | 3152 } |
3144 printf(" --------------------------------------\n"); | 3153 printf(" --------------------------------------\n"); |
3145 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3154 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3146 } | 3155 } |
3147 | 3156 |
3148 #endif // DEBUG | 3157 #endif // DEBUG |
3149 } // namespace internal | 3158 } // namespace internal |
3150 } // namespace v8 | 3159 } // namespace v8 |
OLD | NEW |