| 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/slot-set.h" | 10 #include "src/heap/slot-set.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 cur_page = cur_page->next_page(); | 64 cur_page = cur_page->next_page(); |
| 65 if (cur_page == space_->anchor()) return false; | 65 if (cur_page == space_->anchor()) return false; |
| 66 cur_page->heap()->mark_compact_collector()->SweepOrWaitUntilSweepingCompleted( | 66 cur_page->heap()->mark_compact_collector()->SweepOrWaitUntilSweepingCompleted( |
| 67 cur_page); | 67 cur_page); |
| 68 cur_addr_ = cur_page->area_start(); | 68 cur_addr_ = cur_page->area_start(); |
| 69 cur_end_ = cur_page->area_end(); | 69 cur_end_ = cur_page->area_end(); |
| 70 DCHECK(cur_page->SweepingDone()); | 70 DCHECK(cur_page->SweepingDone()); |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 PauseAllocationObserversScope::PauseAllocationObserversScope(Heap* heap) |
| 75 : heap_(heap) { |
| 76 AllSpaces spaces(heap_); |
| 77 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
| 78 space->PauseAllocationObservers(); |
| 79 } |
| 80 } |
| 81 |
| 82 PauseAllocationObserversScope::~PauseAllocationObserversScope() { |
| 83 AllSpaces spaces(heap_); |
| 84 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) { |
| 85 space->ResumeAllocationObservers(); |
| 86 } |
| 87 } |
| 74 | 88 |
| 75 // ----------------------------------------------------------------------------- | 89 // ----------------------------------------------------------------------------- |
| 76 // CodeRange | 90 // CodeRange |
| 77 | 91 |
| 78 | 92 |
| 79 CodeRange::CodeRange(Isolate* isolate) | 93 CodeRange::CodeRange(Isolate* isolate) |
| 80 : isolate_(isolate), | 94 : isolate_(isolate), |
| 81 code_range_(NULL), | 95 code_range_(NULL), |
| 82 free_list_(0), | 96 free_list_(0), |
| 83 allocation_list_(0), | 97 allocation_list_(0), |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 | 972 |
| 959 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == | 973 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::NEW_SPACE) == |
| 960 ObjectSpace::kObjectSpaceNewSpace); | 974 ObjectSpace::kObjectSpaceNewSpace); |
| 961 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == | 975 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::OLD_SPACE) == |
| 962 ObjectSpace::kObjectSpaceOldSpace); | 976 ObjectSpace::kObjectSpaceOldSpace); |
| 963 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == | 977 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::CODE_SPACE) == |
| 964 ObjectSpace::kObjectSpaceCodeSpace); | 978 ObjectSpace::kObjectSpaceCodeSpace); |
| 965 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == | 979 STATIC_ASSERT(static_cast<ObjectSpace>(1 << AllocationSpace::MAP_SPACE) == |
| 966 ObjectSpace::kObjectSpaceMapSpace); | 980 ObjectSpace::kObjectSpaceMapSpace); |
| 967 | 981 |
| 982 void Space::AllocationStep(Address soon_object, int size) { |
| 983 if (!allocation_observers_paused_) { |
| 984 for (int i = 0; i < allocation_observers_->length(); ++i) { |
| 985 AllocationObserver* o = (*allocation_observers_)[i]; |
| 986 o->AllocationStep(size, soon_object, size); |
| 987 } |
| 988 } |
| 989 } |
| 968 | 990 |
| 969 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, | 991 PagedSpace::PagedSpace(Heap* heap, AllocationSpace space, |
| 970 Executability executable) | 992 Executability executable) |
| 971 : Space(heap, space, executable), free_list_(this) { | 993 : Space(heap, space, executable), free_list_(this) { |
| 972 area_size_ = MemoryAllocator::PageAreaSize(space); | 994 area_size_ = MemoryAllocator::PageAreaSize(space); |
| 973 accounting_stats_.Clear(); | 995 accounting_stats_.Clear(); |
| 974 | 996 |
| 975 allocation_info_.Reset(nullptr, nullptr); | 997 allocation_info_.Reset(nullptr, nullptr); |
| 976 | 998 |
| 977 anchor_.InitializeAsAnchor(this); | 999 anchor_.InitializeAsAnchor(this); |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0); | 1485 InlineAllocationStep(old_top, allocation_info_.top(), nullptr, 0); |
| 1464 } | 1486 } |
| 1465 | 1487 |
| 1466 | 1488 |
| 1467 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { | 1489 void NewSpace::UpdateInlineAllocationLimit(int size_in_bytes) { |
| 1468 if (heap()->inline_allocation_disabled()) { | 1490 if (heap()->inline_allocation_disabled()) { |
| 1469 // Lowest limit when linear allocation was disabled. | 1491 // Lowest limit when linear allocation was disabled. |
| 1470 Address high = to_space_.page_high(); | 1492 Address high = to_space_.page_high(); |
| 1471 Address new_top = allocation_info_.top() + size_in_bytes; | 1493 Address new_top = allocation_info_.top() + size_in_bytes; |
| 1472 allocation_info_.set_limit(Min(new_top, high)); | 1494 allocation_info_.set_limit(Min(new_top, high)); |
| 1473 } else if (inline_allocation_observers_paused_ || | 1495 } else if (allocation_observers_paused_ || top_on_previous_step_ == 0) { |
| 1474 top_on_previous_step_ == 0) { | |
| 1475 // Normal limit is the end of the current page. | 1496 // Normal limit is the end of the current page. |
| 1476 allocation_info_.set_limit(to_space_.page_high()); | 1497 allocation_info_.set_limit(to_space_.page_high()); |
| 1477 } else { | 1498 } else { |
| 1478 // Lower limit during incremental marking. | 1499 // Lower limit during incremental marking. |
| 1479 Address high = to_space_.page_high(); | 1500 Address high = to_space_.page_high(); |
| 1480 Address new_top = allocation_info_.top() + size_in_bytes; | 1501 Address new_top = allocation_info_.top() + size_in_bytes; |
| 1481 Address new_limit = new_top + GetNextInlineAllocationStepSize() - 1; | 1502 Address new_limit = new_top + GetNextInlineAllocationStepSize() - 1; |
| 1482 allocation_info_.set_limit(Min(new_limit, high)); | 1503 allocation_info_.set_limit(Min(new_limit, high)); |
| 1483 } | 1504 } |
| 1484 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1505 DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 Address new_top = old_top + aligned_size_in_bytes; | 1566 Address new_top = old_top + aligned_size_in_bytes; |
| 1546 Address soon_object = old_top + filler_size; | 1567 Address soon_object = old_top + filler_size; |
| 1547 InlineAllocationStep(new_top, new_top, soon_object, size_in_bytes); | 1568 InlineAllocationStep(new_top, new_top, soon_object, size_in_bytes); |
| 1548 UpdateInlineAllocationLimit(aligned_size_in_bytes); | 1569 UpdateInlineAllocationLimit(aligned_size_in_bytes); |
| 1549 } | 1570 } |
| 1550 return true; | 1571 return true; |
| 1551 } | 1572 } |
| 1552 | 1573 |
| 1553 | 1574 |
| 1554 void NewSpace::StartNextInlineAllocationStep() { | 1575 void NewSpace::StartNextInlineAllocationStep() { |
| 1555 if (!inline_allocation_observers_paused_) { | 1576 if (!allocation_observers_paused_) { |
| 1556 top_on_previous_step_ = | 1577 top_on_previous_step_ = |
| 1557 inline_allocation_observers_.length() ? allocation_info_.top() : 0; | 1578 allocation_observers_->length() ? allocation_info_.top() : 0; |
| 1558 UpdateInlineAllocationLimit(0); | 1579 UpdateInlineAllocationLimit(0); |
| 1559 } | 1580 } |
| 1560 } | 1581 } |
| 1561 | 1582 |
| 1562 | 1583 |
| 1563 intptr_t NewSpace::GetNextInlineAllocationStepSize() { | 1584 intptr_t NewSpace::GetNextInlineAllocationStepSize() { |
| 1564 intptr_t next_step = 0; | 1585 intptr_t next_step = 0; |
| 1565 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1586 for (int i = 0; i < allocation_observers_->length(); ++i) { |
| 1566 InlineAllocationObserver* o = inline_allocation_observers_[i]; | 1587 AllocationObserver* o = (*allocation_observers_)[i]; |
| 1567 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) | 1588 next_step = next_step ? Min(next_step, o->bytes_to_next_step()) |
| 1568 : o->bytes_to_next_step(); | 1589 : o->bytes_to_next_step(); |
| 1569 } | 1590 } |
| 1570 DCHECK(inline_allocation_observers_.length() == 0 || next_step != 0); | 1591 DCHECK(allocation_observers_->length() == 0 || next_step != 0); |
| 1571 return next_step; | 1592 return next_step; |
| 1572 } | 1593 } |
| 1573 | 1594 |
| 1574 | 1595 void NewSpace::AddAllocationObserver(AllocationObserver* observer) { |
| 1575 void NewSpace::AddInlineAllocationObserver(InlineAllocationObserver* observer) { | 1596 Space::AddAllocationObserver(observer); |
| 1576 inline_allocation_observers_.Add(observer); | |
| 1577 StartNextInlineAllocationStep(); | 1597 StartNextInlineAllocationStep(); |
| 1578 } | 1598 } |
| 1579 | 1599 |
| 1580 | 1600 void NewSpace::RemoveAllocationObserver(AllocationObserver* observer) { |
| 1581 void NewSpace::RemoveInlineAllocationObserver( | 1601 Space::RemoveAllocationObserver(observer); |
| 1582 InlineAllocationObserver* observer) { | |
| 1583 bool removed = inline_allocation_observers_.RemoveElement(observer); | |
| 1584 // Only used in assertion. Suppress unused variable warning. | |
| 1585 static_cast<void>(removed); | |
| 1586 DCHECK(removed); | |
| 1587 StartNextInlineAllocationStep(); | 1602 StartNextInlineAllocationStep(); |
| 1588 } | 1603 } |
| 1589 | 1604 |
| 1590 | 1605 void NewSpace::PauseAllocationObservers() { |
| 1591 void NewSpace::PauseInlineAllocationObservers() { | |
| 1592 // Do a step to account for memory allocated so far. | 1606 // Do a step to account for memory allocated so far. |
| 1593 InlineAllocationStep(top(), top(), nullptr, 0); | 1607 InlineAllocationStep(top(), top(), nullptr, 0); |
| 1594 inline_allocation_observers_paused_ = true; | 1608 Space::PauseAllocationObservers(); |
| 1595 top_on_previous_step_ = 0; | 1609 top_on_previous_step_ = 0; |
| 1596 UpdateInlineAllocationLimit(0); | 1610 UpdateInlineAllocationLimit(0); |
| 1597 } | 1611 } |
| 1598 | 1612 |
| 1599 | 1613 void NewSpace::ResumeAllocationObservers() { |
| 1600 void NewSpace::ResumeInlineAllocationObservers() { | |
| 1601 DCHECK(top_on_previous_step_ == 0); | 1614 DCHECK(top_on_previous_step_ == 0); |
| 1602 inline_allocation_observers_paused_ = false; | 1615 Space::ResumeAllocationObservers(); |
| 1603 StartNextInlineAllocationStep(); | 1616 StartNextInlineAllocationStep(); |
| 1604 } | 1617 } |
| 1605 | 1618 |
| 1606 | 1619 |
| 1607 void NewSpace::InlineAllocationStep(Address top, Address new_top, | 1620 void NewSpace::InlineAllocationStep(Address top, Address new_top, |
| 1608 Address soon_object, size_t size) { | 1621 Address soon_object, size_t size) { |
| 1609 if (top_on_previous_step_) { | 1622 if (top_on_previous_step_) { |
| 1610 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); | 1623 int bytes_allocated = static_cast<int>(top - top_on_previous_step_); |
| 1611 for (int i = 0; i < inline_allocation_observers_.length(); ++i) { | 1624 for (int i = 0; i < allocation_observers_->length(); ++i) { |
| 1612 inline_allocation_observers_[i]->InlineAllocationStep(bytes_allocated, | 1625 (*allocation_observers_)[i]->AllocationStep(bytes_allocated, soon_object, |
| 1613 soon_object, size); | 1626 size); |
| 1614 } | 1627 } |
| 1615 top_on_previous_step_ = new_top; | 1628 top_on_previous_step_ = new_top; |
| 1616 } | 1629 } |
| 1617 } | 1630 } |
| 1618 | 1631 |
| 1619 #ifdef VERIFY_HEAP | 1632 #ifdef VERIFY_HEAP |
| 1620 // We do not use the SemiSpaceIterator because verification doesn't assume | 1633 // We do not use the SemiSpaceIterator because verification doesn't assume |
| 1621 // that it works (it depends on the invariants we are checking). | 1634 // that it works (it depends on the invariants we are checking). |
| 1622 void NewSpace::Verify() { | 1635 void NewSpace::Verify() { |
| 1623 // The allocation pointer should be in the space or at the very end. | 1636 // The allocation pointer should be in the space or at the very end. |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2497 // if it is big enough. | 2510 // if it is big enough. |
| 2498 owner_->Free(owner_->top(), old_linear_size); | 2511 owner_->Free(owner_->top(), old_linear_size); |
| 2499 owner_->SetTopAndLimit(nullptr, nullptr); | 2512 owner_->SetTopAndLimit(nullptr, nullptr); |
| 2500 | 2513 |
| 2501 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - | 2514 owner_->heap()->incremental_marking()->OldSpaceStep(size_in_bytes - |
| 2502 old_linear_size); | 2515 old_linear_size); |
| 2503 | 2516 |
| 2504 int new_node_size = 0; | 2517 int new_node_size = 0; |
| 2505 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); | 2518 FreeSpace* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
| 2506 if (new_node == nullptr) return nullptr; | 2519 if (new_node == nullptr) return nullptr; |
| 2520 owner_->AllocationStep(new_node->address(), size_in_bytes); |
| 2507 | 2521 |
| 2508 int bytes_left = new_node_size - size_in_bytes; | 2522 int bytes_left = new_node_size - size_in_bytes; |
| 2509 DCHECK(bytes_left >= 0); | 2523 DCHECK(bytes_left >= 0); |
| 2510 | 2524 |
| 2511 #ifdef DEBUG | 2525 #ifdef DEBUG |
| 2512 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { | 2526 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { |
| 2513 reinterpret_cast<Object**>(new_node->address())[i] = | 2527 reinterpret_cast<Object**>(new_node->address())[i] = |
| 2514 Smi::FromInt(kCodeZapValue); | 2528 Smi::FromInt(kCodeZapValue); |
| 2515 } | 2529 } |
| 2516 #endif | 2530 #endif |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3008 | 3022 |
| 3009 if (Heap::ShouldZapGarbage()) { | 3023 if (Heap::ShouldZapGarbage()) { |
| 3010 // Make the object consistent so the heap can be verified in OldSpaceStep. | 3024 // Make the object consistent so the heap can be verified in OldSpaceStep. |
| 3011 // We only need to do this in debug builds or if verify_heap is on. | 3025 // We only need to do this in debug builds or if verify_heap is on. |
| 3012 reinterpret_cast<Object**>(object->address())[0] = | 3026 reinterpret_cast<Object**>(object->address())[0] = |
| 3013 heap()->fixed_array_map(); | 3027 heap()->fixed_array_map(); |
| 3014 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); | 3028 reinterpret_cast<Object**>(object->address())[1] = Smi::FromInt(0); |
| 3015 } | 3029 } |
| 3016 | 3030 |
| 3017 heap()->incremental_marking()->OldSpaceStep(object_size); | 3031 heap()->incremental_marking()->OldSpaceStep(object_size); |
| 3032 AllocationStep(object->address(), object_size); |
| 3018 return object; | 3033 return object; |
| 3019 } | 3034 } |
| 3020 | 3035 |
| 3021 | 3036 |
| 3022 size_t LargeObjectSpace::CommittedPhysicalMemory() { | 3037 size_t LargeObjectSpace::CommittedPhysicalMemory() { |
| 3023 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); | 3038 if (!base::VirtualMemory::HasLazyCommits()) return CommittedMemory(); |
| 3024 size_t size = 0; | 3039 size_t size = 0; |
| 3025 LargePage* current = first_page_; | 3040 LargePage* current = first_page_; |
| 3026 while (current != NULL) { | 3041 while (current != NULL) { |
| 3027 size += current->CommittedPhysicalMemory(); | 3042 size += current->CommittedPhysicalMemory(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3234 object->ShortPrint(); | 3249 object->ShortPrint(); |
| 3235 PrintF("\n"); | 3250 PrintF("\n"); |
| 3236 } | 3251 } |
| 3237 printf(" --------------------------------------\n"); | 3252 printf(" --------------------------------------\n"); |
| 3238 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3253 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3239 } | 3254 } |
| 3240 | 3255 |
| 3241 #endif // DEBUG | 3256 #endif // DEBUG |
| 3242 } // namespace internal | 3257 } // namespace internal |
| 3243 } // namespace v8 | 3258 } // namespace v8 |
| OLD | NEW |