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

[ptr-compr][cleanup] Replace READ_[WEAK_]FIELD with TaggedField<>::load()

The latter is better because it takes field type into account when
decompressing field value.

Drive-by: use [DECL_]ACCESSOR macros for some fields.

Bug: v8:9353
Change-Id: I3d7f07d11b1e379e3e6cf0310d836af6b48c1338
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1680539
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62444}
parent 1b92e36f
......@@ -580,12 +580,12 @@ enum class MessageTemplate {
#define TEMPLATE(NAME, STRING) k##NAME,
MESSAGE_TEMPLATES(TEMPLATE)
#undef TEMPLATE
kLastMessage
kMessageCount
};
inline MessageTemplate MessageTemplateFromInt(int message_id) {
DCHECK_LE(0, message_id);
DCHECK_LT(message_id, static_cast<int>(MessageTemplate::kLastMessage));
DCHECK_LT(static_cast<unsigned>(message_id),
static_cast<unsigned>(MessageTemplate::kMessageCount));
return static_cast<MessageTemplate>(message_id);
}
......
......@@ -1156,7 +1156,7 @@ const char* MessageFormatter::TemplateString(MessageTemplate index) {
return STRING;
MESSAGE_TEMPLATES(CASE)
#undef CASE
case MessageTemplate::kLastMessage:
case MessageTemplate::kMessageCount:
default:
return nullptr;
}
......
......@@ -1232,8 +1232,8 @@ Handle<String> Factory::NewConsString(Handle<String> left, Handle<String> right,
result->set_hash_field(String::kEmptyHashField);
result->set_length(length);
result->set_first(isolate(), *left, mode);
result->set_second(isolate(), *right, mode);
result->set_first(*left, mode);
result->set_second(*right, mode);
return result;
}
......
......@@ -331,7 +331,9 @@ int Code::SizeIncludingMetadata() const {
}
ByteArray Code::unchecked_relocation_info() const {
return ByteArray::unchecked_cast(READ_FIELD(*this, kRelocationInfoOffset));
Isolate* isolate = GetIsolateForPtrCompr(*this);
return ByteArray::unchecked_cast(
TaggedField<HeapObject, kRelocationInfoOffset>::load(isolate, *this));
}
byte* Code::relocation_start() const {
......
......@@ -72,12 +72,10 @@ enum FixedArraySubInstanceType {
class FixedArrayBase : public HeapObject {
public:
// [length]: length of the array.
inline int length() const;
inline void set_length(int value);
DECL_INT_ACCESSORS(length)
// Get and set the length using acquire loads and release stores.
inline int synchronized_length() const;
inline void synchronized_set_length(int value);
DECL_SYNCHRONIZED_INT_ACCESSORS(length)
inline Object unchecked_synchronized_length() const;
......@@ -285,8 +283,7 @@ class WeakFixedArray : public HeapObject {
DECL_INT_ACCESSORS(length)
// Get and set the length using acquire loads and release stores.
inline int synchronized_length() const;
inline void synchronized_set_length(int value);
DECL_SYNCHRONIZED_INT_ACCESSORS(length)
// Gives access to raw memory which stores the array's data.
inline MaybeObjectSlot data_start();
......@@ -364,9 +361,7 @@ class WeakArrayList : public HeapObject {
DECL_INT_ACCESSORS(length)
// Get and set the capacity using acquire loads and release stores.
inline int synchronized_capacity() const;
inline void synchronized_set_capacity(int value);
DECL_SYNCHRONIZED_INT_ACCESSORS(capacity)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
......
......@@ -27,7 +27,8 @@ int FreeSpace::Size() { return size(); }
FreeSpace FreeSpace::next() {
DCHECK(IsValid());
return FreeSpace::unchecked_cast(READ_FIELD(*this, kNextOffset));
return FreeSpace::unchecked_cast(
TaggedField<Object, kNextOffset>::load(*this));
}
void FreeSpace::set_next(FreeSpace next) {
......
......@@ -39,13 +39,10 @@ class HeapObject : public Object {
// of primitive (non-JS) objects like strings, heap numbers etc.
inline void set_map_no_write_barrier(Map value);
// Get the map using acquire load.
inline Map synchronized_map() const;
inline MapWord synchronized_map_word() const;
// Set the map using release store
// Access the map using acquire load and release store.
DECL_GETTER(synchronized_map, Map)
inline void synchronized_set_map(Map value);
inline void synchronized_set_map_word(MapWord map_word);
// Compare-and-swaps map word using release store, returns true if the map
// word was actually swapped.
inline bool synchronized_compare_and_swap_map_word(MapWord old_map_word,
......@@ -61,6 +58,10 @@ class HeapObject : public Object {
DECL_GETTER(map_word, MapWord)
inline void set_map_word(MapWord map_word);
// Access the map word using acquire load and release store.
DECL_GETTER(synchronized_map_word, MapWord)
inline void synchronized_set_map_word(MapWord map_word);
// TODO(v8:7464): Once RO_SPACE is shared between isolates, this method can be
// removed as ReadOnlyRoots will be accessible from a global variable. For now
// this method exists to help remove GetIsolate/GetHeap from HeapObject, in a
......
......@@ -61,13 +61,14 @@ bool JSArray::HasArrayPrototype(Isolate* isolate) {
ACCESSORS(JSArrayIterator, iterated_object, Object, kIteratedObjectOffset)
ACCESSORS(JSArrayIterator, next_index, Object, kNextIndexOffset)
SMI_ACCESSORS(JSArrayIterator, raw_kind, kKindOffset)
IterationKind JSArrayIterator::kind() const {
return static_cast<IterationKind>(
Smi::cast(READ_FIELD(*this, kKindOffset)).value());
return static_cast<IterationKind>(raw_kind());
}
void JSArrayIterator::set_kind(IterationKind kind) {
WRITE_FIELD(*this, kKindOffset, Smi::FromInt(static_cast<int>(kind)));
set_raw_kind(static_cast<int>(kind));
}
} // namespace internal
......
......@@ -180,6 +180,9 @@ class JSArrayIterator : public JSObject {
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
TORQUE_GENERATED_JSARRAY_ITERATOR_FIELDS)
private:
DECL_INT_ACCESSORS(raw_kind)
OBJECT_CONSTRUCTORS(JSArrayIterator, JSObject);
};
......
......@@ -20,15 +20,13 @@ namespace internal {
OBJECT_CONSTRUCTORS_IMPL(JSV8BreakIterator, JSObject)
inline void JSV8BreakIterator::set_type(Type type) {
DCHECK_GT(JSV8BreakIterator::Type::COUNT, type);
WRITE_FIELD(*this, kBreakIteratorTypeOffset,
Smi::FromInt(static_cast<int>(type)));
inline JSV8BreakIterator::Type JSV8BreakIterator::type() const {
return static_cast<JSV8BreakIterator::Type>(raw_type());
}
inline JSV8BreakIterator::Type JSV8BreakIterator::type() const {
Object value = READ_FIELD(*this, kBreakIteratorTypeOffset);
return static_cast<JSV8BreakIterator::Type>(Smi::ToInt(value));
inline void JSV8BreakIterator::set_type(Type type) {
DCHECK_GT(JSV8BreakIterator::Type::COUNT, type);
set_raw_type(static_cast<int>(type));
}
ACCESSORS(JSV8BreakIterator, locale, String, kLocaleOffset)
......@@ -42,6 +40,8 @@ ACCESSORS(JSV8BreakIterator, bound_next, Object, kBoundNextOffset)
ACCESSORS(JSV8BreakIterator, bound_current, Object, kBoundCurrentOffset)
ACCESSORS(JSV8BreakIterator, bound_break_type, Object, kBoundBreakTypeOffset)
SMI_ACCESSORS(JSV8BreakIterator, raw_type, kBreakIteratorTypeOffset)
CAST_ACCESSOR(JSV8BreakIterator)
} // namespace internal
......
......@@ -70,10 +70,13 @@ class JSV8BreakIterator : public JSObject {
DECL_ACCESSORS(bound_current, Object)
DECL_ACCESSORS(bound_break_type, Object)
// Layout description.
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
TORQUE_GENERATED_JSV8BREAK_ITERATOR_FIELDS)
private:
DECL_INT_ACCESSORS(raw_type)
OBJECT_CONSTRUCTORS(JSV8BreakIterator, JSObject);
};
......
......@@ -421,7 +421,7 @@ int JSObject::GetInObjectPropertyOffset(int index) {
Object JSObject::InObjectPropertyAt(int index) {
int offset = GetInObjectPropertyOffset(index);
return READ_FIELD(*this, offset);
return TaggedField<Object>::load(*this, offset);
}
Object JSObject::InObjectPropertyAtPut(int index, Object value,
......@@ -607,11 +607,11 @@ bool JSFunction::has_closure_feedback_cell_array() const {
}
Context JSFunction::context() {
return Context::cast(READ_FIELD(*this, kContextOffset));
return TaggedField<Context, kContextOffset>::load(*this);
}
bool JSFunction::has_context() const {
return READ_FIELD(*this, kContextOffset).IsContext();
return TaggedField<HeapObject, kContextOffset>::load(*this).IsContext();
}
JSGlobalProxy JSFunction::global_proxy() { return context().global_proxy(); }
......@@ -620,7 +620,7 @@ NativeContext JSFunction::native_context() {
return context().native_context();
}
void JSFunction::set_context(Object value) {
void JSFunction::set_context(HeapObject value) {
DCHECK(value.IsUndefined() || value.IsContext());
WRITE_FIELD(*this, kContextOffset, value);
WRITE_BARRIER(*this, kContextOffset, value);
......@@ -747,12 +747,11 @@ int JSMessageObject::GetEndPosition() const {
}
MessageTemplate JSMessageObject::type() const {
Object value = READ_FIELD(*this, kMessageTypeOffset);
return MessageTemplateFromInt(Smi::ToInt(value));
return MessageTemplateFromInt(raw_type());
}
void JSMessageObject::set_type(MessageTemplate value) {
WRITE_FIELD(*this, kMessageTypeOffset, Smi::FromInt(static_cast<int>(value)));
set_raw_type(static_cast<int>(value));
}
ACCESSORS(JSMessageObject, argument, Object, kArgumentsOffset)
......@@ -763,6 +762,7 @@ ACCESSORS(JSMessageObject, bytecode_offset, Smi, kBytecodeOffsetOffset)
SMI_ACCESSORS(JSMessageObject, start_position, kStartPositionOffset)
SMI_ACCESSORS(JSMessageObject, end_position, kEndPositionOffset)
SMI_ACCESSORS(JSMessageObject, error_level, kErrorLevelOffset)
SMI_ACCESSORS(JSMessageObject, raw_type, kMessageTypeOffset)
DEF_GETTER(JSObject, GetElementsKind, ElementsKind) {
ElementsKind kind = map(isolate).elements_kind();
......
......@@ -976,7 +976,7 @@ class JSFunction : public JSObject {
// [context]: The context for this function.
inline Context context();
inline bool has_context() const;
inline void set_context(Object context);
inline void set_context(HeapObject context);
inline JSGlobalProxy global_proxy();
inline NativeContext native_context();
inline int length();
......@@ -1397,8 +1397,7 @@ class JSMessageObject : public JSObject {
// EnsureSourcePositionsAvailable must have been called before calling this.
Handle<String> GetSourceLine() const;
inline int error_level() const;
inline void set_error_level(int level);
DECL_INT_ACCESSORS(error_level)
DECL_CAST(JSMessageObject)
......@@ -1414,8 +1413,6 @@ class JSMessageObject : public JSObject {
using BodyDescriptor = FixedBodyDescriptor<HeapObject::kMapOffset,
kPointerFieldsEndOffset, kSize>;
OBJECT_CONSTRUCTORS(JSMessageObject, JSObject);
private:
friend class Factory;
......@@ -1430,12 +1427,14 @@ class JSMessageObject : public JSObject {
DECL_ACCESSORS(bytecode_offset, Smi)
// [start_position]: the start position in the script for the error message.
inline int start_position() const;
inline void set_start_position(int value);
DECL_INT_ACCESSORS(start_position)
// [end_position]: the end position in the script for the error message.
inline int end_position() const;
inline void set_end_position(int value);
DECL_INT_ACCESSORS(end_position)
DECL_INT_ACCESSORS(raw_type)
OBJECT_CONSTRUCTORS(JSMessageObject, JSObject);
};
// The [Async-from-Sync Iterator] object
......
......@@ -11,8 +11,10 @@
#undef NEVER_READ_ONLY_SPACE
#undef NEVER_READ_ONLY_SPACE_IMPL
#undef DECL_PRIMITIVE_ACCESSORS
#undef DECL_SYNCHRONIZED_PRIMITIVE_ACCESSORS
#undef DECL_BOOLEAN_ACCESSORS
#undef DECL_INT_ACCESSORS
#undef DECL_SYNCHRONIZED_INT_ACCESSORS
#undef DECL_INT32_ACCESSORS
#undef DECL_UINT16_ACCESSORS
#undef DECL_INT16_ACCESSORS
......@@ -47,8 +49,6 @@
#undef TYPE_CHECKER
#undef RELAXED_INT16_ACCESSORS
#undef FIELD_ADDR
#undef READ_FIELD
#undef READ_WEAK_FIELD
#undef ACQUIRE_READ_FIELD
#undef RELAXED_READ_FIELD
#undef RELAXED_READ_WEAK_FIELD
......
......@@ -47,10 +47,17 @@
inline type name() const; \
inline void set_##name(type value);
#define DECL_SYNCHRONIZED_PRIMITIVE_ACCESSORS(name, type) \
inline type synchronized_##name() const; \
inline void synchronized_set_##name(type value);
#define DECL_BOOLEAN_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, bool)
#define DECL_INT_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, int)
#define DECL_SYNCHRONIZED_INT_ACCESSORS(name) \
DECL_SYNCHRONIZED_PRIMITIVE_ACCESSORS(name, int)
#define DECL_INT32_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, int32_t)
#define DECL_UINT16_ACCESSORS(name) \
......@@ -254,10 +261,6 @@
#define FIELD_ADDR(p, offset) ((p).ptr() + offset - kHeapObjectTag)
#define READ_FIELD(p, offset) TaggedField<Object>::load(p, offset)
#define READ_WEAK_FIELD(p, offset) TaggedField<MaybeObject>::load(p, offset)
#define ACQUIRE_READ_FIELD(p, offset) \
TaggedField<Object>::Acquire_Load(p, offset)
......
......@@ -708,18 +708,18 @@ HeapObject MapWord::ToForwardingAddress() {
#ifdef VERIFY_HEAP
void HeapObject::VerifyObjectField(Isolate* isolate, int offset) {
VerifyPointer(isolate, READ_FIELD(*this, offset));
VerifyPointer(isolate, TaggedField<Object>::load(isolate, *this, offset));
STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size);
}
void HeapObject::VerifyMaybeObjectField(Isolate* isolate, int offset) {
MaybeObject::VerifyMaybeObjectPointer(isolate,
READ_WEAK_FIELD(*this, offset));
MaybeObject::VerifyMaybeObjectPointer(
isolate, TaggedField<MaybeObject>::load(isolate, *this, offset));
STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size);
}
void HeapObject::VerifySmiField(int offset) {
CHECK(READ_FIELD(*this, offset).IsSmi());
CHECK(TaggedField<Object>::load(*this, offset).IsSmi());
STATIC_ASSERT(!COMPRESS_POINTERS_BOOL || kTaggedSize == kInt32Size);
}
......@@ -753,8 +753,8 @@ void HeapObject::set_map(Map value) {
}
}
Map HeapObject::synchronized_map() const {
return synchronized_map_word().ToMap();
DEF_GETTER(HeapObject, synchronized_map, Map) {
return synchronized_map_word(isolate).ToMap();
}
void HeapObject::synchronized_set_map(Map value) {
......@@ -803,8 +803,8 @@ void HeapObject::set_map_word(MapWord map_word) {
MapField::Relaxed_Store(*this, map_word);
}
MapWord HeapObject::synchronized_map_word() const {
return MapField::Acquire_Load(*this);
DEF_GETTER(HeapObject, synchronized_map_word, MapWord) {
return MapField::Acquire_Load(isolate, *this);
}
void HeapObject::synchronized_set_map_word(MapWord map_word) {
......
......@@ -6617,8 +6617,8 @@ Handle<String> StringTable::LookupString(Isolate* isolate,
} else { // !FLAG_thin_strings
if (string->IsConsString()) {
Handle<ConsString> cons = Handle<ConsString>::cast(string);
cons->set_first(isolate, *result);
cons->set_second(isolate, ReadOnlyRoots(isolate).empty_string());
cons->set_first(*result);
cons->set_second(ReadOnlyRoots(isolate).empty_string());
} else if (string->IsSlicedString()) {
STATIC_ASSERT(static_cast<int>(ConsString::kSize) ==
static_cast<int>(SlicedString::kSize));
......@@ -6629,8 +6629,8 @@ Handle<String> StringTable::LookupString(Isolate* isolate,
: isolate->factory()->cons_string_map();
string->set_map(*map);
Handle<ConsString> cons = Handle<ConsString>::cast(string);
cons->set_first(isolate, *result);
cons->set_second(isolate, ReadOnlyRoots(isolate).empty_string());
cons->set_first(*result);
cons->set_second(ReadOnlyRoots(isolate).empty_string());
}
}
return result;
......
......@@ -54,7 +54,7 @@ template <class Derived>
Object SmallOrderedHashTable<Derived>::KeyAt(int entry) const {
DCHECK_LT(entry, Capacity());
Offset entry_offset = GetDataEntryOffset(entry, Derived::kKeyIndex);
return READ_FIELD(*this, entry_offset);
return TaggedField<Object>::load(*this, entry_offset);
}
template <class Derived>
......@@ -63,7 +63,7 @@ Object SmallOrderedHashTable<Derived>::GetDataEntry(int entry,
DCHECK_LT(entry, Capacity());
DCHECK_LE(static_cast<unsigned>(relative_index), Derived::kEntrySize);
Offset entry_offset = GetDataEntryOffset(entry, relative_index);
return READ_FIELD(*this, entry_offset);
return TaggedField<Object>::load(*this, entry_offset);
}
OBJECT_CONSTRUCTORS_IMPL(SmallOrderedHashSet,
......
......@@ -21,6 +21,9 @@ namespace internal {
OBJECT_CONSTRUCTORS_IMPL(PropertyArray, HeapObject)
CAST_ACCESSOR(PropertyArray)
SMI_ACCESSORS(PropertyArray, length_and_hash, kLengthAndHashOffset)
SYNCHRONIZED_SMI_ACCESSORS(PropertyArray, length_and_hash, kLengthAndHashOffset)
Object PropertyArray::get(int index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return get(isolate, index);
......@@ -53,34 +56,24 @@ void PropertyArray::set(int index, Object value, WriteBarrierMode mode) {
ObjectSlot PropertyArray::data_start() { return RawField(kHeaderSize); }
int PropertyArray::length() const {
Object value_obj = READ_FIELD(*this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
return LengthField::decode(value);
return LengthField::decode(length_and_hash());
}
void PropertyArray::initialize_length(int len) {
DCHECK_LT(static_cast<unsigned>(len),
static_cast<unsigned>(LengthField::kMax));
WRITE_FIELD(*this, kLengthAndHashOffset, Smi::FromInt(len));
DCHECK(LengthField::is_valid(len));
set_length_and_hash(len);
}
int PropertyArray::synchronized_length() const {
Object value_obj = ACQUIRE_READ_FIELD(*this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
return LengthField::decode(value);
return LengthField::decode(synchronized_length_and_hash());
}
int PropertyArray::Hash() const {
Object value_obj = READ_FIELD(*this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
return HashField::decode(value);
}
int PropertyArray::Hash() const { return HashField::decode(length_and_hash()); }
void PropertyArray::SetHash(int hash) {
Object value_obj = READ_FIELD(*this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
int value = length_and_hash();
value = HashField::update(value, hash);
WRITE_FIELD(*this, kLengthAndHashOffset, Smi::FromInt(value));
set_length_and_hash(value);
}
void PropertyArray::CopyElements(Isolate* isolate, int dst_index,
......
......@@ -68,6 +68,11 @@ class PropertyArray : public HeapObject {
static const int kNoHashSentinel = 0;
private:
DECL_INT_ACCESSORS(length_and_hash)
DECL_SYNCHRONIZED_INT_ACCESSORS(length_and_hash)
OBJECT_CONSTRUCTORS(PropertyArray, HeapObject);
};
......
......@@ -399,7 +399,7 @@ String String::GetUnderlying() {
STATIC_ASSERT(static_cast<int>(ConsString::kFirstOffset) ==
static_cast<int>(ThinString::kActualOffset));
const int kUnderlyingOffset = SlicedString::kParentOffset;
return String::cast(READ_FIELD(*this, kUnderlyingOffset));
return TaggedField<String, kUnderlyingOffset>::load(*this);
}
template <class Visitor>
......@@ -529,7 +529,7 @@ int SeqOneByteString::SeqOneByteStringSize(InstanceType instance_type) {
}
String SlicedString::parent() {
return String::cast(READ_FIELD(*this, kParentOffset));
return TaggedField<String, kParentOffset>::load(*this);
}
void SlicedString::set_parent(Isolate* isolate, String parent,
......@@ -541,32 +541,18 @@ void SlicedString::set_parent(Isolate* isolate, String parent,
SMI_ACCESSORS(SlicedString, offset, kOffsetOffset)
String ConsString::first() {
return String::cast(READ_FIELD(*this, kFirstOffset));
}
Object ConsString::unchecked_first() { return READ_FIELD(*this, kFirstOffset); }
ACCESSORS(ConsString, first, String, kFirstOffset)
void ConsString::set_first(Isolate* isolate, String value,
WriteBarrierMode mode) {
WRITE_FIELD(*this, kFirstOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, kFirstOffset, value, mode);
Object ConsString::unchecked_first() {
return TaggedField<Object, kFirstOffset>::load(*this);
}
String ConsString::second() {
return String::cast(READ_FIELD(*this, kSecondOffset));
}
ACCESSORS(ConsString, second, String, kSecondOffset)
Object ConsString::unchecked_second() {
return RELAXED_READ_FIELD(*this, kSecondOffset);
}
void ConsString::set_second(Isolate* isolate, String value,
WriteBarrierMode mode) {
WRITE_FIELD(*this, kSecondOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, kSecondOffset, value, mode);
}
ACCESSORS(ThinString, actual, String, kActualOffset)
DEF_GETTER(ThinString, unchecked_actual, HeapObject) {
......
......@@ -61,8 +61,8 @@ Handle<String> String::SlowFlatten(Isolate* isolate, Handle<ConsString> cons,
WriteToFlat(*cons, flat->GetChars(no_gc), 0, length);
result = flat;
}
cons->set_first(isolate, *result);
cons->set_second(isolate, ReadOnlyRoots(isolate).empty_string());
cons->set_first(*result);
cons->set_second(ReadOnlyRoots(isolate).empty_string());
DCHECK(result->IsFlat());
return result;
}
......
......@@ -153,13 +153,11 @@ class String : public Name {
inline const Char* GetChars(const DisallowHeapAllocation& no_gc);
// Get and set the length of the string.
inline int length() const;
inline void set_length(int value);
DECL_INT_ACCESSORS(length)
// Get and set the length of the string using acquire loads and release
// stores.
inline int synchronized_length() const;
inline void synchronized_set_length(int value);
DECL_SYNCHRONIZED_INT_ACCESSORS(length)
// Returns whether this string has only one-byte chars, i.e. all of them can
// be one-byte encoded. This might be the case even if the string is
......@@ -597,20 +595,18 @@ class SeqTwoByteString : public SeqString {
class ConsString : public String {
public:
// First string of the cons cell.
inline String first();
DECL_ACCESSORS(first, String)
// Doesn't check that the result is a string, even in debug mode. This is
// useful during GC where the mark bits confuse the checks.
inline Object unchecked_first();
inline void set_first(Isolate* isolate, String first,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
// Second string of the cons cell.
inline String second();
DECL_ACCESSORS(second, String)
// Doesn't check that the result is a string, even in debug mode. This is
// useful during GC where the mark bits confuse the checks.
inline Object unchecked_second();
inline void set_second(Isolate* isolate, String second,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
// Dispatched behavior.
V8_EXPORT_PRIVATE uint16_t Get(int index);
......
......@@ -3265,7 +3265,7 @@ void CppClassGenerator::GenerateFieldAccessorForSmi(const Field& f) {
// Generate implementation in inline header.
inl_ << "template <class D, class P>\n";
inl_ << type << " " << gen_name_ << "<D, P>::" << name << "() const {\n";
inl_ << " return Smi::cast(READ_FIELD(*this, " << offset << "));\n";
inl_ << " return TaggedField<Smi, " << offset << ">::load(*this);\n";
inl_ << "}\n";
inl_ << "template <class D, class P>\n";
......@@ -3290,6 +3290,7 @@ void CppClassGenerator::GenerateFieldAccessorForObject(const Field& f) {
hdr_ << " // Torque type: " << field_type->ToString() << "\n";
}
hdr_ << " inline " << type << " " << name << "() const;\n";
hdr_ << " inline " << type << " " << name << "(Isolate* isolate) const;\n";
hdr_ << " inline void set_" << name << "(" << type
<< " value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER);\n\n";
......@@ -3302,10 +3303,20 @@ void CppClassGenerator::GenerateFieldAccessorForObject(const Field& f) {
// Generate implementation in inline header.
inl_ << "template <class D, class P>\n";
inl_ << type << " " << gen_name_ << "<D, P>::" << name << "() const {\n";
inl_ << " Object value = READ_FIELD(*this, " << offset << ");\n";
inl_ << " Isolate* isolate = GetIsolateForPtrCompr(*this);\n";
inl_ << " return " << gen_name_ << "::" << name << "(isolate);\n";
inl_ << "}\n";
inl_ << "template <class D, class P>\n";
inl_ << type << " " << gen_name_ << "<D, P>::" << name
<< "(Isolate* isolate) const {\n";
if (class_type) {
inl_ << " return " << type << "::cast(value);\n";
inl_ << " return TaggedField<" << type << ", " << offset
<< ">::load(isolate, *this);\n";
} else {
// TODO(tebbi): load value as HeapObject when possible
inl_ << " Object value = TaggedField<Object, " << offset
<< ">::load(isolate, *this);\n";
inl_ << " DCHECK(" << type_check << ");\n";
inl_ << " return value;\n";
}
......@@ -3453,26 +3464,24 @@ void GenerateClassFieldVerifier(const std::string& class_name,
}
// We already verified the index field because it was listed earlier, so we
// can assume it's safe to read here.
cc_contents << " for (int i = 0; i < Smi::ToInt(READ_FIELD(o, "
<< class_name << "::k"
<< CamelifyString((*f.index)->name_and_type.name)
<< "Offset)); ++i) {\n";
cc_contents << " for (int i = 0; i < TaggedField<Smi, " << class_name
<< "::k" << CamelifyString((*f.index)->name_and_type.name)
<< "Offset>::load(o).value(); ++i) {\n";
} else {
cc_contents << " {\n";
}
const char* object_type = f.is_weak ? "MaybeObject" : "Object";
const char* read_fn = f.is_weak ? "READ_WEAK_FIELD" : "READ_FIELD";
const char* verify_fn =
f.is_weak ? "VerifyMaybeObjectPointer" : "VerifyPointer";
const char* index_offset = f.index ? " + i * kTaggedSize" : "";
const char* index_offset = f.index ? "i * kTaggedSize" : "0";
// Name the local var based on the field name for nicer CHECK output.
const std::string value = f.name_and_type.name + "__value";
// Read the field.
cc_contents << " " << object_type << " " << value << " = " << read_fn
<< "(o, " << class_name << "::k"
<< CamelifyString(f.name_and_type.name) << "Offset"
cc_contents << " " << object_type << " " << value << " = TaggedField<"
<< object_type << ", " << class_name << "::k"
<< CamelifyString(f.name_and_type.name) << "Offset>::load(o, "
<< index_offset << ");\n";
// Call VerifyPointer or VerifyMaybeObjectPointer on it.
......
......@@ -51,10 +51,11 @@ CAST_ACCESSOR(WasmModuleObject)
CAST_ACCESSOR(WasmTableObject)
CAST_ACCESSOR(AsmWasmData)
#define OPTIONAL_ACCESSORS(holder, name, type, offset) \
bool holder::has_##name() { \
return !READ_FIELD(*this, offset).IsUndefined(); \
} \
#define OPTIONAL_ACCESSORS(holder, name, type, offset) \
DEF_GETTER(holder, has_##name, bool) { \
Object value = TaggedField<Object, offset>::load(isolate, *this); \
return !value.IsUndefined(GetReadOnlyRoots(isolate)); \
} \
ACCESSORS(holder, name, type, offset)
#define PRIMITIVE_ACCESSORS(holder, name, type, offset) \
......
......@@ -49,7 +49,7 @@ template <class CppType>
class Managed;
#define DECL_OPTIONAL_ACCESSORS(name, type) \
V8_INLINE bool has_##name(); \
DECL_GETTER(has_##name, bool) \
DECL_ACCESSORS(name, type)
// A helper for an entry in an indirect function table (IFT).
......
......@@ -625,8 +625,8 @@ TEST(ConsStringWithEmptyFirstFlatten) {
i::Handle<i::String> new_fst = isolate->factory()->empty_string();
i::Handle<i::String> new_snd =
isolate->factory()->NewStringFromAsciiChecked("snd012345012345678");
cons->set_first(isolate, *new_fst);
cons->set_second(isolate, *new_snd);
cons->set_first(*new_fst);
cons->set_second(*new_snd);
CHECK(!cons->IsFlat());
CHECK_EQ(initial_length, new_fst->length() + new_snd->length());
CHECK_EQ(initial_length, cons->length());
......
......@@ -254,8 +254,6 @@ extras_accessors = [
'Map, prototype, Object, kPrototypeOffset',
'Oddball, kind_offset, int, kKindOffset',
'HeapNumber, value, double, kValueOffset',
'ConsString, first, String, kFirstOffset',
'ConsString, second, String, kSecondOffset',
'ExternalString, resource, Object, kResourceOffset',
'SeqOneByteString, chars, char, kHeaderSize',
'SeqTwoByteString, chars, char, kHeaderSize',
......
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