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

Member Function Documentation

◆ Canonicalize()

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

Definition at line 20485 of file object.cc.

20485 {
20486 SafepointMutexLocker ml(
20487 thread->isolate_group()->constant_canonicalization_mutex());
20488 return CanonicalizeLocked(thread);
20489}
virtual InstancePtr CanonicalizeLocked(Thread *thread) const
Definition object.cc:20491

◆ 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 20300 of file object.cc.

20300 {
20301 if (this->ptr() == other.ptr()) {
20302 return true; // "===".
20303 }
20304
20305 if (other.IsNull() || (this->clazz() != other.clazz())) {
20306 return false;
20307 }
20308
20309 {
20310 NoSafepointScope no_safepoint;
20311 // Raw bits compare.
20312 const intptr_t instance_size = SizeFromClass();
20313 ASSERT(instance_size != 0);
20314 const intptr_t other_instance_size = other.SizeFromClass();
20315 ASSERT(other_instance_size != 0);
20316 if (instance_size != other_instance_size) {
20317 return false;
20318 }
20319 uword this_addr = reinterpret_cast<uword>(this->untag());
20320 uword other_addr = reinterpret_cast<uword>(other.untag());
20321 for (intptr_t offset = Instance::NextFieldOffset(); offset < instance_size;
20323 if ((reinterpret_cast<CompressedObjectPtr*>(this_addr + offset)
20324 ->Decompress(untag()->heap_base())) !=
20325 (reinterpret_cast<CompressedObjectPtr*>(other_addr + offset)
20326 ->Decompress(untag()->heap_base()))) {
20327 return false;
20328 }
20329 }
20330 }
20331 return true;
20332}
static intptr_t NextFieldOffset()
Definition object.h:8326
intptr_t SizeFromClass() const
Definition object.h:8187
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)
ObjectPtr CompressedObjectPtr
Point offset

◆ CanonicalizeFieldsLocked()

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

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

Definition at line 20446 of file object.cc.

20446 {
20447 const intptr_t class_id = GetClassId();
20448 if (class_id >= kNumPredefinedCids) {
20449 // Iterate over all fields, canonicalize numbers and strings, expect all
20450 // other instances to be canonical otherwise report error (return false).
20451 Zone* zone = thread->zone();
20452 Object& obj = Object::Handle(zone);
20453 const intptr_t instance_size = SizeFromClass();
20454 ASSERT(instance_size != 0);
20455 const auto unboxed_fields_bitmap =
20456 thread->isolate_group()->class_table()->GetUnboxedFieldsMapAt(class_id);
20457 for (intptr_t offset = Instance::NextFieldOffset(); offset < instance_size;
20459 if (unboxed_fields_bitmap.Get(offset / kCompressedWordSize)) {
20460 continue;
20461 }
20462 obj = this->FieldAddrAtOffset(offset)->Decompress(untag()->heap_base());
20463 if (obj.IsInstance()) {
20464 obj = Instance::Cast(obj).CanonicalizeLocked(thread);
20465 this->SetFieldAtOffset(offset, obj);
20466 } else {
20467 ASSERT(obj.IsNull() || obj.IsSentinel());
20468 }
20469 }
20470 } else {
20471#if defined(DEBUG) && !defined(DART_COMPRESSED_POINTERS)
20472 // Make sure that we are not missing any fields.
20473 IsolateGroup* group = IsolateGroup::Current();
20474 CheckForPointers has_pointers(group);
20475 this->ptr()->untag()->VisitPointersPrecise(&has_pointers);
20476 ASSERT(!has_pointers.has_pointers());
20477#endif // DEBUG
20478 }
20479}
static IsolateGroup * Current()
Definition isolate.h:534
UntaggedObject * untag() const
intptr_t GetClassId() const
Definition object.h:341
static Object & Handle()
Definition object.h:407
void VisitPointersPrecise(ObjectPointerVisitor *visitor)
@ 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 20357 of file object.cc.

20357 {
20358 if (GetClassId() == kNullCid) {
20359 return kNullIdentityHash;
20360 }
20361 Thread* thread = Thread::Current();
20362 uint32_t hash = thread->heap()->GetCanonicalHash(ptr());
20363 if (hash != 0) {
20364 return hash;
20365 }
20366 Zone* zone = thread->zone();
20367 const Class& cls = Class::Handle(zone, clazz());
20368 const bool is_symbol = Symbol::IsSymbolCid(thread, cls.id());
20369
20370 NoSafepointScope no_safepoint(thread);
20371
20372 if (is_symbol) {
20373 hash = Symbol::CanonicalizeHash(thread, *this);
20374 } else {
20375 const intptr_t class_id = cls.id();
20376 ASSERT(class_id != 0);
20377 hash = class_id;
20378 uword this_addr = reinterpret_cast<uword>(this->untag());
20379 Object& obj = Object::Handle(zone);
20380 Instance& instance = Instance::Handle(zone);
20381
20382 const auto unboxed_fields_bitmap =
20383 thread->isolate_group()->class_table()->GetUnboxedFieldsMapAt(
20384 GetClassId());
20385
20386 for (intptr_t offset = Instance::NextFieldOffset();
20387 offset < cls.host_next_field_offset(); offset += kCompressedWordSize) {
20388 if (unboxed_fields_bitmap.Get(offset / kCompressedWordSize)) {
20389 if (kCompressedWordSize == 8) {
20391 hash, *reinterpret_cast<uint32_t*>(this_addr + offset));
20393 hash, *reinterpret_cast<uint32_t*>(this_addr + offset + 4));
20394 } else {
20396 hash, *reinterpret_cast<uint32_t*>(this_addr + offset));
20397 }
20398 } else {
20399 obj = reinterpret_cast<CompressedObjectPtr*>(this_addr + offset)
20400 ->Decompress(untag()->heap_base());
20401 if (obj.IsSentinel()) {
20402 hash = CombineHashes(hash, 11);
20403 } else {
20404 instance ^= obj.ptr();
20405 hash = CombineHashes(hash, instance.CanonicalizeHash());
20406 }
20407 }
20408 }
20410 }
20411 thread->heap()->SetCanonicalHash(ptr(), hash);
20412 return hash;
20413}
static uint32_t hash(const SkShaderBase::GradientInfo &v)
friend class Class
Definition object.h:8404
friend class Thread
Definition object.h:1025
static constexpr intptr_t kHashBits
Definition object.h:323
ClassPtr clazz() const
Definition object.h:13192
static bool IsSymbolCid(Thread *thread, classid_t class_id)
Definition object.cc:20334
static uint32_t CanonicalizeHash(Thread *thread, const Instance &instance)
Definition object.cc:20340
static Thread * Current()
Definition thread.h:361
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:10763
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 20491 of file object.cc.

20491 {
20492 if (!this->ptr()->IsHeapObject() || this->IsCanonical()) {
20493 return this->ptr();
20494 }
20495 ASSERT(!IsNull());
20497 Zone* zone = thread->zone();
20498 const Class& cls = Class::Handle(zone, this->clazz());
20499 Instance& result =
20500 Instance::Handle(zone, cls.LookupCanonicalInstance(zone, *this));
20501 if (!result.IsNull()) {
20502 return result.ptr();
20503 }
20504 if (IsNew()) {
20505 ASSERT((thread->isolate() == Dart::vm_isolate()) || !InVMIsolateHeap());
20506 // Create a canonical object in old space.
20507 result ^= Object::Clone(*this, Heap::kOld);
20508 } else {
20509 result = this->ptr();
20510 }
20511 ASSERT(result.IsOld());
20512 result.SetCanonical();
20513 return cls.InsertCanonicalConstant(zone, result);
20514}
static Isolate * vm_isolate()
Definition dart.h:68
@ kOld
Definition heap.h:39
virtual void CanonicalizeFieldsLocked(Thread *thread) const
Definition object.cc:20446
static ObjectPtr Clone(const Object &orig, Heap::Space space, bool load_with_relaxed_atomics=false)
Definition object.cc:2960
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 20481 of file object.cc.

20481 {
20483}
static ObjectPtr RawCast(ObjectPtr obj)
Definition object.h:325

◆ DataOffsetFor()

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

Definition at line 21029 of file object.cc.

21029 {
21031 // Elements start at offset 0 of the external data.
21032 return 0;
21033 }
21034 if (IsTypedDataClassId(cid)) {
21036 }
21037 switch (cid) {
21038 case kArrayCid:
21039 case kImmutableArrayCid:
21040 return Array::data_offset();
21041 case kTypeArgumentsCid:
21043 case kOneByteStringCid:
21045 case kTwoByteStringCid:
21047 case kRecordCid:
21048 return Record::field_offset(0);
21049 default:
21050 UNIMPLEMENTED();
21051 return Array::data_offset();
21052 }
21053}
static intptr_t data_offset()
Definition object.h:10814
static intptr_t data_offset()
Definition object.h:10533
static intptr_t field_offset(intptr_t index)
Definition object.h:11422
static intptr_t data_offset()
Definition object.h:10674
static intptr_t types_offset()
Definition object.h:8560
static intptr_t payload_offset()
Definition object.h:11643
#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 21008 of file object.cc.

21008 {
21012 }
21013 switch (cid) {
21014 case kArrayCid:
21015 case kImmutableArrayCid:
21017 case kTypeArgumentsCid:
21019 case kOneByteStringCid:
21021 case kTwoByteStringCid:
21023 default:
21024 UNIMPLEMENTED();
21025 return 0;
21026 }
21027}
static constexpr intptr_t kBytesPerElement
Definition object.h:10897
static constexpr intptr_t kBytesPerElement
Definition object.h:10521
static constexpr intptr_t kBytesPerElement
Definition object.h:10662
intptr_t ElementSizeInBytes() const
Definition object.h:11505
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:8573

◆ 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 4888 of file object.cc.

4893 {
4894 auto thread = Thread::Current();
4895 auto zone = thread->zone();
4896 const auto& library = Library::Handle(zone, klass.library());
4897 return Instance::EvaluateCompiledExpression(thread, *this, library, klass,
4898 kernel_buffer, type_definitions,
4899 arguments, type_arguments);
4900}
ObjectPtr EvaluateCompiledExpression(const Class &klass, const ExternalTypedData &kernel_buffer, const Array &type_definitions, const Array &arguments, const TypeArguments &type_arguments) const
Definition object.cc:4888

◆ 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 4902 of file object.cc.

4910 {
4911 auto zone = Thread::Current()->zone();
4912#if defined(DART_PRECOMPILED_RUNTIME)
4913 const auto& error_str = String::Handle(
4914 zone,
4915 String::New("Expression evaluation not available in precompiled mode."));
4916 return ApiError::New(error_str);
4917#else
4918 if (IsInternalOnlyClassId(klass.id()) || (klass.id() == kTypeArgumentsCid)) {
4919 const auto& exception = Instance::Handle(
4920 zone, String::New("Expressions can be evaluated only with regular Dart "
4921 "instances/classes."));
4922 return UnhandledException::New(exception, StackTrace::null_instance());
4923 }
4924
4925 const auto& url = String::Handle(zone, library.url());
4926 const auto& klass_name = klass.IsTopLevel()
4927 ? String::null_string()
4928 : String::Handle(zone, klass.UserVisibleName());
4929
4930 const auto& result = Object::Handle(
4931 zone,
4932 LoadExpressionEvaluationFunction(zone, kernel_buffer, url, klass_name));
4933 if (result.IsError()) return result.ptr();
4934
4935 const auto& eval_function = Function::Cast(result);
4936
4937#if defined(DEBUG)
4938 for (intptr_t i = 0; i < arguments.Length(); ++i) {
4939 ASSERT(arguments.At(i) != Object::optimized_out().ptr());
4940 }
4941#endif // defined(DEBUG)
4942
4943 auto& all_arguments = Array::Handle(zone, arguments.ptr());
4944 if (!eval_function.is_static()) {
4945 // `this` may be optimized out (e.g. not accessible from breakpoint due to
4946 // not being captured by closure). We allow this as long as the evaluation
4947 // function doesn't actually need `this`.
4948 if (receiver.IsNull() || receiver.ptr() == Object::optimized_out().ptr()) {
4949 if (EvaluationFunctionNeedsReceiver(thread, zone, eval_function)) {
4950 return Object::optimized_out().ptr();
4951 }
4952 }
4953
4954 all_arguments = Array::New(1 + arguments.Length());
4955 auto& param = PassiveObject::Handle();
4956 all_arguments.SetAt(0, receiver);
4957 for (intptr_t i = 0; i < arguments.Length(); i++) {
4958 param = arguments.At(i);
4959 all_arguments.SetAt(i + 1, param);
4960 }
4961 }
4962
4963 return EvaluateCompiledExpressionHelper(zone, eval_function, type_definitions,
4964 all_arguments, type_arguments);
4965#endif // !defined(DART_PRECOMPILED_RUNTIME)
4966}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10933
static PassiveObject & Handle()
Definition object.h:1077
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition object.cc:23777
Zone * zone() const
static UnhandledExceptionPtr New(const Instance &exception, const Instance &stacktrace, Heap::Space space=Heap::kNew)
Definition object.cc:19989
static bool EvaluationFunctionNeedsReceiver(Thread *thread, Zone *zone, const Function &eval_function)
Definition object.cc:4828
static ObjectPtr EvaluateCompiledExpressionHelper(Zone *zone, const Function &eval_function, const Array &type_definitions, const Array &arguments, const TypeArguments &type_arguments)
Definition object.cc:4837
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:4804

◆ GetField()

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

Definition at line 20516 of file object.cc.

20516 {
20517 if (field.is_unboxed()) {
20518 switch (field.guarded_cid()) {
20519 case kDoubleCid:
20520 return Double::New(*reinterpret_cast<double_t*>(FieldAddr(field)));
20521 case kFloat32x4Cid:
20522 return Float32x4::New(
20523 *reinterpret_cast<simd128_value_t*>(FieldAddr(field)));
20524 case kFloat64x2Cid:
20525 return Float64x2::New(
20526 *reinterpret_cast<simd128_value_t*>(FieldAddr(field)));
20527 default:
20528 return Integer::New(*reinterpret_cast<int64_t*>(FieldAddr(field)));
20529 }
20530 } else {
20531 return FieldAddr(field)->Decompress(untag()->heap_base());
20532 }
20533}
static DoublePtr New(double d, Heap::Space space=Heap::kNew)
Definition object.cc:23481
static Float32x4Ptr New(float value0, float value1, float value2, float value3, Heap::Space space=Heap::kNew)
Definition object.cc:25386
static Float64x2Ptr New(double value0, double value1, Heap::Space space=Heap::kNew)
Definition object.cc:25554
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition object.cc:23063

◆ GetNativeField()

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

Definition at line 13281 of file object.h.

13281 {
13282 ASSERT(IsValidNativeIndex(index));
13283 NoSafepointScope no_safepoint;
13284 TypedDataPtr native_fields = static_cast<TypedDataPtr>(
13285 NativeFieldsAddr()->Decompress(untag()->heap_base()));
13286 if (native_fields == TypedData::null()) {
13287 return 0;
13288 }
13289 return reinterpret_cast<intptr_t*>(native_fields->untag()->data())[index];
13290}
bool IsValidNativeIndex(int index) const
Definition object.h:8241
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 13292 of file object.h.

13293 {
13294 NoSafepointScope no_safepoint;
13295 ASSERT(num_fields == NumNativeFields());
13296 ASSERT(field_values != nullptr);
13297 TypedDataPtr native_fields = static_cast<TypedDataPtr>(
13298 NativeFieldsAddr()->Decompress(untag()->heap_base()));
13299 if (native_fields == TypedData::null()) {
13300 for (intptr_t i = 0; i < num_fields; i++) {
13301 field_values[i] = 0;
13302 }
13303 }
13304 intptr_t* fields =
13305 reinterpret_cast<intptr_t*>(native_fields->untag()->data());
13306 for (intptr_t i = 0; i < num_fields; i++) {
13307 field_values[i] = fields[i];
13308 }
13309}
uint16_t NumNativeFields() const
Definition object.h:8251

◆ GetType()

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

Definition at line 20561 of file object.cc.

20561 {
20562 if (IsNull()) {
20563 return Type::NullType();
20564 }
20565 Thread* thread = Thread::Current();
20566 Zone* zone = thread->zone();
20567 const Class& cls = Class::Handle(zone, clazz());
20568 if (!cls.is_finalized()) {
20569 // Various predefined classes can be instantiated by the VM or
20570 // Dart_NewString/Integer/TypedData/... before the class is finalized.
20571 ASSERT(cls.is_prefinalized());
20572 cls.EnsureDeclarationLoaded();
20573 }
20574 if (cls.IsClosureClass()) {
20575 FunctionType& signature = FunctionType::Handle(
20576 zone, Closure::Cast(*this).GetInstantiatedSignature(zone));
20577 if (!signature.IsFinalized()) {
20578 signature.SetIsFinalized();
20579 }
20580 signature ^= signature.Canonicalize(thread);
20581 return signature.ptr();
20582 }
20583 if (IsRecord()) {
20584 ASSERT(cls.IsRecordClass());
20585 auto& record_type =
20586 RecordType::Handle(zone, Record::Cast(*this).GetRecordType());
20587 ASSERT(record_type.IsFinalized());
20588 ASSERT(record_type.IsCanonical());
20589 return record_type.ptr();
20590 }
20591 Type& type = Type::Handle(zone);
20592 if (!cls.IsGeneric()) {
20593 type = cls.DeclarationType();
20594 }
20595 if (type.IsNull()) {
20596 TypeArguments& type_arguments = TypeArguments::Handle(zone);
20597 const intptr_t num_type_arguments = cls.NumTypeArguments();
20598 if (num_type_arguments > 0) {
20599 type_arguments = GetTypeArguments();
20600 if (!type_arguments.IsNull()) {
20601 type_arguments = type_arguments.FromInstanceTypeArguments(thread, cls);
20602 }
20603 }
20604 type = Type::New(cls, type_arguments, Nullability::kNonNullable, space);
20605 type.SetIsFinalized();
20606 type ^= type.Canonicalize(thread);
20607 }
20608 return type.ptr();
20609}
virtual TypeArgumentsPtr GetTypeArguments() const
Definition object.cc:20611
static TypePtr New(const Class &clazz, const TypeArguments &arguments, Nullability nullability=Nullability::kLegacy, Heap::Space space=Heap::kOld)
Definition object.cc:22492
static TypePtr NullType()
Definition object.cc:21862

◆ GetTypeArguments()

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

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

Definition at line 20611 of file object.cc.

20611 {
20612 ASSERT(!IsType());
20613 const Class& cls = Class::Handle(clazz());
20614 intptr_t field_offset = cls.host_type_arguments_field_offset();
20615 ASSERT(field_offset != Class::kNoTypeArguments);
20616 TypeArguments& type_arguments = TypeArguments::Handle();
20617 type_arguments ^=
20618 FieldAddrAtOffset(field_offset)->Decompress(untag()->heap_base());
20619 return type_arguments.ptr();
20620}
static constexpr intptr_t kNoTypeArguments
Definition object.h:1376

◆ HashCode()

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

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

Definition at line 20253 of file object.cc.

20253 {
20254 // TODO(koda): Optimize for all builtin classes and all classes
20255 // that do not override hashCode.
20256 return DartLibraryCalls::HashCode(*this);
20257}
static ObjectPtr HashCode(const Instance &receiver)

◆ IdentityHashCode()

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

Definition at line 20260 of file object.cc.

20260 {
20261 if (IsInteger()) return Integer::Cast(*this).ptr();
20262
20263#if defined(HASH_IN_OBJECT_HEADER)
20264 intptr_t hash = Object::GetCachedHash(ptr());
20265#else
20266 intptr_t hash = thread->heap()->GetHash(ptr());
20267#endif
20268 if (hash == 0) {
20269 if (IsNull()) {
20271 } else if (IsBool()) {
20272 hash = Bool::Cast(*this).value() ? kTrueIdentityHash : kFalseIdentityHash;
20273 } else if (IsDouble()) {
20274 double val = Double::Cast(*this).value();
20275 if ((val >= kMinInt64RepresentableAsDouble) &&
20277 int64_t ival = static_cast<int64_t>(val);
20278 if (static_cast<double>(ival) == val) {
20279 return Integer::New(ival);
20280 }
20281 }
20282
20283 uint64_t uval = bit_cast<uint64_t>(val);
20284 hash = ((uval >> 32) ^ (uval)) & kSmiMax;
20285 } else {
20286 do {
20287 hash = thread->random()->NextUInt32() & 0x3FFFFFFF;
20288 } while (hash == 0);
20289 }
20290
20291#if defined(HASH_IN_OBJECT_HEADER)
20292 hash = Object::SetCachedHashIfNotSet(ptr(), hash);
20293#else
20294 hash = thread->heap()->SetHashIfNotSet(ptr(), hash);
20295#endif
20296 }
20297 return Smi::New(hash);
20298}
static SmiPtr New(intptr_t value)
Definition object.h:9985
bool IsDouble(const dart::Object &a)
static constexpr intptr_t kFalseIdentityHash
Definition object.h:10765
const intptr_t kSmiMax
Definition globals.h:28
static constexpr intptr_t kTrueIdentityHash
Definition object.h:10764
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 8308 of file object.h.

8308 {
8309 return RoundedAllocationSize(sizeof(UntaggedInstance));
8310 }
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 20188 of file object.cc.

20192 {
20193 Thread* thread = Thread::Current();
20194 Zone* zone = thread->zone();
20195 Class& klass = Class::Handle(zone, clazz());
20196 CHECK_ERROR(klass.EnsureIsFinalized(thread));
20197
20198 Function& function = Function::Handle(
20200
20201 if (!function.IsNull() && check_is_entrypoint) {
20202 CHECK_ERROR(function.VerifyCallEntryPoint());
20203 }
20204
20205 // We don't pass any explicit type arguments, which will be understood as
20206 // using dynamic for any function type arguments by lower layers.
20207 const int kTypeArgsLen = 0;
20208 const Array& args_descriptor = Array::Handle(
20209 zone, ArgumentsDescriptor::NewBoxed(kTypeArgsLen, args.Length(),
20210 arg_names, Heap::kNew));
20211
20212 const auto& inst_type_args =
20213 klass.NumTypeArguments() > 0
20215 : Object::null_type_arguments();
20216
20217 if (function.IsNull()) {
20218 // Didn't find a method: try to find a getter and invoke call on its result.
20219 const String& getter_name =
20221 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name);
20222 if (!function.IsNull()) {
20223 if (check_is_entrypoint) {
20225 }
20226 ASSERT(function.kind() != UntaggedFunction::kMethodExtractor);
20227 // Invoke the getter.
20228 const int kNumArgs = 1;
20229 const Array& getter_args = Array::Handle(zone, Array::New(kNumArgs));
20230 getter_args.SetAt(0, *this);
20231 const Array& getter_args_descriptor = Array::Handle(
20233 kTypeArgsLen, getter_args.Length(), Heap::kNew));
20234 const Object& getter_result = Object::Handle(
20235 zone, InvokeInstanceFunction(thread, *this, function, getter_name,
20236 getter_args, getter_args_descriptor,
20237 respect_reflectable, inst_type_args));
20238 if (getter_result.IsError()) {
20239 return getter_result.ptr();
20240 }
20241 // Replace the closure as the receiver in the arguments list.
20242 args.SetAt(0, getter_result);
20243 return DartEntry::InvokeClosure(thread, args, args_descriptor);
20244 }
20245 }
20246
20247 // Found an ordinary method.
20248 return InvokeInstanceFunction(thread, *this, function, function_name, args,
20249 args_descriptor, respect_reflectable,
20250 inst_type_args);
20251}
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)
static StringPtr GetterName(const String &field_name)
Definition object.cc:11843
@ kNew
Definition heap.h:38
static FunctionPtr ResolveDynamicAnyArgs(Zone *zone, const Class &receiver_class, const String &function_name, bool allow_add=true)
Definition resolver.cc:198
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:27272
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:14363
const char *const function_name
#define CHECK_ERROR(value, message)

◆ InvokeGetter()

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

Definition at line 20081 of file object.cc.

20083 {
20084 Thread* thread = Thread::Current();
20085 Zone* zone = thread->zone();
20086
20087 Class& klass = Class::Handle(zone, clazz());
20088 CHECK_ERROR(klass.EnsureIsFinalized(thread));
20089 const auto& inst_type_args =
20090 klass.NumTypeArguments() > 0
20092 : Object::null_type_arguments();
20093
20094 const String& internal_getter_name =
20095 String::Handle(zone, Field::GetterName(getter_name));
20096 Function& function = Function::Handle(
20097 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, internal_getter_name));
20098
20099 if (!function.IsNull() && check_is_entrypoint) {
20100 // The getter must correspond to either an entry-point field or a getter
20101 // method explicitly marked.
20102 Field& field = Field::Handle(zone);
20103 if (function.kind() == UntaggedFunction::kImplicitGetter) {
20104 field = function.accessor_field();
20105 }
20106 if (!field.IsNull()) {
20107 CHECK_ERROR(field.VerifyEntryPoint(EntryPointPragma::kGetterOnly));
20108 } else {
20109 CHECK_ERROR(function.VerifyCallEntryPoint());
20110 }
20111 }
20112
20113 // Check for method extraction when method extractors are not created.
20114 if (function.IsNull() && !FLAG_lazy_dispatchers) {
20115 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name);
20116
20117 if (!function.IsNull() && check_is_entrypoint) {
20118 CHECK_ERROR(function.VerifyClosurizedEntryPoint());
20119 }
20120
20121 if (!function.IsNull() && function.SafeToClosurize()) {
20122 const Function& closure_function =
20123 Function::Handle(zone, function.ImplicitClosureFunction());
20124 return closure_function.ImplicitInstanceClosure(*this);
20125 }
20126 }
20127
20128 const int kTypeArgsLen = 0;
20129 const int kNumArgs = 1;
20130 const Array& args = Array::Handle(zone, Array::New(kNumArgs));
20131 args.SetAt(0, *this);
20132 const Array& args_descriptor = Array::Handle(
20133 zone,
20134 ArgumentsDescriptor::NewBoxed(kTypeArgsLen, args.Length(), Heap::kNew));
20135
20136 return InvokeInstanceFunction(thread, *this, function, internal_getter_name,
20137 args, args_descriptor, respect_reflectable,
20138 inst_type_args);
20139}

◆ InvokeSetter()

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

Definition at line 20141 of file object.cc.

20144 {
20145 Thread* thread = Thread::Current();
20146 Zone* zone = thread->zone();
20147
20148 const Class& klass = Class::Handle(zone, clazz());
20149 CHECK_ERROR(klass.EnsureIsFinalized(thread));
20150 const auto& inst_type_args =
20151 klass.NumTypeArguments() > 0
20153 : Object::null_type_arguments();
20154
20155 const String& internal_setter_name =
20156 String::Handle(zone, Field::SetterName(setter_name));
20157 const Function& setter = Function::Handle(
20158 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, internal_setter_name));
20159
20160 if (check_is_entrypoint) {
20161 // The setter must correspond to either an entry-point field or a setter
20162 // method explicitly marked.
20163 Field& field = Field::Handle(zone);
20164 if (setter.kind() == UntaggedFunction::kImplicitSetter) {
20165 field = setter.accessor_field();
20166 }
20167 if (!field.IsNull()) {
20168 CHECK_ERROR(field.VerifyEntryPoint(EntryPointPragma::kSetterOnly));
20169 } else if (!setter.IsNull()) {
20170 CHECK_ERROR(setter.VerifyCallEntryPoint());
20171 }
20172 }
20173
20174 const int kTypeArgsLen = 0;
20175 const int kNumArgs = 2;
20176 const Array& args = Array::Handle(zone, Array::New(kNumArgs));
20177 args.SetAt(0, *this);
20178 args.SetAt(1, value);
20179 const Array& args_descriptor = Array::Handle(
20180 zone,
20181 ArgumentsDescriptor::NewBoxed(kTypeArgsLen, args.Length(), Heap::kNew));
20182
20183 return InvokeInstanceFunction(thread, *this, setter, internal_setter_name,
20184 args, args_descriptor, respect_reflectable,
20185 inst_type_args);
20186}
static StringPtr SetterName(const String &field_name)
Definition object.cc:11855

◆ IsAssignableTo()

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

Definition at line 20670 of file object.cc.

20673 {
20674 ASSERT(!other.IsDynamicType());
20675 // In strong mode, compute NNBD_SUBTYPE(runtimeType, other).
20676 // In weak mode, compute LEGACY_SUBTYPE(runtimeType, other).
20677 return RuntimeTypeIsSubtypeOf(other, other_instantiator_type_arguments,
20678 other_function_type_arguments);
20679}

◆ IsCallable()

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

Definition at line 20954 of file object.cc.

20954 {
20955 Class& cls = Class::Handle(clazz());
20956 if (cls.IsClosureClass()) {
20957 if (function != nullptr) {
20958 *function = Closure::Cast(*this).function();
20959 }
20960 return true;
20961 }
20962 // Try to resolve a "call" method.
20963 Zone* zone = Thread::Current()->zone();
20964 Function& call_function = Function::Handle(
20965 zone, Resolver::ResolveDynamicAnyArgs(zone, cls, Symbols::DynamicCall(),
20966 /*allow_add=*/false));
20967 if (call_function.IsNull()) {
20968 return false;
20969 }
20970 if (function != nullptr) {
20971 *function = call_function.ptr();
20972 }
20973 return true;
20974}

◆ IsIdenticalTo()

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

Definition at line 20902 of file object.cc.

20902 {
20903 if (ptr() == other.ptr()) return true;
20904 if (IsInteger() && other.IsInteger()) {
20905 return Integer::Cast(*this).Equals(other);
20906 }
20907 if (IsDouble() && other.IsDouble()) {
20908 double other_value = Double::Cast(other).value();
20909 return Double::Cast(*this).BitwiseEqualsToDouble(other_value);
20910 }
20911 return false;
20912}

◆ IsInstanceOf()

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

Definition at line 20655 of file object.cc.

20658 {
20659 ASSERT(!other.IsDynamicType());
20660 if (IsNull()) {
20661 return Instance::NullIsInstanceOf(other, other_instantiator_type_arguments,
20662 other_function_type_arguments);
20663 }
20664 // In strong mode, compute NNBD_SUBTYPE(runtimeType, other).
20665 // In weak mode, compute LEGACY_SUBTYPE(runtimeType, other).
20666 return RuntimeTypeIsSubtypeOf(other, other_instantiator_type_arguments,
20667 other_function_type_arguments);
20668}

◆ IsPointer()

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

Definition at line 25843 of file object.cc.

25843 {
25844 return Pointer::IsPointer(*this);
25845}
virtual bool IsPointer() const
Definition object.cc:25843

◆ IsValidNativeIndex()

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

Definition at line 8241 of file object.h.

8241 {
8242 return ((index >= 0) && (index < clazz()->untag()->num_native_fields_));
8243 }

◆ NativeFieldsDataAddr()

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

Definition at line 20914 of file object.cc.

20914 {
20915 ASSERT(Thread::Current()->no_safepoint_scope_depth() > 0);
20916 TypedDataPtr native_fields = static_cast<TypedDataPtr>(
20917 NativeFieldsAddr()->Decompress(untag()->heap_base()));
20918 if (native_fields == TypedData::null()) {
20919 return nullptr;
20920 }
20921 return reinterpret_cast<intptr_t*>(native_fields->untag()->data());
20922}

◆ NativeFieldsOffset()

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

Definition at line 8328 of file object.h.

8328{ return sizeof(UntaggedObject); }

◆ New()

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

Definition at line 20976 of file object.cc.

20976 {
20977 Thread* thread = Thread::Current();
20978 if (cls.EnsureIsAllocateFinalized(thread) != Error::null()) {
20979 return Instance::null();
20980 }
20981 return NewAlreadyFinalized(cls, space);
20982}
static InstancePtr NewAlreadyFinalized(const Class &cls, Heap::Space space=Heap::kNew)
Definition object.cc:20984

◆ NewAlreadyFinalized()

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

Definition at line 20984 of file object.cc.

20984 {
20985 ASSERT(cls.is_allocate_finalized());
20986 intptr_t instance_size = cls.host_instance_size();
20987 ASSERT(instance_size > 0);
20988 // Initialize everything after the object header with Object::null(), since
20989 // this isn't a predefined class.
20990 const uword ptr_field_end_offset =
20991 instance_size - (Instance::ContainsCompressedPointers()
20993 : kWordSize);
20994 return static_cast<InstancePtr>(Object::Allocate(
20995 cls.id(), instance_size, space, Instance::ContainsCompressedPointers(),
20996 from_offset<Instance>(), ptr_field_end_offset));
20997}
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:2820
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 8326 of file object.h.

8326{ return sizeof(UntaggedInstance); }

◆ NullIsAssignableTo() [1/2]

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

Definition at line 20715 of file object.cc.

20715 {
20716 // "Left Null" rule: null is assignable when destination type is either
20717 // legacy or nullable. Otherwise it is not assignable or we cannot tell
20718 // without instantiating type parameter.
20719 if (other.IsLegacy() || other.IsNullable()) {
20720 return true;
20721 }
20722 if (other.IsFutureOrType()) {
20723 return NullIsAssignableTo(AbstractType::Handle(other.UnwrapFutureOr()));
20724 }
20725 // Since the TAVs are not available, for non-nullable type parameters
20726 // this returns a conservative approximation of "not assignable" .
20727 return false;
20728}
static bool NullIsAssignableTo(const AbstractType &other)
Definition object.cc:20715

◆ 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 20732 of file object.cc.

20735 {
20736 // Do checks that don't require instantiation first.
20737 if (NullIsAssignableTo(other)) return true;
20738 if (!other.IsTypeParameter()) return false;
20739 const auto& type = AbstractType::Handle(other.InstantiateFrom(
20740 other_instantiator_type_arguments, other_function_type_arguments,
20742 return NullIsAssignableTo(type);
20743}
@ kAllFree
Definition object.h:2920

◆ NumNativeFields()

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

Definition at line 8251 of file object.h.

8251 {
8252 return clazz()->untag()->num_native_fields_;
8253 }

◆ OperatorEquals()

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

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

Definition at line 20896 of file object.cc.

20896 {
20897 // TODO(koda): Optimize for all builtin classes and all classes
20898 // that do not override operator==.
20899 return DartLibraryCalls::Equals(*this, other) == Object::bool_true().ptr();
20900}
static ObjectPtr Equals(const Instance &left, const Instance &right)

◆ 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:13281
ObjectPtr GetField(const Field &field) const
Definition object.cc:20516
void AddCommonObjectProperties(JSONObject *jsobj, const char *protocol_type, bool ref) const
uint8_t value

◆ SetField()

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

Definition at line 20535 of file object.cc.

20535 {
20536 if (field.is_unboxed()) {
20537 switch (field.guarded_cid()) {
20538 case kDoubleCid:
20539 StoreNonPointer(reinterpret_cast<double_t*>(FieldAddr(field)),
20540 Double::Cast(value).value());
20541 break;
20542 case kFloat32x4Cid:
20543 StoreNonPointer(reinterpret_cast<simd128_value_t*>(FieldAddr(field)),
20544 Float32x4::Cast(value).value());
20545 break;
20546 case kFloat64x2Cid:
20547 StoreNonPointer(reinterpret_cast<simd128_value_t*>(FieldAddr(field)),
20548 Float64x2::Cast(value).value());
20549 break;
20550 default:
20551 StoreNonPointer(reinterpret_cast<int64_t*>(FieldAddr(field)),
20552 Integer::Cast(value).AsInt64Value());
20553 break;
20554 }
20555 } else {
20556 field.RecordStore(value);
20557 StoreCompressedPointer(FieldAddr(field), value.ptr());
20558 }
20559}
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 20924 of file object.cc.

20924 {
20925 ASSERT(IsValidNativeIndex(index));
20926 Object& native_fields =
20927 Object::Handle(NativeFieldsAddr()->Decompress(untag()->heap_base()));
20928 if (native_fields.IsNull()) {
20929 // Allocate backing storage for the native fields.
20930 native_fields = TypedData::New(kIntPtrCid, NumNativeFields());
20931 StoreCompressedPointer(NativeFieldsAddr(), native_fields.ptr());
20932 }
20933 intptr_t byte_offset = index * sizeof(intptr_t);
20934 TypedData::Cast(native_fields).SetIntPtr(byte_offset, value);
20935}
static TypedDataPtr New(intptr_t class_id, intptr_t len, Heap::Space space=Heap::kNew)
Definition object.cc:25666

◆ SetNativeFields()

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

Definition at line 20937 of file object.cc.

20938 {
20939 ASSERT(num_native_fields == NumNativeFields());
20940 ASSERT(field_values != nullptr);
20941 Object& native_fields =
20942 Object::Handle(NativeFieldsAddr()->Decompress(untag()->heap_base()));
20943 if (native_fields.IsNull()) {
20944 // Allocate backing storage for the native fields.
20945 native_fields = TypedData::New(kIntPtrCid, NumNativeFields());
20946 StoreCompressedPointer(NativeFieldsAddr(), native_fields.ptr());
20947 }
20948 for (uint16_t i = 0; i < num_native_fields; i++) {
20949 intptr_t byte_offset = i * sizeof(intptr_t);
20950 TypedData::Cast(native_fields).SetIntPtr(byte_offset, field_values[i]);
20951 }
20952}

◆ SetTypeArguments()

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

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

Definition at line 20622 of file object.cc.

20622 {
20623 ASSERT(!IsType());
20624 ASSERT(value.IsNull() || value.IsCanonical());
20625 const Class& cls = Class::Handle(clazz());
20626 intptr_t field_offset = cls.host_type_arguments_field_offset();
20627 ASSERT(field_offset != Class::kNoTypeArguments);
20628 SetFieldAtOffset(field_offset, value);
20629}

◆ SizeFromClass()

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

Definition at line 8187 of file object.h.

8187 {
8188#if defined(DEBUG)
8189 const Class& cls = Class::Handle(clazz());
8190 ASSERT(cls.is_finalized() || cls.is_prefinalized());
8191#endif
8192 return (clazz()->untag()->host_instance_size_in_words_ *
8194 }

◆ UnroundedSize()

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

Definition at line 8307 of file object.h.

8307{ return sizeof(UntaggedInstance); }

Friends And Related Symbol Documentation

◆ ByteBuffer

friend class ByteBuffer
friend

Definition at line 8403 of file object.h.

◆ Class

friend class Class
friend

Definition at line 8404 of file object.h.

◆ ClassDeserializationCluster

friend class ClassDeserializationCluster
friend

Definition at line 8415 of file object.h.

◆ Closure

friend class Closure
friend

Definition at line 8405 of file object.h.

◆ DeferredObject

friend class DeferredObject
friend

Definition at line 8407 of file object.h.

◆ FlowGraphDeserializer

friend class FlowGraphDeserializer
friend

Definition at line 8409 of file object.h.

◆ FlowGraphSerializer

friend class FlowGraphSerializer
friend

Definition at line 8408 of file object.h.

◆ InstanceDeserializationCluster

friend class InstanceDeserializationCluster
friend

Definition at line 8414 of file object.h.

◆ InstanceMorpher

friend class InstanceMorpher
friend

Definition at line 8416 of file object.h.

◆ InstanceSerializationCluster

friend class InstanceSerializationCluster
friend

Definition at line 8413 of file object.h.

◆ Obfuscator

friend class Obfuscator
friend

Definition at line 8417 of file object.h.

◆ Pointer

friend class Pointer
friend

Definition at line 8406 of file object.h.

◆ RegExp

friend class RegExp
friend

Definition at line 8410 of file object.h.

◆ StubCode

friend class StubCode
friend

Definition at line 8411 of file object.h.

◆ TypedDataView

friend class TypedDataView
friend

Definition at line 8412 of file object.h.


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