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/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 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 void NewSpace::ResetAllocationInfo() { | 1393 void NewSpace::ResetAllocationInfo() { |
1394 Address old_top = allocation_info_.top(); | 1394 Address old_top = allocation_info_.top(); |
1395 to_space_.Reset(); | 1395 to_space_.Reset(); |
1396 UpdateAllocationInfo(); | 1396 UpdateAllocationInfo(); |
1397 pages_used_ = 0; | 1397 pages_used_ = 0; |
1398 // Clear all mark-bits in the to-space. | 1398 // Clear all mark-bits in the to-space. |
1399 NewSpacePageIterator it(&to_space_); | 1399 NewSpacePageIterator it(&to_space_); |
1400 while (it.has_next()) { | 1400 while (it.has_next()) { |
1401 Bitmap::Clear(it.next()); | 1401 Bitmap::Clear(it.next()); |
1402 } | 1402 } |
1403 if (top_on_previous_step_) { | 1403 InlineAllocationStep(old_top, allocation_info_.top()); |
1404 int bytes_allocated = static_cast<int>(old_top - top_on_previous_step_); | |
1405 heap()->incremental_marking()->Step(bytes_allocated, | |
1406 IncrementalMarking::GC_VIA_STACK_GUARD); | |
1407 top_on_previous_step_ = allocation_info_.top(); | |
1408 } | |
1409 } | 1404 } |
1410 | 1405 |
1411 | 1406 |
1412 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { | 1407 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { |
1413 if (heap()->inline_allocation_disabled()) { | 1408 if (heap()->inline_allocation_disabled()) { |
1414 // Lowest limit when linear allocation was disabled. | 1409 // Lowest limit when linear allocation was disabled. |
1415 Address high = to_space_.page_high(); | 1410 Address high = to_space_.page_high(); |
1416 Address new_top = allocation_info_.top() + size_in_bytes; | 1411 Address new_top = allocation_info_.top() + size_in_bytes; |
1417 allocation_info_.set_limit(Min(new_top, high)); | 1412 allocation_info_.set_limit(Min(new_top, high)); |
1418 } else if (inline_allocation_limit_step() == 0) { | 1413 } else if (inline_allocation_limit_step() == 0) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 Address high = to_space_.page_high(); | 1472 Address high = to_space_.page_high(); |
1478 int filler_size = Heap::GetFillToAlign(old_top, alignment); | 1473 int filler_size = Heap::GetFillToAlign(old_top, alignment); |
1479 int aligned_size_in_bytes = size_in_bytes + filler_size; | 1474 int aligned_size_in_bytes = size_in_bytes + filler_size; |
1480 | 1475 |
1481 if (old_top + aligned_size_in_bytes >= high) { | 1476 if (old_top + aligned_size_in_bytes >= high) { |
1482 // Not enough room in the page, try to allocate a new one. | 1477 // Not enough room in the page, try to allocate a new one. |
1483 if (!AddFreshPage()) { | 1478 if (!AddFreshPage()) { |
1484 return false; | 1479 return false; |
1485 } | 1480 } |
1486 | 1481 |
1487 if (top_on_previous_step_) { | 1482 InlineAllocationStep(old_top, allocation_info_.top()); |
1488 // Do a step for the bytes allocated on the last page. | |
1489 int bytes_allocated = static_cast<int>(old_top - top_on_previous_step_); | |
1490 heap()->incremental_marking()->Step( | |
1491 bytes_allocated, IncrementalMarking::GC_VIA_STACK_GUARD); | |
1492 top_on_previous_step_ = allocation_info_.top(); | |
1493 } | |
1494 | 1483 |
1495 old_top = allocation_info_.top(); | 1484 old_top = allocation_info_.top(); |
1496 high = to_space_.page_high(); | 1485 high = to_space_.page_high(); |
1497 filler_size = Heap::GetFillToAlign(old_top, alignment); | 1486 filler_size = Heap::GetFillToAlign(old_top, alignment); |
1498 aligned_size_in_bytes = size_in_bytes + filler_size; | 1487 aligned_size_in_bytes = size_in_bytes + filler_size; |
1499 } | 1488 } |
1500 | 1489 |
1501 DCHECK(old_top + aligned_size_in_bytes < high); | 1490 DCHECK(old_top + aligned_size_in_bytes < high); |
1502 | 1491 |
1503 if (allocation_info_.limit() < high) { | 1492 if (allocation_info_.limit() < high) { |
1504 // Either the limit has been lowered because linear allocation was disabled | 1493 // Either the limit has been lowered because linear allocation was disabled |
1505 // or because incremental marking wants to get a chance to do a step. Set | 1494 // or because incremental marking wants to get a chance to do a step. Set |
1506 // the new limit accordingly. | 1495 // the new limit accordingly. |
1507 if (top_on_previous_step_) { | 1496 Address new_top = old_top + aligned_size_in_bytes; |
1508 Address new_top = old_top + aligned_size_in_bytes; | 1497 InlineAllocationStep(new_top, new_top); |
1509 int bytes_allocated = static_cast<int>(new_top - top_on_previous_step_); | |
1510 heap()->incremental_marking()->Step( | |
1511 bytes_allocated, IncrementalMarking::GC_VIA_STACK_GUARD); | |
1512 top_on_previous_step_ = new_top; | |
1513 } | |
1514 UpdateInlineAllocationLimit(aligned_size_in_bytes); | 1498 UpdateInlineAllocationLimit(aligned_size_in_bytes); |
1515 } | 1499 } |
1516 return true; | 1500 return true; |
1517 } | 1501 } |
1518 | 1502 |
1519 | 1503 |
| 1504 void NewSpace::InlineAllocationStep(Address top, Address new_top) { |
| 1505 if (top_on_previous_step_) { |
| 1506 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); |
| 1507 heap()->incremental_marking()->Step(bytes_allocated, |
| 1508 IncrementalMarking::GC_VIA_STACK_GUARD); |
| 1509 top_on_previous_step_ = new_top; |
| 1510 } |
| 1511 } |
| 1512 |
1520 #ifdef VERIFY_HEAP | 1513 #ifdef VERIFY_HEAP |
1521 // We do not use the SemiSpaceIterator because verification doesn't assume | 1514 // We do not use the SemiSpaceIterator because verification doesn't assume |
1522 // that it works (it depends on the invariants we are checking). | 1515 // that it works (it depends on the invariants we are checking). |
1523 void NewSpace::Verify() { | 1516 void NewSpace::Verify() { |
1524 // The allocation pointer should be in the space or at the very end. | 1517 // The allocation pointer should be in the space or at the very end. |
1525 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1518 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
1526 | 1519 |
1527 // There should be objects packed in from the low address up to the | 1520 // There should be objects packed in from the low address up to the |
1528 // allocation pointer. | 1521 // allocation pointer. |
1529 Address current = to_space_.first_page()->area_start(); | 1522 Address current = to_space_.first_page()->area_start(); |
(...skipping 1614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3144 object->ShortPrint(); | 3137 object->ShortPrint(); |
3145 PrintF("\n"); | 3138 PrintF("\n"); |
3146 } | 3139 } |
3147 printf(" --------------------------------------\n"); | 3140 printf(" --------------------------------------\n"); |
3148 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3141 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3149 } | 3142 } |
3150 | 3143 |
3151 #endif // DEBUG | 3144 #endif // DEBUG |
3152 } // namespace internal | 3145 } // namespace internal |
3153 } // namespace v8 | 3146 } // namespace v8 |
OLD | NEW |