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

#include <object.h>

Inheritance diagram for dart::Array:
dart::Instance dart::Object

Classes

struct  ArrayTraits
 

Public Member Functions

intptr_t Length () const
 
bool Equals (const Array &other) const
 
template<std::memory_order order = std::memory_order_relaxed>
ObjectPtr At (intptr_t index) const
 
template<std::memory_order order = std::memory_order_relaxed>
void SetAt (intptr_t index, const Object &value) const
 
template<std::memory_order order = std::memory_order_relaxed>
void SetAt (intptr_t index, const Object &value, Thread *thread) const
 
ObjectPtr AtAcquire (intptr_t index) const
 
void SetAtRelease (intptr_t index, const Object &value) const
 
bool IsImmutable () const
 
virtual TypeArgumentsPtr GetTypeArguments () const
 
virtual void SetTypeArguments (const TypeArguments &value) const
 
virtual bool CanonicalizeEquals (const Instance &other) const
 
virtual uint32_t CanonicalizeHash () const
 
virtual void CanonicalizeFieldsLocked (Thread *thread) const
 
void MakeImmutable () const
 
void Truncate (intptr_t new_length) const
 
ArrayPtr Slice (intptr_t start, intptr_t count, bool with_type_argument) const
 
ArrayPtr Copy () const
 
- Public Member Functions inherited from dart::Instance
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 constexpr bool UseCardMarkingForAllocation (const intptr_t array_length)
 
static intptr_t LengthOf (const ArrayPtr array)
 
static intptr_t length_offset ()
 
static intptr_t data_offset ()
 
static intptr_t element_offset (intptr_t index)
 
static intptr_t index_at_offset (intptr_t offset_in_bytes)
 
static bool Equals (ArrayPtr a, ArrayPtr b)
 
static CompressedObjectPtrDataOf (ArrayPtr array)
 
static intptr_t type_arguments_offset ()
 
static constexpr bool IsValidLength (intptr_t len)
 
static intptr_t InstanceSize ()
 
static constexpr intptr_t UnroundedSize (intptr_t len)
 
static constexpr intptr_t InstanceSize (intptr_t len)
 
static ArrayPtr New (intptr_t len, Heap::Space space=Heap::kNew)
 
static ArrayPtr NewUninitialized (intptr_t len, Heap::Space space=Heap::kNew)
 
static ArrayPtr New (intptr_t len, const AbstractType &element_type, Heap::Space space=Heap::kNew)
 
static ArrayPtr Grow (const Array &source, intptr_t new_length, Heap::Space space=Heap::kNew)
 
static ArrayPtr MakeFixedLength (const GrowableObjectArray &growable_array, bool unique=false)
 
- Static Public Member Functions inherited from dart::Instance
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)
 

Static Public Attributes

static constexpr intptr_t kMaxLengthForWriteBarrierElimination = 8
 
static constexpr intptr_t kElementTypeTypeArgPos = 0
 
static constexpr intptr_t kBytesPerElement = ArrayTraits::kElementSize
 
static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement
 
static constexpr intptr_t kMaxNewSpaceElements
 
- Static Public Attributes inherited from dart::Object
static constexpr intptr_t kHashBits = 30
 
static const ClassId kClassId = kObjectCid
 

Static Protected Member Functions

static ArrayPtr New (intptr_t class_id, intptr_t len, Heap::Space space=Heap::kNew)
 
static ArrayPtr NewUninitialized (intptr_t class_id, intptr_t len, Heap::Space space=Heap::kNew)
 
- 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)
 

Friends

class Class
 
class ImmutableArray
 
class Object
 
class String
 
class MessageDeserializer
 

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
 
- Protected Member Functions inherited from dart::Instance
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
 
- Protected Attributes inherited from dart::Object
ObjectPtr ptr_
 

Detailed Description

Definition at line 10815 of file object.h.

Member Function Documentation

◆ At()

template<std::memory_order order = std::memory_order_relaxed>
ObjectPtr dart::Array::At ( intptr_t  index) const
inline

Definition at line 10875 of file object.h.

10875 {
10876 ASSERT((0 <= index) && (index < Length()));
10877 return untag()->element<order>(index);
10878 }
intptr_t Length() const
Definition: object.h:10829
#define ASSERT(E)
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

◆ AtAcquire()

ObjectPtr dart::Array::AtAcquire ( intptr_t  index) const
inline

Definition at line 10891 of file object.h.

10891 {
10892 ASSERT((0 <= index) && (index < Length()));
10893 return untag()->element<std::memory_order_acquire>(index);
10894 }

◆ CanonicalizeEquals()

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

Reimplemented from dart::Instance.

Definition at line 24702 of file object.cc.

24702 {
24703 if (this->ptr() == other.ptr()) {
24704 // Both handles point to the same raw instance.
24705 return true;
24706 }
24707
24708 // An Array may be compared to an ImmutableArray.
24709 if (!other.IsArray() || other.IsNull()) {
24710 return false;
24711 }
24712
24713 // First check if both arrays have the same length and elements.
24714 const Array& other_arr = Array::Cast(other);
24715
24716 intptr_t len = this->Length();
24717 if (len != other_arr.Length()) {
24718 return false;
24719 }
24720
24721 for (intptr_t i = 0; i < len; i++) {
24722 if (this->At(i) != other_arr.At(i)) {
24723 return false;
24724 }
24725 }
24726
24727 // Now check if both arrays have the same type arguments.
24728 if (GetTypeArguments() == other.GetTypeArguments()) {
24729 return true;
24730 }
24731 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments());
24732 const TypeArguments& other_type_args =
24733 TypeArguments::Handle(other.GetTypeArguments());
24734 if (!type_args.Equals(other_type_args)) {
24735 return false;
24736 }
24737 return true;
24738}
virtual TypeArgumentsPtr GetTypeArguments() const
Definition: object.h:10905
ObjectPtr At(intptr_t index) const
Definition: object.h:10875
ObjectPtr ptr() const
Definition: object.h:332
static Object & Handle()
Definition: object.h:407

◆ CanonicalizeFieldsLocked()

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

Reimplemented from dart::Instance.

Definition at line 24971 of file object.cc.

24971 {
24973 intptr_t len = Length();
24974 if (len > 0) {
24975 Zone* zone = thread->zone();
24976 Instance& obj = Instance::Handle(zone);
24977 for (intptr_t i = 0; i < len; i++) {
24978 obj ^= At(i);
24979 obj = obj.CanonicalizeLocked(thread);
24980 this->SetAt(i, obj);
24981 }
24982 }
24983}
bool IsImmutable() const
Definition: object.h:10900
void SetAt(intptr_t index, const Object &value) const
Definition: object.h:10880

◆ CanonicalizeHash()

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

Reimplemented from dart::Instance.

Definition at line 24740 of file object.cc.

24740 {
24741 intptr_t len = Length();
24742 if (len == 0) {
24743 return 1;
24744 }
24745 Thread* thread = Thread::Current();
24746 uint32_t hash = thread->heap()->GetCanonicalHash(ptr());
24747 if (hash != 0) {
24748 return hash;
24749 }
24750 hash = len;
24751 Instance& member = Instance::Handle(GetTypeArguments());
24752 hash = CombineHashes(hash, member.CanonicalizeHash());
24753 for (intptr_t i = 0; i < len; i++) {
24754 member ^= At(i);
24755 hash = CombineHashes(hash, member.CanonicalizeHash());
24756 }
24758 thread->heap()->SetCanonicalHash(ptr(), hash);
24759 return hash;
24760}
static uint32_t hash(const SkShaderBase::GradientInfo &v)
friend class Thread
Definition: object.h:1025
static constexpr intptr_t kHashBits
Definition: object.h:323
static Thread * Current()
Definition: thread.h:362
uint32_t CombineHashes(uint32_t hash, uint32_t other_hash)
Definition: hash.h:12
uint32_t FinalizeHash(uint32_t hash, intptr_t hashbits=kBitsPerInt32)
Definition: hash.h:20

◆ Copy()

ArrayPtr dart::Array::Copy ( ) const
inline

Definition at line 10997 of file object.h.

10997 {
10998 return Slice(0, Length(), /*with_type_argument=*/true);
10999 }
ArrayPtr Slice(intptr_t start, intptr_t count, bool with_type_argument) const
Definition: object.cc:24810

◆ data_offset()

static intptr_t dart::Array::data_offset ( )
inlinestatic

Definition at line 10835 of file object.h.

10835 {
10836 return OFFSET_OF_RETURNED_VALUE(UntaggedArray, data);
10837 }
static int8_t data[kExtLength]
#define OFFSET_OF_RETURNED_VALUE(type, accessor)
Definition: globals.h:143

◆ DataOf()

static CompressedObjectPtr * dart::Array::DataOf ( ArrayPtr  array)
inlinestatic

Definition at line 10870 of file object.h.

10870 {
10871 return array->untag()->data();
10872 }

◆ element_offset()

static intptr_t dart::Array::element_offset ( intptr_t  index)
inlinestatic

Definition at line 10838 of file object.h.

10838 {
10839 return OFFSET_OF_RETURNED_VALUE(UntaggedArray, data) +
10840 kBytesPerElement * index;
10841 }
static constexpr intptr_t kBytesPerElement
Definition: object.h:10923

◆ Equals() [1/2]

static bool dart::Array::Equals ( ArrayPtr  a,
ArrayPtr  b 
)
inlinestatic

Definition at line 10854 of file object.h.

10854 {
10855 if (a == b) return true;
10856 if (a->IsRawNull() || b->IsRawNull()) return false;
10857 if (a->untag()->length() != b->untag()->length()) return false;
10858 if (a->untag()->type_arguments() != b->untag()->type_arguments()) {
10859 return false;
10860 }
10861 const intptr_t length = LengthOf(a);
10862 return memcmp(a->untag()->data(), b->untag()->data(),
10863 kBytesPerElement * length) == 0;
10864 }
static intptr_t LengthOf(const ArrayPtr array)
Definition: object.h:10830
static bool b
struct MyStruct a[10]
size_t length

◆ Equals() [2/2]

bool dart::Array::Equals ( const Array other) const
inline

Definition at line 10865 of file object.h.

10865 {
10866 NoSafepointScope scope;
10867 return Equals(ptr(), other.ptr());
10868 }
static bool Equals(ArrayPtr a, ArrayPtr b)
Definition: object.h:10854

◆ GetTypeArguments()

virtual TypeArgumentsPtr dart::Array::GetTypeArguments ( ) const
inlinevirtual

Reimplemented from dart::Instance.

Definition at line 10905 of file object.h.

10905 {
10906 return untag()->type_arguments();
10907 }

◆ Grow()

ArrayPtr dart::Array::Grow ( const Array source,
intptr_t  new_length,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24853 of file object.cc.

24855 {
24856 Thread* thread = Thread::Current();
24857 Zone* zone = thread->zone();
24858 const Array& result =
24859 Array::Handle(zone, Array::NewUninitialized(new_length, space));
24860 intptr_t old_length = 0;
24861 if (!source.IsNull()) {
24862 old_length = source.Length();
24863 result.SetTypeArguments(
24864 TypeArguments::Handle(zone, source.GetTypeArguments()));
24865 } else {
24866 result.SetTypeArguments(Object::null_type_arguments());
24867 }
24868 ASSERT(new_length > old_length); // Unnecessary copying of array.
24869 if (!UseCardMarkingForAllocation(new_length)) {
24870 NoSafepointScope no_safepoint(thread);
24871 for (intptr_t i = 0; i < old_length; i++) {
24872 result.untag()->set_element(i, source.untag()->element(i), thread);
24873 }
24874 for (intptr_t i = old_length; i < new_length; i++) {
24875 ASSERT(result.untag()->element(i) == Object::null());
24876 }
24877 } else {
24878 for (intptr_t i = 0; i < old_length; i++) {
24879 result.untag()->set_element(i, source.untag()->element(i), thread);
24880 if (((i + 1) % kSlotsPerInterruptCheck) == 0) {
24881 thread->CheckForSafepoint();
24882 }
24883 }
24884 for (intptr_t i = old_length; i < new_length; i++) {
24885 result.untag()->set_element(i, Object::null(), thread);
24886 if (((i + 1) % kSlotsPerInterruptCheck) == 0) {
24887 thread->CheckForSafepoint();
24888 }
24889 }
24890 }
24891 return result.ptr();
24892}
static constexpr bool UseCardMarkingForAllocation(const intptr_t array_length)
Definition: object.h:10818
static ArrayPtr NewUninitialized(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10964
static ObjectPtr null()
Definition: object.h:433
SkBitmap source
Definition: examples.cpp:28
GAsyncResult * result
static constexpr intptr_t kSlotsPerInterruptCheck
Definition: page.h:359

◆ index_at_offset()

static intptr_t dart::Array::index_at_offset ( intptr_t  offset_in_bytes)
inlinestatic

Definition at line 10842 of file object.h.

10842 {
10843 intptr_t index = (offset_in_bytes - data_offset()) / kBytesPerElement;
10844 ASSERT(index >= 0);
10845 return index;
10846 }
static intptr_t data_offset()
Definition: object.h:10835

◆ InstanceSize() [1/2]

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

Definition at line 10936 of file object.h.

10936 {
10937 ASSERT(sizeof(UntaggedArray) ==
10938 OFFSET_OF_RETURNED_VALUE(UntaggedArray, data));
10939 return 0;
10940 }

◆ InstanceSize() [2/2]

static constexpr intptr_t dart::Array::InstanceSize ( intptr_t  len)
inlinestaticconstexpr

Definition at line 10949 of file object.h.

10949 {
10951 }
static intptr_t UnroundedSize()
Definition: object.h:8336
static constexpr intptr_t RoundedAllocationSize(intptr_t size)
Definition: object.h:758

◆ IsImmutable()

bool dart::Array::IsImmutable ( ) const
inline

Definition at line 10900 of file object.h.

10900{ return ptr()->GetClassId() == kImmutableArrayCid; }
intptr_t GetClassId() const
Definition: raw_object.h:885

◆ IsValidLength()

static constexpr bool dart::Array::IsValidLength ( intptr_t  len)
inlinestaticconstexpr

Definition at line 10932 of file object.h.

10932 {
10933 return 0 <= len && len <= kMaxElements;
10934 }
static constexpr intptr_t kMaxElements
Definition: object.h:10924

◆ Length()

intptr_t dart::Array::Length ( ) const
inline

Definition at line 10829 of file object.h.

10829{ return LengthOf(ptr()); }

◆ length_offset()

static intptr_t dart::Array::length_offset ( )
inlinestatic

Definition at line 10834 of file object.h.

10834{ return OFFSET_OF(UntaggedArray, length_); }
#define OFFSET_OF(type, field)
Definition: globals.h:138

◆ LengthOf()

static intptr_t dart::Array::LengthOf ( const ArrayPtr  array)
inlinestatic

Definition at line 10830 of file object.h.

10830 {
10831 return Smi::Value(array->untag()->length());
10832 }
intptr_t Value() const
Definition: object.h:9990

◆ MakeFixedLength()

ArrayPtr dart::Array::MakeFixedLength ( const GrowableObjectArray growable_array,
bool  unique = false 
)
static

Definition at line 24935 of file object.cc.

24936 {
24937 ASSERT(!growable_array.IsNull());
24938 Thread* thread = Thread::Current();
24939 Zone* zone = thread->zone();
24940 intptr_t used_len = growable_array.Length();
24941 // Get the type arguments and prepare to copy them.
24942 const TypeArguments& type_arguments =
24943 TypeArguments::Handle(growable_array.GetTypeArguments());
24944 if (used_len == 0) {
24945 if (type_arguments.IsNull() && !unique) {
24946 // This is a raw List (as in no type arguments), so we can return the
24947 // simple empty array.
24948 return Object::empty_array().ptr();
24949 }
24950
24951 // The backing array may be a shared instance, or may not have correct
24952 // type parameters. Create a new empty array.
24953 Heap::Space space = thread->IsDartMutatorThread() ? Heap::kNew : Heap::kOld;
24954 Array& array = Array::Handle(zone, Array::New(0, space));
24955 array.SetTypeArguments(type_arguments);
24956 return array.ptr();
24957 }
24958 const Array& array = Array::Handle(zone, growable_array.data());
24959 ASSERT(array.IsArray());
24960 array.SetTypeArguments(type_arguments);
24961
24962 // Null the GrowableObjectArray, we are removing its backing array.
24963 growable_array.SetLength(0);
24964 growable_array.SetData(Object::empty_array());
24965
24966 // Truncate the old backing array and return it.
24967 array.Truncate(used_len);
24968 return array.ptr();
24969}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10959
@ kNew
Definition: heap.h:38
@ kOld
Definition: heap.h:39

◆ MakeImmutable()

void dart::Array::MakeImmutable ( ) const

Definition at line 24837 of file object.cc.

24837 {
24838 if (IsImmutable()) return;
24839 ASSERT(!IsCanonical());
24840 untag()->SetClassId(kImmutableArrayCid);
24841}
bool IsCanonical() const
Definition: object.h:335

◆ New() [1/3]

ArrayPtr dart::Array::New ( intptr_t  class_id,
intptr_t  len,
Heap::Space  space = Heap::kNew 
)
staticprotected

Definition at line 24792 of file object.cc.

24792 {
24794 return NewUninitialized(class_id, len, space);
24795 }
24796
24797 Thread* thread = Thread::Current();
24798 Array& result =
24799 Array::Handle(thread->zone(), NewUninitialized(class_id, len, space));
24800 result.SetTypeArguments(Object::null_type_arguments());
24801 for (intptr_t i = 0; i < len; i++) {
24802 result.SetAt(i, Object::null_object(), thread);
24803 if (((i + 1) % kSlotsPerInterruptCheck) == 0) {
24804 thread->CheckForSafepoint();
24805 }
24806 }
24807 return result.ptr();
24808}

◆ New() [2/3]

ArrayPtr dart::Array::New ( intptr_t  len,
const AbstractType element_type,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24762 of file object.cc.

24764 {
24765 const Array& result = Array::Handle(Array::New(len, space));
24766 if (!element_type.IsDynamicType()) {
24767 TypeArguments& type_args = TypeArguments::Handle(TypeArguments::New(1));
24768 type_args.SetTypeAt(0, element_type);
24769 type_args = type_args.Canonicalize(Thread::Current());
24770 result.SetTypeArguments(type_args);
24771 }
24772 return result.ptr();
24773}
static TypeArgumentsPtr New(intptr_t len, Heap::Space space=Heap::kOld)
Definition: object.cc:7675

◆ New() [3/3]

static ArrayPtr dart::Array::New ( intptr_t  len,
Heap::Space  space = Heap::kNew 
)
inlinestatic

Definition at line 10959 of file object.h.

10959 {
10960 return New(kArrayCid, len, space);
10961 }

◆ NewUninitialized() [1/2]

ArrayPtr dart::Array::NewUninitialized ( intptr_t  class_id,
intptr_t  len,
Heap::Space  space = Heap::kNew 
)
staticprotected

Definition at line 24775 of file object.cc.

24777 {
24778 if (!IsValidLength(len)) {
24779 // This should be caught before we reach here.
24780 FATAL("Fatal error in Array::New: invalid len %" Pd "\n", len);
24781 }
24782 auto raw = Object::AllocateVariant<Array>(class_id, space, len);
24783 NoSafepointScope no_safepoint;
24784 raw->untag()->set_length(Smi::New(len));
24786 ASSERT(raw->IsOldObject());
24787 raw->untag()->SetCardRememberedBitUnsynchronized();
24788 }
24789 return raw;
24790}
static constexpr bool IsValidLength(intptr_t len)
Definition: object.h:10932
static SmiPtr New(intptr_t value)
Definition: object.h:10006
#define FATAL(error)
#define Pd
Definition: globals.h:408

◆ NewUninitialized() [2/2]

static ArrayPtr dart::Array::NewUninitialized ( intptr_t  len,
Heap::Space  space = Heap::kNew 
)
inlinestatic

Definition at line 10964 of file object.h.

10965 {
10966 return NewUninitialized(kArrayCid, len, space);
10967 }

◆ SetAt() [1/2]

template<std::memory_order order = std::memory_order_relaxed>
void dart::Array::SetAt ( intptr_t  index,
const Object value 
) const
inline

Definition at line 10880 of file object.h.

10880 {
10881 ASSERT((0 <= index) && (index < Length()));
10882 untag()->set_element<order>(index, value.ptr());
10883 }
uint8_t value

◆ SetAt() [2/2]

template<std::memory_order order = std::memory_order_relaxed>
void dart::Array::SetAt ( intptr_t  index,
const Object value,
Thread thread 
) const
inline

Definition at line 10885 of file object.h.

10885 {
10886 ASSERT((0 <= index) && (index < Length()));
10887 untag()->set_element<order>(index, value.ptr(), thread);
10888 }

◆ SetAtRelease()

void dart::Array::SetAtRelease ( intptr_t  index,
const Object value 
) const
inline

Definition at line 10895 of file object.h.

10895 {
10896 ASSERT((0 <= index) && (index < Length()));
10897 untag()->set_element<std::memory_order_release>(index, value.ptr());
10898 }

◆ SetTypeArguments()

virtual void dart::Array::SetTypeArguments ( const TypeArguments value) const
inlinevirtual

Reimplemented from dart::Instance.

Definition at line 10908 of file object.h.

10908 {
10909 // An Array is raw or takes one type argument. However, its type argument
10910 // vector may be longer than 1 due to a type optimization reusing the type
10911 // argument vector of the instantiator.
10912 ASSERT(value.IsNull() ||
10913 ((value.Length() >= 1) &&
10914 value.IsInstantiated() /*&& value.IsCanonical()*/));
10915 // TODO(asiva): Values read from a message snapshot are not properly marked
10916 // as canonical. See for example tests/isolate/mandel_isolate_test.dart.
10917 StoreArrayPointer(&untag()->type_arguments_, value.ptr());
10918 }

◆ Slice()

ArrayPtr dart::Array::Slice ( intptr_t  start,
intptr_t  count,
bool  with_type_argument 
) const

Definition at line 24810 of file object.cc.

24812 {
24813 Thread* thread = Thread::Current();
24814 Zone* zone = thread->zone();
24815 const Array& dest = Array::Handle(zone, Array::NewUninitialized(count));
24816 if (with_type_argument) {
24817 dest.SetTypeArguments(TypeArguments::Handle(zone, GetTypeArguments()));
24818 } else {
24819 dest.SetTypeArguments(Object::null_type_arguments());
24820 }
24822 NoSafepointScope no_safepoint(thread);
24823 for (int i = 0; i < count; i++) {
24824 dest.untag()->set_element(i, untag()->element(i + start), thread);
24825 }
24826 } else {
24827 for (int i = 0; i < count; i++) {
24828 dest.untag()->set_element(i, untag()->element(i + start), thread);
24829 if (((i + 1) % kSlotsPerInterruptCheck) == 0) {
24830 thread->CheckForSafepoint();
24831 }
24832 }
24833 }
24834 return dest.ptr();
24835}
int count
Definition: FontMgrTest.cpp:50
dest
Definition: zip.py:79

◆ Truncate()

void dart::Array::Truncate ( intptr_t  new_length) const

Definition at line 24894 of file object.cc.

24894 {
24895 if (IsNull()) {
24896 return;
24897 }
24898 Thread* thread = Thread::Current();
24899 Zone* zone = thread->zone();
24900 const Array& array = Array::Handle(zone, this->ptr());
24901
24902 intptr_t old_len = array.Length();
24903 ASSERT(new_len <= old_len);
24904 if (old_len == new_len) {
24905 return;
24906 }
24907 intptr_t old_size = Array::InstanceSize(old_len);
24908 intptr_t new_size = Array::InstanceSize(new_len);
24909
24910 NoSafepointScope no_safepoint;
24911
24912 // If there is any left over space fill it with either an Array object or
24913 // just a plain object (depending on the amount of left over space) so
24914 // that it can be traversed over successfully during garbage collection.
24915 Object::MakeUnusedSpaceTraversable(array, old_size, new_size);
24916
24917 // Update the size in the header field and length of the array object.
24918 // These release operations are balanced by acquire operations in the
24919 // concurrent sweeper.
24920 uword old_tags = array.untag()->tags_;
24921 uword new_tags;
24922 ASSERT(kArrayCid == UntaggedObject::ClassIdTag::decode(old_tags));
24923 do {
24924 new_tags = UntaggedObject::SizeTag::update(new_size, old_tags);
24925 } while (!array.untag()->tags_.compare_exchange_weak(
24926 old_tags, new_tags, std::memory_order_release));
24927
24928 // Between the CAS of the header above and the SetLength below, the array is
24929 // temporarily in an inconsistent state. The header is considered the
24930 // overriding source of object size by UntaggedObject::HeapSize, but the
24931 // ASSERTs in UntaggedObject::HeapSizeFromClass must handle this special case.
24932 array.SetLengthRelease(new_len);
24933}
static intptr_t InstanceSize()
Definition: object.h:10936
static constexpr ClassIdTagType decode(uword value)
Definition: bitfield.h:171
static void MakeUnusedSpaceTraversable(const Object &obj, intptr_t original_size, intptr_t used_size)
Definition: object.cc:1610
bool IsNull() const
Definition: object.h:363
static constexpr uword update(intptr_t size, uword tag)
Definition: raw_object.h:212
uintptr_t uword
Definition: globals.h:501

◆ type_arguments_offset()

static intptr_t dart::Array::type_arguments_offset ( )
inlinestatic

Definition at line 10928 of file object.h.

10928 {
10929 return OFFSET_OF(UntaggedArray, type_arguments_);
10930 }

◆ UnroundedSize()

static constexpr intptr_t dart::Array::UnroundedSize ( intptr_t  len)
inlinestaticconstexpr

Definition at line 10942 of file object.h.

10942 {
10943 // Ensure that variable length data is not adding to the object length.
10944 ASSERT(sizeof(UntaggedArray) ==
10945 (sizeof(UntaggedInstance) + (2 * kBytesPerElement)));
10947 return sizeof(UntaggedArray) + (len * kBytesPerElement);
10948 }

◆ UseCardMarkingForAllocation()

static constexpr bool dart::Array::UseCardMarkingForAllocation ( const intptr_t  array_length)
inlinestaticconstexpr

Definition at line 10818 of file object.h.

10819 {
10820 return Array::InstanceSize(array_length) > kNewAllocatableSize;
10821 }
static constexpr intptr_t kNewAllocatableSize
Definition: spaces.h:54

Friends And Related Function Documentation

◆ Class

friend class Class
friend

Definition at line 11029 of file object.h.

◆ ImmutableArray

friend class ImmutableArray
friend

Definition at line 11030 of file object.h.

◆ MessageDeserializer

friend class MessageDeserializer
friend

Definition at line 11033 of file object.h.

◆ Object

friend class Object
friend

Definition at line 11031 of file object.h.

◆ String

friend class String
friend

Definition at line 11032 of file object.h.

Member Data Documentation

◆ kBytesPerElement

constexpr intptr_t dart::Array::kBytesPerElement = ArrayTraits::kElementSize
staticconstexpr

Definition at line 10923 of file object.h.

◆ kElementTypeTypeArgPos

constexpr intptr_t dart::Array::kElementTypeTypeArgPos = 0
staticconstexpr

Definition at line 10903 of file object.h.

◆ kMaxElements

constexpr intptr_t dart::Array::kMaxElements = kSmiMax / kBytesPerElement
staticconstexpr

Definition at line 10924 of file object.h.

◆ kMaxLengthForWriteBarrierElimination

constexpr intptr_t dart::Array::kMaxLengthForWriteBarrierElimination = 8
staticconstexpr

Definition at line 10827 of file object.h.

◆ kMaxNewSpaceElements

constexpr intptr_t dart::Array::kMaxNewSpaceElements
staticconstexpr
Initial value:
=
(kNewAllocatableSize - sizeof(UntaggedArray)) / kBytesPerElement

Definition at line 10925 of file object.h.


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