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 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == | 943 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == |
944 ObjectSpace::kObjectSpaceNewSpace); | 944 ObjectSpace::kObjectSpaceNewSpace); |
945 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == | 945 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == |
946 ObjectSpace::kObjectSpaceOldSpace); | 946 ObjectSpace::kObjectSpaceOldSpace); |
947 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == | 947 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == |
948 ObjectSpace::kObjectSpaceCodeSpace); | 948 ObjectSpace::kObjectSpaceCodeSpace); |
949 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == | 949 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == |
950 ObjectSpace::kObjectSpaceMapSpace); | 950 ObjectSpace::kObjectSpaceMapSpace); |
951 | 951 |
952 | 952 |
| 953 void Space::AllocationStep(Address soon_object, int size) { |
| 954 if (!allocation_observers_paused_) { |
| 955 for (int i = 0; i < allocation_observers_->length(); ++i) { |
| 956 AllocationObserver* o = (*allocation_observers_)[i]; |
| 957 o->AllocationStep(size, soon_object, size); |
| 958 } |
| 959 } |
| 960 } |
| 961 |
| 962 |
953 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, | 963 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, |
954 Executability executable) | 964 Executability executable) |
955 : Space(heap, space, executable), free_list_(this) { | 965 : Space(heap, space, executable), free_list_(this) { |
956 area_size_ = MemoryAllocator::PageAreaSize(space); | 966 area_size_ = MemoryAllocator::PageAreaSize(space); |
957 accounting_stats_.Clear(); | 967 accounting_stats_.Clear(); |
958 | 968 |
959 allocation_info_.Reset(nullptr, nullptr); | 969 allocation_info_.Reset(nullptr, nullptr); |
960 | 970 |
961 anchor_.InitializeAsAnchor(this); | 971 anchor_.InitializeAsAnchor(this); |
962 } | 972 } |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0); | 1546 InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0); |
1537 } | 1547 } |
1538 | 1548 |
1539 | 1549 |
1540 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { | 1550 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { |
1541 if (heap()->inline_allocation_disabled()) { | 1551 if (heap()->inline_allocation_disabled()) { |
1542 // Lowest limit when linear allocation was disabled. | 1552 // Lowest limit when linear allocation was disabled. |
1543 Address high = to_space_.page_high(); | 1553 Address high = to_space_.page_high(); |
1544 Address new_top = allocation_info_.top() + size_in_bytes; | 1554 Address new_top = allocation_info_.top() + size_in_bytes; |
1545 allocation_info_.set_limit(Min(new_top, high)); | 1555 allocation_info_.set_limit(Min(new_top, high)); |
1546 } else if (inline_allocation_observers_paused_ || | 1556 } else if (allocation_observers_paused_ || top_on_previous_step_ == 0) { |
1547 top_on_previous_step_ == 0) { | |
1548 // Normal limit is the end of the current page. | 1557 // Normal limit is the end of the current page. |
1549 allocation_info_.set_limit(to_space_.page_high()); | 1558 allocation_info_.set_limit(to_space_.page_high()); |
1550 } else { | 1559 } else { |
1551 // Lower limit during incremental marking. | 1560 // Lower limit during incremental marking. |
1552 Address high = to_space_.page_high(); | 1561 Address high = to_space_.page_high(); |
1553 Address new_top = allocation_info_.top() + size_in_bytes; | 1562 Address new_top = allocation_info_.top() + size_in_bytes; |
1554 Address new_limit = new_top + GetNextInlineAllocationStepSize() - 1; | 1563 Address new_limit = new_top + GetNextInlineAllocationStepSize() - 1; |
1555 allocation_info_.set_limit(Min(new_limit, high)); | 1564 allocation_info_.set_limit(Min(new_limit, high)); |
1556 } | 1565 } |
1557 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1566 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 Address new_top = old_top + aligned_size_in_bytes; | 1646 Address new_top = old_top + aligned_size_in_bytes; |
1638 Address soon_object = old_top + filler_size; | 1647 Address soon_object = old_top + filler_size; |
1639 InlineAllocationStep(new_top, new_top, soon_object, size_in_bytes); | 1648 InlineAllocationStep(new_top, new_top, soon_object, size_in_bytes); |
1640 UpdateInlineAllocationLimit(aligned_size_in_bytes); | 1649 UpdateInlineAllocationLimit(aligned_size_in_bytes); |
1641 } | 1650 } |
1642 return true; | 1651 return true; |
1643 } | 1652 } |
1644 | 1653 |
1645 | 1654 |
1646 void NewSpace::StartNextInlineAllocationStep() { | 1655 void NewSpace::StartNextInlineAllocationStep() { |
1647 if (!inline_allocation_observers_paused_) { | 1656 if (!allocation_observers_paused_) { |
1648 top_on_previous_step_ = | 1657 top_on_previous_step_ = |
1649 inline_allocation_observers_.length() ? allocation_info_.top() : 0; | 1658 allocation_observers_->length() ? allocation_info_.top() : 0; |
1650 UpdateInlineAllocationLimit(0); | 1659 UpdateInlineAllocationLimit(0); |
1651 } | 1660 } |
1652 } | 1661 } |
1653 | 1662 |
1654 | 1663 |
1655 intptr_t NewSpace::GetNextInlineAllocationStepSize() { | 1664 intptr_t NewSpace::GetNextInlineAllocationStepSize() { |
1656 intptr_t next_step = 0; | 1665 intptr_t next_step = 0; |
1657 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1666 for (int i = 0; i < allocation_observers_->length(); ++i) { |
1658 InlineAllocationObserver* o = inline_allocation_observers_[i]; | 1667 AllocationObserver* o = (*allocation_observers_)[i]; |
1659 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) | 1668 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) |
1660 : o->bytes_to_next_step(); | 1669 : o->bytes_to_next_step(); |
1661 } | 1670 } |
1662 DCHECK(inline_allocation_observers_.length() == 0 || next_step != 0); | 1671 DCHECK(allocation_observers_->length() == 0 || next_step != 0); |
1663 return next_step; | 1672 return next_step; |
1664 } | 1673 } |
1665 | 1674 |
1666 | 1675 |
1667 void NewSpace::AddInlineAllocationObserver(InlineAllocationObserver* observer) { | 1676 void NewSpace::AddAllocationObserver(AllocationObserver* observer) { |
1668 inline_allocation_observers_.Add(observer); | 1677 Space::AddAllocationObserver(observer); |
1669 StartNextInlineAllocationStep(); | 1678 StartNextInlineAllocationStep(); |
1670 } | 1679 } |
1671 | 1680 |
1672 | 1681 |
1673 void NewSpace::RemoveInlineAllocationObserver( | 1682 void NewSpace::RemoveAllocationObserver(AllocationObserver* observer) { |
1674 InlineAllocationObserver* observer) { | 1683 Space::RemoveAllocationObserver(observer); |
1675 bool removed = inline_allocation_observers_.RemoveElement(observer); | |
1676 // Only used in assertion. Suppress unused variable warning. | |
1677 static_cast<void>(removed); | |
1678 DCHECK(removed); | |
1679 StartNextInlineAllocationStep(); | 1684 StartNextInlineAllocationStep(); |
1680 } | 1685 } |
1681 | 1686 |
1682 | 1687 |
1683 void NewSpace::PauseInlineAllocationObservers() { | 1688 void NewSpace::PauseAllocationObservers() { |
1684 // Do a step to account for memory allocated so far. | 1689 // Do a step to account for memory allocated so far. |
1685 InlineAllocationStep(top(), top(), nullptr, 0); | 1690 InlineAllocationStep(top(), top(), nullptr, 0); |
1686 inline_allocation_observers_paused_ = true; | 1691 Space::PauseAllocationObservers(); |
1687 top_on_previous_step_ = 0; | 1692 top_on_previous_step_ = 0; |
1688 UpdateInlineAllocationLimit(0); | 1693 UpdateInlineAllocationLimit(0); |
1689 } | 1694 } |
1690 | 1695 |
1691 | 1696 |
1692 void NewSpace::ResumeInlineAllocationObservers() { | 1697 void NewSpace::ResumeAllocationObservers() { |
1693 DCHECK(top_on_previous_step_ == 0); | 1698 DCHECK(top_on_previous_step_ == 0); |
1694 inline_allocation_observers_paused_ = false; | 1699 Space::ResumeAllocationObservers(); |
1695 StartNextInlineAllocationStep(); | 1700 StartNextInlineAllocationStep(); |
1696 } | 1701 } |
1697 | 1702 |
1698 | 1703 |
1699 void NewSpace::InlineAllocationStep(Address top, Address new_top, | 1704 void NewSpace::InlineAllocationStep(Address top, Address new_top, |
1700 Address soon_object, size_t size) { | 1705 Address soon_object, size_t size) { |
1701 if (top_on_previous_step_) { | 1706 if (top_on_previous_step_) { |
1702 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); | 1707 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); |
1703 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1708 for (int i = 0; i < allocation_observers_->length(); ++i) { |
1704 inline_allocation_observers_[i]->InlineAllocationStep(bytes_allocated, | 1709 (*allocation_observers_)[i]->AllocationStep(bytes_allocated, soon_object, |
1705 soon_object, size); | 1710 size); |
1706 } | 1711 } |
1707 top_on_previous_step_ = new_top; | 1712 top_on_previous_step_ = new_top; |
1708 } | 1713 } |
1709 } | 1714 } |
1710 | 1715 |
1711 #ifdef VERIFY_HEAP | 1716 #ifdef VERIFY_HEAP |
1712 // We do not use the SemiSpaceIterator because verification doesn't assume | 1717 // We do not use the SemiSpaceIterator because verification doesn't assume |
1713 // that it works (it depends on the invariants we are checking). | 1718 // that it works (it depends on the invariants we are checking). |
1714 void NewSpace::Verify() { | 1719 void NewSpace::Verify() { |
1715 // The allocation pointer should be in the space or at the very end. | 1720 // The allocation pointer should be in the space or at the very end. |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2622 // if it is big enough. | 2627 // if it is big enough. |
2623 owner_->Free(owner_->top(), old_linear_size); | 2628 owner_->Free(owner_->top(), old_linear_size); |
2624 owner_->SetTopAndLimit(nullptr, nullptr); | 2629 owner_->SetTopAndLimit(nullptr, nullptr); |
2625 | 2630 |
2626 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - | 2631 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - |
2627 old_linear_size); | 2632 old_linear_size); |
2628 | 2633 |
2629 int new_node_size = 0; | 2634 int new_node_size = 0; |
2630 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); | 2635 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
2631 if (new_node == nullptr) return nullptr; | 2636 if (new_node == nullptr) return nullptr; |
| 2637 owner_->AllocationStep(new_node->address(), size_in_bytes); |
2632 | 2638 |
2633 int bytes_left = new_node_size - size_in_bytes; | 2639 int bytes_left = new_node_size - size_in_bytes; |
2634 DCHECK(bytes_left >= 0); | 2640 DCHECK(bytes_left >= 0); |
2635 | 2641 |
2636 #ifdef DEBUG | 2642 #ifdef DEBUG |
2637 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { | 2643 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { |
2638 reinterpret_cast<Object**>(new_node->address())[i] = | 2644 reinterpret_cast<Object**>(new_node->address())[i] = |
2639 Smi::FromInt(kCodeZapValue); | 2645 Smi::FromInt(kCodeZapValue); |
2640 } | 2646 } |
2641 #endif | 2647 #endif |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3133 | 3139 |
3134 if (Heap::ShouldZapGarbage()) { | 3140 if (Heap::ShouldZapGarbage()) { |
3135 // Make the object consistent so the heap can be verified in OldSpaceStep. | 3141 // 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. | 3142 // We only need to do this in debug builds or if verify_heap is on. |
3137 reinterpret_cast<Object**>(object->address())[0] = | 3143 reinterpret_cast<Object**>(object->address())[0] = |
3138 heap()->fixed_array_map(); | 3144 heap()->fixed_array_map(); |
3139 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 3145 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); |
3140 } | 3146 } |
3141 | 3147 |
3142 heap()->incremental_marking()->OldSpaceStep(object_size); | 3148 heap()->incremental_marking()->OldSpaceStep(object_size); |
| 3149 AllocationStep(object->address(), object_size); |
3143 return object; | 3150 return object; |
3144 } | 3151 } |
3145 | 3152 |
3146 | 3153 |
3147 size_t LargeObjectSpace::CommittedPhysicalMemory() { | 3154 size_t LargeObjectSpace::CommittedPhysicalMemory() { |
3148 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 3155 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); |
3149 size_t size = 0; | 3156 size_t size = 0; |
3150 LargePage* current = first_page_; | 3157 LargePage* current = first_page_; |
3151 while (current != NULL) { | 3158 while (current != NULL) { |
3152 size += current->CommittedPhysicalMemory(); | 3159 size += current->CommittedPhysicalMemory(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3364 object->ShortPrint(); | 3371 object->ShortPrint(); |
3365 PrintF("\n"); | 3372 PrintF("\n"); |
3366 } | 3373 } |
3367 printf(" --------------------------------------\n"); | 3374 printf(" --------------------------------------\n"); |
3368 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3375 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3369 } | 3376 } |
3370 | 3377 |
3371 #endif // DEBUG | 3378 #endif // DEBUG |
3372 } // namespace internal | 3379 } // namespace internal |
3373 } // namespace v8 | 3380 } // namespace v8 |
OLD | NEW |