Commit da2300f6 authored by Pierre Langlois's avatar Pierre Langlois Committed by Commit Bot

[heap] Relax accesses to a page's live byte count.

Each page has a `live_byte_count_` field in its header and it is always accessed
with atomic operations. However, apart from one corner case, this field is only
accessed by the main thread so let's remove the atomicity by default.

To summarise, this changes the MarkingState accessors in the following way:

- IncrementalMarkingState:

Accesses of live_byte_count_ are now non-atomic. Concurrent marking uses local
maps of live bytes per page so we have exclusive access to the field when using
this.

- MajorAtomicMarkingState:

This accessor does not guarantee exclusive access to live_byte_count_ so we need
to keep the access atomic. This is used by the scavenger when migrating an
object that was marked black, since marking an object black will implicitly
increment the live_byte_count_.

Additionally, the live_bytes() and SetLiveBytes() accessor methods were not used
so remove them.

- MajorNonAtomicMarkingState:

Accesses of live_byte_count_ are not actually non-atomic.

- MinorNonAtomicMarkingState:

The `young_generation_live_byte_count_` field is atomic so we can set the memory
order manual to relax accesses.

Change-Id: I4c6457843783157ca878540e34ad50878afee20c
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel
Reviewed-on: https://chromium-review.googlesource.com/c/1456095Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Pierre Langlois <pierre.langlois@arm.com>
Cr-Commit-Position: refs/heads/master@{#59548}
parent 82faa6d3
......@@ -5,6 +5,7 @@
#ifndef V8_HEAP_MARK_COMPACT_H_
#define V8_HEAP_MARK_COMPACT_H_
#include <atomic>
#include <vector>
#include "src/heap/concurrent-marking.h"
......@@ -325,15 +326,18 @@ class MinorNonAtomicMarkingState final
}
void IncrementLiveBytes(MemoryChunk* chunk, intptr_t by) {
chunk->young_generation_live_byte_count_ += by;
chunk->young_generation_live_byte_count_.fetch_add(
by, std::memory_order_relaxed);
}
intptr_t live_bytes(MemoryChunk* chunk) const {
return chunk->young_generation_live_byte_count_;
return chunk->young_generation_live_byte_count_.load(
std::memory_order_relaxed);
}
void SetLiveBytes(MemoryChunk* chunk, intptr_t value) {
chunk->young_generation_live_byte_count_ = value;
chunk->young_generation_live_byte_count_.store(value,
std::memory_order_relaxed);
}
};
......@@ -348,7 +352,8 @@ class IncrementalMarkingState final
return chunk->marking_bitmap_;
}
// Concurrent marking uses local live bytes.
// Concurrent marking uses local live bytes so we may do these accesses
// non-atomically.
void IncrementLiveBytes(MemoryChunk* chunk, intptr_t by) {
chunk->live_byte_count_ += by;
}
......@@ -373,15 +378,8 @@ class MajorAtomicMarkingState final
}
void IncrementLiveBytes(MemoryChunk* chunk, intptr_t by) {
chunk->live_byte_count_ += by;
}
intptr_t live_bytes(MemoryChunk* chunk) const {
return chunk->live_byte_count_;
}
void SetLiveBytes(MemoryChunk* chunk, intptr_t value) {
chunk->live_byte_count_ = value;
std::atomic_fetch_add(
reinterpret_cast<std::atomic<intptr_t>*>(&chunk->live_byte_count_), by);
}
};
......
......@@ -383,7 +383,7 @@ class MemoryChunk {
+ kSystemPointerSize // Address area_end_
+ kSystemPointerSize // Address owner_
+ kIntptrSize // intptr_t progress_bar_
+ kIntptrSize // std::atomic<intptr_t> live_byte_count_
+ kIntptrSize // intptr_t live_byte_count_
+ kSystemPointerSize * NUMBER_OF_REMEMBERED_SET_TYPES // SlotSet* array
+ kSystemPointerSize *
NUMBER_OF_REMEMBERED_SET_TYPES // TypedSlotSet* array
......@@ -721,7 +721,7 @@ class MemoryChunk {
std::atomic<intptr_t> progress_bar_;
// Count of bytes marked black on page.
std::atomic<intptr_t> live_byte_count_;
intptr_t live_byte_count_;
// A single slot set for small pages (of size kPageSize) or an array of slot
// set for large pages. In the latter case the number of entries in the array
......
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