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 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 InlineAllocationStep(old_top, allocation_info_.top()); | 1405 InlineAllocationStep(old_top, allocation_info_.top()); |
1406 } | 1406 } |
1407 | 1407 |
1408 | 1408 |
1409 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { | 1409 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { |
1410 if (heap()->inline_allocation_disabled()) { | 1410 if (heap()->inline_allocation_disabled()) { |
1411 // Lowest limit when linear allocation was disabled. | 1411 // Lowest limit when linear allocation was disabled. |
1412 Address high = to_space_.page_high(); | 1412 Address high = to_space_.page_high(); |
1413 Address new_top = allocation_info_.top() + size_in_bytes; | 1413 Address new_top = allocation_info_.top() + size_in_bytes; |
1414 allocation_info_.set_limit(Min(new_top, high)); | 1414 allocation_info_.set_limit(Min(new_top, high)); |
1415 } else if (inline_allocation_limit_step_ == 0) { | 1415 } else if (top_on_previous_step_ == 0) { |
1416 // Normal limit is the end of the current page. | 1416 // Normal limit is the end of the current page. |
1417 allocation_info_.set_limit(to_space_.page_high()); | 1417 allocation_info_.set_limit(to_space_.page_high()); |
1418 } else { | 1418 } else { |
1419 // Lower limit during incremental marking. | 1419 // Lower limit during incremental marking. |
1420 Address high = to_space_.page_high(); | 1420 Address high = to_space_.page_high(); |
1421 Address new_top = allocation_info_.top() + size_in_bytes; | 1421 Address new_top = allocation_info_.top() + size_in_bytes; |
1422 Address new_limit = new_top + inline_allocation_limit_step_; | 1422 Address new_limit = new_top + inline_allocation_limit_step_ - 1; |
1423 allocation_info_.set_limit(Min(new_limit, high)); | 1423 allocation_info_.set_limit(Min(new_limit, high)); |
1424 } | 1424 } |
1425 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1425 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
1426 } | 1426 } |
1427 | 1427 |
1428 | 1428 |
1429 bool NewSpace::AddFreshPage() { | 1429 bool NewSpace::AddFreshPage() { |
1430 Address top = allocation_info_.top(); | 1430 Address top = allocation_info_.top(); |
1431 if (NewSpacePage::IsAtStart(top)) { | 1431 if (NewSpacePage::IsAtStart(top)) { |
1432 // The current page is already empty. Don't try to make another. | 1432 // The current page is already empty. Don't try to make another. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 // or because idle scavenge job wants to get a chance to post a task. | 1497 // or because idle scavenge job wants to get a chance to post a task. |
1498 // Set the new limit accordingly. | 1498 // Set the new limit accordingly. |
1499 Address new_top = old_top + aligned_size_in_bytes; | 1499 Address new_top = old_top + aligned_size_in_bytes; |
1500 InlineAllocationStep(new_top, new_top); | 1500 InlineAllocationStep(new_top, new_top); |
1501 UpdateInlineAllocationLimit(aligned_size_in_bytes); | 1501 UpdateInlineAllocationLimit(aligned_size_in_bytes); |
1502 } | 1502 } |
1503 return true; | 1503 return true; |
1504 } | 1504 } |
1505 | 1505 |
1506 | 1506 |
| 1507 void NewSpace::UpdateInlineAllocationLimitStep() { |
| 1508 intptr_t step = 0; |
| 1509 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { |
| 1510 InlineAllocationObserver& observer = inline_allocation_observers_[i]; |
| 1511 step = step ? Min(step, observer.step_size()) : observer.step_size(); |
| 1512 } |
| 1513 inline_allocation_limit_step_ = step; |
| 1514 top_on_previous_step_ = step ? allocation_info_.top() : 0; |
| 1515 UpdateInlineAllocationLimit(0); |
| 1516 } |
| 1517 |
| 1518 |
| 1519 void NewSpace::AddInlineAllocationObserver( |
| 1520 intptr_t step_size, InlineAllocationObserver::callback_t callback, |
| 1521 void* callback_arg) { |
| 1522 DCHECK(callback != nullptr); |
| 1523 InlineAllocationObserver observer(step_size, callback, callback_arg); |
| 1524 inline_allocation_observers_.Add(observer); |
| 1525 UpdateInlineAllocationLimitStep(); |
| 1526 } |
| 1527 |
| 1528 |
| 1529 void NewSpace::RemoveInlineAllocationObserver( |
| 1530 InlineAllocationObserver::callback_t callback) { |
| 1531 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { |
| 1532 if (inline_allocation_observers_[i].callback() == callback) { |
| 1533 inline_allocation_observers_.Remove(i); |
| 1534 UpdateInlineAllocationLimitStep(); |
| 1535 return; |
| 1536 } |
| 1537 } |
| 1538 UNREACHABLE(); |
| 1539 } |
| 1540 |
| 1541 |
1507 void NewSpace::InlineAllocationStep(Address top, Address new_top) { | 1542 void NewSpace::InlineAllocationStep(Address top, Address new_top) { |
1508 if (top_on_previous_step_) { | 1543 if (top_on_previous_step_) { |
1509 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); | 1544 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); |
1510 heap()->ScheduleIdleScavengeIfNeeded(bytes_allocated); | 1545 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { |
1511 heap()->incremental_marking()->Step(bytes_allocated, | 1546 inline_allocation_observers_[i].step(bytes_allocated); |
1512 IncrementalMarking::GC_VIA_STACK_GUARD); | 1547 } |
1513 top_on_previous_step_ = new_top; | 1548 top_on_previous_step_ = new_top; |
1514 } | 1549 } |
1515 } | 1550 } |
1516 | 1551 |
1517 #ifdef VERIFY_HEAP | 1552 #ifdef VERIFY_HEAP |
1518 // We do not use the SemiSpaceIterator because verification doesn't assume | 1553 // We do not use the SemiSpaceIterator because verification doesn't assume |
1519 // that it works (it depends on the invariants we are checking). | 1554 // that it works (it depends on the invariants we are checking). |
1520 void NewSpace::Verify() { | 1555 void NewSpace::Verify() { |
1521 // The allocation pointer should be in the space or at the very end. | 1556 // The allocation pointer should be in the space or at the very end. |
1522 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1557 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3158 object->ShortPrint(); | 3193 object->ShortPrint(); |
3159 PrintF("\n"); | 3194 PrintF("\n"); |
3160 } | 3195 } |
3161 printf(" --------------------------------------\n"); | 3196 printf(" --------------------------------------\n"); |
3162 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3197 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3163 } | 3198 } |
3164 | 3199 |
3165 #endif // DEBUG | 3200 #endif // DEBUG |
3166 } // namespace internal | 3201 } // namespace internal |
3167 } // namespace v8 | 3202 } // namespace v8 |
OLD | NEW |