Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 11253 of file object.h.

Constructor & Destructor Documentation

◆ RecordShape() [1/3]

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

Definition at line 11273 of file object.h.

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

◆ RecordShape() [2/3]

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

Definition at line 11274 of file object.h.

11274 : value_(Smi::Value(smi_value)) {
11275 ASSERT(value_ >= 0);
11276 }
intptr_t Value() const
Definition object.h:9969

◆ RecordShape() [3/3]

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

Definition at line 11277 of file object.h.

11280 ASSERT(value_ >= 0);
11281 }
static constexpr S encode(T value)
Definition bitfield.h:167
intptr_t field_names_index() const
Definition object.h:11290
intptr_t num_fields() const
Definition object.h:11288

Member Function Documentation

◆ AsInt()

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

Definition at line 11296 of file object.h.

11296{ return value_; }

◆ AsSmi()

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

Definition at line 11294 of file object.h.

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

◆ field_names_index()

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

Definition at line 11290 of file object.h.

11290 {
11291 return FieldNamesIndexBitField::decode(value_);
11292 }
static constexpr T decode(S value)
Definition bitfield.h:173

◆ ForUnnamed()

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

Definition at line 11282 of file object.h.

11282 {
11283 return RecordShape(num_fields, 0);
11284 }
RecordShape(intptr_t value)
Definition object.h:11273

◆ GetFieldNames()

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

Definition at line 28069 of file object.cc.

28069 {
28070 ObjectStore* object_store = thread->isolate_group()->object_store();
28071 Array& table =
28072 Array::Handle(thread->zone(), object_store->record_field_names());
28073 ASSERT(!table.IsNull());
28075}
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 11286 of file object.h.

11286{ return field_names_index() != 0; }

◆ num_fields()

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

Definition at line 11288 of file object.h.

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

◆ operator!=()

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

Definition at line 11301 of file object.h.

11301 {
11302 return value_ != other.value_;
11303 }

◆ operator==()

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

Definition at line 11298 of file object.h.

11298 {
11299 return value_ == other.value_;
11300 }

◆ Register()

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

Definition at line 27980 of file object.cc.

27982 {
27983 ASSERT(!field_names.IsNull());
27984 ASSERT(field_names.IsImmutable());
27985 ASSERT(field_names.ptr() == Object::empty_array().ptr() ||
27986 field_names.Length() > 0);
27987
27988 Zone* zone = thread->zone();
27989 IsolateGroup* isolate_group = thread->isolate_group();
27990 ObjectStore* object_store = isolate_group->object_store();
27991
27992 if (object_store->record_field_names<std::memory_order_acquire>() ==
27993 Array::null()) {
27994 // First-time initialization.
27995 SafepointWriteRwLocker ml(thread, isolate_group->program_lock());
27996 if (object_store->record_field_names() == Array::null()) {
27997 // Reserve record field names index 0 for records without named fields.
27999 HashTables::New<RecordFieldNamesMap>(16, Heap::kOld));
28000 map.InsertOrGetValue(Object::empty_array(),
28001 Smi::Handle(zone, Smi::New(0)));
28002 ASSERT(map.NumOccupied() == 1);
28003 object_store->set_record_field_names_map(map.Release());
28004 const auto& table = Array::Handle(zone, Array::New(16));
28005 table.SetAt(0, Object::empty_array());
28006 object_store->set_record_field_names<std::memory_order_release>(table);
28007 }
28008 }
28009
28010#if defined(DART_PRECOMPILER)
28011 const intptr_t kMaxNumFields = compiler::target::RecordShape::kMaxNumFields;
28012 const intptr_t kMaxFieldNamesIndex =
28013 compiler::target::RecordShape::kMaxFieldNamesIndex;
28014#else
28017#endif
28018
28019 if (num_fields > kMaxNumFields) {
28020 FATAL("Too many record fields");
28021 }
28022 if (field_names.ptr() == Object::empty_array().ptr()) {
28024 }
28025
28026 {
28027 SafepointReadRwLocker ml(thread, isolate_group->program_lock());
28028 RecordFieldNamesMap map(object_store->record_field_names_map());
28029 Smi& index = Smi::Handle(zone);
28030 index ^= map.GetOrNull(field_names);
28031 ASSERT(map.Release().ptr() == object_store->record_field_names_map());
28032 if (!index.IsNull()) {
28033 return RecordShape(num_fields, index.Value());
28034 }
28035 }
28036
28037 SafepointWriteRwLocker ml(thread, isolate_group->program_lock());
28038 RecordFieldNamesMap map(object_store->record_field_names_map());
28039 const intptr_t new_index = map.NumOccupied();
28040 if (new_index > kMaxFieldNamesIndex) {
28041 FATAL("Too many record shapes");
28042 }
28043
28044 const intptr_t index = Smi::Value(Smi::RawCast(map.InsertOrGetValue(
28045 field_names, Smi::Handle(zone, Smi::New(new_index)))));
28046 ASSERT(index > 0);
28047
28048 if (index == new_index) {
28049 ASSERT(map.NumOccupied() == (new_index + 1));
28050 Array& table = Array::Handle(zone, object_store->record_field_names());
28051 intptr_t capacity = table.Length();
28052 if (index >= table.Length()) {
28053 capacity = capacity + (capacity >> 2);
28054 table = Array::Grow(table, capacity);
28055 object_store->set_record_field_names(table);
28056 }
28057 table.SetAt(index, field_names);
28058 } else {
28059 ASSERT(index < new_index);
28060 }
28061 object_store->set_record_field_names_map(map.Release());
28062
28063 const RecordShape shape(num_fields, index);
28064 ASSERT(shape.GetFieldNames(thread) == field_names.ptr());
28065 ASSERT(shape.num_fields() == num_fields);
28066 return shape;
28067}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10933
static ArrayPtr Grow(const Array &source, intptr_t new_length, Heap::Space space=Heap::kNew)
Definition object.cc:24932
@ kOld
Definition heap.h:39
static ObjectPtr null()
Definition object.h:433
static RecordShape ForUnnamed(intptr_t num_fields)
Definition object.h:11282
static constexpr intptr_t kMaxFieldNamesIndex
Definition object.h:11271
static constexpr intptr_t kMaxNumFields
Definition object.h:11266
#define FATAL(error)
UnorderedHashMap< RecordFieldNamesMapTraits > RecordFieldNamesMap
Definition object.cc:27978
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:153

Definition at line 11267 of file object.h.

◆ kFieldNamesIndexShift

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

Definition at line 11269 of file object.h.

◆ kMaxFieldNamesIndex

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

Definition at line 11271 of file object.h.

◆ kMaxNumFields

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

Definition at line 11266 of file object.h.

◆ kNumFieldsMask

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

Definition at line 11265 of file object.h.


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