Update FixedArray atomic accessor styles

Upcoming CLs will need atomic accessors for non-smi values. This CL
adds the full set of relaxed and acquire/release indexed accessors,
and I also take the opportunity to update the old
`synchronized_set(i, v)` style to `set(i, v, ReleaseStoreTag)`.

Bug: v8:7790
Change-Id: Ic4fa4ec52319ec943415f0e9ae515a00b04cbbc3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2717305
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72995}
This commit is contained in:
Jakob Gruber 2021-02-24 08:00:54 +01:00 committed by Commit Bot
parent ed60adb549
commit 8b4e0f377d
3 changed files with 49 additions and 13 deletions

View File

@ -31,11 +31,11 @@ OBJECT_CONSTRUCTORS_IMPL(ScriptContextTable, FixedArray)
CAST_ACCESSOR(ScriptContextTable)
int ScriptContextTable::synchronized_used() const {
return Smi::ToInt(synchronized_get(kUsedSlotIndex));
return Smi::ToInt(get(kUsedSlotIndex, kAcquireLoad));
}
void ScriptContextTable::synchronized_set_used(int used) {
synchronized_set(kUsedSlotIndex, Smi::FromInt(used));
set(kUsedSlotIndex, Smi::FromInt(used), kReleaseStore);
}
// static

View File

@ -123,21 +123,50 @@ void FixedArray::NoWriteBarrierSet(FixedArray array, int index, Object value) {
RELAXED_WRITE_FIELD(array, offset, value);
}
Object FixedArray::synchronized_get(int index) const {
Object FixedArray::get(int index, RelaxedLoadTag) const {
IsolateRoot isolate = GetIsolateForPtrCompr(*this);
return synchronized_get(isolate, index);
return get(isolate, index);
}
Object FixedArray::synchronized_get(IsolateRoot isolate, int index) const {
Object FixedArray::get(IsolateRoot isolate, int index, RelaxedLoadTag) const {
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
return RELAXED_READ_FIELD(*this, OffsetOfElementAt(index));
}
void FixedArray::set(int index, Object value, RelaxedStoreTag,
WriteBarrierMode mode) {
DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
RELAXED_WRITE_FIELD(*this, OffsetOfElementAt(index), value);
CONDITIONAL_WRITE_BARRIER(*this, OffsetOfElementAt(index), value, mode);
}
void FixedArray::set(int index, Smi value, RelaxedStoreTag tag) {
DCHECK(Object(value).IsSmi());
set(index, value, tag, SKIP_WRITE_BARRIER);
}
Object FixedArray::get(int index, AcquireLoadTag) const {
IsolateRoot isolate = GetIsolateForPtrCompr(*this);
return get(isolate, index);
}
Object FixedArray::get(IsolateRoot isolate, int index, AcquireLoadTag) const {
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
return ACQUIRE_READ_FIELD(*this, OffsetOfElementAt(index));
}
void FixedArray::synchronized_set(int index, Smi value) {
void FixedArray::set(int index, Object value, ReleaseStoreTag,
WriteBarrierMode mode) {
DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
DCHECK(Object(value).IsSmi());
RELEASE_WRITE_FIELD(*this, OffsetOfElementAt(index), value);
CONDITIONAL_WRITE_BARRIER(*this, OffsetOfElementAt(index), value, mode);
}
void FixedArray::set(int index, Smi value, ReleaseStoreTag tag) {
DCHECK(Object(value).IsSmi());
set(index, value, tag, SKIP_WRITE_BARRIER);
}
void FixedArray::set_undefined(int index) {

View File

@ -111,12 +111,19 @@ class FixedArray
Isolate* isolate, Handle<FixedArray> array, int index,
Handle<Object> value);
// Synchronized setters and getters.
inline Object synchronized_get(int index) const;
inline Object synchronized_get(IsolateRoot isolate, int index) const;
// Currently only Smis are written with release semantics, hence we can avoid
// a write barrier.
inline void synchronized_set(int index, Smi value);
// Relaxed accessors.
inline Object get(int index, RelaxedLoadTag) const;
inline Object get(IsolateRoot isolate, int index, RelaxedLoadTag) const;
inline void set(int index, Object value, RelaxedStoreTag,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline void set(int index, Smi value, RelaxedStoreTag);
// Acquire/release accessors.
inline Object get(int index, AcquireLoadTag) const;
inline Object get(IsolateRoot isolate, int index, AcquireLoadTag) const;
inline void set(int index, Object value, ReleaseStoreTag,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline void set(int index, Smi value, ReleaseStoreTag);
// Setter that uses write barrier.
inline void set(int index, Object value);