From 8548ea5d1a38412531a71c5a647baf8c1c8b1ea0 Mon Sep 17 00:00:00 2001 From: hpayer Date: Tue, 4 Aug 2015 00:02:42 -0700 Subject: [PATCH] AdjustLiveBytes and friends takes a heap object pointer instead of an address. That makes going to the page safe. Addresses can be in arbitrary locations of an object, e.g. in a large object but not on the first 1M page. BUG= Review URL: https://codereview.chromium.org/1256203004 Cr-Commit-Position: refs/heads/master@{#29991} --- src/factory.cc | 2 +- src/heap/heap.cc | 14 +++++++------- src/heap/heap.h | 2 +- src/heap/incremental-marking-inl.h | 2 +- src/heap/incremental-marking.cc | 12 +++++------- src/heap/mark-compact-inl.h | 4 ++-- src/heap/mark-compact.cc | 4 ++-- src/heap/mark-compact.h | 4 ++-- src/heap/spaces.cc | 4 ++-- src/heap/spaces.h | 6 +++--- src/objects.cc | 12 +++++------- src/runtime/runtime-regexp.cc | 2 +- 12 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index 2fe1854..ea4f69a 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -2064,7 +2064,7 @@ void Factory::ReinitializeJSProxy(Handle proxy, InstanceType type, if (size_difference > 0) { Address address = proxy->address(); heap->CreateFillerObjectAt(address + map->instance_size(), size_difference); - heap->AdjustLiveBytes(address, -size_difference, + heap->AdjustLiveBytes(*proxy, -size_difference, Heap::CONCURRENT_TO_SWEEPER); } diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 64445f0..0432ee7 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -2307,7 +2307,7 @@ class ScavengingVisitor : public StaticVisitorBase { if (marks_handling == TRANSFER_MARKS) { if (Marking::TransferColor(source, target)) { - MemoryChunk::IncrementLiveBytesFromGC(target->address(), size); + MemoryChunk::IncrementLiveBytesFromGC(target, size); } } } @@ -3723,13 +3723,13 @@ bool Heap::CanMoveObjectStart(HeapObject* object) { } -void Heap::AdjustLiveBytes(Address address, int by, InvocationMode mode) { +void Heap::AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode) { if (incremental_marking()->IsMarking() && - Marking::IsBlack(Marking::MarkBitFrom(address))) { + Marking::IsBlack(Marking::MarkBitFrom(object->address()))) { if (mode == SEQUENTIAL_TO_SWEEPER) { - MemoryChunk::IncrementLiveBytesFromGC(address, by); + MemoryChunk::IncrementLiveBytesFromGC(object, by); } else { - MemoryChunk::IncrementLiveBytesFromMutator(address, by); + MemoryChunk::IncrementLiveBytesFromMutator(object, by); } } } @@ -3776,7 +3776,7 @@ FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object, // Maintain consistency of live bytes during incremental marking marking()->TransferMark(object->address(), new_start); - AdjustLiveBytes(new_start, -bytes_to_trim, Heap::CONCURRENT_TO_SWEEPER); + AdjustLiveBytes(new_object, -bytes_to_trim, Heap::CONCURRENT_TO_SWEEPER); // Notify the heap profiler of change in object layout. OnMoveEvent(new_object, object, new_object->Size()); @@ -3837,7 +3837,7 @@ void Heap::RightTrimFixedArray(FixedArrayBase* object, int elements_to_trim) { object->synchronized_set_length(len - elements_to_trim); // Maintain consistency of live bytes during incremental marking - AdjustLiveBytes(object->address(), -bytes_to_trim, mode); + AdjustLiveBytes(object, -bytes_to_trim, mode); // Notify the heap profiler of change in object layout. The array may not be // moved during GC, and size has to be adjusted nevertheless. diff --git a/src/heap/heap.h b/src/heap/heap.h index 398cffe..54dfc7a 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -795,7 +795,7 @@ class Heap { enum InvocationMode { SEQUENTIAL_TO_SWEEPER, CONCURRENT_TO_SWEEPER }; // Maintain consistency of live bytes during incremental marking. - void AdjustLiveBytes(Address address, int by, InvocationMode mode); + void AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode); // Trim the given array from the left. Note that this relocates the object // start and hence is only valid if there is only a single reference to it. diff --git a/src/heap/incremental-marking-inl.h b/src/heap/incremental-marking-inl.h index 42b3dcb..d523841 100644 --- a/src/heap/incremental-marking-inl.h +++ b/src/heap/incremental-marking-inl.h @@ -85,7 +85,7 @@ void IncrementalMarking::BlackToGreyAndUnshift(HeapObject* obj, DCHECK(IsMarking()); Marking::BlackToGrey(mark_bit); int obj_size = obj->Size(); - MemoryChunk::IncrementLiveBytesFromGC(obj->address(), -obj_size); + MemoryChunk::IncrementLiveBytesFromGC(obj, -obj_size); bytes_scanned_ -= obj_size; int64_t old_bytes_rescanned = bytes_rescanned_; bytes_rescanned_ = old_bytes_rescanned + obj_size; diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index 22051ea..947c961 100644 --- a/src/heap/incremental-marking.cc +++ b/src/heap/incremental-marking.cc @@ -127,8 +127,7 @@ static void MarkObjectGreyDoNotEnqueue(Object* obj) { HeapObject* heap_obj = HeapObject::cast(obj); MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(obj)); if (Marking::IsBlack(mark_bit)) { - MemoryChunk::IncrementLiveBytesFromGC(heap_obj->address(), - -heap_obj->Size()); + MemoryChunk::IncrementLiveBytesFromGC(heap_obj, -heap_obj->Size()); } Marking::AnyToGrey(mark_bit); } @@ -140,7 +139,7 @@ static inline void MarkBlackOrKeepBlack(HeapObject* heap_object, DCHECK(!Marking::IsImpossible(mark_bit)); if (Marking::IsBlack(mark_bit)) return; Marking::MarkBlack(mark_bit); - MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(), size); + MemoryChunk::IncrementLiveBytesFromGC(heap_object, size); } @@ -256,8 +255,7 @@ class IncrementalMarkingMarkingVisitor MarkBit mark_bit = Marking::MarkBitFrom(heap_object); if (Marking::IsWhite(mark_bit)) { Marking::MarkBlack(mark_bit); - MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(), - heap_object->Size()); + MemoryChunk::IncrementLiveBytesFromGC(heap_object, heap_object->Size()); return true; } return false; @@ -720,7 +718,7 @@ void IncrementalMarking::Hurry() { if (FLAG_cleanup_code_caches_at_gc) { PolymorphicCodeCache* poly_cache = heap_->polymorphic_code_cache(); Marking::GreyToBlack(Marking::MarkBitFrom(poly_cache)); - MemoryChunk::IncrementLiveBytesFromGC(poly_cache->address(), + MemoryChunk::IncrementLiveBytesFromGC(poly_cache, PolymorphicCodeCache::kSize); } @@ -734,7 +732,7 @@ void IncrementalMarking::Hurry() { MarkBit mark_bit = Marking::MarkBitFrom(cache); if (Marking::IsGrey(mark_bit)) { Marking::GreyToBlack(mark_bit); - MemoryChunk::IncrementLiveBytesFromGC(cache->address(), cache->Size()); + MemoryChunk::IncrementLiveBytesFromGC(cache, cache->Size()); } } context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); diff --git a/src/heap/mark-compact-inl.h b/src/heap/mark-compact-inl.h index 1ac9a59..de8df3d 100644 --- a/src/heap/mark-compact-inl.h +++ b/src/heap/mark-compact-inl.h @@ -33,7 +33,7 @@ void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) { DCHECK(Marking::MarkBitFrom(obj) == mark_bit); if (Marking::IsWhite(mark_bit)) { Marking::WhiteToBlack(mark_bit); - MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size()); + MemoryChunk::IncrementLiveBytesFromGC(obj, obj->Size()); DCHECK(obj->GetIsolate()->heap()->Contains(obj)); marking_deque_.PushBlack(obj); } @@ -44,7 +44,7 @@ void MarkCompactCollector::SetMark(HeapObject* obj, MarkBit mark_bit) { DCHECK(Marking::IsWhite(mark_bit)); DCHECK(Marking::MarkBitFrom(obj) == mark_bit); Marking::WhiteToBlack(mark_bit); - MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size()); + MemoryChunk::IncrementLiveBytesFromGC(obj, obj->Size()); } diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc index 878efd6..3cc08f4 100644 --- a/src/heap/mark-compact.cc +++ b/src/heap/mark-compact.cc @@ -1770,7 +1770,7 @@ static void DiscoverGreyObjectsWithIterator(Heap* heap, MarkBit markbit = Marking::MarkBitFrom(object); if ((object->map() != filler_map) && Marking::IsGrey(markbit)) { Marking::GreyToBlack(markbit); - MemoryChunk::IncrementLiveBytesFromGC(object->address(), object->Size()); + MemoryChunk::IncrementLiveBytesFromGC(object, object->Size()); marking_deque->PushBlack(object); if (marking_deque->IsFull()) return; } @@ -1815,7 +1815,7 @@ static void DiscoverGreyObjectsOnPage(MarkingDeque* marking_deque, Marking::GreyToBlack(markbit); Address addr = cell_base + offset * kPointerSize; HeapObject* object = HeapObject::FromAddress(addr); - MemoryChunk::IncrementLiveBytesFromGC(object->address(), object->Size()); + MemoryChunk::IncrementLiveBytesFromGC(object, object->Size()); marking_deque->PushBlack(object); if (marking_deque->IsFull()) return; offset += 2; diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h index 8f68917..e403feb 100644 --- a/src/heap/mark-compact.h +++ b/src/heap/mark-compact.h @@ -211,7 +211,7 @@ class MarkingDeque { DCHECK(object->IsHeapObject()); if (IsFull()) { Marking::BlackToGrey(object); - MemoryChunk::IncrementLiveBytesFromGC(object->address(), -object->Size()); + MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size()); SetOverflowed(); } else { array_[top_] = object; @@ -252,7 +252,7 @@ class MarkingDeque { DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object))); if (IsFull()) { Marking::BlackToGrey(object); - MemoryChunk::IncrementLiveBytesFromGC(object->address(), -object->Size()); + MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size()); SetOverflowed(); } else { bottom_ = ((bottom_ - 1) & mask_); diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc index 268d23e..ba0ddb6 100644 --- a/src/heap/spaces.cc +++ b/src/heap/spaces.cc @@ -922,8 +922,8 @@ bool MemoryAllocator::CommitExecutableMemory(base::VirtualMemory* vm, // ----------------------------------------------------------------------------- // MemoryChunk implementation -void MemoryChunk::IncrementLiveBytesFromMutator(Address address, int by) { - MemoryChunk* chunk = MemoryChunk::FromAddress(address); +void MemoryChunk::IncrementLiveBytesFromMutator(HeapObject* object, int by) { + MemoryChunk* chunk = MemoryChunk::FromAddress(object->address()); if (!chunk->InNewSpace() && !static_cast(chunk)->WasSwept()) { static_cast(chunk->owner())->IncrementUnsweptFreeBytes(-by); } diff --git a/src/heap/spaces.h b/src/heap/spaces.h index b7ff832..e9b23e5 100644 --- a/src/heap/spaces.h +++ b/src/heap/spaces.h @@ -522,11 +522,11 @@ class MemoryChunk { progress_bar(); } - static void IncrementLiveBytesFromGC(Address address, int by) { - MemoryChunk::FromAddress(address)->IncrementLiveBytes(by); + static void IncrementLiveBytesFromGC(HeapObject* object, int by) { + MemoryChunk::FromAddress(object->address())->IncrementLiveBytes(by); } - static void IncrementLiveBytesFromMutator(Address address, int by); + static void IncrementLiveBytesFromMutator(HeapObject* object, int by); static const intptr_t kAlignment = (static_cast(1) << kPageSizeBits); diff --git a/src/objects.cc b/src/objects.cc index 4a6019d..51675d4 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -946,8 +946,7 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) { self->set_resource(resource); if (is_internalized) self->Hash(); // Force regeneration of the hash value. - heap->AdjustLiveBytes(this->address(), new_size - size, - Heap::CONCURRENT_TO_SWEEPER); + heap->AdjustLiveBytes(this, new_size - size, Heap::CONCURRENT_TO_SWEEPER); return true; } @@ -1007,8 +1006,7 @@ bool String::MakeExternal(v8::String::ExternalOneByteStringResource* resource) { self->set_resource(resource); if (is_internalized) self->Hash(); // Force regeneration of the hash value. - heap->AdjustLiveBytes(this->address(), new_size - size, - Heap::CONCURRENT_TO_SWEEPER); + heap->AdjustLiveBytes(this, new_size - size, Heap::CONCURRENT_TO_SWEEPER); return true; } @@ -2149,7 +2147,7 @@ void JSObject::MigrateFastToFast(Handle object, Handle new_map) { Address address = object->address(); heap->CreateFillerObjectAt( address + new_instance_size, instance_size_delta); - heap->AdjustLiveBytes(address, -instance_size_delta, + heap->AdjustLiveBytes(*object, -instance_size_delta, Heap::CONCURRENT_TO_SWEEPER); } @@ -4687,7 +4685,7 @@ void JSObject::MigrateFastToSlow(Handle object, Heap* heap = isolate->heap(); heap->CreateFillerObjectAt(object->address() + new_instance_size, instance_size_delta); - heap->AdjustLiveBytes(object->address(), -instance_size_delta, + heap->AdjustLiveBytes(*object, -instance_size_delta, Heap::CONCURRENT_TO_SWEEPER); } @@ -9234,7 +9232,7 @@ Handle SeqString::Truncate(Handle string, int new_length) { // that are a multiple of pointer size. heap->CreateFillerObjectAt(start_of_string + new_size, delta); } - heap->AdjustLiveBytes(start_of_string, -delta, Heap::CONCURRENT_TO_SWEEPER); + heap->AdjustLiveBytes(*string, -delta, Heap::CONCURRENT_TO_SWEEPER); // We are storing the new length using release store after creating a filler // for the left-over space to avoid races with the sweeper thread. diff --git a/src/runtime/runtime-regexp.cc b/src/runtime/runtime-regexp.cc index 67e1384..e742d64 100644 --- a/src/runtime/runtime-regexp.cc +++ b/src/runtime/runtime-regexp.cc @@ -643,7 +643,7 @@ MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithEmptyString( if (!heap->lo_space()->Contains(*answer)) { heap->CreateFillerObjectAt(end_of_string, delta); } - heap->AdjustLiveBytes(answer->address(), -delta, Heap::CONCURRENT_TO_SWEEPER); + heap->AdjustLiveBytes(*answer, -delta, Heap::CONCURRENT_TO_SWEEPER); return *answer; } -- 2.7.4