Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: src/heap/mark-compact.cc

Issue 1820263002: [heap] Optimize migration of objects round two (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/heap-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 }; 1543 };
1544 1544
1545 class MarkCompactCollector::HeapObjectVisitor { 1545 class MarkCompactCollector::HeapObjectVisitor {
1546 public: 1546 public:
1547 virtual ~HeapObjectVisitor() {} 1547 virtual ~HeapObjectVisitor() {}
1548 virtual bool Visit(HeapObject* object) = 0; 1548 virtual bool Visit(HeapObject* object) = 0;
1549 }; 1549 };
1550 1550
1551 class MarkCompactCollector::EvacuateVisitorBase 1551 class MarkCompactCollector::EvacuateVisitorBase
1552 : public MarkCompactCollector::HeapObjectVisitor { 1552 : public MarkCompactCollector::HeapObjectVisitor {
1553 public: 1553 protected:
1554 enum MigrationMode { kFast, kProfiled };
1555
1554 EvacuateVisitorBase(Heap* heap, CompactionSpaceCollection* compaction_spaces) 1556 EvacuateVisitorBase(Heap* heap, CompactionSpaceCollection* compaction_spaces)
1555 : heap_(heap), compaction_spaces_(compaction_spaces) {} 1557 : heap_(heap),
1558 compaction_spaces_(compaction_spaces),
1559 profiling_(
1560 heap->isolate()->cpu_profiler()->is_profiling() ||
1561 heap->isolate()->logger()->is_logging_code_events() ||
1562 heap->isolate()->heap_profiler()->is_tracking_object_moves()) {}
1556 1563
1557 inline bool TryEvacuateObject(PagedSpace* target_space, HeapObject* object, 1564 inline bool TryEvacuateObject(PagedSpace* target_space, HeapObject* object,
1558 HeapObject** target_object) { 1565 HeapObject** target_object) {
1559 int size = object->Size(); 1566 int size = object->Size();
1560 AllocationAlignment alignment = object->RequiredAlignment(); 1567 AllocationAlignment alignment = object->RequiredAlignment();
1561 AllocationResult allocation = target_space->AllocateRaw(size, alignment); 1568 AllocationResult allocation = target_space->AllocateRaw(size, alignment);
1562 if (allocation.To(target_object)) { 1569 if (allocation.To(target_object)) {
1563 MigrateObject(*target_object, object, size, target_space->identity()); 1570 MigrateObject(*target_object, object, size, target_space->identity());
1564 return true; 1571 return true;
1565 } 1572 }
1566 return false; 1573 return false;
1567 } 1574 }
1568 1575
1569 inline void MigrateObject(HeapObject* dst, HeapObject* src, int size, 1576 inline void MigrateObject(HeapObject* dst, HeapObject* src, int size,
1570 AllocationSpace dest) { 1577 AllocationSpace dest) {
1578 if (profiling_) {
1579 MigrateObject<kProfiled>(dst, src, size, dest);
1580 } else {
1581 MigrateObject<kFast>(dst, src, size, dest);
1582 }
1583 }
1584
1585 template <MigrationMode mode>
1586 inline void MigrateObject(HeapObject* dst, HeapObject* src, int size,
1587 AllocationSpace dest) {
1571 Address dst_addr = dst->address(); 1588 Address dst_addr = dst->address();
1572 Address src_addr = src->address(); 1589 Address src_addr = src->address();
1573 DCHECK(heap_->AllowedToBeMigrated(src, dest)); 1590 DCHECK(heap_->AllowedToBeMigrated(src, dest));
1574 DCHECK(dest != LO_SPACE); 1591 DCHECK(dest != LO_SPACE);
1575 if (dest == OLD_SPACE) { 1592 if (dest == OLD_SPACE) {
1576 DCHECK_OBJECT_SIZE(size); 1593 DCHECK_OBJECT_SIZE(size);
1577 DCHECK(IsAligned(size, kPointerSize)); 1594 DCHECK(IsAligned(size, kPointerSize));
1578 heap_->MoveBlock(dst_addr, src_addr, size); 1595 heap_->CopyBlock(dst_addr, src_addr, size);
1579 if (FLAG_ignition && dst->IsBytecodeArray()) { 1596 if ((mode == kProfiled) && FLAG_ignition && dst->IsBytecodeArray()) {
1580 PROFILE(heap_->isolate(), 1597 PROFILE(heap_->isolate(),
1581 CodeMoveEvent(AbstractCode::cast(src), dst_addr)); 1598 CodeMoveEvent(AbstractCode::cast(src), dst_addr));
1582 } 1599 }
1583 RecordMigratedSlotVisitor visitor; 1600 RecordMigratedSlotVisitor visitor;
1584 dst->IterateBodyFast(dst->map()->instance_type(), size, &visitor); 1601 dst->IterateBodyFast(dst->map()->instance_type(), size, &visitor);
1585 } else if (dest == CODE_SPACE) { 1602 } else if (dest == CODE_SPACE) {
1586 DCHECK_CODEOBJECT_SIZE(size, heap_->code_space()); 1603 DCHECK_CODEOBJECT_SIZE(size, heap_->code_space());
1587 PROFILE(heap_->isolate(), 1604 if (mode == kProfiled) {
1588 CodeMoveEvent(AbstractCode::cast(src), dst_addr)); 1605 PROFILE(heap_->isolate(),
1589 heap_->MoveBlock(dst_addr, src_addr, size); 1606 CodeMoveEvent(AbstractCode::cast(src), dst_addr));
1607 }
1608 heap_->CopyBlock(dst_addr, src_addr, size);
1590 RememberedSet<OLD_TO_OLD>::InsertTyped(Page::FromAddress(dst_addr), 1609 RememberedSet<OLD_TO_OLD>::InsertTyped(Page::FromAddress(dst_addr),
1591 RELOCATED_CODE_OBJECT, dst_addr); 1610 RELOCATED_CODE_OBJECT, dst_addr);
1592 Code::cast(dst)->Relocate(dst_addr - src_addr); 1611 Code::cast(dst)->Relocate(dst_addr - src_addr);
1593 } else { 1612 } else {
1594 DCHECK_OBJECT_SIZE(size); 1613 DCHECK_OBJECT_SIZE(size);
1595 DCHECK(dest == NEW_SPACE); 1614 DCHECK(dest == NEW_SPACE);
1596 heap_->MoveBlock(dst_addr, src_addr, size); 1615 heap_->CopyBlock(dst_addr, src_addr, size);
1597 } 1616 }
1598 heap_->OnMoveEvent(dst, src, size); 1617 if (mode == kProfiled) {
1618 heap_->OnMoveEvent(dst, src, size);
1619 }
1599 Memory::Address_at(src_addr) = dst_addr; 1620 Memory::Address_at(src_addr) = dst_addr;
1600 } 1621 }
1601 1622
1602 protected:
1603 Heap* heap_; 1623 Heap* heap_;
1604 CompactionSpaceCollection* compaction_spaces_; 1624 CompactionSpaceCollection* compaction_spaces_;
1625 bool profiling_;
1605 }; 1626 };
1606 1627
1607 class MarkCompactCollector::EvacuateNewSpaceVisitor final 1628 class MarkCompactCollector::EvacuateNewSpaceVisitor final
1608 : public MarkCompactCollector::EvacuateVisitorBase { 1629 : public MarkCompactCollector::EvacuateVisitorBase {
1609 public: 1630 public:
1610 static const intptr_t kLabSize = 4 * KB; 1631 static const intptr_t kLabSize = 4 * KB;
1611 static const intptr_t kMaxLabObjectSize = 256; 1632 static const intptr_t kMaxLabObjectSize = 256;
1612 1633
1613 explicit EvacuateNewSpaceVisitor(Heap* heap, 1634 explicit EvacuateNewSpaceVisitor(Heap* heap,
1614 CompactionSpaceCollection* compaction_spaces, 1635 CompactionSpaceCollection* compaction_spaces,
(...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after
3791 MarkBit mark_bit = Marking::MarkBitFrom(host); 3812 MarkBit mark_bit = Marking::MarkBitFrom(host);
3792 if (Marking::IsBlack(mark_bit)) { 3813 if (Marking::IsBlack(mark_bit)) {
3793 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); 3814 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host);
3794 RecordRelocSlot(host, &rinfo, target); 3815 RecordRelocSlot(host, &rinfo, target);
3795 } 3816 }
3796 } 3817 }
3797 } 3818 }
3798 3819
3799 } // namespace internal 3820 } // namespace internal
3800 } // namespace v8 3821 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698