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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 cur_page = cur_page->next_page(); | 63 cur_page = cur_page->next_page(); |
64 if (cur_page == space_->anchor()) return false; | 64 if (cur_page == space_->anchor()) return false; |
65 cur_page->heap()->mark_compact_collector()->SweepOrWaitUntilSweepingCompleted( | 65 cur_page->heap()->mark_compact_collector()->SweepOrWaitUntilSweepingCompleted( |
66 cur_page); | 66 cur_page); |
67 cur_addr_ = cur_page->area_start(); | 67 cur_addr_ = cur_page->area_start(); |
68 cur_end_ = cur_page->area_end(); | 68 cur_end_ = cur_page->area_end(); |
69 DCHECK(cur_page->SweepingDone()); | 69 DCHECK(cur_page->SweepingDone()); |
70 return true; | 70 return true; |
71 } | 71 } |
72 | 72 |
| 73 PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap) |
| 74 : heap_(heap) { |
| 75 AllSpaces spaces(heap_); |
| 76 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
| 77 space->PauseAllocationObservers(); |
| 78 } |
| 79 } |
| 80 |
| 81 PauseAllocationObserversScope::~PauseAllocationObserversScope() { |
| 82 AllSpaces spaces(heap_); |
| 83 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
| 84 space->ResumeAllocationObservers(); |
| 85 } |
| 86 } |
73 | 87 |
74 // ----------------------------------------------------------------------------- | 88 // ----------------------------------------------------------------------------- |
75 // CodeRange | 89 // CodeRange |
76 | 90 |
77 | 91 |
78 CodeRange::CodeRange(Isolate* isolate) | 92 CodeRange::CodeRange(Isolate* isolate) |
79 : isolate_(isolate), | 93 : isolate_(isolate), |
80 code_range_(NULL), | 94 code_range_(NULL), |
81 free_list_(0), | 95 free_list_(0), |
82 allocation_list_(0), | 96 allocation_list_(0), |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 | 955 |
942 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == | 956 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == |
943 ObjectSpace::kObjectSpaceNewSpace); | 957 ObjectSpace::kObjectSpaceNewSpace); |
944 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == | 958 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == |
945 ObjectSpace::kObjectSpaceOldSpace); | 959 ObjectSpace::kObjectSpaceOldSpace); |
946 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == | 960 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == |
947 ObjectSpace::kObjectSpaceCodeSpace); | 961 ObjectSpace::kObjectSpaceCodeSpace); |
948 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == | 962 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == |
949 ObjectSpace::kObjectSpaceMapSpace); | 963 ObjectSpace::kObjectSpaceMapSpace); |
950 | 964 |
| 965 void Space::AllocationStep(Address soon_object, int size) { |
| 966 if (!allocation_observers_paused_) { |
| 967 for (int i = 0; i < allocation_observers_->length(); ++i) { |
| 968 AllocationObserver* o = (*allocation_observers_)[i]; |
| 969 o->AllocationStep(size, soon_object, size); |
| 970 } |
| 971 } |
| 972 } |
951 | 973 |
952 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, | 974 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, |
953 Executability executable) | 975 Executability executable) |
954 : Space(heap, space, executable), free_list_(this) { | 976 : Space(heap, space, executable), free_list_(this) { |
955 area_size_ = MemoryAllocator::PageAreaSize(space); | 977 area_size_ = MemoryAllocator::PageAreaSize(space); |
956 accounting_stats_.Clear(); | 978 accounting_stats_.Clear(); |
957 | 979 |
958 allocation_info_.Reset(nullptr, nullptr); | 980 allocation_info_.Reset(nullptr, nullptr); |
959 | 981 |
960 anchor_.InitializeAsAnchor(this); | 982 anchor_.InitializeAsAnchor(this); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0); | 1524 InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0); |
1503 } | 1525 } |
1504 | 1526 |
1505 | 1527 |
1506 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { | 1528 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { |
1507 if (heap()->inline_allocation_disabled()) { | 1529 if (heap()->inline_allocation_disabled()) { |
1508 // Lowest limit when linear allocation was disabled. | 1530 // Lowest limit when linear allocation was disabled. |
1509 Address high = to_space_.page_high(); | 1531 Address high = to_space_.page_high(); |
1510 Address new_top = allocation_info_.top() + size_in_bytes; | 1532 Address new_top = allocation_info_.top() + size_in_bytes; |
1511 allocation_info_.set_limit(Min(new_top, high)); | 1533 allocation_info_.set_limit(Min(new_top, high)); |
1512 } else if (inline_allocation_observers_paused_ || | 1534 } else if (allocation_observers_paused_ || top_on_previous_step_ == 0) { |
1513 top_on_previous_step_ == 0) { | |
1514 // Normal limit is the end of the current page. | 1535 // Normal limit is the end of the current page. |
1515 allocation_info_.set_limit(to_space_.page_high()); | 1536 allocation_info_.set_limit(to_space_.page_high()); |
1516 } else { | 1537 } else { |
1517 // Lower limit during incremental marking. | 1538 // Lower limit during incremental marking. |
1518 Address high = to_space_.page_high(); | 1539 Address high = to_space_.page_high(); |
1519 Address new_top = allocation_info_.top() + size_in_bytes; | 1540 Address new_top = allocation_info_.top() + size_in_bytes; |
1520 Address new_limit = new_top + GetNextInlineAllocationStepSize() - 1; | 1541 Address new_limit = new_top + GetNextInlineAllocationStepSize() - 1; |
1521 allocation_info_.set_limit(Min(new_limit, high)); | 1542 allocation_info_.set_limit(Min(new_limit, high)); |
1522 } | 1543 } |
1523 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1544 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 Address new_top = old_top + aligned_size_in_bytes; | 1605 Address new_top = old_top + aligned_size_in_bytes; |
1585 Address soon_object = old_top + filler_size; | 1606 Address soon_object = old_top + filler_size; |
1586 InlineAllocationStep(new_top, new_top, soon_object, size_in_bytes); | 1607 InlineAllocationStep(new_top, new_top, soon_object, size_in_bytes); |
1587 UpdateInlineAllocationLimit(aligned_size_in_bytes); | 1608 UpdateInlineAllocationLimit(aligned_size_in_bytes); |
1588 } | 1609 } |
1589 return true; | 1610 return true; |
1590 } | 1611 } |
1591 | 1612 |
1592 | 1613 |
1593 void NewSpace::StartNextInlineAllocationStep() { | 1614 void NewSpace::StartNextInlineAllocationStep() { |
1594 if (!inline_allocation_observers_paused_) { | 1615 if (!allocation_observers_paused_) { |
1595 top_on_previous_step_ = | 1616 top_on_previous_step_ = |
1596 inline_allocation_observers_.length() ? allocation_info_.top() : 0; | 1617 allocation_observers_->length() ? allocation_info_.top() : 0; |
1597 UpdateInlineAllocationLimit(0); | 1618 UpdateInlineAllocationLimit(0); |
1598 } | 1619 } |
1599 } | 1620 } |
1600 | 1621 |
1601 | 1622 |
1602 intptr_t NewSpace::GetNextInlineAllocationStepSize() { | 1623 intptr_t NewSpace::GetNextInlineAllocationStepSize() { |
1603 intptr_t next_step = 0; | 1624 intptr_t next_step = 0; |
1604 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1625 for (int i = 0; i < allocation_observers_->length(); ++i) { |
1605 InlineAllocationObserver* o = inline_allocation_observers_[i]; | 1626 AllocationObserver* o = (*allocation_observers_)[i]; |
1606 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) | 1627 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) |
1607 : o->bytes_to_next_step(); | 1628 : o->bytes_to_next_step(); |
1608 } | 1629 } |
1609 DCHECK(inline_allocation_observers_.length() == 0 || next_step != 0); | 1630 DCHECK(allocation_observers_->length() == 0 || next_step != 0); |
1610 return next_step; | 1631 return next_step; |
1611 } | 1632 } |
1612 | 1633 |
1613 | 1634 void NewSpace::AddAllocationObserver(AllocationObserver* observer) { |
1614 void NewSpace::AddInlineAllocationObserver(InlineAllocationObserver* observer) { | 1635 Space::AddAllocationObserver(observer); |
1615 inline_allocation_observers_.Add(observer); | |
1616 StartNextInlineAllocationStep(); | 1636 StartNextInlineAllocationStep(); |
1617 } | 1637 } |
1618 | 1638 |
1619 | 1639 void NewSpace::RemoveAllocationObserver(AllocationObserver* observer) { |
1620 void NewSpace::RemoveInlineAllocationObserver( | 1640 Space::RemoveAllocationObserver(observer); |
1621 InlineAllocationObserver* observer) { | |
1622 bool removed = inline_allocation_observers_.RemoveElement(observer); | |
1623 // Only used in assertion. Suppress unused variable warning. | |
1624 static_cast<void>(removed); | |
1625 DCHECK(removed); | |
1626 StartNextInlineAllocationStep(); | 1641 StartNextInlineAllocationStep(); |
1627 } | 1642 } |
1628 | 1643 |
1629 | 1644 void NewSpace::PauseAllocationObservers() { |
1630 void NewSpace::PauseInlineAllocationObservers() { | |
1631 // Do a step to account for memory allocated so far. | 1645 // Do a step to account for memory allocated so far. |
1632 InlineAllocationStep(top(), top(), nullptr, 0); | 1646 InlineAllocationStep(top(), top(), nullptr, 0); |
1633 inline_allocation_observers_paused_ = true; | 1647 Space::PauseAllocationObservers(); |
1634 top_on_previous_step_ = 0; | 1648 top_on_previous_step_ = 0; |
1635 UpdateInlineAllocationLimit(0); | 1649 UpdateInlineAllocationLimit(0); |
1636 } | 1650 } |
1637 | 1651 |
1638 | 1652 void NewSpace::ResumeAllocationObservers() { |
1639 void NewSpace::ResumeInlineAllocationObservers() { | |
1640 DCHECK(top_on_previous_step_ == 0); | 1653 DCHECK(top_on_previous_step_ == 0); |
1641 inline_allocation_observers_paused_ = false; | 1654 Space::ResumeAllocationObservers(); |
1642 StartNextInlineAllocationStep(); | 1655 StartNextInlineAllocationStep(); |
1643 } | 1656 } |
1644 | 1657 |
1645 | 1658 |
1646 void NewSpace::InlineAllocationStep(Address top, Address new_top, | 1659 void NewSpace::InlineAllocationStep(Address top, Address new_top, |
1647 Address soon_object, size_t size) { | 1660 Address soon_object, size_t size) { |
1648 if (top_on_previous_step_) { | 1661 if (top_on_previous_step_) { |
1649 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); | 1662 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); |
1650 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1663 for (int i = 0; i < allocation_observers_->length(); ++i) { |
1651 inline_allocation_observers_[i]->InlineAllocationStep(bytes_allocated, | 1664 (*allocation_observers_)[i]->AllocationStep(bytes_allocated, soon_object, |
1652 soon_object, size); | 1665 size); |
1653 } | 1666 } |
1654 top_on_previous_step_ = new_top; | 1667 top_on_previous_step_ = new_top; |
1655 } | 1668 } |
1656 } | 1669 } |
1657 | 1670 |
1658 #ifdef VERIFY_HEAP | 1671 #ifdef VERIFY_HEAP |
1659 // We do not use the SemiSpaceIterator because verification doesn't assume | 1672 // We do not use the SemiSpaceIterator because verification doesn't assume |
1660 // that it works (it depends on the invariants we are checking). | 1673 // that it works (it depends on the invariants we are checking). |
1661 void NewSpace::Verify() { | 1674 void NewSpace::Verify() { |
1662 // The allocation pointer should be in the space or at the very end. | 1675 // The allocation pointer should be in the space or at the very end. |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2543 // if it is big enough. | 2556 // if it is big enough. |
2544 owner_->Free(owner_->top(), old_linear_size); | 2557 owner_->Free(owner_->top(), old_linear_size); |
2545 owner_->SetTopAndLimit(nullptr, nullptr); | 2558 owner_->SetTopAndLimit(nullptr, nullptr); |
2546 | 2559 |
2547 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - | 2560 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - |
2548 old_linear_size); | 2561 old_linear_size); |
2549 | 2562 |
2550 int new_node_size = 0; | 2563 int new_node_size = 0; |
2551 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); | 2564 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
2552 if (new_node == nullptr) return nullptr; | 2565 if (new_node == nullptr) return nullptr; |
| 2566 owner_->AllocationStep(new_node->address(), size_in_bytes); |
2553 | 2567 |
2554 int bytes_left = new_node_size - size_in_bytes; | 2568 int bytes_left = new_node_size - size_in_bytes; |
2555 DCHECK(bytes_left >= 0); | 2569 DCHECK(bytes_left >= 0); |
2556 | 2570 |
2557 #ifdef DEBUG | 2571 #ifdef DEBUG |
2558 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { | 2572 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { |
2559 reinterpret_cast<Object**>(new_node->address())[i] = | 2573 reinterpret_cast<Object**>(new_node->address())[i] = |
2560 Smi::FromInt(kCodeZapValue); | 2574 Smi::FromInt(kCodeZapValue); |
2561 } | 2575 } |
2562 #endif | 2576 #endif |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3054 | 3068 |
3055 if (Heap::ShouldZapGarbage()) { | 3069 if (Heap::ShouldZapGarbage()) { |
3056 // Make the object consistent so the heap can be verified in OldSpaceStep. | 3070 // Make the object consistent so the heap can be verified in OldSpaceStep. |
3057 // We only need to do this in debug builds or if verify_heap is on. | 3071 // We only need to do this in debug builds or if verify_heap is on. |
3058 reinterpret_cast<Object**>(object->address())[0] = | 3072 reinterpret_cast<Object**>(object->address())[0] = |
3059 heap()->fixed_array_map(); | 3073 heap()->fixed_array_map(); |
3060 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 3074 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); |
3061 } | 3075 } |
3062 | 3076 |
3063 heap()->incremental_marking()->OldSpaceStep(object_size); | 3077 heap()->incremental_marking()->OldSpaceStep(object_size); |
| 3078 AllocationStep(object->address(), object_size); |
3064 return object; | 3079 return object; |
3065 } | 3080 } |
3066 | 3081 |
3067 | 3082 |
3068 size_t LargeObjectSpace::CommittedPhysicalMemory() { | 3083 size_t LargeObjectSpace::CommittedPhysicalMemory() { |
3069 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 3084 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); |
3070 size_t size = 0; | 3085 size_t size = 0; |
3071 LargePage* current = first_page_; | 3086 LargePage* current = first_page_; |
3072 while (current != NULL) { | 3087 while (current != NULL) { |
3073 size += current->CommittedPhysicalMemory(); | 3088 size += current->CommittedPhysicalMemory(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 object->ShortPrint(); | 3300 object->ShortPrint(); |
3286 PrintF("\n"); | 3301 PrintF("\n"); |
3287 } | 3302 } |
3288 printf(" --------------------------------------\n"); | 3303 printf(" --------------------------------------\n"); |
3289 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3304 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3290 } | 3305 } |
3291 | 3306 |
3292 #endif // DEBUG | 3307 #endif // DEBUG |
3293 } // namespace internal | 3308 } // namespace internal |
3294 } // namespace v8 | 3309 } // namespace v8 |
OLD | NEW |