Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
 
intptr_t SizeFromClass () const
 
InstancePtr Canonicalize (Thread *thread) const
 
virtual InstancePtr CanonicalizeLocked (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
 
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 10794 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 10854 of file object.h.

10854 {
10855 return untag()->element<order>(index);
10856 }
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)

◆ AtAcquire()

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

Definition at line 10867 of file object.h.

10867 {
10868 return untag()->element<std::memory_order_acquire>(index);
10869 }

◆ CanonicalizeEquals()

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

Reimplemented from dart::Instance.

Definition at line 24781 of file object.cc.

24781 {
24782 if (this->ptr() == other.ptr()) {
24783 // Both handles point to the same raw instance.
24784 return true;
24785 }
24786
24787 // An Array may be compared to an ImmutableArray.
24788 if (!other.IsArray() || other.IsNull()) {
24789 return false;
24790 }
24791
24792 // First check if both arrays have the same length and elements.
24793 const Array& other_arr = Array::Cast(other);
24794
24795 intptr_t len = this->Length();
24796 if (len != other_arr.Length()) {
24797 return false;
24798 }
24799
24800 for (intptr_t i = 0; i < len; i++) {
24801 if (this->At(i) != other_arr.At(i)) {
24802 return false;
24803 }
24804 }
24805
24806 // Now check if both arrays have the same type arguments.
24807 if (GetTypeArguments() == other.GetTypeArguments()) {
24808 return true;
24809 }
24810 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments());
24811 const TypeArguments& other_type_args =
24812 TypeArguments::Handle(other.GetTypeArguments());
24813 if (!type_args.Equals(other_type_args)) {
24814 return false;
24815 }
24816 return true;
24817}
virtual TypeArgumentsPtr GetTypeArguments() const
Definition object.h:10879
ObjectPtr At(intptr_t index) const
Definition object.h:10854
intptr_t Length() const
Definition object.h:10808
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 25050 of file object.cc.

25050 {
25052 intptr_t len = Length();
25053 if (len > 0) {
25054 Zone* zone = thread->zone();
25055 Instance& obj = Instance::Handle(zone);
25056 for (intptr_t i = 0; i < len; i++) {
25057 obj ^= At(i);
25058 obj = obj.CanonicalizeLocked(thread);
25059 this->SetAt(i, obj);
25060 }
25061 }
25062}
bool IsImmutable() const
Definition object.h:10874
void SetAt(intptr_t index, const Object &value) const
Definition object.h:10858
#define ASSERT(E)

◆ CanonicalizeHash()

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

Reimplemented from dart::Instance.

Definition at line 24819 of file object.cc.

24819 {
24820 intptr_t len = Length();
24821 if (len == 0) {
24822 return 1;
24823 }
24824 Thread* thread = Thread::Current();
24825 uint32_t hash = thread->heap()->GetCanonicalHash(ptr());
24826 if (hash != 0) {
24827 return hash;
24828 }
24829 hash = len;
24830 Instance& member = Instance::Handle(GetTypeArguments());
24831 hash = CombineHashes(hash, member.CanonicalizeHash());
24832 for (intptr_t i = 0; i < len; i++) {
24833 member ^= At(i);
24834 hash = CombineHashes(hash, member.CanonicalizeHash());
24835 }
24837 thread->heap()->SetCanonicalHash(ptr(), hash);
24838 return hash;
24839}
static uint32_t hash(const SkShaderBase::GradientInfo &v)
static constexpr intptr_t kHashBits
Definition object.h:323
static Thread * Current()
Definition thread.h:361
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 10971 of file object.h.

10971 {
10972 return Slice(0, Length(), /*with_type_argument=*/true);
10973 }
ArrayPtr Slice(intptr_t start, intptr_t count, bool with_type_argument) const
Definition object.cc:24889

◆ data_offset()

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

Definition at line 10814 of file object.h.

10814 {
10815 return OFFSET_OF_RETURNED_VALUE(UntaggedArray, data);
10816 }
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 10849 of file object.h.

10849 {
10850 return array->untag()->data();
10851 }

◆ element_offset()

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

Definition at line 10817 of file object.h.

10817 {
10818 return OFFSET_OF_RETURNED_VALUE(UntaggedArray, data) +
10819 kBytesPerElement * index;
10820 }
static constexpr intptr_t kBytesPerElement
Definition object.h:10897

◆ Equals() [1/2]

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

Definition at line 10833 of file object.h.

10833 {
10834 if (a == b) return true;
10835 if (a->IsRawNull() || b->IsRawNull()) return false;
10836 if (a->untag()->length() != b->untag()->length()) return false;
10837 if (a->untag()->type_arguments() != b->untag()->type_arguments()) {
10838 return false;
10839 }
10840 const intptr_t length = LengthOf(a);
10841 return memcmp(a->untag()->data(), b->untag()->data(),
10842 kBytesPerElement * length) == 0;
10843 }
static intptr_t LengthOf(const ArrayPtr array)
Definition object.h:10809
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 10844 of file object.h.

10844 {
10845 NoSafepointScope scope;
10846 return Equals(ptr(), other.ptr());
10847 }
static bool Equals(ArrayPtr a, ArrayPtr b)
Definition object.h:10833

◆ GetTypeArguments()

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

Reimplemented from dart::Instance.

Definition at line 10879 of file object.h.

10879 {
10880 return untag()->type_arguments();
10881 }

◆ Grow()

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

Definition at line 24932 of file object.cc.

24934 {
24935 Thread* thread = Thread::Current();
24936 Zone* zone = thread->zone();
24937 const Array& result =
24938 Array::Handle(zone, Array::NewUninitialized(new_length, space));
24939 intptr_t old_length = 0;
24940 if (!source.IsNull()) {
24941 old_length = source.Length();
24942 result.SetTypeArguments(
24943 TypeArguments::Handle(zone, source.GetTypeArguments()));
24944 } else {
24945 result.SetTypeArguments(Object::null_type_arguments());
24946 }
24947 ASSERT(new_length > old_length); // Unnecessary copying of array.
24948 if (!UseCardMarkingForAllocation(new_length)) {
24949 NoSafepointScope no_safepoint(thread);
24950 for (intptr_t i = 0; i < old_length; i++) {
24951 result.untag()->set_element(i, source.untag()->element(i), thread);
24952 }
24953 for (intptr_t i = old_length; i < new_length; i++) {
24954 ASSERT(result.untag()->element(i) == Object::null());
24955 }
24956 } else {
24957 for (intptr_t i = 0; i < old_length; i++) {
24958 result.untag()->set_element(i, source.untag()->element(i), thread);
24959 if (((i + 1) % KB) == 0) {
24960 thread->CheckForSafepoint();
24961 }
24962 }
24963 for (intptr_t i = old_length; i < new_length; i++) {
24964 result.untag()->set_element(i, Object::null(), thread);
24965 if (((i + 1) % KB) == 0) {
24966 thread->CheckForSafepoint();
24967 }
24968 }
24969 }
24970 return result.ptr();
24971}
static constexpr bool UseCardMarkingForAllocation(const intptr_t array_length)
Definition object.h:10797
static ArrayPtr NewUninitialized(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10938
static ObjectPtr null()
Definition object.h:433
SkBitmap source
Definition examples.cpp:28
GAsyncResult * result
constexpr intptr_t KB
Definition globals.h:528

◆ index_at_offset()

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

Definition at line 10821 of file object.h.

10821 {
10822 intptr_t index = (offset_in_bytes - data_offset()) / kBytesPerElement;
10823 ASSERT(index >= 0);
10824 return index;
10825 }
static intptr_t data_offset()
Definition object.h:10814

◆ InstanceSize() [1/2]

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

Definition at line 10910 of file object.h.

10910 {
10911 ASSERT(sizeof(UntaggedArray) ==
10912 OFFSET_OF_RETURNED_VALUE(UntaggedArray, data));
10913 return 0;
10914 }

◆ InstanceSize() [2/2]

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

Definition at line 10923 of file object.h.

10923 {
10925 }
static intptr_t UnroundedSize()
Definition object.h:8307
static constexpr intptr_t RoundedAllocationSize(intptr_t size)
Definition object.h:758

◆ IsImmutable()

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

Definition at line 10874 of file object.h.

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

◆ IsValidLength()

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

Definition at line 10906 of file object.h.

10906 {
10907 return 0 <= len && len <= kMaxElements;
10908 }
static constexpr intptr_t kMaxElements
Definition object.h:10898

◆ Length()

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

Definition at line 10808 of file object.h.

10808{ return LengthOf(ptr()); }

◆ length_offset()

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

Definition at line 10813 of file object.h.

10813{ 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 10809 of file object.h.

10809 {
10810 return Smi::Value(array->untag()->length());
10811 }
intptr_t Value() const
Definition object.h:9969

◆ MakeFixedLength()

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

Definition at line 25014 of file object.cc.

25015 {
25016 ASSERT(!growable_array.IsNull());
25017 Thread* thread = Thread::Current();
25018 Zone* zone = thread->zone();
25019 intptr_t used_len = growable_array.Length();
25020 // Get the type arguments and prepare to copy them.
25021 const TypeArguments& type_arguments =
25022 TypeArguments::Handle(growable_array.GetTypeArguments());
25023 if (used_len == 0) {
25024 if (type_arguments.IsNull() && !unique) {
25025 // This is a raw List (as in no type arguments), so we can return the
25026 // simple empty array.
25027 return Object::empty_array().ptr();
25028 }
25029
25030 // The backing array may be a shared instance, or may not have correct
25031 // type parameters. Create a new empty array.
25032 Heap::Space space = thread->IsDartMutatorThread() ? Heap::kNew : Heap::kOld;
25033 Array& array = Array::Handle(zone, Array::New(0, space));
25034 array.SetTypeArguments(type_arguments);
25035 return array.ptr();
25036 }
25037 const Array& array = Array::Handle(zone, growable_array.data());
25038 ASSERT(array.IsArray());
25039 array.SetTypeArguments(type_arguments);
25040
25041 // Null the GrowableObjectArray, we are removing its backing array.
25042 growable_array.SetLength(0);
25043 growable_array.SetData(Object::empty_array());
25044
25045 // Truncate the old backing array and return it.
25046 array.Truncate(used_len);
25047 return array.ptr();
25048}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10933
@ kNew
Definition heap.h:38
@ kOld
Definition heap.h:39

◆ MakeImmutable()

void dart::Array::MakeImmutable ( ) const

Definition at line 24916 of file object.cc.

24916 {
24917 if (IsImmutable()) return;
24918 ASSERT(!IsCanonical());
24919 untag()->SetClassId(kImmutableArrayCid);
24920}
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 24871 of file object.cc.

24871 {
24872 if (!UseCardMarkingForAllocation(len)) {
24873 return NewUninitialized(class_id, len, space);
24874 }
24875
24876 Thread* thread = Thread::Current();
24877 Array& result =
24878 Array::Handle(thread->zone(), NewUninitialized(class_id, len, space));
24879 result.SetTypeArguments(Object::null_type_arguments());
24880 for (intptr_t i = 0; i < len; i++) {
24881 result.SetAt(i, Object::null_object(), thread);
24882 if (((i + 1) % KB) == 0) {
24883 thread->CheckForSafepoint();
24884 }
24885 }
24886 return result.ptr();
24887}

◆ New() [2/3]

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

Definition at line 24841 of file object.cc.

24843 {
24844 const Array& result = Array::Handle(Array::New(len, space));
24845 if (!element_type.IsDynamicType()) {
24846 TypeArguments& type_args = TypeArguments::Handle(TypeArguments::New(1));
24847 type_args.SetTypeAt(0, element_type);
24848 type_args = type_args.Canonicalize(Thread::Current());
24849 result.SetTypeArguments(type_args);
24850 }
24851 return result.ptr();
24852}
static TypeArgumentsPtr New(intptr_t len, Heap::Space space=Heap::kOld)
Definition object.cc:7733

◆ New() [3/3]

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

Definition at line 10933 of file object.h.

10933 {
10934 return New(kArrayCid, len, space);
10935 }

◆ NewUninitialized() [1/2]

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

Definition at line 24854 of file object.cc.

24856 {
24857 if (!IsValidLength(len)) {
24858 // This should be caught before we reach here.
24859 FATAL("Fatal error in Array::New: invalid len %" Pd "\n", len);
24860 }
24861 auto raw = Object::AllocateVariant<Array>(class_id, space, len);
24862 NoSafepointScope no_safepoint;
24863 raw->untag()->set_length(Smi::New(len));
24864 if (UseCardMarkingForAllocation(len)) {
24865 ASSERT(raw->IsOldObject());
24866 raw->untag()->SetCardRememberedBitUnsynchronized();
24867 }
24868 return raw;
24869}
static constexpr bool IsValidLength(intptr_t len)
Definition object.h:10906
static SmiPtr New(intptr_t value)
Definition object.h:9985
#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 10938 of file object.h.

10939 {
10940 return NewUninitialized(kArrayCid, len, space);
10941 }

◆ 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 10858 of file object.h.

10858 {
10859 untag()->set_element<order>(index, value.ptr());
10860 }
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 10862 of file object.h.

10862 {
10863 untag()->set_element<order>(index, value.ptr(), thread);
10864 }

◆ SetAtRelease()

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

Definition at line 10870 of file object.h.

10870 {
10871 untag()->set_element<std::memory_order_release>(index, value.ptr());
10872 }

◆ SetTypeArguments()

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

Reimplemented from dart::Instance.

Definition at line 10882 of file object.h.

10882 {
10883 // An Array is raw or takes one type argument. However, its type argument
10884 // vector may be longer than 1 due to a type optimization reusing the type
10885 // argument vector of the instantiator.
10886 ASSERT(value.IsNull() ||
10887 ((value.Length() >= 1) &&
10888 value.IsInstantiated() /*&& value.IsCanonical()*/));
10889 // TODO(asiva): Values read from a message snapshot are not properly marked
10890 // as canonical. See for example tests/isolate/mandel_isolate_test.dart.
10891 StoreArrayPointer(&untag()->type_arguments_, value.ptr());
10892 }

◆ Slice()

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

Definition at line 24889 of file object.cc.

24891 {
24892 Thread* thread = Thread::Current();
24893 Zone* zone = thread->zone();
24894 const Array& dest = Array::Handle(zone, Array::NewUninitialized(count));
24895 if (with_type_argument) {
24896 dest.SetTypeArguments(TypeArguments::Handle(zone, GetTypeArguments()));
24897 } else {
24898 dest.SetTypeArguments(Object::null_type_arguments());
24899 }
24901 NoSafepointScope no_safepoint(thread);
24902 for (int i = 0; i < count; i++) {
24903 dest.untag()->set_element(i, untag()->element(i + start), thread);
24904 }
24905 } else {
24906 for (int i = 0; i < count; i++) {
24907 dest.untag()->set_element(i, untag()->element(i + start), thread);
24908 if (((i + 1) % KB) == 0) {
24909 thread->CheckForSafepoint();
24910 }
24911 }
24912 }
24913 return dest.ptr();
24914}
int count
dest
Definition zip.py:79

◆ Truncate()

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

Definition at line 24973 of file object.cc.

24973 {
24974 if (IsNull()) {
24975 return;
24976 }
24977 Thread* thread = Thread::Current();
24978 Zone* zone = thread->zone();
24979 const Array& array = Array::Handle(zone, this->ptr());
24980
24981 intptr_t old_len = array.Length();
24982 ASSERT(new_len <= old_len);
24983 if (old_len == new_len) {
24984 return;
24985 }
24986 intptr_t old_size = Array::InstanceSize(old_len);
24987 intptr_t new_size = Array::InstanceSize(new_len);
24988
24989 NoSafepointScope no_safepoint;
24990
24991 // If there is any left over space fill it with either an Array object or
24992 // just a plain object (depending on the amount of left over space) so
24993 // that it can be traversed over successfully during garbage collection.
24994 Object::MakeUnusedSpaceTraversable(array, old_size, new_size);
24995
24996 // Update the size in the header field and length of the array object.
24997 // These release operations are balanced by acquire operations in the
24998 // concurrent sweeper.
24999 uword old_tags = array.untag()->tags_;
25000 uword new_tags;
25001 ASSERT(kArrayCid == UntaggedObject::ClassIdTag::decode(old_tags));
25002 do {
25003 new_tags = UntaggedObject::SizeTag::update(new_size, old_tags);
25004 } while (!array.untag()->tags_.compare_exchange_weak(
25005 old_tags, new_tags, std::memory_order_release));
25006
25007 // Between the CAS of the header above and the SetLength below, the array is
25008 // temporarily in an inconsistent state. The header is considered the
25009 // overriding source of object size by UntaggedObject::HeapSize, but the
25010 // ASSERTs in UntaggedObject::HeapSizeFromClass must handle this special case.
25011 array.SetLengthRelease(new_len);
25012}
static intptr_t InstanceSize()
Definition object.h:10910
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:209
uintptr_t uword
Definition globals.h:501

◆ type_arguments_offset()

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

Definition at line 10902 of file object.h.

10902 {
10903 return OFFSET_OF(UntaggedArray, type_arguments_);
10904 }

◆ UnroundedSize()

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

Definition at line 10916 of file object.h.

10916 {
10917 // Ensure that variable length data is not adding to the object length.
10918 ASSERT(sizeof(UntaggedArray) ==
10919 (sizeof(UntaggedInstance) + (2 * kBytesPerElement)));
10920 ASSERT(IsValidLength(len));
10921 return sizeof(UntaggedArray) + (len * kBytesPerElement);
10922 }

◆ UseCardMarkingForAllocation()

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

Definition at line 10797 of file object.h.

10798 {
10799 return Array::InstanceSize(array_length) > kNewAllocatableSize;
10800 }
static constexpr intptr_t kNewAllocatableSize
Definition spaces.h:54

Friends And Related Symbol Documentation

◆ Class

friend class Class
friend

Definition at line 11003 of file object.h.

◆ ImmutableArray

friend class ImmutableArray
friend

Definition at line 11004 of file object.h.

◆ MessageDeserializer

friend class MessageDeserializer
friend

Definition at line 11007 of file object.h.

◆ Object

friend class Object
friend

Definition at line 11005 of file object.h.

◆ String

friend class String
friend

Definition at line 11006 of file object.h.

Member Data Documentation

◆ kBytesPerElement

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

Definition at line 10897 of file object.h.

◆ kElementTypeTypeArgPos

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

Definition at line 10877 of file object.h.

◆ kMaxElements

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

Definition at line 10898 of file object.h.

◆ kMaxLengthForWriteBarrierElimination

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

Definition at line 10806 of file object.h.

◆ kMaxNewSpaceElements

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

Definition at line 10899 of file object.h.


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