Commit 7f3f7e8a authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[heap] Use std::atomic for page flags.

Bug: chromium:852420,chromium:852420
Change-Id: I873666df415c6b4919f8b3385494c9a08f105188
Reviewed-on: https://chromium-review.googlesource.com/1170700Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55055}
parent 17ad3ae4
......@@ -156,7 +156,7 @@ HeapObject* Factory::AllocateRawArray(int size, PretenureFlag pretenure) {
isolate()->heap()->AllocateRawWithRetryOrFail(size, space);
if (size > kMaxRegularHeapObjectSize && FLAG_use_marking_progress_bar) {
MemoryChunk* chunk = MemoryChunk::FromAddress(result->address());
chunk->SetFlag<AccessMode::ATOMIC>(MemoryChunk::HAS_PROGRESS_BAR);
chunk->SetFlag(MemoryChunk::HAS_PROGRESS_BAR);
}
return result;
}
......@@ -376,7 +376,7 @@ MaybeHandle<FixedArray> Factory::TryNewFixedArray(int length,
if (!allocation.To(&result)) return MaybeHandle<FixedArray>();
if (size > kMaxRegularHeapObjectSize && FLAG_use_marking_progress_bar) {
MemoryChunk* chunk = MemoryChunk::FromAddress(result->address());
chunk->SetFlag<AccessMode::ATOMIC>(MemoryChunk::HAS_PROGRESS_BAR);
chunk->SetFlag(MemoryChunk::HAS_PROGRESS_BAR);
}
result->set_map_after_allocation(*fixed_array_map(), SKIP_WRITE_BARRIER);
Handle<FixedArray> array(FixedArray::cast(result), isolate());
......
......@@ -419,8 +419,8 @@ void MarkCompactCollector::RecordSlot(HeapObject* object,
HeapObject* target) {
Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target));
Page* source_page = Page::FromAddress(reinterpret_cast<Address>(object));
if (target_page->IsEvacuationCandidate<AccessMode::ATOMIC>() &&
!source_page->ShouldSkipEvacuationSlotRecording<AccessMode::ATOMIC>()) {
if (target_page->IsEvacuationCandidate() &&
!source_page->ShouldSkipEvacuationSlotRecording()) {
RememberedSet<OLD_TO_OLD>::Insert(source_page,
reinterpret_cast<Address>(slot));
}
......
......@@ -2176,7 +2176,7 @@ bool SemiSpace::EnsureCurrentCapacity() {
DCHECK_NOT_NULL(current_page);
memory_chunk_list_.PushBack(current_page);
marking_state->ClearLiveness(current_page);
current_page->SetFlags(first_page()->GetFlags(),
current_page->SetFlags(first_page()->flags(),
static_cast<uintptr_t>(Page::kCopyAllFlags));
heap()->CreateFillerObjectAt(current_page->area_start(),
static_cast<int>(current_page->area_size()),
......@@ -2575,7 +2575,7 @@ bool SemiSpace::GrowTo(size_t new_capacity) {
memory_chunk_list_.PushBack(new_page);
marking_state->ClearLiveness(new_page);
// Duplicate the flags that was set on the old page.
new_page->SetFlags(last_page()->GetFlags(), Page::kCopyOnFlipFlagsMask);
new_page->SetFlags(last_page()->flags(), Page::kCopyOnFlipFlagsMask);
}
AccountCommitted(delta);
current_capacity_ = new_capacity;
......@@ -2650,7 +2650,7 @@ void SemiSpace::RemovePage(Page* page) {
}
void SemiSpace::PrependPage(Page* page) {
page->SetFlags(current_page()->GetFlags(),
page->SetFlags(current_page()->flags(),
static_cast<uintptr_t>(Page::kCopyAllFlags));
page->set_owner(this);
memory_chunk_list_.PushFront(page);
......@@ -2666,7 +2666,7 @@ void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) {
DCHECK(from->first_page());
DCHECK(to->first_page());
intptr_t saved_to_space_flags = to->current_page()->GetFlags();
intptr_t saved_to_space_flags = to->current_page()->flags();
// We swap all properties but id_.
std::swap(from->current_capacity_, to->current_capacity_);
......
......@@ -563,36 +563,24 @@ class MemoryChunk {
return this->address() + (index << kPointerSizeLog2);
}
template <AccessMode access_mode = AccessMode::NON_ATOMIC>
void SetFlag(Flag flag) {
if (access_mode == AccessMode::NON_ATOMIC) {
flags_ |= flag;
} else {
base::AsAtomicWord::SetBits<uintptr_t>(&flags_, flag, flag);
}
}
void SetFlag(Flag flag) { SetFlags(flag, flag); }
template <AccessMode access_mode = AccessMode::NON_ATOMIC>
bool IsFlagSet(Flag flag) {
return (GetFlags<access_mode>() & flag) != 0;
}
bool IsFlagSet(Flag flag) { return (flags() & flag) != 0; }
void ClearFlag(Flag flag) { flags_ &= ~flag; }
// Set or clear multiple flags at a time. The flags in the mask are set to
// the value in "flags", the rest retain the current value in |flags_|.
void SetFlags(uintptr_t flags, uintptr_t mask) {
flags_ = (flags_ & ~mask) | (flags & mask);
uintptr_t old_flags;
uintptr_t new_flags;
do {
old_flags = flags_;
new_flags = (old_flags & ~mask) | (flags & mask);
} while (!flags_.compare_exchange_weak(old_flags, new_flags));
}
// Return all current flags.
template <AccessMode access_mode = AccessMode::NON_ATOMIC>
uintptr_t GetFlags() {
if (access_mode == AccessMode::NON_ATOMIC) {
return flags_;
} else {
return base::AsAtomicWord::Relaxed_Load(&flags_);
}
}
uintptr_t flags() { return flags_; }
bool NeverEvacuate() { return IsFlagSet(NEVER_EVACUATE); }
......@@ -602,18 +590,15 @@ class MemoryChunk {
return !IsEvacuationCandidate() && !IsFlagSet(NEVER_ALLOCATE_ON_PAGE);
}
template <AccessMode access_mode = AccessMode::NON_ATOMIC>
bool IsEvacuationCandidate() {
DCHECK(!(IsFlagSet<access_mode>(NEVER_EVACUATE) &&
IsFlagSet<access_mode>(EVACUATION_CANDIDATE)));
return IsFlagSet<access_mode>(EVACUATION_CANDIDATE);
DCHECK(!(IsFlagSet(NEVER_EVACUATE) && IsFlagSet(EVACUATION_CANDIDATE)));
return IsFlagSet(EVACUATION_CANDIDATE);
}
template <AccessMode access_mode = AccessMode::NON_ATOMIC>
bool ShouldSkipEvacuationSlotRecording() {
uintptr_t flags = GetFlags<access_mode>();
return ((flags & kSkipEvacuationSlotsRecordingMask) != 0) &&
((flags & COMPACTION_WAS_ABORTED) == 0);
uintptr_t current_flags = flags();
return ((current_flags & kSkipEvacuationSlotsRecordingMask) != 0) &&
((current_flags & COMPACTION_WAS_ABORTED) == 0);
}
Executability executable() {
......@@ -653,7 +638,7 @@ class MemoryChunk {
VirtualMemory* reserved_memory() { return &reservation_; }
size_t size_;
uintptr_t flags_;
std::atomic<uintptr_t> flags_;
// Start and end of allocatable memory on this chunk.
Address area_start_;
......
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