Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
dart::RecordShape Class Reference

#include <object.h>

Public Member Functions

 RecordShape (intptr_t value)
 
 RecordShape (SmiPtr smi_value)
 
 RecordShape (intptr_t num_fields, intptr_t field_names_index)
 
bool HasNamedFields () const
 
intptr_t num_fields () const
 
intptr_t field_names_index () const
 
SmiPtr AsSmi () const
 
intptr_t AsInt () const
 
bool operator== (const RecordShape &other) const
 
bool operator!= (const RecordShape &other) const
 
ArrayPtr GetFieldNames (Thread *thread) const
 

Static Public Member Functions

static RecordShape ForUnnamed (intptr_t num_fields)
 
static RecordShape Register (Thread *thread, intptr_t num_fields, const Array &field_names)
 

Static Public Attributes

static constexpr intptr_t kNumFieldsMask = NumFieldsBitField::mask()
 
static constexpr intptr_t kMaxNumFields = kNumFieldsMask
 
static constexpr intptr_t kFieldNamesIndexMask
 
static constexpr intptr_t kFieldNamesIndexShift
 
static constexpr intptr_t kMaxFieldNamesIndex = kFieldNamesIndexMask
 

Detailed Description

Definition at line 11279 of file object.h.

Constructor & Destructor Documentation

◆ RecordShape() [1/3]

dart::RecordShape::RecordShape ( intptr_t  value)
inlineexplicit

Definition at line 11299 of file object.h.

11299: value_(value) { ASSERT(value_ >= 0); }
#define ASSERT(E)
uint8_t value

◆ RecordShape() [2/3]

dart::RecordShape::RecordShape ( SmiPtr  smi_value)
inlineexplicit

Definition at line 11300 of file object.h.

11300 : value_(Smi::Value(smi_value)) {
11301 ASSERT(value_ >= 0);
11302 }
intptr_t Value() const
Definition: object.h:9990

◆ RecordShape() [3/3]

dart::RecordShape::RecordShape ( intptr_t  num_fields,
intptr_t  field_names_index 
)
inline

Definition at line 11303 of file object.h.

11306 ASSERT(value_ >= 0);
11307 }
static constexpr S encode(T value)
Definition: bitfield.h:165
intptr_t field_names_index() const
Definition: object.h:11316
intptr_t num_fields() const
Definition: object.h:11314

Member Function Documentation

◆ AsInt()

intptr_t dart::RecordShape::AsInt ( ) const
inline

Definition at line 11322 of file object.h.

11322{ return value_; }

◆ AsSmi()

SmiPtr dart::RecordShape::AsSmi ( ) const
inline

Definition at line 11320 of file object.h.

11320{ return Smi::New(value_); }
static SmiPtr New(intptr_t value)
Definition: object.h:10006

◆ field_names_index()

intptr_t dart::RecordShape::field_names_index ( ) const
inline

Definition at line 11316 of file object.h.

11316 {
11317 return FieldNamesIndexBitField::decode(value_);
11318 }
static constexpr T decode(S value)
Definition: bitfield.h:171

◆ ForUnnamed()

static RecordShape dart::RecordShape::ForUnnamed ( intptr_t  num_fields)
inlinestatic

Definition at line 11308 of file object.h.

11308 {
11309 return RecordShape(num_fields, 0);
11310 }
RecordShape(intptr_t value)
Definition: object.h:11299

◆ GetFieldNames()

ArrayPtr dart::RecordShape::GetFieldNames ( Thread thread) const

Definition at line 27987 of file object.cc.

27987 {
27988 ObjectStore* object_store = thread->isolate_group()->object_store();
27989 Array& table =
27990 Array::Handle(thread->zone(), object_store->record_field_names());
27991 ASSERT(!table.IsNull());
27993}
SI F table(const skcms_Curve *curve, F v)
static Object & Handle()
Definition: object.h:407
static ObjectPtr RawCast(ObjectPtr obj)
Definition: object.h:325

◆ HasNamedFields()

bool dart::RecordShape::HasNamedFields ( ) const
inline

Definition at line 11312 of file object.h.

11312{ return field_names_index() != 0; }

◆ num_fields()

intptr_t dart::RecordShape::num_fields ( ) const
inline

Definition at line 11314 of file object.h.

11314{ return NumFieldsBitField::decode(value_); }

◆ operator!=()

bool dart::RecordShape::operator!= ( const RecordShape other) const
inline

Definition at line 11327 of file object.h.

11327 {
11328 return value_ != other.value_;
11329 }

◆ operator==()

bool dart::RecordShape::operator== ( const RecordShape other) const
inline

Definition at line 11324 of file object.h.

11324 {
11325 return value_ == other.value_;
11326 }

◆ Register()

RecordShape dart::RecordShape::Register ( Thread thread,
intptr_t  num_fields,
const Array field_names 
)
static

Definition at line 27898 of file object.cc.

27900 {
27901 ASSERT(!field_names.IsNull());
27902 ASSERT(field_names.IsImmutable());
27903 ASSERT(field_names.ptr() == Object::empty_array().ptr() ||
27904 field_names.Length() > 0);
27905
27906 Zone* zone = thread->zone();
27907 IsolateGroup* isolate_group = thread->isolate_group();
27908 ObjectStore* object_store = isolate_group->object_store();
27909
27910 if (object_store->record_field_names<std::memory_order_acquire>() ==
27911 Array::null()) {
27912 // First-time initialization.
27913 SafepointWriteRwLocker ml(thread, isolate_group->program_lock());
27914 if (object_store->record_field_names() == Array::null()) {
27915 // Reserve record field names index 0 for records without named fields.
27917 HashTables::New<RecordFieldNamesMap>(16, Heap::kOld));
27918 map.InsertOrGetValue(Object::empty_array(),
27919 Smi::Handle(zone, Smi::New(0)));
27920 ASSERT(map.NumOccupied() == 1);
27921 object_store->set_record_field_names_map(map.Release());
27922 const auto& table = Array::Handle(zone, Array::New(16));
27923 table.SetAt(0, Object::empty_array());
27924 object_store->set_record_field_names<std::memory_order_release>(table);
27925 }
27926 }
27927
27928#if defined(DART_PRECOMPILER)
27930 const intptr_t kMaxFieldNamesIndex =
27932#else
27935#endif
27936
27937 if (num_fields > kMaxNumFields) {
27938 FATAL("Too many record fields");
27939 }
27940 if (field_names.ptr() == Object::empty_array().ptr()) {
27942 }
27943
27944 {
27945 SafepointReadRwLocker ml(thread, isolate_group->program_lock());
27946 RecordFieldNamesMap map(object_store->record_field_names_map());
27947 Smi& index = Smi::Handle(zone);
27948 index ^= map.GetOrNull(field_names);
27949 ASSERT(map.Release().ptr() == object_store->record_field_names_map());
27950 if (!index.IsNull()) {
27951 return RecordShape(num_fields, index.Value());
27952 }
27953 }
27954
27955 SafepointWriteRwLocker ml(thread, isolate_group->program_lock());
27956 RecordFieldNamesMap map(object_store->record_field_names_map());
27957 const intptr_t new_index = map.NumOccupied();
27958 if (new_index > kMaxFieldNamesIndex) {
27959 FATAL("Too many record shapes");
27960 }
27961
27962 const intptr_t index = Smi::Value(Smi::RawCast(map.InsertOrGetValue(
27963 field_names, Smi::Handle(zone, Smi::New(new_index)))));
27964 ASSERT(index > 0);
27965
27966 if (index == new_index) {
27967 ASSERT(map.NumOccupied() == (new_index + 1));
27968 Array& table = Array::Handle(zone, object_store->record_field_names());
27969 intptr_t capacity = table.Length();
27970 if (index >= table.Length()) {
27971 capacity = capacity + (capacity >> 2);
27972 table = Array::Grow(table, capacity);
27973 object_store->set_record_field_names(table);
27974 }
27975 table.SetAt(index, field_names);
27976 } else {
27977 ASSERT(index < new_index);
27978 }
27979 object_store->set_record_field_names_map(map.Release());
27980
27981 const RecordShape shape(num_fields, index);
27982 ASSERT(shape.GetFieldNames(thread) == field_names.ptr());
27983 ASSERT(shape.num_fields() == num_fields);
27984 return shape;
27985}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10959
static ArrayPtr Grow(const Array &source, intptr_t new_length, Heap::Space space=Heap::kNew)
Definition: object.cc:24853
@ kOld
Definition: heap.h:39
static ObjectPtr null()
Definition: object.h:433
static RecordShape ForUnnamed(intptr_t num_fields)
Definition: object.h:11308
static constexpr intptr_t kMaxFieldNamesIndex
Definition: object.h:11297
static constexpr intptr_t kMaxNumFields
Definition: object.h:11292
static const word kMaxFieldNamesIndex
Definition: runtime_api.h:613
#define FATAL(error)
UnorderedHashMap< RecordFieldNamesMapTraits > RecordFieldNamesMap
Definition: object.cc:27896
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680

Member Data Documentation

◆ kFieldNamesIndexMask

constexpr intptr_t dart::RecordShape::kFieldNamesIndexMask
staticconstexpr
Initial value:
=
static constexpr S mask()
Definition: bitfield.h:151

Definition at line 11293 of file object.h.

◆ kFieldNamesIndexShift

constexpr intptr_t dart::RecordShape::kFieldNamesIndexShift
staticconstexpr
Initial value:
=
static constexpr int shift()
Definition: bitfield.h:159

Definition at line 11295 of file object.h.

◆ kMaxFieldNamesIndex

constexpr intptr_t dart::RecordShape::kMaxFieldNamesIndex = kFieldNamesIndexMask
staticconstexpr

Definition at line 11297 of file object.h.

◆ kMaxNumFields

constexpr intptr_t dart::RecordShape::kMaxNumFields = kNumFieldsMask
staticconstexpr

Definition at line 11292 of file object.h.

◆ kNumFieldsMask

constexpr intptr_t dart::RecordShape::kNumFieldsMask = NumFieldsBitField::mask()
staticconstexpr

Definition at line 11291 of file object.h.


The documentation for this class was generated from the following files: