Commit d03768b0 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap] Avoid repeated loads of object size

The iterator already provides the size.

Bug: chromium:651354
Change-Id: I683bfe5c82441bf39c21b18daa58eba91b798c64
Reviewed-on: https://chromium-review.googlesource.com/543495
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46092}
parent 19115187
...@@ -493,7 +493,7 @@ bool Heap::InOldSpaceSlow(Address address) { ...@@ -493,7 +493,7 @@ bool Heap::InOldSpaceSlow(Address address) {
return old_space_->ContainsSlow(address); return old_space_->ContainsSlow(address);
} }
bool Heap::ShouldBePromoted(Address old_address, int object_size) { bool Heap::ShouldBePromoted(Address old_address) {
Page* page = Page::FromAddress(old_address); Page* page = Page::FromAddress(old_address);
Address age_mark = new_space_->age_mark(); Address age_mark = new_space_->age_mark();
return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) && return page->IsFlagSet(MemoryChunk::NEW_SPACE_BELOW_AGE_MARK) &&
......
...@@ -866,7 +866,7 @@ class Heap { ...@@ -866,7 +866,7 @@ class Heap {
// An object should be promoted if the object has survived a // An object should be promoted if the object has survived a
// scavenge operation. // scavenge operation.
inline bool ShouldBePromoted(Address old_address, int object_size); inline bool ShouldBePromoted(Address old_address);
void ClearNormalizedMapCaches(); void ClearNormalizedMapCaches();
......
...@@ -1649,7 +1649,7 @@ class YoungGenerationRecordMigratedSlotVisitor final ...@@ -1649,7 +1649,7 @@ class YoungGenerationRecordMigratedSlotVisitor final
class HeapObjectVisitor { class HeapObjectVisitor {
public: public:
virtual ~HeapObjectVisitor() {} virtual ~HeapObjectVisitor() {}
virtual bool Visit(HeapObject* object) = 0; virtual bool Visit(HeapObject* object, int size) = 0;
}; };
class EvacuateVisitorBase : public HeapObjectVisitor { class EvacuateVisitorBase : public HeapObjectVisitor {
...@@ -1710,11 +1710,10 @@ class EvacuateVisitorBase : public HeapObjectVisitor { ...@@ -1710,11 +1710,10 @@ class EvacuateVisitorBase : public HeapObjectVisitor {
} }
inline bool TryEvacuateObject(PagedSpace* target_space, HeapObject* object, inline bool TryEvacuateObject(PagedSpace* target_space, HeapObject* object,
HeapObject** target_object) { int size, HeapObject** target_object) {
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
if (AbortCompactionForTesting(object)) return false; if (AbortCompactionForTesting(object)) return false;
#endif // VERIFY_HEAP #endif // VERIFY_HEAP
int size = object->Size();
AllocationAlignment alignment = object->RequiredAlignment(); AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = target_space->AllocateRaw(size, alignment); AllocationResult allocation = target_space->AllocateRaw(size, alignment);
if (allocation.To(target_object)) { if (allocation.To(target_object)) {
...@@ -1779,11 +1778,10 @@ class EvacuateNewSpaceVisitor final : public EvacuateVisitorBase { ...@@ -1779,11 +1778,10 @@ class EvacuateNewSpaceVisitor final : public EvacuateVisitorBase {
semispace_copied_size_(0), semispace_copied_size_(0),
local_pretenuring_feedback_(local_pretenuring_feedback) {} local_pretenuring_feedback_(local_pretenuring_feedback) {}
inline bool Visit(HeapObject* object) override { inline bool Visit(HeapObject* object, int size) override {
int size = object->Size();
HeapObject* target_object = nullptr; HeapObject* target_object = nullptr;
if (heap_->ShouldBePromoted(object->address(), size) && if (heap_->ShouldBePromoted(object->address()) &&
TryEvacuateObject(compaction_spaces_->Get(OLD_SPACE), object, TryEvacuateObject(compaction_spaces_->Get(OLD_SPACE), object, size,
&target_object)) { &target_object)) {
promoted_size_ += size; promoted_size_ += size;
return true; return true;
...@@ -1791,7 +1789,7 @@ class EvacuateNewSpaceVisitor final : public EvacuateVisitorBase { ...@@ -1791,7 +1789,7 @@ class EvacuateNewSpaceVisitor final : public EvacuateVisitorBase {
heap_->UpdateAllocationSite<Heap::kCached>(object, heap_->UpdateAllocationSite<Heap::kCached>(object,
local_pretenuring_feedback_); local_pretenuring_feedback_);
HeapObject* target = nullptr; HeapObject* target = nullptr;
AllocationSpace space = AllocateTargetObject(object, &target); AllocationSpace space = AllocateTargetObject(object, size, &target);
MigrateObject(HeapObject::cast(target), object, size, space); MigrateObject(HeapObject::cast(target), object, size, space);
semispace_copied_size_ += size; semispace_copied_size_ += size;
return true; return true;
...@@ -1807,9 +1805,8 @@ class EvacuateNewSpaceVisitor final : public EvacuateVisitorBase { ...@@ -1807,9 +1805,8 @@ class EvacuateNewSpaceVisitor final : public EvacuateVisitorBase {
kStickyBailoutOldSpace, kStickyBailoutOldSpace,
}; };
inline AllocationSpace AllocateTargetObject(HeapObject* old_object, inline AllocationSpace AllocateTargetObject(HeapObject* old_object, int size,
HeapObject** target_object) { HeapObject** target_object) {
const int size = old_object->Size();
AllocationAlignment alignment = old_object->RequiredAlignment(); AllocationAlignment alignment = old_object->RequiredAlignment();
AllocationResult allocation; AllocationResult allocation;
AllocationSpace space_allocated_in = space_to_allocate_; AllocationSpace space_allocated_in = space_to_allocate_;
...@@ -1933,7 +1930,7 @@ class EvacuateNewSpacePageVisitor final : public HeapObjectVisitor { ...@@ -1933,7 +1930,7 @@ class EvacuateNewSpacePageVisitor final : public HeapObjectVisitor {
} }
} }
inline bool Visit(HeapObject* object) { inline bool Visit(HeapObject* object, int size) {
if (mode == NEW_TO_NEW) { if (mode == NEW_TO_NEW) {
heap_->UpdateAllocationSite<Heap::kCached>(object, heap_->UpdateAllocationSite<Heap::kCached>(object,
local_pretenuring_feedback_); local_pretenuring_feedback_);
...@@ -1960,11 +1957,11 @@ class EvacuateOldSpaceVisitor final : public EvacuateVisitorBase { ...@@ -1960,11 +1957,11 @@ class EvacuateOldSpaceVisitor final : public EvacuateVisitorBase {
RecordMigratedSlotVisitor* record_visitor) RecordMigratedSlotVisitor* record_visitor)
: EvacuateVisitorBase(heap, compaction_spaces, record_visitor) {} : EvacuateVisitorBase(heap, compaction_spaces, record_visitor) {}
inline bool Visit(HeapObject* object) override { inline bool Visit(HeapObject* object, int size) override {
CompactionSpace* target_space = compaction_spaces_->Get( CompactionSpace* target_space = compaction_spaces_->Get(
Page::FromAddress(object->address())->owner()->identity()); Page::FromAddress(object->address())->owner()->identity());
HeapObject* target_object = nullptr; HeapObject* target_object = nullptr;
if (TryEvacuateObject(target_space, object, &target_object)) { if (TryEvacuateObject(target_space, object, size, &target_object)) {
DCHECK(object->map_word().IsForwardingAddress()); DCHECK(object->map_word().IsForwardingAddress());
return true; return true;
} }
...@@ -1976,7 +1973,7 @@ class EvacuateRecordOnlyVisitor final : public HeapObjectVisitor { ...@@ -1976,7 +1973,7 @@ class EvacuateRecordOnlyVisitor final : public HeapObjectVisitor {
public: public:
explicit EvacuateRecordOnlyVisitor(Heap* heap) : heap_(heap) {} explicit EvacuateRecordOnlyVisitor(Heap* heap) : heap_(heap) {}
inline bool Visit(HeapObject* object) { inline bool Visit(HeapObject* object, int size) {
RecordMigratedSlotVisitor visitor(heap_->mark_compact_collector()); RecordMigratedSlotVisitor visitor(heap_->mark_compact_collector());
object->IterateBody(&visitor); object->IterateBody(&visitor);
return true; return true;
...@@ -2155,7 +2152,7 @@ class ObjectStatsVisitor : public HeapObjectVisitor { ...@@ -2155,7 +2152,7 @@ class ObjectStatsVisitor : public HeapObjectVisitor {
live_collector_.CollectGlobalStatistics(); live_collector_.CollectGlobalStatistics();
} }
bool Visit(HeapObject* obj) override { bool Visit(HeapObject* obj, int size) override {
if (ObjectMarking::IsBlack(obj, MarkingState::Internal(obj))) { if (ObjectMarking::IsBlack(obj, MarkingState::Internal(obj))) {
live_collector_.CollectStatistics(obj); live_collector_.CollectStatistics(obj);
} else { } else {
...@@ -2177,7 +2174,7 @@ void MarkCompactCollector::VisitAllObjects(HeapObjectVisitor* visitor) { ...@@ -2177,7 +2174,7 @@ void MarkCompactCollector::VisitAllObjects(HeapObjectVisitor* visitor) {
std::unique_ptr<ObjectIterator> it(space_it.next()->GetObjectIterator()); std::unique_ptr<ObjectIterator> it(space_it.next()->GetObjectIterator());
ObjectIterator* obj_it = it.get(); ObjectIterator* obj_it = it.get();
while ((obj = obj_it->Next()) != nullptr) { while ((obj = obj_it->Next()) != nullptr) {
visitor->Visit(obj); visitor->Visit(obj, obj->Size());
} }
} }
} }
...@@ -4144,7 +4141,7 @@ bool LiveObjectVisitor::VisitBlackObjects(MemoryChunk* chunk, ...@@ -4144,7 +4141,7 @@ bool LiveObjectVisitor::VisitBlackObjects(MemoryChunk* chunk,
IterationMode iteration_mode) { IterationMode iteration_mode) {
for (auto object_and_size : LiveObjectRange<kBlackObjects>(chunk, state)) { for (auto object_and_size : LiveObjectRange<kBlackObjects>(chunk, state)) {
HeapObject* const object = object_and_size.first; HeapObject* const object = object_and_size.first;
if (!visitor->Visit(object)) { if (!visitor->Visit(object, object_and_size.second)) {
if (iteration_mode == kClearMarkbits) { if (iteration_mode == kClearMarkbits) {
state.bitmap()->ClearRange( state.bitmap()->ClearRange(
chunk->AddressToMarkbitIndex(chunk->area_start()), chunk->AddressToMarkbitIndex(chunk->area_start()),
...@@ -4173,7 +4170,7 @@ bool LiveObjectVisitor::VisitGreyObjectsNoFail(MemoryChunk* chunk, ...@@ -4173,7 +4170,7 @@ bool LiveObjectVisitor::VisitGreyObjectsNoFail(MemoryChunk* chunk,
for (auto object_and_size : LiveObjectRange<kGreyObjects>(chunk, state)) { for (auto object_and_size : LiveObjectRange<kGreyObjects>(chunk, state)) {
HeapObject* const object = object_and_size.first; HeapObject* const object = object_and_size.first;
DCHECK(ObjectMarking::IsGrey(object, state)); DCHECK(ObjectMarking::IsGrey(object, state));
if (!visitor->Visit(object)) { if (!visitor->Visit(object, object_and_size.second)) {
UNREACHABLE(); UNREACHABLE();
} }
} }
...@@ -4187,7 +4184,7 @@ void LiveObjectVisitor::RecomputeLiveBytes(MemoryChunk* chunk, ...@@ -4187,7 +4184,7 @@ void LiveObjectVisitor::RecomputeLiveBytes(MemoryChunk* chunk,
const MarkingState& state) { const MarkingState& state) {
int new_live_size = 0; int new_live_size = 0;
for (auto object_and_size : LiveObjectRange<kAllLiveObjects>(chunk, state)) { for (auto object_and_size : LiveObjectRange<kAllLiveObjects>(chunk, state)) {
new_live_size += object_and_size.first->Size(); new_live_size += object_and_size.second;
} }
state.SetLiveBytes(new_live_size); state.SetLiveBytes(new_live_size);
} }
......
...@@ -222,7 +222,7 @@ class ScavengingVisitor : public StaticVisitorBase { ...@@ -222,7 +222,7 @@ class ScavengingVisitor : public StaticVisitorBase {
SLOW_DCHECK(object->Size() == object_size); SLOW_DCHECK(object->Size() == object_size);
Heap* heap = map->GetHeap(); Heap* heap = map->GetHeap();
if (!heap->ShouldBePromoted(object->address(), object_size)) { if (!heap->ShouldBePromoted(object->address())) {
// A semi-space copy may fail due to fragmentation. In that case, we // A semi-space copy may fail due to fragmentation. In that case, we
// try to promote the object. // try to promote the object.
if (SemiSpaceCopyObject<alignment>(map, slot, object, object_size)) { if (SemiSpaceCopyObject<alignment>(map, slot, object, object_size)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment