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

[ptr-compr][cleanup] Inline trivial methods of ObjectBoilerplateDescription

... and add getters with Isolate parameter.

Bug: v8:9353, v8:9396
Change-Id: Iab1e4652859f0a8922af6243bac3caee0888df63
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1679503Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62413}
parent b9ea6954
......@@ -580,7 +580,7 @@ Handle<ObjectBoilerplateDescription> Factory::NewObjectBoilerplateDescription(
if (has_different_size_backing_store) {
DCHECK_IMPLIES((boilerplate == (all_properties - index_keys)),
has_seen_proto);
description->set_backing_store_size(isolate(), backing_store_size);
description->set_backing_store_size(backing_store_size);
}
description->set_flags(0);
......
......@@ -15,6 +15,10 @@
namespace v8 {
namespace internal {
//
// ObjectBoilerplateDescription
//
OBJECT_CONSTRUCTORS_IMPL(ObjectBoilerplateDescription, FixedArray)
CAST_ACCESSOR(ObjectBoilerplateDescription)
......@@ -22,6 +26,70 @@ CAST_ACCESSOR(ObjectBoilerplateDescription)
SMI_ACCESSORS(ObjectBoilerplateDescription, flags,
FixedArray::OffsetOfElementAt(kLiteralTypeOffset))
Object ObjectBoilerplateDescription::name(int index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return name(isolate, index);
}
Object ObjectBoilerplateDescription::name(Isolate* isolate, int index) const {
// get() already checks for out of bounds access, but we do not want to allow
// access to the last element, if it is the number of properties.
DCHECK_NE(size(), index);
return get(isolate, 2 * index + kDescriptionStartIndex);
}
Object ObjectBoilerplateDescription::value(int index) const {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return value(isolate, index);
}
Object ObjectBoilerplateDescription::value(Isolate* isolate, int index) const {
return get(isolate, 2 * index + 1 + kDescriptionStartIndex);
}
void ObjectBoilerplateDescription::set_key_value(int index, Object key,
Object value) {
DCHECK_LT(index, size());
DCHECK_GE(index, 0);
set(2 * index + kDescriptionStartIndex, key);
set(2 * index + 1 + kDescriptionStartIndex, value);
}
int ObjectBoilerplateDescription::size() const {
DCHECK_EQ(0, (length() - kDescriptionStartIndex -
(this->has_number_of_properties() ? 1 : 0)) %
2);
// Rounding is intended.
return (length() - kDescriptionStartIndex) / 2;
}
bool ObjectBoilerplateDescription::has_number_of_properties() const {
return (length() - kDescriptionStartIndex) % 2 != 0;
}
int ObjectBoilerplateDescription::backing_store_size() const {
if (has_number_of_properties()) {
// If present, the last entry contains the number of properties.
return Smi::ToInt(this->get(length() - 1));
}
// If the number is not given explicitly, we assume there are no
// properties with computed names.
return size();
}
void ObjectBoilerplateDescription::set_backing_store_size(
int backing_store_size) {
DCHECK(has_number_of_properties());
DCHECK_NE(size(), backing_store_size);
CHECK(Smi::IsValid(backing_store_size));
// TODO(ishell): move this value to the header
set(length() - 1, Smi::FromInt(backing_store_size));
}
//
// ClassBoilerplate
//
OBJECT_CONSTRUCTORS_IMPL(ClassBoilerplate, FixedArray)
CAST_ACCESSOR(ClassBoilerplate)
......@@ -52,6 +120,10 @@ ACCESSORS(ClassBoilerplate, instance_elements_template, Object,
ACCESSORS(ClassBoilerplate, instance_computed_properties, FixedArray,
FixedArray::OffsetOfElementAt(kPrototypeComputedPropertiesIndex))
//
// ArrayBoilerplateDescription
//
OBJECT_CONSTRUCTORS_IMPL(ArrayBoilerplateDescription, Struct)
CAST_ACCESSOR(ArrayBoilerplateDescription)
......
......@@ -17,56 +17,6 @@
namespace v8 {
namespace internal {
Object ObjectBoilerplateDescription::name(int index) const {
// get() already checks for out of bounds access, but we do not want to allow
// access to the last element, if it is the number of properties.
DCHECK_NE(size(), index);
return get(2 * index + kDescriptionStartIndex);
}
Object ObjectBoilerplateDescription::value(int index) const {
return get(2 * index + 1 + kDescriptionStartIndex);
}
void ObjectBoilerplateDescription::set_key_value(int index, Object key,
Object value) {
DCHECK_LT(index, size());
DCHECK_GE(index, 0);
set(2 * index + kDescriptionStartIndex, key);
set(2 * index + 1 + kDescriptionStartIndex, value);
}
int ObjectBoilerplateDescription::size() const {
DCHECK_EQ(0, (length() - kDescriptionStartIndex -
(this->has_number_of_properties() ? 1 : 0)) %
2);
// Rounding is intended.
return (length() - kDescriptionStartIndex) / 2;
}
int ObjectBoilerplateDescription::backing_store_size() const {
if (has_number_of_properties()) {
// If present, the last entry contains the number of properties.
return Smi::ToInt(this->get(length() - 1));
}
// If the number is not given explicitly, we assume there are no
// properties with computed names.
return size();
}
void ObjectBoilerplateDescription::set_backing_store_size(
Isolate* isolate, int backing_store_size) {
DCHECK(has_number_of_properties());
DCHECK_NE(size(), backing_store_size);
Handle<Object> backing_store_size_obj =
isolate->factory()->NewNumberFromInt(backing_store_size);
set(length() - 1, *backing_store_size_obj);
}
bool ObjectBoilerplateDescription::has_number_of_properties() const {
return (length() - kDescriptionStartIndex) % 2 != 0;
}
namespace {
inline int EncodeComputedEntry(ClassBoilerplate::ValueKind value_kind,
......
......@@ -21,20 +21,23 @@ class ClassLiteral;
// of properties in the backing store. This number includes properties with
// computed names that are not
// in the list.
// TODO(ishell): Don't derive from FixedArray as it already has its own map.
class ObjectBoilerplateDescription : public FixedArray {
public:
Object name(int index) const;
Object value(int index) const;
inline Object name(int index) const;
inline Object name(Isolate* isolate, int index) const;
void set_key_value(int index, Object key, Object value);
inline Object value(int index) const;
inline Object value(Isolate* isolate, int index) const;
inline void set_key_value(int index, Object key, Object value);
// The number of boilerplate properties.
int size() const;
inline int size() const;
// Number of boilerplate properties and properties with computed names.
int backing_store_size() const;
void set_backing_store_size(Isolate* isolate, int backing_store_size);
inline int backing_store_size() const;
inline void set_backing_store_size(int backing_store_size);
// Used to encode ObjectLiteral::Flags for nested object literals
// Stored as the first element of the fixed array
......@@ -47,7 +50,7 @@ class ObjectBoilerplateDescription : public FixedArray {
DECL_PRINTER(ObjectBoilerplateDescription)
private:
bool has_number_of_properties() const;
inline bool has_number_of_properties() const;
OBJECT_CONSTRUCTORS(ObjectBoilerplateDescription, FixedArray);
};
......
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