| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
| 6 | 6 |
| 7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 EvacuateVisitorBase(Heap* heap, CompactionSpaceCollection* compaction_spaces) | 1634 EvacuateVisitorBase(Heap* heap, CompactionSpaceCollection* compaction_spaces) |
| 1635 : heap_(heap), | 1635 : heap_(heap), |
| 1636 compaction_spaces_(compaction_spaces), | 1636 compaction_spaces_(compaction_spaces), |
| 1637 profiling_( | 1637 profiling_( |
| 1638 heap->isolate()->cpu_profiler()->is_profiling() || | 1638 heap->isolate()->cpu_profiler()->is_profiling() || |
| 1639 heap->isolate()->logger()->is_logging_code_events() || | 1639 heap->isolate()->logger()->is_logging_code_events() || |
| 1640 heap->isolate()->heap_profiler()->is_tracking_object_moves()) {} | 1640 heap->isolate()->heap_profiler()->is_tracking_object_moves()) {} |
| 1641 | 1641 |
| 1642 inline bool TryEvacuateObject(PagedSpace* target_space, HeapObject* object, | 1642 inline bool TryEvacuateObject(PagedSpace* target_space, HeapObject* object, |
| 1643 HeapObject** target_object) { | 1643 HeapObject** target_object) { |
| 1644 #ifdef VERIFY_HEAP |
| 1645 if (AbortCompactionForTesting(object)) return false; |
| 1646 #endif // VERIFY_HEAP |
| 1644 int size = object->Size(); | 1647 int size = object->Size(); |
| 1645 AllocationAlignment alignment = object->RequiredAlignment(); | 1648 AllocationAlignment alignment = object->RequiredAlignment(); |
| 1646 AllocationResult allocation = target_space->AllocateRaw(size, alignment); | 1649 AllocationResult allocation = target_space->AllocateRaw(size, alignment); |
| 1647 if (allocation.To(target_object)) { | 1650 if (allocation.To(target_object)) { |
| 1648 MigrateObject(*target_object, object, size, target_space->identity()); | 1651 MigrateObject(*target_object, object, size, target_space->identity()); |
| 1649 return true; | 1652 return true; |
| 1650 } | 1653 } |
| 1651 return false; | 1654 return false; |
| 1652 } | 1655 } |
| 1653 | 1656 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 DCHECK_OBJECT_SIZE(size); | 1694 DCHECK_OBJECT_SIZE(size); |
| 1692 DCHECK(dest == NEW_SPACE); | 1695 DCHECK(dest == NEW_SPACE); |
| 1693 heap_->CopyBlock(dst_addr, src_addr, size); | 1696 heap_->CopyBlock(dst_addr, src_addr, size); |
| 1694 } | 1697 } |
| 1695 if (mode == kProfiled) { | 1698 if (mode == kProfiled) { |
| 1696 heap_->OnMoveEvent(dst, src, size); | 1699 heap_->OnMoveEvent(dst, src, size); |
| 1697 } | 1700 } |
| 1698 Memory::Address_at(src_addr) = dst_addr; | 1701 Memory::Address_at(src_addr) = dst_addr; |
| 1699 } | 1702 } |
| 1700 | 1703 |
| 1704 #ifdef VERIFY_HEAP |
| 1705 bool AbortCompactionForTesting(HeapObject* object) { |
| 1706 if (FLAG_stress_compaction) { |
| 1707 const uintptr_t mask = static_cast<uintptr_t>(FLAG_random_seed) & |
| 1708 Page::kPageAlignmentMask & ~kPointerAlignmentMask; |
| 1709 if ((reinterpret_cast<uintptr_t>(object->address()) & |
| 1710 Page::kPageAlignmentMask) == mask) { |
| 1711 Page* page = Page::FromAddress(object->address()); |
| 1712 if (page->IsFlagSet(Page::COMPACTION_WAS_ABORTED_FOR_TESTING)) { |
| 1713 page->ClearFlag(Page::COMPACTION_WAS_ABORTED_FOR_TESTING); |
| 1714 } else { |
| 1715 page->SetFlag(Page::COMPACTION_WAS_ABORTED_FOR_TESTING); |
| 1716 return true; |
| 1717 } |
| 1718 } |
| 1719 } |
| 1720 return false; |
| 1721 } |
| 1722 #endif // VERIFY_HEAP |
| 1723 |
| 1701 Heap* heap_; | 1724 Heap* heap_; |
| 1702 CompactionSpaceCollection* compaction_spaces_; | 1725 CompactionSpaceCollection* compaction_spaces_; |
| 1703 bool profiling_; | 1726 bool profiling_; |
| 1704 }; | 1727 }; |
| 1705 | 1728 |
| 1706 class MarkCompactCollector::EvacuateNewSpaceVisitor final | 1729 class MarkCompactCollector::EvacuateNewSpaceVisitor final |
| 1707 : public MarkCompactCollector::EvacuateVisitorBase { | 1730 : public MarkCompactCollector::EvacuateVisitorBase { |
| 1708 public: | 1731 public: |
| 1709 static const intptr_t kLabSize = 4 * KB; | 1732 static const intptr_t kLabSize = 4 * KB; |
| 1710 static const intptr_t kMaxLabObjectSize = 256; | 1733 static const intptr_t kMaxLabObjectSize = 256; |
| (...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3941 MarkBit mark_bit = Marking::MarkBitFrom(host); | 3964 MarkBit mark_bit = Marking::MarkBitFrom(host); |
| 3942 if (Marking::IsBlack(mark_bit)) { | 3965 if (Marking::IsBlack(mark_bit)) { |
| 3943 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 3966 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
| 3944 RecordRelocSlot(host, &rinfo, target); | 3967 RecordRelocSlot(host, &rinfo, target); |
| 3945 } | 3968 } |
| 3946 } | 3969 } |
| 3947 } | 3970 } |
| 3948 | 3971 |
| 3949 } // namespace internal | 3972 } // namespace internal |
| 3950 } // namespace v8 | 3973 } // namespace v8 |
| OLD | NEW |