Commit 8b4e0f37 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

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: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72995}
parent ed60adb5
......@@ -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
......
......@@ -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 ACQUIRE_READ_FIELD(*this, OffsetOfElementAt(index));
return RELAXED_READ_FIELD(*this, OffsetOfElementAt(index));
}
void FixedArray::synchronized_set(int index, Smi value) {
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::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()));
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) {
......
......@@ -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);
......
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