Commit b2d47f24 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr] Add getters with Isolate to fixed array-like and JSObject

Bug: v8:9353
Change-Id: I740b2987da1719af6c3d4a6471e7f047801cfd5b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1678368Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62391}
parent 5870236e
......@@ -52,9 +52,15 @@ SMI_ACCESSORS(Context, length, kLengthOffset)
CAST_ACCESSOR(NativeContext)
Object Context::get(int index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return get(isolate, index);
}
Object Context::get(Isolate* isolate, int index) const {
DCHECK_LT(static_cast<unsigned>(index),
static_cast<unsigned>(this->length()));
return RELAXED_READ_FIELD(*this, OffsetOfElementAt(index));
return TaggedField<Object>::Relaxed_Load(isolate, *this,
OffsetOfElementAt(index));
}
void Context::set(int index, Object value) {
......
......@@ -455,6 +455,7 @@ class Context : public HeapObject {
// Setter and getter for elements.
V8_INLINE Object get(int index) const;
V8_INLINE Object get(Isolate* isolate, int index) const;
V8_INLINE void set(int index, Object value);
// Setter with explicit barrier mode.
V8_INLINE void set(int index, Object value, WriteBarrierMode mode);
......
......@@ -155,13 +155,22 @@ FeedbackSlot FeedbackVector::ToSlot(int index) {
}
MaybeObject FeedbackVector::Get(FeedbackSlot slot) const {
return get(GetIndex(slot));
Isolate* isolate = GetIsolateForPtrCompr(*this);
return Get(isolate, slot);
}
MaybeObject FeedbackVector::Get(Isolate* isolate, FeedbackSlot slot) const {
return get(isolate, GetIndex(slot));
}
MaybeObject FeedbackVector::get(int index) const {
DCHECK_GE(index, 0);
DCHECK_LT(index, this->length());
int offset = kFeedbackSlotsOffset + index * kTaggedSize;
Isolate* isolate = GetIsolateForPtrCompr(*this);
return get(isolate, index);
}
MaybeObject FeedbackVector::get(Isolate* isolate, int index) const {
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
int offset = OffsetOfElementAt(index);
return RELAXED_READ_WEAK_FIELD(*this, offset);
}
......@@ -180,7 +189,7 @@ void FeedbackVector::Set(FeedbackSlot slot, MaybeObject value,
void FeedbackVector::set(int index, MaybeObject value, WriteBarrierMode mode) {
DCHECK_GE(index, 0);
DCHECK_LT(index, this->length());
int offset = kFeedbackSlotsOffset + index * kTaggedSize;
int offset = OffsetOfElementAt(index);
RELAXED_WRITE_WEAK_FIELD(*this, offset, value);
CONDITIONAL_WEAK_WRITE_BARRIER(*this, offset, value, mode);
}
......
......@@ -233,7 +233,9 @@ class FeedbackVector : public HeapObject {
// Conversion from an integer index to the underlying array to a slot.
static inline FeedbackSlot ToSlot(int index);
inline MaybeObject Get(FeedbackSlot slot) const;
inline MaybeObject Get(Isolate* isolate, FeedbackSlot slot) const;
inline MaybeObject get(int index) const;
inline MaybeObject get(Isolate* isolate, int index) const;
inline void Set(FeedbackSlot slot, MaybeObject value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline void set(int index, MaybeObject value,
......@@ -322,11 +324,13 @@ class FeedbackVector : public HeapObject {
class BodyDescriptor;
// Garbage collection support.
static constexpr int SizeFor(int length) {
return kFeedbackSlotsOffset + length * kTaggedSize;
static constexpr int OffsetOfElementAt(int index) {
return kFeedbackSlotsOffset + index * kTaggedSize;
}
// Garbage collection support.
static constexpr int SizeFor(int length) { return OffsetOfElementAt(length); }
private:
static void AddToVectorsForProfilingTools(Isolate* isolate,
Handle<FeedbackVector> vector);
......
......@@ -90,51 +90,57 @@ bool FixedArray::ContainsOnlySmisOrHoles() {
}
Object FixedArray::get(int index) const {
DCHECK(index >= 0 && index < this->length());
return RELAXED_READ_FIELD(*this, kHeaderSize + index * kTaggedSize);
Isolate* isolate = GetIsolateForPtrCompr(*this);
return get(isolate, index);
}
Object FixedArray::get(Isolate* isolate, int index) const {
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
return TaggedField<Object>::Relaxed_Load(isolate, *this,
OffsetOfElementAt(index));
}
Handle<Object> FixedArray::get(FixedArray array, int index, Isolate* isolate) {
return handle(array.get(index), isolate);
return handle(array.get(isolate, index), isolate);
}
bool FixedArray::is_the_hole(Isolate* isolate, int index) {
return get(index).IsTheHole(isolate);
return get(isolate, index).IsTheHole(isolate);
}
void FixedArray::set(int index, Smi value) {
DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
DCHECK_LT(index, this->length());
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
DCHECK(Object(value).IsSmi());
int offset = kHeaderSize + index * kTaggedSize;
int offset = OffsetOfElementAt(index);
RELAXED_WRITE_FIELD(*this, offset, value);
}
void FixedArray::set(int index, Object value) {
DCHECK_NE(GetReadOnlyRoots().fixed_cow_array_map(), map());
DCHECK(IsFixedArray());
DCHECK_GE(index, 0);
DCHECK_LT(index, this->length());
int offset = kHeaderSize + index * kTaggedSize;
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
int offset = OffsetOfElementAt(index);
RELAXED_WRITE_FIELD(*this, offset, value);
WRITE_BARRIER(*this, offset, value);
}
void FixedArray::set(int index, Object value, WriteBarrierMode mode) {
DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map());
DCHECK_GE(index, 0);
DCHECK_LT(index, this->length());
int offset = kHeaderSize + index * kTaggedSize;
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
int offset = OffsetOfElementAt(index);
RELAXED_WRITE_FIELD(*this, offset, value);
CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode);
}
// static
void FixedArray::NoWriteBarrierSet(FixedArray array, int index, Object value) {
DCHECK_NE(array.map(), array.GetReadOnlyRoots().fixed_cow_array_map());
DCHECK_GE(index, 0);
DCHECK_LT(index, array.length());
DCHECK_LT(static_cast<unsigned>(index),
static_cast<unsigned>(array.length()));
DCHECK(!ObjectInYoungGeneration(value));
RELAXED_WRITE_FIELD(array, kHeaderSize + index * kTaggedSize, value);
int offset = OffsetOfElementAt(index);
RELAXED_WRITE_FIELD(array, offset, value);
}
void FixedArray::set_undefined(int index) {
......@@ -382,8 +388,14 @@ void FixedDoubleArray::FillWithHoles(int from, int to) {
}
MaybeObject WeakFixedArray::Get(int index) const {
DCHECK(index >= 0 && index < this->length());
return RELAXED_READ_WEAK_FIELD(*this, OffsetOfElementAt(index));
Isolate* isolate = GetIsolateForPtrCompr(*this);
return Get(isolate, index);
}
MaybeObject WeakFixedArray::Get(Isolate* isolate, int index) const {
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
return TaggedField<MaybeObject>::Relaxed_Load(isolate, *this,
OffsetOfElementAt(index));
}
void WeakFixedArray::Set(int index, MaybeObject value) {
......@@ -424,8 +436,14 @@ void WeakFixedArray::CopyElements(Isolate* isolate, int dst_index,
}
MaybeObject WeakArrayList::Get(int index) const {
DCHECK(index >= 0 && index < this->capacity());
return RELAXED_READ_WEAK_FIELD(*this, OffsetOfElementAt(index));
Isolate* isolate = GetIsolateForPtrCompr(*this);
return Get(isolate, index);
}
MaybeObject WeakArrayList::Get(Isolate* isolate, int index) const {
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(capacity()));
return TaggedField<MaybeObject>::Relaxed_Load(isolate, *this,
OffsetOfElementAt(index));
}
void WeakArrayList::Set(int index, MaybeObject value, WriteBarrierMode mode) {
......@@ -478,6 +496,10 @@ Object ArrayList::Get(int index) const {
return FixedArray::cast(*this).get(kFirstIndex + index);
}
Object ArrayList::Get(Isolate* isolate, int index) const {
return FixedArray::cast(*this).get(isolate, kFirstIndex + index);
}
ObjectSlot ArrayList::Slot(int index) {
return RawField(OffsetOfElementAt(kFirstIndex + index));
}
......@@ -589,6 +611,10 @@ Object TemplateList::get(int index) const {
return FixedArray::cast(*this).get(kFirstElementIndex + index);
}
Object TemplateList::get(Isolate* isolate, int index) const {
return FixedArray::cast(*this).get(isolate, kFirstElementIndex + index);
}
void TemplateList::set(int index, Object value) {
FixedArray::cast(*this).set(kFirstElementIndex + index, value);
}
......
......@@ -114,6 +114,8 @@ class FixedArray : public FixedArrayBase {
public:
// Setter and getter for elements.
inline Object get(int index) const;
inline Object get(Isolate* isolate, int index) const;
static inline Handle<Object> get(FixedArray array, int index,
Isolate* isolate);
......@@ -268,6 +270,7 @@ class WeakFixedArray : public HeapObject {
DECL_CAST(WeakFixedArray)
inline MaybeObject Get(int index) const;
inline MaybeObject Get(Isolate* isolate, int index) const;
// Setter that uses write barrier.
inline void Set(int index, MaybeObject value);
......@@ -337,6 +340,7 @@ class WeakArrayList : public HeapObject {
const MaybeObjectHandle& value);
inline MaybeObject Get(int index) const;
inline MaybeObject Get(Isolate* isolate, int index) const;
// Set the element at index to obj. The underlying array must be large enough.
// If you need to grow the WeakArrayList, use the static AddToEnd() method
......@@ -438,6 +442,7 @@ class ArrayList : public FixedArray {
// storage capacity, i.e., length().
inline void SetLength(int length);
inline Object Get(int index) const;
inline Object Get(Isolate* isolate, int index) const;
inline ObjectSlot Slot(int index);
// Set the element at index to obj. The underlying array must be large enough.
......@@ -577,6 +582,7 @@ class TemplateList : public FixedArray {
static Handle<TemplateList> New(Isolate* isolate, int size);
inline int length() const;
inline Object get(int index) const;
inline Object get(Isolate* isolate, int index) const;
inline void set(int index, Object value);
static Handle<TemplateList> Add(Isolate* isolate, Handle<TemplateList> list,
Handle<Object> value);
......
......@@ -308,29 +308,39 @@ void JSObject::SetEmbedderField(int index, Smi value) {
EmbedderDataSlot(*this, index).store_smi(value);
}
bool JSObject::IsUnboxedDoubleField(FieldIndex index) {
bool JSObject::IsUnboxedDoubleField(FieldIndex index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return IsUnboxedDoubleField(isolate, index);
}
bool JSObject::IsUnboxedDoubleField(Isolate* isolate, FieldIndex index) const {
if (!FLAG_unbox_double_fields) return false;
return map().IsUnboxedDoubleField(index);
return map(isolate).IsUnboxedDoubleField(isolate, index);
}
// Access fast-case object properties at index. The use of these routines
// is needed to correctly distinguish between properties stored in-object and
// properties stored in the properties array.
Object JSObject::RawFastPropertyAt(FieldIndex index) {
DCHECK(!IsUnboxedDoubleField(index));
Object JSObject::RawFastPropertyAt(FieldIndex index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return RawFastPropertyAt(isolate, index);
}
Object JSObject::RawFastPropertyAt(Isolate* isolate, FieldIndex index) const {
DCHECK(!IsUnboxedDoubleField(isolate, index));
if (index.is_inobject()) {
return READ_FIELD(*this, index.offset());
return TaggedField<Object>::load(isolate, *this, index.offset());
} else {
return property_array().get(index.outobject_array_index());
return property_array(isolate).get(isolate, index.outobject_array_index());
}
}
double JSObject::RawFastDoublePropertyAt(FieldIndex index) {
double JSObject::RawFastDoublePropertyAt(FieldIndex index) const {
DCHECK(IsUnboxedDoubleField(index));
return ReadField<double>(index.offset());
}
uint64_t JSObject::RawFastDoublePropertyAsBitsAt(FieldIndex index) {
uint64_t JSObject::RawFastDoublePropertyAsBitsAt(FieldIndex index) const {
DCHECK(IsUnboxedDoubleField(index));
return ReadField<uint64_t>(index.offset());
}
......
......@@ -627,15 +627,17 @@ class JSObject : public JSReceiver {
int unused_property_fields,
const char* reason);
inline bool IsUnboxedDoubleField(FieldIndex index);
inline bool IsUnboxedDoubleField(FieldIndex index) const;
inline bool IsUnboxedDoubleField(Isolate* isolate, FieldIndex index) const;
// Access fast-case object properties at index.
static Handle<Object> FastPropertyAt(Handle<JSObject> object,
Representation representation,
FieldIndex index);
inline Object RawFastPropertyAt(FieldIndex index);
inline double RawFastDoublePropertyAt(FieldIndex index);
inline uint64_t RawFastDoublePropertyAsBitsAt(FieldIndex index);
inline Object RawFastPropertyAt(FieldIndex index) const;
inline Object RawFastPropertyAt(Isolate* isolate, FieldIndex index) const;
inline double RawFastDoublePropertyAt(FieldIndex index) const;
inline uint64_t RawFastDoublePropertyAsBitsAt(FieldIndex index) const;
inline void FastPropertyAtPut(FieldIndex index, Object value);
inline void RawFastPropertyAtPut(
......
......@@ -145,9 +145,14 @@ bool Map::EquivalentToForNormalization(const Map other,
}
bool Map::IsUnboxedDoubleField(FieldIndex index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return IsUnboxedDoubleField(isolate, index);
}
bool Map::IsUnboxedDoubleField(Isolate* isolate, FieldIndex index) const {
if (!FLAG_unbox_double_fields) return false;
if (!index.is_inobject()) return false;
return !layout_descriptor().IsTagged(index.property_index());
return !layout_descriptor(isolate).IsTagged(index.property_index());
}
bool Map::TooManyFastProperties(StoreOrigin store_origin) const {
......
......@@ -852,6 +852,7 @@ class Map : public HeapObject {
// Returns true if given field is unboxed double.
inline bool IsUnboxedDoubleField(FieldIndex index) const;
inline bool IsUnboxedDoubleField(Isolate* isolate, FieldIndex index) const;
void PrintMapDetails(std::ostream& os);
......
......@@ -22,9 +22,15 @@ OBJECT_CONSTRUCTORS_IMPL(PropertyArray, HeapObject)
CAST_ACCESSOR(PropertyArray)
Object PropertyArray::get(int index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return get(isolate, index);
}
Object PropertyArray::get(Isolate* isolate, int index) const {
DCHECK_LT(static_cast<unsigned>(index),
static_cast<unsigned>(this->length()));
return RELAXED_READ_FIELD(*this, OffsetOfElementAt(index));
return TaggedField<Object>::Relaxed_Load(isolate, *this,
OffsetOfElementAt(index));
}
void PropertyArray::set(int index, Object value) {
......
......@@ -30,6 +30,7 @@ class PropertyArray : public HeapObject {
inline int Hash() const;
inline Object get(int index) const;
inline Object get(Isolate* isolate, int index) const;
inline void set(int index, Object value);
// Setter with explicit barrier mode.
......
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