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 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1648 top_on_previous_step_ = | 1648 top_on_previous_step_ = |
1649 inline_allocation_observers_.length() ? allocation_info_.top() : 0; | 1649 inline_allocation_observers_.length() ? allocation_info_.top() : 0; |
1650 UpdateInlineAllocationLimit(0); | 1650 UpdateInlineAllocationLimit(0); |
1651 } | 1651 } |
1652 } | 1652 } |
1653 | 1653 |
1654 | 1654 |
1655 intptr_t NewSpace::GetNextInlineAllocationStepSize() { | 1655 intptr_t NewSpace::GetNextInlineAllocationStepSize() { |
1656 intptr_t next_step = 0; | 1656 intptr_t next_step = 0; |
1657 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1657 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { |
1658 InlineAllocationObserver* o = inline_allocation_observers_[i]; | 1658 AllocationObserver* o = inline_allocation_observers_[i]; |
1659 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) | 1659 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) |
1660 : o->bytes_to_next_step(); | 1660 : o->bytes_to_next_step(); |
1661 } | 1661 } |
1662 DCHECK(inline_allocation_observers_.length() == 0 || next_step != 0); | 1662 DCHECK(inline_allocation_observers_.length() == 0 || next_step != 0); |
1663 return next_step; | 1663 return next_step; |
1664 } | 1664 } |
1665 | 1665 |
1666 | 1666 |
1667 void NewSpace::AddInlineAllocationObserver(InlineAllocationObserver* observer) { | 1667 void NewSpace::AddInlineAllocationObserver(AllocationObserver* observer) { |
1668 inline_allocation_observers_.Add(observer); | 1668 inline_allocation_observers_.Add(observer); |
1669 StartNextInlineAllocationStep(); | 1669 StartNextInlineAllocationStep(); |
1670 } | 1670 } |
1671 | 1671 |
1672 | 1672 |
1673 void NewSpace::RemoveInlineAllocationObserver( | 1673 void NewSpace::RemoveInlineAllocationObserver(AllocationObserver* observer) { |
1674 InlineAllocationObserver* observer) { | |
1675 bool removed = inline_allocation_observers_.RemoveElement(observer); | 1674 bool removed = inline_allocation_observers_.RemoveElement(observer); |
1676 // Only used in assertion. Suppress unused variable warning. | 1675 // Only used in assertion. Suppress unused variable warning. |
1677 static_cast<void>(removed); | 1676 static_cast<void>(removed); |
1678 DCHECK(removed); | 1677 DCHECK(removed); |
1679 StartNextInlineAllocationStep(); | 1678 StartNextInlineAllocationStep(); |
1680 } | 1679 } |
1681 | 1680 |
1682 | 1681 |
1683 void NewSpace::PauseInlineAllocationObservers() { | 1682 void NewSpace::PauseInlineAllocationObservers() { |
1684 // Do a step to account for memory allocated so far. | 1683 // Do a step to account for memory allocated so far. |
1685 InlineAllocationStep(top(), top(), nullptr, 0); | 1684 InlineAllocationStep(top(), top(), nullptr, 0); |
1686 inline_allocation_observers_paused_ = true; | 1685 inline_allocation_observers_paused_ = true; |
1687 top_on_previous_step_ = 0; | 1686 top_on_previous_step_ = 0; |
1688 UpdateInlineAllocationLimit(0); | 1687 UpdateInlineAllocationLimit(0); |
1689 } | 1688 } |
1690 | 1689 |
1691 | 1690 |
1692 void NewSpace::ResumeInlineAllocationObservers() { | 1691 void NewSpace::ResumeInlineAllocationObservers() { |
1693 DCHECK(top_on_previous_step_ == 0); | 1692 DCHECK(top_on_previous_step_ == 0); |
1694 inline_allocation_observers_paused_ = false; | 1693 inline_allocation_observers_paused_ = false; |
1695 StartNextInlineAllocationStep(); | 1694 StartNextInlineAllocationStep(); |
1696 } | 1695 } |
1697 | 1696 |
1698 | 1697 |
1699 void NewSpace::InlineAllocationStep(Address top, Address new_top, | 1698 void NewSpace::InlineAllocationStep(Address top, Address new_top, |
1700 Address soon_object, size_t size) { | 1699 Address soon_object, size_t size) { |
1701 if (top_on_previous_step_) { | 1700 if (top_on_previous_step_) { |
1702 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); | 1701 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); |
1703 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1702 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { |
1704 inline_allocation_observers_[i]->InlineAllocationStep(bytes_allocated, | 1703 inline_allocation_observers_[i]->AllocationStep(bytes_allocated, |
1705 soon_object, size); | 1704 soon_object, size); |
1706 } | 1705 } |
1707 top_on_previous_step_ = new_top; | 1706 top_on_previous_step_ = new_top; |
1708 } | 1707 } |
1709 } | 1708 } |
1710 | 1709 |
1711 #ifdef VERIFY_HEAP | 1710 #ifdef VERIFY_HEAP |
1712 // We do not use the SemiSpaceIterator because verification doesn't assume | 1711 // We do not use the SemiSpaceIterator because verification doesn't assume |
1713 // that it works (it depends on the invariants we are checking). | 1712 // that it works (it depends on the invariants we are checking). |
1714 void NewSpace::Verify() { | 1713 void NewSpace::Verify() { |
1715 // The allocation pointer should be in the space or at the very end. | 1714 // The allocation pointer should be in the space or at the very end. |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2616 // Don't free list allocate if there is linear space available. | 2615 // Don't free list allocate if there is linear space available. |
2617 DCHECK(owner_->limit() - owner_->top() < size_in_bytes); | 2616 DCHECK(owner_->limit() - owner_->top() < size_in_bytes); |
2618 | 2617 |
2619 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); | 2618 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); |
2620 // Mark the old linear allocation area with a free space map so it can be | 2619 // Mark the old linear allocation area with a free space map so it can be |
2621 // skipped when scanning the heap. This also puts it back in the free list | 2620 // skipped when scanning the heap. This also puts it back in the free list |
2622 // if it is big enough. | 2621 // if it is big enough. |
2623 owner_->Free(owner_->top(), old_linear_size); | 2622 owner_->Free(owner_->top(), old_linear_size); |
2624 owner_->SetTopAndLimit(nullptr, nullptr); | 2623 owner_->SetTopAndLimit(nullptr, nullptr); |
2625 | 2624 |
2626 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - | 2625 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - |
ofrobots
2016/01/23 16:16:31
You probably need to notify the observers here too
ofrobots
2016/01/26 00:41:51
*bump*
mattloring
2016/01/26 00:42:48
Done.
| |
2627 old_linear_size); | 2626 old_linear_size); |
2628 | 2627 |
2629 int new_node_size = 0; | 2628 int new_node_size = 0; |
2630 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); | 2629 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
2631 if (new_node == nullptr) return nullptr; | 2630 if (new_node == nullptr) return nullptr; |
2632 | 2631 |
2633 int bytes_left = new_node_size - size_in_bytes; | 2632 int bytes_left = new_node_size - size_in_bytes; |
2634 DCHECK(bytes_left >= 0); | 2633 DCHECK(bytes_left >= 0); |
2635 | 2634 |
2636 #ifdef DEBUG | 2635 #ifdef DEBUG |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3133 | 3132 |
3134 if (Heap::ShouldZapGarbage()) { | 3133 if (Heap::ShouldZapGarbage()) { |
3135 // Make the object consistent so the heap can be verified in OldSpaceStep. | 3134 // Make the object consistent so the heap can be verified in OldSpaceStep. |
3136 // We only need to do this in debug builds or if verify_heap is on. | 3135 // We only need to do this in debug builds or if verify_heap is on. |
3137 reinterpret_cast<Object**>(object->address())[0] = | 3136 reinterpret_cast<Object**>(object->address())[0] = |
3138 heap()->fixed_array_map(); | 3137 heap()->fixed_array_map(); |
3139 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 3138 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); |
3140 } | 3139 } |
3141 | 3140 |
3142 heap()->incremental_marking()->OldSpaceStep(object_size); | 3141 heap()->incremental_marking()->OldSpaceStep(object_size); |
3142 for (int i = 0; i < allocation_observers_.length(); ++i) { | |
3143 AllocationObserver* o = allocation_observers_[i]; | |
3144 o->AllocationStep(object_size, object->address(), object_size); | |
3145 } | |
ofrobots
2016/01/23 16:16:31
This loop has been duplicated in a few places. It
mattloring
2016/01/26 00:42:48
Done.
| |
3143 return object; | 3146 return object; |
3144 } | 3147 } |
3145 | 3148 |
3146 | 3149 |
3147 size_t LargeObjectSpace::CommittedPhysicalMemory() { | 3150 size_t LargeObjectSpace::CommittedPhysicalMemory() { |
3148 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 3151 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); |
3149 size_t size = 0; | 3152 size_t size = 0; |
3150 LargePage* current = first_page_; | 3153 LargePage* current = first_page_; |
3151 while (current != NULL) { | 3154 while (current != NULL) { |
3152 size += current->CommittedPhysicalMemory(); | 3155 size += current->CommittedPhysicalMemory(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3364 object->ShortPrint(); | 3367 object->ShortPrint(); |
3365 PrintF("\n"); | 3368 PrintF("\n"); |
3366 } | 3369 } |
3367 printf(" --------------------------------------\n"); | 3370 printf(" --------------------------------------\n"); |
3368 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3371 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3369 } | 3372 } |
3370 | 3373 |
3371 #endif // DEBUG | 3374 #endif // DEBUG |
3372 } // namespace internal | 3375 } // namespace internal |
3373 } // namespace v8 | 3376 } // namespace v8 |
OLD | NEW |