Commit 8548ea5d authored by hpayer's avatar hpayer Committed by Commit bot

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}
parent 5ee31769
......@@ -2064,7 +2064,7 @@ void Factory::ReinitializeJSProxy(Handle<JSProxy> 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);
}
......
......@@ -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.
......
......@@ -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.
......
......@@ -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;
......
......@@ -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);
......
......@@ -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());
}
......
......@@ -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;
......
......@@ -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_);
......
......@@ -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<Page*>(chunk)->WasSwept()) {
static_cast<PagedSpace*>(chunk->owner())->IncrementUnsweptFreeBytes(-by);
}
......
......@@ -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<uintptr_t>(1) << kPageSizeBits);
......
......@@ -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<JSObject> object, Handle<Map> 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<JSObject> 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<String> SeqString::Truncate(Handle<SeqString> 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.
......
......@@ -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;
}
......
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