Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
dart::Instance Class Reference

#include <object.h>

Inheritance diagram for dart::Instance:
dart::Object dart::AbstractType dart::Array dart::Bool dart::Capability dart::Closure dart::DynamicLibrary dart::FinalizerBase dart::FinalizerEntry dart::Float32x4 dart::Float64x2 dart::FutureOr dart::GrowableObjectArray dart::Int32x4 dart::LibraryPrefix dart::LinkedHashBase dart::MirrorReference dart::Number dart::Pointer dart::PointerBase dart::ReceivePort dart::Record dart::RegExp dart::SendPort dart::StackTrace dart::String dart::SuspendState dart::TransferableTypedData dart::TypeArguments dart::UserTag dart::WeakProperty dart::WeakReference

Public Member Functions

virtual bool OperatorEquals (const Instance &other) const
 
bool IsIdenticalTo (const Instance &other) const
 
virtual bool CanonicalizeEquals (const Instance &other) const
 
virtual uint32_t CanonicalizeHash () const
 
intptr_t SizeFromClass () const
 
InstancePtr Canonicalize (Thread *thread) const
 
virtual InstancePtr CanonicalizeLocked (Thread *thread) const
 
virtual void CanonicalizeFieldsLocked (Thread *thread) const
 
InstancePtr CopyShallowToOldSpace (Thread *thread) const
 
ObjectPtr GetField (const Field &field) const
 
void SetField (const Field &field, const Object &value) const
 
AbstractTypePtr GetType (Heap::Space space) const
 
virtual TypeArgumentsPtr GetTypeArguments () const
 
virtual void SetTypeArguments (const TypeArguments &value) const
 
bool IsInstanceOf (const AbstractType &other, const TypeArguments &other_instantiator_type_arguments, const TypeArguments &other_function_type_arguments) const
 
bool IsAssignableTo (const AbstractType &other, const TypeArguments &other_instantiator_type_arguments, const TypeArguments &other_function_type_arguments) const
 
bool IsValidNativeIndex (int index) const
 
intptr_t * NativeFieldsDataAddr () const
 
intptr_t GetNativeField (int index) const
 
void GetNativeFields (uint16_t num_fields, intptr_t *field_values) const
 
void SetNativeFields (uint16_t num_fields, const intptr_t *field_values) const
 
uint16_t NumNativeFields () const
 
void SetNativeField (int index, intptr_t value) const
 
bool IsCallable (Function *function) const
 
ObjectPtr Invoke (const String &selector, const Array &arguments, const Array &argument_names, bool respect_reflectable=true, bool check_is_entrypoint=false) const
 
ObjectPtr InvokeGetter (const String &selector, bool respect_reflectable=true, bool check_is_entrypoint=false) const
 
ObjectPtr InvokeSetter (const String &selector, const Instance &argument, bool respect_reflectable=true, bool check_is_entrypoint=false) const
 
ObjectPtr EvaluateCompiledExpression (const Class &klass, const ExternalTypedData &kernel_buffer, const Array &type_definitions, const Array &arguments, const TypeArguments &type_arguments) const
 
virtual ObjectPtr HashCode () const
 
IntegerPtr IdentityHashCode (Thread *thread) const
 
virtual bool IsPointer () const
 
- Public Member Functions inherited from dart::Object
virtual ~Object ()
 
ObjectPtr ptr () const
 
void operator= (ObjectPtr value)
 
bool IsCanonical () const
 
void SetCanonical () const
 
void ClearCanonical () const
 
bool IsImmutable () const
 
void SetImmutable () const
 
void ClearImmutable () const
 
intptr_t GetClassId () const
 
ClassPtr clazz () const
 
 CLASS_LIST_FOR_HANDLES (DEFINE_CLASS_TESTER)
 
bool IsNull () const
 
virtual const char * ToCString () const
 
void PrintJSON (JSONStream *stream, bool ref=true) const
 
virtual void PrintJSONImpl (JSONStream *stream, bool ref) const
 
void PrintImplementationFields (JSONStream *stream) const
 
virtual void PrintImplementationFieldsImpl (const JSONArray &jsarr_fields) const
 
virtual const char * JSONType () const
 
virtual StringPtr DictionaryName () const
 
bool IsNew () const
 
bool IsOld () const
 
bool InVMIsolateHeap () const
 
void Print () const
 

Static Public Member Functions

static bool NullIsAssignableTo (const AbstractType &other)
 
static bool NullIsAssignableTo (const AbstractType &other, const TypeArguments &other_instantiator_type_arguments, const TypeArguments &other_function_type_arguments)
 
static ObjectPtr EvaluateCompiledExpression (Thread *thread, const Object &receiver, const Library &library, const Class &klass, const ExternalTypedData &kernel_buffer, const Array &type_definitions, const Array &param_values, const TypeArguments &type_param_values)
 
static intptr_t UnroundedSize ()
 
static intptr_t InstanceSize ()
 
static InstancePtr New (const Class &cls, Heap::Space space=Heap::kNew)
 
static InstancePtr NewAlreadyFinalized (const Class &cls, Heap::Space space=Heap::kNew)
 
static intptr_t DataOffsetFor (intptr_t cid)
 
static intptr_t ElementSizeFor (intptr_t cid)
 
static intptr_t NextFieldOffset ()
 
static intptr_t NativeFieldsOffset ()
 
- Static Public Member Functions inherited from dart::Object
static ObjectPtr RawCast (ObjectPtr obj)
 
static constexpr bool ContainsCompressedPointers ()
 
static intptr_t tags_offset ()
 
static ObjectHandle ()
 
static ObjectHandle (Zone *zone)
 
static ObjectHandle (ObjectPtr ptr)
 
static ObjectHandle (Zone *zone, ObjectPtr ptr)
 
static ObjectZoneHandle ()
 
static ObjectZoneHandle (Zone *zone)
 
static ObjectZoneHandle (ObjectPtr ptr)
 
static ObjectZoneHandle (Zone *zone, ObjectPtr ptr)
 
static ObjectReadOnlyHandle ()
 
static ObjectPtr null ()
 
static void set_vm_isolate_snapshot_object_table (const Array &table)
 
static ClassPtr class_class ()
 
static ClassPtr dynamic_class ()
 
static ClassPtr void_class ()
 
static ClassPtr type_parameters_class ()
 
static ClassPtr type_arguments_class ()
 
static ClassPtr patch_class_class ()
 
static ClassPtr function_class ()
 
static ClassPtr closure_data_class ()
 
static ClassPtr ffi_trampoline_data_class ()
 
static ClassPtr field_class ()
 
static ClassPtr script_class ()
 
static ClassPtr library_class ()
 
static ClassPtr namespace_class ()
 
static ClassPtr kernel_program_info_class ()
 
static ClassPtr code_class ()
 
static ClassPtr instructions_class ()
 
static ClassPtr instructions_section_class ()
 
static ClassPtr instructions_table_class ()
 
static ClassPtr object_pool_class ()
 
static ClassPtr pc_descriptors_class ()
 
static ClassPtr code_source_map_class ()
 
static ClassPtr compressed_stackmaps_class ()
 
static ClassPtr var_descriptors_class ()
 
static ClassPtr exception_handlers_class ()
 
static ClassPtr context_class ()
 
static ClassPtr context_scope_class ()
 
static ClassPtr sentinel_class ()
 
static ClassPtr api_error_class ()
 
static ClassPtr language_error_class ()
 
static ClassPtr unhandled_exception_class ()
 
static ClassPtr unwind_error_class ()
 
static ClassPtr singletargetcache_class ()
 
static ClassPtr unlinkedcall_class ()
 
static ClassPtr monomorphicsmiablecall_class ()
 
static ClassPtr icdata_class ()
 
static ClassPtr megamorphic_cache_class ()
 
static ClassPtr subtypetestcache_class ()
 
static ClassPtr loadingunit_class ()
 
static ClassPtr weak_serialization_reference_class ()
 
static ClassPtr weak_array_class ()
 
static void InitNullAndBool (IsolateGroup *isolate_group)
 
static void Init (IsolateGroup *isolate_group)
 
static void InitVtables ()
 
static void FinishInit (IsolateGroup *isolate_group)
 
static void FinalizeVMIsolate (IsolateGroup *isolate_group)
 
static void FinalizeReadOnlyObject (ObjectPtr object)
 
static void Cleanup ()
 
static ErrorPtr Init (IsolateGroup *isolate_group, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
 
static void MakeUnusedSpaceTraversable (const Object &obj, intptr_t original_size, intptr_t used_size)
 
static intptr_t InstanceSize ()
 
template<class FakeObject >
static void VerifyBuiltinVtable (intptr_t cid)
 
static void VerifyBuiltinVtables ()
 
static bool ShouldHaveImmutabilityBitSet (classid_t class_id)
 

Protected Member Functions

virtual void PrintSharedInstanceJSON (JSONObject *jsobj, bool ref, bool include_id=true) const
 
- Protected Member Functions inherited from dart::Object
 Object ()
 
uword raw_value () const
 
void setPtr (ObjectPtr value, intptr_t default_cid)
 
void CheckHandle () const
 
cpp_vtable vtable () const
 
void set_vtable (cpp_vtable value)
 
bool Contains (uword addr) const
 
template<typename type , std::memory_order order = std::memory_order_relaxed>
type LoadPointer (type const *addr) const
 
template<typename type , std::memory_order order = std::memory_order_relaxed>
void StorePointer (type const *addr, type value) const
 
template<typename type , typename compressed_type , std::memory_order order = std::memory_order_relaxed>
void StoreCompressedPointer (compressed_type const *addr, type value) const
 
template<typename type >
void StorePointerUnaligned (type const *addr, type value, Thread *thread) const
 
void StoreSmi (SmiPtr const *addr, SmiPtr value) const
 
template<typename FieldType >
void StoreSimd128 (const FieldType *addr, simd128_value_t value) const
 
template<typename FieldType >
FieldType LoadNonPointer (const FieldType *addr) const
 
template<typename FieldType , std::memory_order order>
FieldType LoadNonPointer (const FieldType *addr) const
 
template<typename FieldType , typename ValueType >
void StoreNonPointer (const FieldType *addr, ValueType value) const
 
template<typename FieldType , typename ValueType , std::memory_order order>
void StoreNonPointer (const FieldType *addr, ValueType value) const
 
template<typename FieldType >
FieldType * UnsafeMutableNonPointer (const FieldType *addr) const
 
 CLASS_LIST (STORE_NON_POINTER_ILLEGAL_TYPE)
 
void UnimplementedMethod () const
 
void AddCommonObjectProperties (JSONObject *jsobj, const char *protocol_type, bool ref) const
 

Friends

class ByteBuffer
 
class Class
 
class Closure
 
class Pointer
 
class DeferredObject
 
class FlowGraphSerializer
 
class FlowGraphDeserializer
 
class RegExp
 
class StubCode
 
class TypedDataView
 
class InstanceSerializationCluster
 
class InstanceDeserializationCluster
 
class ClassDeserializationCluster
 
class InstanceMorpher
 
class Obfuscator
 

Additional Inherited Members

- Public Types inherited from dart::Object
enum  NameVisibility { kInternalName = 0 , kScrubbedName , kUserVisibleName }
 
enum class  NameDisambiguation { kYes , kNo }
 
using UntaggedObjectType = UntaggedObject
 
using ObjectPtrType = ObjectPtr
 
- Static Public Attributes inherited from dart::Object
static constexpr intptr_t kHashBits = 30
 
static const ClassId kClassId = kObjectCid
 
- Static Protected Member Functions inherited from dart::Object
static DART_NOINLINE ObjectHandleImpl (Zone *zone, ObjectPtr ptr, intptr_t default_cid)
 
static DART_NOINLINE ObjectZoneHandleImpl (Zone *zone, ObjectPtr ptr, intptr_t default_cid)
 
static DART_NOINLINE ObjectReadOnlyHandleImpl (intptr_t cid)
 
static ObjectPtr Allocate (intptr_t cls_id, intptr_t size, Heap::Space space, bool compressed, uword ptr_field_start_offset, uword ptr_field_end_offset)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType Allocate (Heap::Space space)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType Allocate (Heap::Space space, intptr_t elements)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType AllocateVariant (intptr_t class_id, Heap::Space space)
 
template<typename T >
static DART_FORCE_INLINE T::ObjectPtrType AllocateVariant (intptr_t class_id, Heap::Space space, intptr_t elements)
 
static constexpr intptr_t RoundedAllocationSize (intptr_t size)
 
static ObjectPtr Clone (const Object &orig, Heap::Space space, bool load_with_relaxed_atomics=false)
 
template<typename T >
static DART_FORCE_INLINE uword from_offset ()
 
template<typename T >
static DART_FORCE_INLINE uword to_offset (intptr_t length=0)
 
- Protected Attributes inherited from dart::Object
ObjectPtr ptr_
 

Detailed Description

Definition at line 8202 of file object.h.

Member Function Documentation

◆ Canonicalize()

InstancePtr dart::Instance::Canonicalize ( Thread thread) const

Definition at line 20444 of file object.cc.

20444 {
20445 SafepointMutexLocker ml(
20446 thread->isolate_group()->constant_canonicalization_mutex());
20447 return CanonicalizeLocked(thread);
20448}
virtual InstancePtr CanonicalizeLocked(Thread *thread) const
Definition: object.cc:20450

◆ CanonicalizeEquals()

bool dart::Instance::CanonicalizeEquals ( const Instance other) const
virtual

Reimplemented in dart::AbstractType, dart::Integer, dart::Double, dart::String, dart::Array, dart::GrowableObjectArray, dart::Float32x4, dart::Int32x4, dart::Float64x2, dart::Record, dart::TypedData, dart::LinkedHashBase, dart::Closure, and dart::RegExp.

Definition at line 20259 of file object.cc.

20259 {
20260 if (this->ptr() == other.ptr()) {
20261 return true; // "===".
20262 }
20263
20264 if (other.IsNull() || (this->clazz() != other.clazz())) {
20265 return false;
20266 }
20267
20268 {
20269 NoSafepointScope no_safepoint;
20270 // Raw bits compare.
20271 const intptr_t instance_size = SizeFromClass();
20272 ASSERT(instance_size != 0);
20273 const intptr_t other_instance_size = other.SizeFromClass();
20274 ASSERT(other_instance_size != 0);
20275 if (instance_size != other_instance_size) {
20276 return false;
20277 }
20278 uword this_addr = reinterpret_cast<uword>(this->untag());
20279 uword other_addr = reinterpret_cast<uword>(other.untag());
20280 for (intptr_t offset = Instance::NextFieldOffset(); offset < instance_size;
20282 if ((reinterpret_cast<CompressedObjectPtr*>(this_addr + offset)
20283 ->Decompress(untag()->heap_base())) !=
20284 (reinterpret_cast<CompressedObjectPtr*>(other_addr + offset)
20285 ->Decompress(untag()->heap_base()))) {
20286 return false;
20287 }
20288 }
20289 }
20290 return true;
20291}
static intptr_t NextFieldOffset()
Definition: object.h:8355
intptr_t SizeFromClass() const
Definition: object.h:8216
ObjectPtr Decompress(uword heap_base) const
ObjectPtr ptr() const
Definition: object.h:332
#define ASSERT(E)
uintptr_t uword
Definition: globals.h:501
static constexpr intptr_t kCompressedWordSize
Definition: globals.h:42
raw_obj untag() -> num_entries()) VARIABLE_COMPRESSED_VISITOR(Array, Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(TypedData, TypedData::ElementSizeInBytes(raw_obj->GetClassId()) *Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(Record, RecordShape(raw_obj->untag() ->shape()).num_fields()) VARIABLE_NULL_VISITOR(CompressedStackMaps, CompressedStackMaps::PayloadSizeOf(raw_obj)) VARIABLE_NULL_VISITOR(OneByteString, Smi::Value(raw_obj->untag() ->length())) VARIABLE_NULL_VISITOR(TwoByteString, Smi::Value(raw_obj->untag() ->length())) intptr_t UntaggedField::VisitFieldPointers(FieldPtr raw_obj, ObjectPointerVisitor *visitor)
Definition: raw_object.cc:558
ObjectPtr CompressedObjectPtr
SeparatedVector2 offset

◆ CanonicalizeFieldsLocked()

void dart::Instance::CanonicalizeFieldsLocked ( Thread thread) const
virtual

Reimplemented in dart::Array, dart::Record, dart::LinkedHashBase, and dart::Closure.

Definition at line 20405 of file object.cc.

20405 {
20406 const intptr_t class_id = GetClassId();
20407 if (class_id >= kNumPredefinedCids) {
20408 // Iterate over all fields, canonicalize numbers and strings, expect all
20409 // other instances to be canonical otherwise report error (return false).
20410 Zone* zone = thread->zone();
20411 Object& obj = Object::Handle(zone);
20412 const intptr_t instance_size = SizeFromClass();
20413 ASSERT(instance_size != 0);
20414 const auto unboxed_fields_bitmap =
20415 thread->isolate_group()->class_table()->GetUnboxedFieldsMapAt(class_id);
20416 for (intptr_t offset = Instance::NextFieldOffset(); offset < instance_size;
20418 if (unboxed_fields_bitmap.Get(offset / kCompressedWordSize)) {
20419 continue;
20420 }
20421 obj = this->FieldAddrAtOffset(offset)->Decompress(untag()->heap_base());
20422 if (obj.IsInstance()) {
20423 obj = Instance::Cast(obj).CanonicalizeLocked(thread);
20424 this->SetFieldAtOffset(offset, obj);
20425 } else {
20426 ASSERT(obj.IsNull() || obj.IsSentinel());
20427 }
20428 }
20429 } else {
20430#if defined(DEBUG) && !defined(DART_COMPRESSED_POINTERS)
20431 // Make sure that we are not missing any fields.
20432 IsolateGroup* group = IsolateGroup::Current();
20433 CheckForPointers has_pointers(group);
20434 this->ptr()->untag()->VisitPointersPrecise(&has_pointers);
20435 ASSERT(!has_pointers.has_pointers());
20436#endif // DEBUG
20437 }
20438}
static IsolateGroup * Current()
Definition: isolate.h:539
UntaggedObject * untag() const
intptr_t GetClassId() const
Definition: object.h:341
static Object & Handle()
Definition: object.h:407
void VisitPointersPrecise(ObjectPointerVisitor *visitor)
Definition: raw_object.cc:371
@ kNumPredefinedCids
Definition: class_id.h:257

◆ CanonicalizeHash()

uint32_t dart::Instance::CanonicalizeHash ( ) const
virtual

Reimplemented in dart::TypeArguments, dart::AbstractType, dart::Integer, dart::Double, dart::String, dart::Bool, dart::Array, dart::Float32x4, dart::Int32x4, dart::Float64x2, dart::Record, dart::TypedData, dart::LinkedHashBase, dart::Closure, and dart::RegExp.

Definition at line 20316 of file object.cc.

20316 {
20317 if (GetClassId() == kNullCid) {
20318 return kNullIdentityHash;
20319 }
20320 Thread* thread = Thread::Current();
20321 uint32_t hash = thread->heap()->GetCanonicalHash(ptr());
20322 if (hash != 0) {
20323 return hash;
20324 }
20325 Zone* zone = thread->zone();
20326 const Class& cls = Class::Handle(zone, clazz());
20327 const bool is_symbol = Symbol::IsSymbolCid(thread, cls.id());
20328
20329 NoSafepointScope no_safepoint(thread);
20330
20331 if (is_symbol) {
20332 hash = Symbol::CanonicalizeHash(thread, *this);
20333 } else {
20334 const intptr_t class_id = cls.id();
20335 ASSERT(class_id != 0);
20336 hash = class_id;
20337 uword this_addr = reinterpret_cast<uword>(this->untag());
20338 Object& obj = Object::Handle(zone);
20339 Instance& instance = Instance::Handle(zone);
20340
20341 const auto unboxed_fields_bitmap =
20342 thread->isolate_group()->class_table()->GetUnboxedFieldsMapAt(
20343 GetClassId());
20344
20345 for (intptr_t offset = Instance::NextFieldOffset();
20346 offset < cls.host_next_field_offset(); offset += kCompressedWordSize) {
20347 if (unboxed_fields_bitmap.Get(offset / kCompressedWordSize)) {
20348 if (kCompressedWordSize == 8) {
20350 hash, *reinterpret_cast<uint32_t*>(this_addr + offset));
20352 hash, *reinterpret_cast<uint32_t*>(this_addr + offset + 4));
20353 } else {
20355 hash, *reinterpret_cast<uint32_t*>(this_addr + offset));
20356 }
20357 } else {
20358 obj = reinterpret_cast<CompressedObjectPtr*>(this_addr + offset)
20359 ->Decompress(untag()->heap_base());
20360 if (obj.IsSentinel()) {
20361 hash = CombineHashes(hash, 11);
20362 } else {
20363 instance ^= obj.ptr();
20364 hash = CombineHashes(hash, instance.CanonicalizeHash());
20365 }
20366 }
20367 }
20369 }
20370 thread->heap()->SetCanonicalHash(ptr(), hash);
20371 return hash;
20372}
static uint32_t hash(const SkShaderBase::GradientInfo &v)
friend class Class
Definition: object.h:8433
friend class Thread
Definition: object.h:1025
static constexpr intptr_t kHashBits
Definition: object.h:323
ClassPtr clazz() const
Definition: object.h:13218
static bool IsSymbolCid(Thread *thread, classid_t class_id)
Definition: object.cc:20293
static uint32_t CanonicalizeHash(Thread *thread, const Instance &instance)
Definition: object.cc:20299
static Thread * Current()
Definition: thread.h:362
VkInstance instance
Definition: main.cc:48
void Decompress(const uint8_t *input, intptr_t input_len, uint8_t **output, intptr_t *output_length)
Definition: gzip.cc:15
static constexpr intptr_t kNullIdentityHash
Definition: object.h:10784
uint32_t CombineHashes(uint32_t hash, uint32_t other_hash)
Definition: hash.h:12
@ kNullCid
Definition: class_id.h:252
uint32_t FinalizeHash(uint32_t hash, intptr_t hashbits=kBitsPerInt32)
Definition: hash.h:20

◆ CanonicalizeLocked()

InstancePtr dart::Instance::CanonicalizeLocked ( Thread thread) const
virtual

Reimplemented in dart::TypeArguments, dart::AbstractType, dart::String, and dart::GrowableObjectArray.

Definition at line 20450 of file object.cc.

20450 {
20451 if (!this->ptr()->IsHeapObject() || this->IsCanonical()) {
20452 return this->ptr();
20453 }
20454 ASSERT(!IsNull());
20456 Zone* zone = thread->zone();
20457 const Class& cls = Class::Handle(zone, this->clazz());
20458 Instance& result =
20459 Instance::Handle(zone, cls.LookupCanonicalInstance(zone, *this));
20460 if (!result.IsNull()) {
20461 return result.ptr();
20462 }
20463 if (IsNew()) {
20464 ASSERT((thread->isolate() == Dart::vm_isolate()) || !InVMIsolateHeap());
20465 // Create a canonical object in old space.
20466 result ^= Object::Clone(*this, Heap::kOld);
20467 } else {
20468 result = this->ptr();
20469 }
20470 ASSERT(result.IsOld());
20471 result.SetCanonical();
20472 return cls.InsertCanonicalConstant(zone, result);
20473}
static Isolate * vm_isolate()
Definition: dart.h:68
@ kOld
Definition: heap.h:39
virtual void CanonicalizeFieldsLocked(Thread *thread) const
Definition: object.cc:20405
static ObjectPtr Clone(const Object &orig, Heap::Space space, bool load_with_relaxed_atomics=false)
Definition: object.cc:2899
bool InVMIsolateHeap() const
Definition: object.h:395
bool IsCanonical() const
Definition: object.h:335
bool IsNew() const
Definition: object.h:390
bool IsNull() const
Definition: object.h:363
GAsyncResult * result

◆ CopyShallowToOldSpace()

InstancePtr dart::Instance::CopyShallowToOldSpace ( Thread thread) const

Definition at line 20440 of file object.cc.

20440 {
20442}
static ObjectPtr RawCast(ObjectPtr obj)
Definition: object.h:325

◆ DataOffsetFor()

intptr_t dart::Instance::DataOffsetFor ( intptr_t  cid)
static

Definition at line 20988 of file object.cc.

20988 {
20990 // Elements start at offset 0 of the external data.
20991 return 0;
20992 }
20993 if (IsTypedDataClassId(cid)) {
20995 }
20996 switch (cid) {
20997 case kArrayCid:
20998 case kImmutableArrayCid:
20999 return Array::data_offset();
21000 case kTypeArgumentsCid:
21002 case kOneByteStringCid:
21004 case kTwoByteStringCid:
21006 case kRecordCid:
21007 return Record::field_offset(0);
21008 default:
21009 UNIMPLEMENTED();
21010 return Array::data_offset();
21011 }
21012}
static intptr_t data_offset()
Definition: object.h:10835
static intptr_t data_offset()
Definition: object.h:10554
static intptr_t field_offset(intptr_t index)
Definition: object.h:11448
static intptr_t data_offset()
Definition: object.h:10695
static intptr_t types_offset()
Definition: object.h:8589
static intptr_t payload_offset()
Definition: object.h:11669
#define UNIMPLEMENTED
bool IsTypedDataClassId(intptr_t index)
Definition: class_id.h:433
const intptr_t cid
bool IsExternalTypedDataClassId(intptr_t index)
Definition: class_id.h:447

◆ ElementSizeFor()

intptr_t dart::Instance::ElementSizeFor ( intptr_t  cid)
static

Definition at line 20967 of file object.cc.

20967 {
20971 }
20972 switch (cid) {
20973 case kArrayCid:
20974 case kImmutableArrayCid:
20976 case kTypeArgumentsCid:
20978 case kOneByteStringCid:
20980 case kTwoByteStringCid:
20982 default:
20983 UNIMPLEMENTED();
20984 return 0;
20985 }
20986}
static constexpr intptr_t kBytesPerElement
Definition: object.h:10923
static constexpr intptr_t kBytesPerElement
Definition: object.h:10542
static constexpr intptr_t kBytesPerElement
Definition: object.h:10683
intptr_t ElementSizeInBytes() const
Definition: object.h:11531
bool IsTypedDataViewClassId(intptr_t index)
Definition: class_id.h:439
bool IsUnmodifiableTypedDataViewClassId(intptr_t index)
Definition: class_id.h:453
static constexpr intptr_t kElementSize
Definition: object.h:8602

◆ EvaluateCompiledExpression() [1/2]

ObjectPtr dart::Instance::EvaluateCompiledExpression ( const Class klass,
const ExternalTypedData kernel_buffer,
const Array type_definitions,
const Array arguments,
const TypeArguments type_arguments 
) const

Definition at line 4833 of file object.cc.

4838 {
4839 auto thread = Thread::Current();
4840 auto zone = thread->zone();
4841 const auto& library = Library::Handle(zone, klass.library());
4842 return Instance::EvaluateCompiledExpression(thread, *this, library, klass,
4843 kernel_buffer, type_definitions,
4844 arguments, type_arguments);
4845}
ObjectPtr EvaluateCompiledExpression(const Class &klass, const ExternalTypedData &kernel_buffer, const Array &type_definitions, const Array &arguments, const TypeArguments &type_arguments) const
Definition: object.cc:4833

◆ EvaluateCompiledExpression() [2/2]

ObjectPtr dart::Instance::EvaluateCompiledExpression ( Thread thread,
const Object receiver,
const Library library,
const Class klass,
const ExternalTypedData kernel_buffer,
const Array type_definitions,
const Array param_values,
const TypeArguments type_param_values 
)
static

Definition at line 4847 of file object.cc.

4855 {
4856 auto zone = Thread::Current()->zone();
4857#if defined(DART_PRECOMPILED_RUNTIME)
4858 const auto& error_str = String::Handle(
4859 zone,
4860 String::New("Expression evaluation not available in precompiled mode."));
4861 return ApiError::New(error_str);
4862#else
4863 if (IsInternalOnlyClassId(klass.id()) || (klass.id() == kTypeArgumentsCid)) {
4864 const auto& exception = Instance::Handle(
4865 zone, String::New("Expressions can be evaluated only with regular Dart "
4866 "instances/classes."));
4867 return UnhandledException::New(exception, StackTrace::null_instance());
4868 }
4869
4870 const auto& url = String::Handle(zone, library.url());
4871 const auto& klass_name = klass.IsTopLevel()
4872 ? String::null_string()
4873 : String::Handle(zone, klass.UserVisibleName());
4874
4875 const auto& result = Object::Handle(
4876 zone,
4877 LoadExpressionEvaluationFunction(zone, kernel_buffer, url, klass_name));
4878 if (result.IsError()) return result.ptr();
4879
4880 const auto& eval_function = Function::Cast(result);
4881
4882#if defined(DEBUG)
4883 for (intptr_t i = 0; i < arguments.Length(); ++i) {
4884 ASSERT(arguments.At(i) != Object::optimized_out().ptr());
4885 }
4886#endif // defined(DEBUG)
4887
4888 auto& all_arguments = Array::Handle(zone, arguments.ptr());
4889 if (!eval_function.is_static()) {
4890 // `this` may be optimized out (e.g. not accessible from breakpoint due to
4891 // not being captured by closure). We allow this as long as the evaluation
4892 // function doesn't actually need `this`.
4893 if (receiver.IsNull() || receiver.ptr() == Object::optimized_out().ptr()) {
4894 if (EvaluationFunctionNeedsReceiver(thread, zone, eval_function)) {
4895 return Object::optimized_out().ptr();
4896 }
4897 }
4898
4899 all_arguments = Array::New(1 + arguments.Length());
4900 auto& param = PassiveObject::Handle();
4901 all_arguments.SetAt(0, receiver);
4902 for (intptr_t i = 0; i < arguments.Length(); i++) {
4903 param = arguments.At(i);
4904 all_arguments.SetAt(i + 1, param);
4905 }
4906 }
4907
4908 return EvaluateCompiledExpressionHelper(zone, eval_function, type_definitions,
4909 all_arguments, type_arguments);
4910#endif // !defined(DART_PRECOMPILED_RUNTIME)
4911}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10959
static PassiveObject & Handle()
Definition: object.h:1077
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
Zone * zone() const
Definition: thread_state.h:37
static UnhandledExceptionPtr New(const Instance &exception, const Instance &stacktrace, Heap::Space space=Heap::kNew)
Definition: object.cc:19939
static bool EvaluationFunctionNeedsReceiver(Thread *thread, Zone *zone, const Function &eval_function)
Definition: object.cc:4773
static ObjectPtr EvaluateCompiledExpressionHelper(Zone *zone, const Function &eval_function, const Array &type_definitions, const Array &arguments, const TypeArguments &type_arguments)
Definition: object.cc:4782
bool IsInternalOnlyClassId(intptr_t index)
Definition: class_id.h:299
static ObjectPtr LoadExpressionEvaluationFunction(Zone *zone, const ExternalTypedData &kernel_buffer, const String &library_url, const String &klass)
Definition: object.cc:4749

◆ GetField()

ObjectPtr dart::Instance::GetField ( const Field field) const

Definition at line 20475 of file object.cc.

20475 {
20476 if (field.is_unboxed()) {
20477 switch (field.guarded_cid()) {
20478 case kDoubleCid:
20479 return Double::New(*reinterpret_cast<double_t*>(FieldAddr(field)));
20480 case kFloat32x4Cid:
20481 return Float32x4::New(
20482 *reinterpret_cast<simd128_value_t*>(FieldAddr(field)));
20483 case kFloat64x2Cid:
20484 return Float64x2::New(
20485 *reinterpret_cast<simd128_value_t*>(FieldAddr(field)));
20486 default:
20487 return Integer::New(*reinterpret_cast<int64_t*>(FieldAddr(field)));
20488 }
20489 } else {
20490 return FieldAddr(field)->Decompress(untag()->heap_base());
20491 }
20492}
static DoublePtr New(double d, Heap::Space space=Heap::kNew)
Definition: object.cc:23402
static Float32x4Ptr New(float value0, float value1, float value2, float value3, Heap::Space space=Heap::kNew)
Definition: object.cc:25307
static Float64x2Ptr New(double value0, double value1, Heap::Space space=Heap::kNew)
Definition: object.cc:25475
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition: object.cc:22984

◆ GetNativeField()

intptr_t dart::Instance::GetNativeField ( int  index) const
inline

Definition at line 13307 of file object.h.

13307 {
13308 ASSERT(IsValidNativeIndex(index));
13309 NoSafepointScope no_safepoint;
13310 TypedDataPtr native_fields = static_cast<TypedDataPtr>(
13311 NativeFieldsAddr()->Decompress(untag()->heap_base()));
13312 if (native_fields == TypedData::null()) {
13313 return 0;
13314 }
13315 return reinterpret_cast<intptr_t*>(native_fields->untag()->data())[index];
13316}
bool IsValidNativeIndex(int index) const
Definition: object.h:8270
static ObjectPtr null()
Definition: object.h:433

◆ GetNativeFields()

void dart::Instance::GetNativeFields ( uint16_t  num_fields,
intptr_t *  field_values 
) const
inline

Definition at line 13318 of file object.h.

13319 {
13320 NoSafepointScope no_safepoint;
13321 ASSERT(num_fields == NumNativeFields());
13322 ASSERT(field_values != nullptr);
13323 TypedDataPtr native_fields = static_cast<TypedDataPtr>(
13324 NativeFieldsAddr()->Decompress(untag()->heap_base()));
13325 if (native_fields == TypedData::null()) {
13326 for (intptr_t i = 0; i < num_fields; i++) {
13327 field_values[i] = 0;
13328 }
13329 }
13330 intptr_t* fields =
13331 reinterpret_cast<intptr_t*>(native_fields->untag()->data());
13332 for (intptr_t i = 0; i < num_fields; i++) {
13333 field_values[i] = fields[i];
13334 }
13335}
uint16_t NumNativeFields() const
Definition: object.h:8280

◆ GetType()

AbstractTypePtr dart::Instance::GetType ( Heap::Space  space) const

Definition at line 20520 of file object.cc.

20520 {
20521 if (IsNull()) {
20522 return Type::NullType();
20523 }
20524 Thread* thread = Thread::Current();
20525 Zone* zone = thread->zone();
20526 const Class& cls = Class::Handle(zone, clazz());
20527 if (!cls.is_finalized()) {
20528 // Various predefined classes can be instantiated by the VM or
20529 // Dart_NewString/Integer/TypedData/... before the class is finalized.
20530 ASSERT(cls.is_prefinalized());
20531 cls.EnsureDeclarationLoaded();
20532 }
20533 if (cls.IsClosureClass()) {
20534 FunctionType& signature = FunctionType::Handle(
20535 zone, Closure::Cast(*this).GetInstantiatedSignature(zone));
20536 if (!signature.IsFinalized()) {
20537 signature.SetIsFinalized();
20538 }
20539 signature ^= signature.Canonicalize(thread);
20540 return signature.ptr();
20541 }
20542 if (IsRecord()) {
20543 ASSERT(cls.IsRecordClass());
20544 auto& record_type =
20545 RecordType::Handle(zone, Record::Cast(*this).GetRecordType());
20546 ASSERT(record_type.IsFinalized());
20547 ASSERT(record_type.IsCanonical());
20548 return record_type.ptr();
20549 }
20550 Type& type = Type::Handle(zone);
20551 if (!cls.IsGeneric()) {
20552 type = cls.DeclarationType();
20553 }
20554 if (type.IsNull()) {
20555 TypeArguments& type_arguments = TypeArguments::Handle(zone);
20556 const intptr_t num_type_arguments = cls.NumTypeArguments();
20557 if (num_type_arguments > 0) {
20558 type_arguments = GetTypeArguments();
20559 if (!type_arguments.IsNull()) {
20560 type_arguments = type_arguments.FromInstanceTypeArguments(thread, cls);
20561 }
20562 }
20563 type = Type::New(cls, type_arguments, Nullability::kNonNullable, space);
20564 type.SetIsFinalized();
20565 type ^= type.Canonicalize(thread);
20566 }
20567 return type.ptr();
20568}
GLenum type
virtual TypeArgumentsPtr GetTypeArguments() const
Definition: object.cc:20570
static TypePtr NullType()
static TypePtr New(const Class &clazz, const TypeArguments &arguments, Nullability nullability=Nullability::kNonNullable, Heap::Space space=Heap::kOld)

◆ GetTypeArguments()

TypeArgumentsPtr dart::Instance::GetTypeArguments ( ) const
virtual

Reimplemented in dart::Array, dart::GrowableObjectArray, dart::LinkedHashBase, and dart::FutureOr.

Definition at line 20570 of file object.cc.

20570 {
20571 ASSERT(!IsType());
20572 const Class& cls = Class::Handle(clazz());
20573 intptr_t field_offset = cls.host_type_arguments_field_offset();
20574 ASSERT(field_offset != Class::kNoTypeArguments);
20575 TypeArguments& type_arguments = TypeArguments::Handle();
20576 type_arguments ^=
20577 FieldAddrAtOffset(field_offset)->Decompress(untag()->heap_base());
20578 return type_arguments.ptr();
20579}
static constexpr intptr_t kNoTypeArguments
Definition: object.h:1374

◆ HashCode()

ObjectPtr dart::Instance::HashCode ( ) const
virtual

Reimplemented in dart::Integer, and dart::String.

Definition at line 20212 of file object.cc.

20212 {
20213 // TODO(koda): Optimize for all builtin classes and all classes
20214 // that do not override hashCode.
20215 return DartLibraryCalls::HashCode(*this);
20216}
static ObjectPtr HashCode(const Instance &receiver)
Definition: dart_entry.cc:631

◆ IdentityHashCode()

IntegerPtr dart::Instance::IdentityHashCode ( Thread thread) const

Definition at line 20219 of file object.cc.

20219 {
20220 if (IsInteger()) return Integer::Cast(*this).ptr();
20221
20222#if defined(HASH_IN_OBJECT_HEADER)
20223 intptr_t hash = Object::GetCachedHash(ptr());
20224#else
20225 intptr_t hash = thread->heap()->GetHash(ptr());
20226#endif
20227 if (hash == 0) {
20228 if (IsNull()) {
20230 } else if (IsBool()) {
20231 hash = Bool::Cast(*this).value() ? kTrueIdentityHash : kFalseIdentityHash;
20232 } else if (IsDouble()) {
20233 double val = Double::Cast(*this).value();
20234 if ((val >= kMinInt64RepresentableAsDouble) &&
20236 int64_t ival = static_cast<int64_t>(val);
20237 if (static_cast<double>(ival) == val) {
20238 return Integer::New(ival);
20239 }
20240 }
20241
20242 uint64_t uval = bit_cast<uint64_t>(val);
20243 hash = ((uval >> 32) ^ (uval)) & kSmiMax;
20244 } else {
20245 do {
20246 hash = thread->random()->NextUInt32() & 0x3FFFFFFF;
20247 } while (hash == 0);
20248 }
20249
20250#if defined(HASH_IN_OBJECT_HEADER)
20251 hash = Object::SetCachedHashIfNotSet(ptr(), hash);
20252#else
20253 hash = thread->heap()->SetHashIfNotSet(ptr(), hash);
20254#endif
20255 }
20256 return Smi::New(hash);
20257}
static SmiPtr New(intptr_t value)
Definition: object.h:10006
bool IsDouble(const dart::Object &a)
Definition: runtime_api.cc:974
static constexpr intptr_t kFalseIdentityHash
Definition: object.h:10786
const intptr_t kSmiMax
Definition: globals.h:28
static constexpr intptr_t kTrueIdentityHash
Definition: object.h:10785
constexpr int64_t kMinInt64RepresentableAsDouble
Definition: globals.h:493
constexpr int64_t kMaxInt64RepresentableAsDouble
Definition: globals.h:494

◆ InstanceSize()

static intptr_t dart::Instance::InstanceSize ( )
inlinestatic

Definition at line 8337 of file object.h.

8337 {
8338 return RoundedAllocationSize(sizeof(UntaggedInstance));
8339 }
static constexpr intptr_t RoundedAllocationSize(intptr_t size)
Definition: object.h:758

◆ Invoke()

ObjectPtr dart::Instance::Invoke ( const String selector,
const Array arguments,
const Array argument_names,
bool  respect_reflectable = true,
bool  check_is_entrypoint = false 
) const

Definition at line 20143 of file object.cc.

20147 {
20148 Thread* thread = Thread::Current();
20149 Zone* zone = thread->zone();
20150 Class& klass = Class::Handle(zone, clazz());
20151 CHECK_ERROR(klass.EnsureIsFinalized(thread));
20152
20153 Function& function = Function::Handle(
20154 zone,
20156 /*allow_add=*/!FLAG_precompiled_mode));
20157
20158 if (!function.IsNull() && check_is_entrypoint) {
20159 CHECK_ERROR(function.VerifyCallEntryPoint());
20160 }
20161
20162 // We don't pass any explicit type arguments, which will be understood as
20163 // using dynamic for any function type arguments by lower layers.
20164 const int kTypeArgsLen = 0;
20165 const Array& args_descriptor = Array::Handle(
20166 zone, ArgumentsDescriptor::NewBoxed(kTypeArgsLen, args.Length(),
20167 arg_names, Heap::kNew));
20168
20169 const auto& inst_type_args =
20170 klass.NumTypeArguments() > 0
20172 : Object::null_type_arguments();
20173
20174 if (function.IsNull()) {
20175 // Didn't find a method: try to find a getter and invoke call on its result.
20176 const String& getter_name =
20178 function =
20179 Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name,
20180 /*allow_add=*/!FLAG_precompiled_mode);
20181 if (!function.IsNull()) {
20182 if (check_is_entrypoint) {
20184 }
20185 ASSERT(function.kind() != UntaggedFunction::kMethodExtractor);
20186 // Invoke the getter.
20187 const int kNumArgs = 1;
20188 const Array& getter_args = Array::Handle(zone, Array::New(kNumArgs));
20189 getter_args.SetAt(0, *this);
20190 const Array& getter_args_descriptor = Array::Handle(
20192 kTypeArgsLen, getter_args.Length(), Heap::kNew));
20193 const Object& getter_result = Object::Handle(
20194 zone, InvokeInstanceFunction(thread, *this, function, getter_name,
20195 getter_args, getter_args_descriptor,
20196 respect_reflectable, inst_type_args));
20197 if (getter_result.IsError()) {
20198 return getter_result.ptr();
20199 }
20200 // Replace the closure as the receiver in the arguments list.
20201 args.SetAt(0, getter_result);
20202 return DartEntry::InvokeClosure(thread, args, args_descriptor);
20203 }
20204 }
20205
20206 // Found an ordinary method.
20207 return InvokeInstanceFunction(thread, *this, function, function_name, args,
20208 args_descriptor, respect_reflectable,
20209 inst_type_args);
20210}
static ArrayPtr NewBoxed(intptr_t type_args_len, intptr_t num_arguments, const Array &optional_arguments_names, Heap::Space space=Heap::kOld)
Definition: dart_entry.h:83
static ObjectPtr InvokeClosure(Thread *thread, const Array &arguments)
Definition: dart_entry.cc:282
static StringPtr GetterName(const String &field_name)
Definition: object.cc:11792
@ kNew
Definition: heap.h:38
static FunctionPtr ResolveDynamicAnyArgs(Zone *zone, const Class &receiver_class, const String &function_name, bool allow_add)
Definition: resolver.cc:185
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Dart_NativeFunction function
Definition: fuchsia.cc:51
DART_WARN_UNUSED_RESULT ErrorPtr EntryPointFieldInvocationError(const String &getter_name)
Definition: object.cc:27196
static ObjectPtr InvokeInstanceFunction(Thread *thread, const Instance &receiver, const Function &function, const String &target_name, const Array &args, const Array &args_descriptor_array, bool respect_reflectable, const TypeArguments &instantiator_type_args)
Definition: object.cc:14316
const char *const function_name
#define CHECK_ERROR(error)
Definition: object.cc:134

◆ InvokeGetter()

ObjectPtr dart::Instance::InvokeGetter ( const String selector,
bool  respect_reflectable = true,
bool  check_is_entrypoint = false 
) const

Definition at line 20031 of file object.cc.

20033 {
20034 Thread* thread = Thread::Current();
20035 Zone* zone = thread->zone();
20036
20037 Class& klass = Class::Handle(zone, clazz());
20038 CHECK_ERROR(klass.EnsureIsFinalized(thread));
20039 const auto& inst_type_args =
20040 klass.NumTypeArguments() > 0
20042 : Object::null_type_arguments();
20043
20044 const String& internal_getter_name =
20045 String::Handle(zone, Field::GetterName(getter_name));
20046 Function& function = Function::Handle(
20047 zone,
20048 Resolver::ResolveDynamicAnyArgs(zone, klass, internal_getter_name,
20049 /*allow_add=*/!FLAG_precompiled_mode));
20050
20051 if (!function.IsNull() && check_is_entrypoint) {
20052 // The getter must correspond to either an entry-point field or a getter
20053 // method explicitly marked.
20054 Field& field = Field::Handle(zone);
20055 if (function.kind() == UntaggedFunction::kImplicitGetter) {
20056 field = function.accessor_field();
20057 }
20058 if (!field.IsNull()) {
20059 CHECK_ERROR(field.VerifyEntryPoint(EntryPointPragma::kGetterOnly));
20060 } else {
20061 CHECK_ERROR(function.VerifyCallEntryPoint());
20062 }
20063 }
20064
20065 // Check for method extraction when method extractors are not lazily created.
20066 if (function.IsNull() && FLAG_precompiled_mode) {
20067 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name,
20068 /*allow_add=*/false);
20069
20070 if (!function.IsNull() && check_is_entrypoint) {
20071 CHECK_ERROR(function.VerifyClosurizedEntryPoint());
20072 }
20073
20074 if (!function.IsNull() && function.SafeToClosurize()) {
20075 const Function& closure_function =
20076 Function::Handle(zone, function.ImplicitClosureFunction());
20077 return closure_function.ImplicitInstanceClosure(*this);
20078 }
20079 }
20080
20081 const int kTypeArgsLen = 0;
20082 const int kNumArgs = 1;
20083 const Array& args = Array::Handle(zone, Array::New(kNumArgs));
20084 args.SetAt(0, *this);
20085 const Array& args_descriptor = Array::Handle(
20086 zone,
20087 ArgumentsDescriptor::NewBoxed(kTypeArgsLen, args.Length(), Heap::kNew));
20088
20089 return InvokeInstanceFunction(thread, *this, function, internal_getter_name,
20090 args, args_descriptor, respect_reflectable,
20091 inst_type_args);
20092}

◆ InvokeSetter()

ObjectPtr dart::Instance::InvokeSetter ( const String selector,
const Instance argument,
bool  respect_reflectable = true,
bool  check_is_entrypoint = false 
) const

Definition at line 20094 of file object.cc.

20097 {
20098 Thread* thread = Thread::Current();
20099 Zone* zone = thread->zone();
20100
20101 const Class& klass = Class::Handle(zone, clazz());
20102 CHECK_ERROR(klass.EnsureIsFinalized(thread));
20103 const auto& inst_type_args =
20104 klass.NumTypeArguments() > 0
20106 : Object::null_type_arguments();
20107
20108 const String& internal_setter_name =
20109 String::Handle(zone, Field::SetterName(setter_name));
20110 const Function& setter = Function::Handle(
20111 zone,
20112 Resolver::ResolveDynamicAnyArgs(zone, klass, internal_setter_name,
20113 /*allow_add=*/!FLAG_precompiled_mode));
20114
20115 if (check_is_entrypoint) {
20116 // The setter must correspond to either an entry-point field or a setter
20117 // method explicitly marked.
20118 Field& field = Field::Handle(zone);
20119 if (setter.kind() == UntaggedFunction::kImplicitSetter) {
20120 field = setter.accessor_field();
20121 }
20122 if (!field.IsNull()) {
20123 CHECK_ERROR(field.VerifyEntryPoint(EntryPointPragma::kSetterOnly));
20124 } else if (!setter.IsNull()) {
20125 CHECK_ERROR(setter.VerifyCallEntryPoint());
20126 }
20127 }
20128
20129 const int kTypeArgsLen = 0;
20130 const int kNumArgs = 2;
20131 const Array& args = Array::Handle(zone, Array::New(kNumArgs));
20132 args.SetAt(0, *this);
20133 args.SetAt(1, value);
20134 const Array& args_descriptor = Array::Handle(
20135 zone,
20136 ArgumentsDescriptor::NewBoxed(kTypeArgsLen, args.Length(), Heap::kNew));
20137
20138 return InvokeInstanceFunction(thread, *this, setter, internal_setter_name,
20139 args, args_descriptor, respect_reflectable,
20140 inst_type_args);
20141}
static StringPtr SetterName(const String &field_name)
Definition: object.cc:11804
uint8_t value

◆ IsAssignableTo()

bool dart::Instance::IsAssignableTo ( const AbstractType other,
const TypeArguments other_instantiator_type_arguments,
const TypeArguments other_function_type_arguments 
) const

Definition at line 20629 of file object.cc.

20632 {
20633 ASSERT(!other.IsDynamicType());
20634 // In strong mode, compute NNBD_SUBTYPE(runtimeType, other).
20635 // In weak mode, compute LEGACY_SUBTYPE(runtimeType, other).
20636 return RuntimeTypeIsSubtypeOf(other, other_instantiator_type_arguments,
20637 other_function_type_arguments);
20638}

◆ IsCallable()

bool dart::Instance::IsCallable ( Function function) const

Definition at line 20913 of file object.cc.

20913 {
20914 Class& cls = Class::Handle(clazz());
20915 if (cls.IsClosureClass()) {
20916 if (function != nullptr) {
20917 *function = Closure::Cast(*this).function();
20918 }
20919 return true;
20920 }
20921 // Try to resolve a "call" method.
20922 Zone* zone = Thread::Current()->zone();
20923 Function& call_function = Function::Handle(
20924 zone, Resolver::ResolveDynamicAnyArgs(zone, cls, Symbols::DynamicCall(),
20925 /*allow_add=*/false));
20926 if (call_function.IsNull()) {
20927 return false;
20928 }
20929 if (function != nullptr) {
20930 *function = call_function.ptr();
20931 }
20932 return true;
20933}

◆ IsIdenticalTo()

bool dart::Instance::IsIdenticalTo ( const Instance other) const

Definition at line 20861 of file object.cc.

20861 {
20862 if (ptr() == other.ptr()) return true;
20863 if (IsInteger() && other.IsInteger()) {
20864 return Integer::Cast(*this).Equals(other);
20865 }
20866 if (IsDouble() && other.IsDouble()) {
20867 double other_value = Double::Cast(other).value();
20868 return Double::Cast(*this).BitwiseEqualsToDouble(other_value);
20869 }
20870 return false;
20871}

◆ IsInstanceOf()

bool dart::Instance::IsInstanceOf ( const AbstractType other,
const TypeArguments other_instantiator_type_arguments,
const TypeArguments other_function_type_arguments 
) const

Definition at line 20614 of file object.cc.

20617 {
20618 ASSERT(!other.IsDynamicType());
20619 if (IsNull()) {
20620 return Instance::NullIsInstanceOf(other, other_instantiator_type_arguments,
20621 other_function_type_arguments);
20622 }
20623 // In strong mode, compute NNBD_SUBTYPE(runtimeType, other).
20624 // In weak mode, compute LEGACY_SUBTYPE(runtimeType, other).
20625 return RuntimeTypeIsSubtypeOf(other, other_instantiator_type_arguments,
20626 other_function_type_arguments);
20627}

◆ IsPointer()

bool dart::Instance::IsPointer ( ) const
virtual

Definition at line 25764 of file object.cc.

25764 {
25765 return Pointer::IsPointer(*this);
25766}
virtual bool IsPointer() const
Definition: object.cc:25764

◆ IsValidNativeIndex()

bool dart::Instance::IsValidNativeIndex ( int  index) const
inline

Definition at line 8270 of file object.h.

8270 {
8271 return ((index >= 0) && (index < clazz()->untag()->num_native_fields_));
8272 }

◆ NativeFieldsDataAddr()

intptr_t * dart::Instance::NativeFieldsDataAddr ( ) const

Definition at line 20873 of file object.cc.

20873 {
20874 ASSERT(Thread::Current()->no_safepoint_scope_depth() > 0);
20875 TypedDataPtr native_fields = static_cast<TypedDataPtr>(
20876 NativeFieldsAddr()->Decompress(untag()->heap_base()));
20877 if (native_fields == TypedData::null()) {
20878 return nullptr;
20879 }
20880 return reinterpret_cast<intptr_t*>(native_fields->untag()->data());
20881}

◆ NativeFieldsOffset()

static intptr_t dart::Instance::NativeFieldsOffset ( )
inlinestatic

Definition at line 8357 of file object.h.

8357{ return sizeof(UntaggedObject); }

◆ New()

InstancePtr dart::Instance::New ( const Class cls,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 20935 of file object.cc.

20935 {
20936 Thread* thread = Thread::Current();
20937 if (cls.EnsureIsAllocateFinalized(thread) != Error::null()) {
20938 return Instance::null();
20939 }
20940 return NewAlreadyFinalized(cls, space);
20941}
static InstancePtr NewAlreadyFinalized(const Class &cls, Heap::Space space=Heap::kNew)
Definition: object.cc:20943

◆ NewAlreadyFinalized()

InstancePtr dart::Instance::NewAlreadyFinalized ( const Class cls,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 20943 of file object.cc.

20943 {
20944 ASSERT(cls.is_allocate_finalized());
20945 intptr_t instance_size = cls.host_instance_size();
20946 ASSERT(instance_size > 0);
20947 // Initialize everything after the object header with Object::null(), since
20948 // this isn't a predefined class.
20949 const uword ptr_field_end_offset =
20950 instance_size - (Instance::ContainsCompressedPointers()
20952 : kWordSize);
20953 return static_cast<InstancePtr>(Object::Allocate(
20954 cls.id(), instance_size, space, Instance::ContainsCompressedPointers(),
20955 from_offset<Instance>(), ptr_field_end_offset));
20956}
static ObjectPtr Allocate(intptr_t cls_id, intptr_t size, Heap::Space space, bool compressed, uword ptr_field_start_offset, uword ptr_field_end_offset)
Definition: object.cc:2759
static constexpr bool ContainsCompressedPointers()
Definition: object.h:329
constexpr intptr_t kWordSize
Definition: globals.h:509

◆ NextFieldOffset()

static intptr_t dart::Instance::NextFieldOffset ( )
inlinestatic

Definition at line 8355 of file object.h.

8355{ return sizeof(UntaggedInstance); }

◆ NullIsAssignableTo() [1/2]

bool dart::Instance::NullIsAssignableTo ( const AbstractType other)
static

Definition at line 20674 of file object.cc.

20674 {
20675 // "Left Null" rule: null is assignable when destination type is
20676 // nullable. Otherwise it is not assignable or we cannot tell
20677 // without instantiating type parameter.
20678 if (other.IsNullable()) {
20679 return true;
20680 }
20681 if (other.IsFutureOrType()) {
20682 return NullIsAssignableTo(AbstractType::Handle(other.UnwrapFutureOr()));
20683 }
20684 // Since the TAVs are not available, for non-nullable type parameters
20685 // this returns a conservative approximation of "not assignable" .
20686 return false;
20687}
static bool NullIsAssignableTo(const AbstractType &other)
Definition: object.cc:20674

◆ NullIsAssignableTo() [2/2]

bool dart::Instance::NullIsAssignableTo ( const AbstractType other,
const TypeArguments other_instantiator_type_arguments,
const TypeArguments other_function_type_arguments 
)
static

Definition at line 20691 of file object.cc.

20694 {
20695 // Do checks that don't require instantiation first.
20696 if (NullIsAssignableTo(other)) return true;
20697 if (!other.IsTypeParameter()) return false;
20698 const auto& type = AbstractType::Handle(other.InstantiateFrom(
20699 other_instantiator_type_arguments, other_function_type_arguments,
20701 return NullIsAssignableTo(type);
20702}
@ kAllFree
Definition: object.h:2940

◆ NumNativeFields()

uint16_t dart::Instance::NumNativeFields ( ) const
inline

Definition at line 8280 of file object.h.

8280 {
8281 return clazz()->untag()->num_native_fields_;
8282 }

◆ OperatorEquals()

bool dart::Instance::OperatorEquals ( const Instance other) const
virtual

Reimplemented in dart::Integer, dart::Double, and dart::String.

Definition at line 20855 of file object.cc.

20855 {
20856 // TODO(koda): Optimize for all builtin classes and all classes
20857 // that do not override operator==.
20858 return DartLibraryCalls::Equals(*this, other) == Object::bool_true().ptr();
20859}
static ObjectPtr Equals(const Instance &left, const Instance &right)
Definition: dart_entry.cc:647

◆ PrintSharedInstanceJSON()

void dart::Instance::PrintSharedInstanceJSON ( JSONObject jsobj,
bool  ref,
bool  include_id = true 
) const
protectedvirtual

Definition at line 1260 of file object_service.cc.

1262 {
1263 AddCommonObjectProperties(jsobj, "Instance", ref);
1264 {
1265 NoSafepointScope safepoint_scope;
1266 uint32_t hash_code = HeapSnapshotWriter::GetHeapSnapshotIdentityHash(
1267 Thread::Current(), ptr());
1268 jsobj->AddProperty64("identityHashCode", hash_code);
1269 }
1270 if (include_id) {
1271 jsobj->AddServiceId(*this);
1272 }
1273 if (ref) {
1274 return;
1275 }
1276
1277 // Add all fields in layout order, from superclass to subclass.
1278 GrowableArray<Class*> classes;
1279 Class& cls = Class::Handle(this->clazz());
1280 if (IsClosure()) {
1281 // Closure fields are not instances. Skip them.
1282 cls = cls.SuperClass();
1283 }
1284 do {
1285 classes.Add(&Class::Handle(cls.ptr()));
1286 cls = cls.SuperClass();
1287 } while (!cls.IsNull());
1288
1289 Array& field_array = Array::Handle();
1290 Field& field = Field::Handle();
1291 Object& field_value = Object::Handle();
1292 {
1293 JSONArray jsarr(jsobj, "fields");
1294 for (intptr_t i = classes.length() - 1; i >= 0; i--) {
1295 field_array = classes[i]->fields();
1296 if (!field_array.IsNull()) {
1297 for (intptr_t j = 0; j < field_array.Length(); j++) {
1298 field ^= field_array.At(j);
1299 if (!field.is_static()) {
1300 field_value = GetField(field);
1301 JSONObject jsfield(&jsarr);
1302 jsfield.AddProperty("decl", field);
1303 jsfield.AddProperty("name", field.UserVisibleNameCString());
1304 jsfield.AddProperty("value", field_value);
1305 }
1306 }
1307 }
1308 }
1309 }
1310
1311 if (NumNativeFields() > 0) {
1312 JSONArray jsarr(jsobj, "_nativeFields");
1313 for (intptr_t i = 0; i < NumNativeFields(); i++) {
1314 intptr_t value = GetNativeField(i);
1315 JSONObject jsfield(&jsarr);
1316 jsfield.AddProperty("index", i);
1317 jsfield.AddProperty("value", value);
1318 }
1319 }
1320}
intptr_t GetNativeField(int index) const
Definition: object.h:13307
ObjectPtr GetField(const Field &field) const
Definition: object.cc:20475
void AddCommonObjectProperties(JSONObject *jsobj, const char *protocol_type, bool ref) const

◆ SetField()

void dart::Instance::SetField ( const Field field,
const Object value 
) const

Definition at line 20494 of file object.cc.

20494 {
20495 if (field.is_unboxed()) {
20496 switch (field.guarded_cid()) {
20497 case kDoubleCid:
20498 StoreNonPointer(reinterpret_cast<double_t*>(FieldAddr(field)),
20499 Double::Cast(value).value());
20500 break;
20501 case kFloat32x4Cid:
20502 StoreNonPointer(reinterpret_cast<simd128_value_t*>(FieldAddr(field)),
20503 Float32x4::Cast(value).value());
20504 break;
20505 case kFloat64x2Cid:
20506 StoreNonPointer(reinterpret_cast<simd128_value_t*>(FieldAddr(field)),
20507 Float64x2::Cast(value).value());
20508 break;
20509 default:
20510 StoreNonPointer(reinterpret_cast<int64_t*>(FieldAddr(field)),
20511 Integer::Cast(value).AsInt64Value());
20512 break;
20513 }
20514 } else {
20515 field.RecordStore(value);
20516 StoreCompressedPointer(FieldAddr(field), value.ptr());
20517 }
20518}
void StoreNonPointer(const FieldType *addr, ValueType value) const
Definition: object.h:819
void StoreCompressedPointer(compressed_type const *addr, type value) const
Definition: object.h:782

◆ SetNativeField()

void dart::Instance::SetNativeField ( int  index,
intptr_t  value 
) const

Definition at line 20883 of file object.cc.

20883 {
20884 ASSERT(IsValidNativeIndex(index));
20885 Object& native_fields =
20886 Object::Handle(NativeFieldsAddr()->Decompress(untag()->heap_base()));
20887 if (native_fields.IsNull()) {
20888 // Allocate backing storage for the native fields.
20889 native_fields = TypedData::New(kIntPtrCid, NumNativeFields());
20890 StoreCompressedPointer(NativeFieldsAddr(), native_fields.ptr());
20891 }
20892 intptr_t byte_offset = index * sizeof(intptr_t);
20893 TypedData::Cast(native_fields).SetIntPtr(byte_offset, value);
20894}
static TypedDataPtr New(intptr_t class_id, intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.cc:25587

◆ SetNativeFields()

void dart::Instance::SetNativeFields ( uint16_t  num_fields,
const intptr_t *  field_values 
) const

Definition at line 20896 of file object.cc.

20897 {
20898 ASSERT(num_native_fields == NumNativeFields());
20899 ASSERT(field_values != nullptr);
20900 Object& native_fields =
20901 Object::Handle(NativeFieldsAddr()->Decompress(untag()->heap_base()));
20902 if (native_fields.IsNull()) {
20903 // Allocate backing storage for the native fields.
20904 native_fields = TypedData::New(kIntPtrCid, NumNativeFields());
20905 StoreCompressedPointer(NativeFieldsAddr(), native_fields.ptr());
20906 }
20907 for (uint16_t i = 0; i < num_native_fields; i++) {
20908 intptr_t byte_offset = i * sizeof(intptr_t);
20909 TypedData::Cast(native_fields).SetIntPtr(byte_offset, field_values[i]);
20910 }
20911}

◆ SetTypeArguments()

void dart::Instance::SetTypeArguments ( const TypeArguments value) const
virtual

Reimplemented in dart::Array, dart::GrowableObjectArray, and dart::LinkedHashBase.

Definition at line 20581 of file object.cc.

20581 {
20582 ASSERT(!IsType());
20583 ASSERT(value.IsNull() || value.IsCanonical());
20584 const Class& cls = Class::Handle(clazz());
20585 intptr_t field_offset = cls.host_type_arguments_field_offset();
20586 ASSERT(field_offset != Class::kNoTypeArguments);
20587 SetFieldAtOffset(field_offset, value);
20588}

◆ SizeFromClass()

intptr_t dart::Instance::SizeFromClass ( ) const
inline

Definition at line 8216 of file object.h.

8216 {
8217#if defined(DEBUG)
8218 const Class& cls = Class::Handle(clazz());
8219 ASSERT(cls.is_finalized() || cls.is_prefinalized());
8220#endif
8221 return (clazz()->untag()->host_instance_size_in_words_ *
8223 }

◆ UnroundedSize()

static intptr_t dart::Instance::UnroundedSize ( )
inlinestatic

Definition at line 8336 of file object.h.

8336{ return sizeof(UntaggedInstance); }

Friends And Related Function Documentation

◆ ByteBuffer

friend class ByteBuffer
friend

Definition at line 8432 of file object.h.

◆ Class

friend class Class
friend

Definition at line 8433 of file object.h.

◆ ClassDeserializationCluster

friend class ClassDeserializationCluster
friend

Definition at line 8444 of file object.h.

◆ Closure

friend class Closure
friend

Definition at line 8434 of file object.h.

◆ DeferredObject

friend class DeferredObject
friend

Definition at line 8436 of file object.h.

◆ FlowGraphDeserializer

friend class FlowGraphDeserializer
friend

Definition at line 8438 of file object.h.

◆ FlowGraphSerializer

friend class FlowGraphSerializer
friend

Definition at line 8437 of file object.h.

◆ InstanceDeserializationCluster

friend class InstanceDeserializationCluster
friend

Definition at line 8443 of file object.h.

◆ InstanceMorpher

friend class InstanceMorpher
friend

Definition at line 8445 of file object.h.

◆ InstanceSerializationCluster

friend class InstanceSerializationCluster
friend

Definition at line 8442 of file object.h.

◆ Obfuscator

friend class Obfuscator
friend

Definition at line 8446 of file object.h.

◆ Pointer

friend class Pointer
friend

Definition at line 8435 of file object.h.

◆ RegExp

friend class RegExp
friend

Definition at line 8439 of file object.h.

◆ StubCode

friend class StubCode
friend

Definition at line 8440 of file object.h.

◆ TypedDataView

friend class TypedDataView
friend

Definition at line 8441 of file object.h.


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