| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 static const char* GetSingletonClassName(int index); | 324 static const char* GetSingletonClassName(int index); |
| 325 | 325 |
| 326 static RawClass* CreateAndRegisterInterface(const char* cname, | 326 static RawClass* CreateAndRegisterInterface(const char* cname, |
| 327 const Script& script, | 327 const Script& script, |
| 328 const Library& lib); | 328 const Library& lib); |
| 329 static void RegisterClass(const Class& cls, | 329 static void RegisterClass(const Class& cls, |
| 330 const char* cname, | 330 const char* cname, |
| 331 const Script& script, | 331 const Script& script, |
| 332 const Library& lib); | 332 const Library& lib); |
| 333 | 333 |
| 334 static void RegisterPrivateClass(const Class& cls, | |
| 335 const char* cname, | |
| 336 const Script& script, | |
| 337 const Library& lib); | |
| 338 | |
| 339 static RawError* Init(Isolate* isolate); | 334 static RawError* Init(Isolate* isolate); |
| 340 static void InitFromSnapshot(Isolate* isolate); | 335 static void InitFromSnapshot(Isolate* isolate); |
| 341 static void InitOnce(); | 336 static void InitOnce(); |
| 342 | 337 |
| 343 static intptr_t InstanceSize() { | 338 static intptr_t InstanceSize() { |
| 344 return RoundedAllocationSize(sizeof(RawObject)); | 339 return RoundedAllocationSize(sizeof(RawObject)); |
| 345 } | 340 } |
| 346 | 341 |
| 347 static const ObjectKind kInstanceKind = kObject; | 342 static const ObjectKind kInstanceKind = kObject; |
| 348 | 343 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 const Class& other, | 608 const Class& other, |
| 614 const AbstractTypeArguments& other_type_arguments, | 609 const AbstractTypeArguments& other_type_arguments, |
| 615 Error* malformed_error) const; | 610 Error* malformed_error) const; |
| 616 | 611 |
| 617 // Check if this is the top level class. | 612 // Check if this is the top level class. |
| 618 bool IsTopLevel() const; | 613 bool IsTopLevel() const; |
| 619 | 614 |
| 620 RawArray* fields() const { return raw_ptr()->fields_; } | 615 RawArray* fields() const { return raw_ptr()->fields_; } |
| 621 void SetFields(const Array& value) const; | 616 void SetFields(const Array& value) const; |
| 622 | 617 |
| 623 // Returns true if non-static fields are defined. | |
| 624 bool HasInstanceFields() const; | |
| 625 | |
| 626 RawArray* functions() const { return raw_ptr()->functions_; } | 618 RawArray* functions() const { return raw_ptr()->functions_; } |
| 627 void SetFunctions(const Array& value) const; | 619 void SetFunctions(const Array& value) const; |
| 628 | 620 |
| 629 void AddClosureFunction(const Function& function) const; | 621 void AddClosureFunction(const Function& function) const; |
| 630 RawFunction* LookupClosureFunction(intptr_t token_index) const; | 622 RawFunction* LookupClosureFunction(intptr_t token_index) const; |
| 631 | 623 |
| 632 RawFunction* LookupDynamicFunction(const String& name) const; | 624 RawFunction* LookupDynamicFunction(const String& name) const; |
| 633 RawFunction* LookupStaticFunction(const String& name) const; | 625 RawFunction* LookupStaticFunction(const String& name) const; |
| 634 RawFunction* LookupConstructor(const String& name) const; | 626 RawFunction* LookupConstructor(const String& name) const; |
| 635 RawFunction* LookupFactory(const String& name) const; | 627 RawFunction* LookupFactory(const String& name) const; |
| (...skipping 3026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3662 static const int kDefaultInitialCapacity = 4; | 3654 static const int kDefaultInitialCapacity = 4; |
| 3663 | 3655 |
| 3664 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); | 3656 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); |
| 3665 friend class Class; | 3657 friend class Class; |
| 3666 friend class Array; | 3658 friend class Array; |
| 3667 }; | 3659 }; |
| 3668 | 3660 |
| 3669 | 3661 |
| 3670 class ByteArray : public Instance { | 3662 class ByteArray : public Instance { |
| 3671 public: | 3663 public: |
| 3672 intptr_t Length() const { | 3664 virtual intptr_t Length() const; |
| 3673 ASSERT(!IsNull()); | |
| 3674 return Smi::Value(raw_ptr()->length_); | |
| 3675 } | |
| 3676 | 3665 |
| 3677 static intptr_t length_offset() { | 3666 static void Copy(uint8_t* dst, |
| 3678 return OFFSET_OF(RawByteArray, length_); | |
| 3679 } | |
| 3680 | |
| 3681 virtual intptr_t ByteLength() const; | |
| 3682 | |
| 3683 static void Copy(void* dst, | |
| 3684 const ByteArray& src, | 3667 const ByteArray& src, |
| 3685 intptr_t src_offset, | 3668 intptr_t src_offset, |
| 3686 intptr_t length); | 3669 intptr_t length); |
| 3687 | 3670 |
| 3688 static void Copy(const ByteArray& dst, | 3671 static void Copy(const ByteArray& dst, |
| 3689 intptr_t dst_offset, | 3672 intptr_t dst_offset, |
| 3690 const void* src, | 3673 const uint8_t* src, |
| 3691 intptr_t length); | 3674 intptr_t length); |
| 3692 | 3675 |
| 3693 static void Copy(const ByteArray& dst, | 3676 static void Copy(const ByteArray& dst, |
| 3694 intptr_t dst_offset, | 3677 intptr_t dst_offset, |
| 3695 const ByteArray& src, | 3678 const ByteArray& src, |
| 3696 intptr_t src_offset, | 3679 intptr_t src_offset, |
| 3697 intptr_t length); | 3680 intptr_t length); |
| 3698 | 3681 |
| 3699 protected: | 3682 private: |
| 3700 virtual uint8_t* ByteAddr(intptr_t byte_offset) const; | 3683 virtual uint8_t* ByteAddr(intptr_t byte_offset) const; |
| 3701 | 3684 |
| 3702 template<typename HandleT, typename RawT> | |
| 3703 static RawT* NewImpl(const Class& cls, | |
| 3704 intptr_t len, | |
| 3705 Heap::Space space); | |
| 3706 | |
| 3707 template<typename HandleT, typename RawT, typename ElementT> | |
| 3708 static RawT* NewImpl(const Class& cls, | |
| 3709 const ElementT* data, | |
| 3710 intptr_t len, | |
| 3711 Heap::Space space); | |
| 3712 | |
| 3713 template<typename HandleT, typename RawT, typename ElementT> | |
| 3714 static RawT* NewExternalImpl(const Class& cls, | |
| 3715 ElementT* data, | |
| 3716 intptr_t len, | |
| 3717 void* peer, | |
| 3718 Dart_PeerFinalizer callback, | |
| 3719 Heap::Space space); | |
| 3720 | |
| 3721 template<typename HandleT, typename RawT, typename ElementT> | |
| 3722 static RawT* ReadFromImpl(SnapshotReader* reader, | |
| 3723 intptr_t object_id, | |
| 3724 intptr_t tags, | |
| 3725 Snapshot::Kind kind); | |
| 3726 | |
| 3727 void SetLength(intptr_t value) const { | |
| 3728 raw_ptr()->length_ = Smi::New(value); | |
| 3729 } | |
| 3730 | |
| 3731 private: | |
| 3732 HEAP_OBJECT_IMPLEMENTATION(ByteArray, Instance); | 3685 HEAP_OBJECT_IMPLEMENTATION(ByteArray, Instance); |
| 3733 friend class Class; | 3686 friend class Class; |
| 3734 }; | 3687 }; |
| 3735 | 3688 |
| 3736 | 3689 |
| 3737 class Int8Array : public ByteArray { | 3690 class InternalByteArray : public ByteArray { |
| 3738 public: | 3691 public: |
| 3739 intptr_t ByteLength() const { | 3692 intptr_t Length() const { |
| 3740 return Length(); | 3693 ASSERT(!IsNull()); |
| 3694 return Smi::Value(raw_ptr()->length_); |
| 3741 } | 3695 } |
| 3742 | 3696 |
| 3743 int8_t At(intptr_t index) const { | 3697 static intptr_t length_offset() { |
| 3744 ASSERT((index >= 0) && (index < Length())); | 3698 return OFFSET_OF(RawInternalByteArray, length_); |
| 3745 return raw_ptr()->data_[index]; | |
| 3746 } | |
| 3747 | |
| 3748 void SetAt(intptr_t index, int8_t value) const { | |
| 3749 ASSERT((index >= 0) && (index < Length())); | |
| 3750 raw_ptr()->data_[index] = value; | |
| 3751 } | 3699 } |
| 3752 | 3700 |
| 3753 static intptr_t data_offset() { | 3701 static intptr_t data_offset() { |
| 3754 return length_offset() + kWordSize; | 3702 return length_offset() + kWordSize; |
| 3755 } | 3703 } |
| 3756 | 3704 |
| 3705 template<typename T> |
| 3706 T At(intptr_t byte_offset) const { |
| 3707 T* addr = Addr<T>(byte_offset); |
| 3708 ASSERT(Utils::IsAligned(reinterpret_cast<intptr_t>(addr), sizeof(T))); |
| 3709 return *addr; |
| 3710 } |
| 3711 |
| 3712 template<typename T> |
| 3713 void SetAt(intptr_t byte_offset, T value) const { |
| 3714 T* addr = Addr<T>(byte_offset); |
| 3715 ASSERT(Utils::IsAligned(reinterpret_cast<intptr_t>(addr), sizeof(T))); |
| 3716 *addr = value; |
| 3717 } |
| 3718 |
| 3719 template<typename T> |
| 3720 T UnalignedAt(intptr_t byte_offset) const { |
| 3721 T result; |
| 3722 memmove(&result, Addr<T>(byte_offset), sizeof(T)); |
| 3723 return result; |
| 3724 } |
| 3725 |
| 3726 template<typename T> |
| 3727 void SetUnalignedAt(intptr_t byte_offset, T value) const { |
| 3728 memmove(Addr<T>(byte_offset), &value, sizeof(T)); |
| 3729 } |
| 3730 |
| 3757 static intptr_t InstanceSize() { | 3731 static intptr_t InstanceSize() { |
| 3758 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_)); | 3732 ASSERT(sizeof(RawInternalByteArray) == |
| 3733 OFFSET_OF_RETURNED_VALUE(RawInternalByteArray, data)); |
| 3759 return 0; | 3734 return 0; |
| 3760 } | 3735 } |
| 3761 | 3736 |
| 3762 static intptr_t InstanceSize(intptr_t len) { | 3737 static intptr_t InstanceSize(intptr_t len) { |
| 3763 return RoundedAllocationSize(sizeof(RawInt8Array) + len); | 3738 return RoundedAllocationSize(sizeof(RawInternalByteArray) + len); |
| 3764 } | 3739 } |
| 3765 | 3740 |
| 3766 static RawInt8Array* New(intptr_t len, | 3741 static RawInternalByteArray* New(intptr_t len, |
| 3767 Heap::Space space = Heap::kNew); | 3742 Heap::Space space = Heap::kNew); |
| 3768 static RawInt8Array* New(const int8_t* data, | 3743 static RawInternalByteArray* New(const uint8_t* data, |
| 3769 intptr_t len, | 3744 intptr_t len, |
| 3770 Heap::Space space = Heap::kNew); | 3745 Heap::Space space = Heap::kNew); |
| 3771 | 3746 |
| 3772 private: | 3747 private: |
| 3773 uint8_t* ByteAddr(intptr_t byte_offset) const { | 3748 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 3774 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 3749 return Addr<uint8_t>(byte_offset); |
| 3775 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 3776 } | 3750 } |
| 3777 | 3751 |
| 3778 HEAP_OBJECT_IMPLEMENTATION(Int8Array, ByteArray); | 3752 template<typename T> |
| 3779 friend class ByteArray; | 3753 T* Addr(intptr_t byte_offset) const { |
| 3754 intptr_t limit = byte_offset + sizeof(T); |
| 3755 // TODO(iposva): Determine if we should throw an exception here. |
| 3756 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 3757 uint8_t* addr = &raw_ptr()->data()[byte_offset]; |
| 3758 return reinterpret_cast<T*>(addr); |
| 3759 } |
| 3760 |
| 3761 void SetLength(intptr_t value) const { |
| 3762 raw_ptr()->length_ = Smi::New(value); |
| 3763 } |
| 3764 |
| 3765 HEAP_OBJECT_IMPLEMENTATION(InternalByteArray, ByteArray); |
| 3780 friend class Class; | 3766 friend class Class; |
| 3781 }; | 3767 }; |
| 3782 | 3768 |
| 3783 | 3769 |
| 3784 class Uint8Array : public ByteArray { | 3770 class ExternalByteArray : public ByteArray { |
| 3785 public: | 3771 public: |
| 3786 intptr_t ByteLength() const { | 3772 intptr_t Length() const { |
| 3787 return Length(); | 3773 ASSERT(!IsNull()); |
| 3788 } | 3774 return Smi::Value(raw_ptr()->length_); |
| 3789 | |
| 3790 uint8_t At(intptr_t index) const { | |
| 3791 ASSERT((index >= 0) && (index < Length())); | |
| 3792 return raw_ptr()->data_[index]; | |
| 3793 } | |
| 3794 | |
| 3795 void SetAt(intptr_t index, uint8_t value) const { | |
| 3796 ASSERT((index >= 0) && (index < Length())); | |
| 3797 raw_ptr()->data_[index] = value; | |
| 3798 } | |
| 3799 | |
| 3800 static intptr_t data_offset() { | |
| 3801 return length_offset() + kWordSize; | |
| 3802 } | |
| 3803 | |
| 3804 static intptr_t InstanceSize() { | |
| 3805 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_)); | |
| 3806 return 0; | |
| 3807 } | |
| 3808 | |
| 3809 static intptr_t InstanceSize(intptr_t len) { | |
| 3810 return RoundedAllocationSize(sizeof(RawUint8Array) + len); | |
| 3811 } | |
| 3812 | |
| 3813 static RawUint8Array* New(intptr_t len, | |
| 3814 Heap::Space space = Heap::kNew); | |
| 3815 static RawUint8Array* New(const uint8_t* data, | |
| 3816 intptr_t len, | |
| 3817 Heap::Space space = Heap::kNew); | |
| 3818 | |
| 3819 private: | |
| 3820 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 3821 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 3822 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 3823 } | |
| 3824 | |
| 3825 HEAP_OBJECT_IMPLEMENTATION(Uint8Array, ByteArray); | |
| 3826 friend class ByteArray; | |
| 3827 friend class Class; | |
| 3828 }; | |
| 3829 | |
| 3830 | |
| 3831 class Int16Array : public ByteArray { | |
| 3832 public: | |
| 3833 intptr_t ByteLength() const { | |
| 3834 return Length() * kBytesPerElement; | |
| 3835 } | |
| 3836 | |
| 3837 int16_t At(intptr_t index) const { | |
| 3838 ASSERT((index >= 0) && (index < Length())); | |
| 3839 return raw_ptr()->data_[index]; | |
| 3840 } | |
| 3841 | |
| 3842 void SetAt(intptr_t index, int16_t value) const { | |
| 3843 ASSERT((index >= 0) && (index < Length())); | |
| 3844 raw_ptr()->data_[index] = value; | |
| 3845 } | |
| 3846 | |
| 3847 static intptr_t data_offset() { | |
| 3848 return length_offset() + kWordSize; | |
| 3849 } | |
| 3850 | |
| 3851 static intptr_t InstanceSize() { | |
| 3852 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_)); | |
| 3853 return 0; | |
| 3854 } | |
| 3855 | |
| 3856 static intptr_t InstanceSize(intptr_t len) { | |
| 3857 intptr_t data_size = len * kBytesPerElement; | |
| 3858 return RoundedAllocationSize(sizeof(RawInt16Array) + data_size); | |
| 3859 } | |
| 3860 | |
| 3861 static RawInt16Array* New(intptr_t len, | |
| 3862 Heap::Space space = Heap::kNew); | |
| 3863 static RawInt16Array* New(const int16_t* data, | |
| 3864 intptr_t len, | |
| 3865 Heap::Space space = Heap::kNew); | |
| 3866 | |
| 3867 private: | |
| 3868 static const intptr_t kBytesPerElement = 2; | |
| 3869 | |
| 3870 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 3871 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 3872 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 3873 } | |
| 3874 | |
| 3875 HEAP_OBJECT_IMPLEMENTATION(Int16Array, ByteArray); | |
| 3876 friend class ByteArray; | |
| 3877 friend class Class; | |
| 3878 }; | |
| 3879 | |
| 3880 | |
| 3881 class Uint16Array : public ByteArray { | |
| 3882 public: | |
| 3883 intptr_t ByteLength() const { | |
| 3884 return Length() * kBytesPerElement; | |
| 3885 } | |
| 3886 | |
| 3887 uint16_t At(intptr_t index) const { | |
| 3888 ASSERT((index >= 0) && (index < Length())); | |
| 3889 return raw_ptr()->data_[index]; | |
| 3890 } | |
| 3891 | |
| 3892 void SetAt(intptr_t index, uint16_t value) const { | |
| 3893 ASSERT((index >= 0) && (index < Length())); | |
| 3894 raw_ptr()->data_[index] = value; | |
| 3895 } | |
| 3896 | |
| 3897 static intptr_t data_offset() { | |
| 3898 return length_offset() + kWordSize; | |
| 3899 } | |
| 3900 | |
| 3901 static intptr_t InstanceSize() { | |
| 3902 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_)); | |
| 3903 return 0; | |
| 3904 } | |
| 3905 | |
| 3906 static intptr_t InstanceSize(intptr_t len) { | |
| 3907 intptr_t data_size = len * kBytesPerElement; | |
| 3908 return RoundedAllocationSize(sizeof(RawUint16Array) + data_size); | |
| 3909 } | |
| 3910 | |
| 3911 static RawUint16Array* New(intptr_t len, | |
| 3912 Heap::Space space = Heap::kNew); | |
| 3913 static RawUint16Array* New(const uint16_t* data, | |
| 3914 intptr_t len, | |
| 3915 Heap::Space space = Heap::kNew); | |
| 3916 | |
| 3917 private: | |
| 3918 static const intptr_t kBytesPerElement = 2; | |
| 3919 | |
| 3920 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 3921 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 3922 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 3923 } | |
| 3924 | |
| 3925 HEAP_OBJECT_IMPLEMENTATION(Uint16Array, ByteArray); | |
| 3926 friend class ByteArray; | |
| 3927 friend class Class; | |
| 3928 }; | |
| 3929 | |
| 3930 | |
| 3931 class Int32Array : public ByteArray { | |
| 3932 public: | |
| 3933 intptr_t ByteLength() const { | |
| 3934 return Length() * kBytesPerElement; | |
| 3935 } | |
| 3936 | |
| 3937 int32_t At(intptr_t index) const { | |
| 3938 ASSERT((index >= 0) && (index < Length())); | |
| 3939 return raw_ptr()->data_[index]; | |
| 3940 } | |
| 3941 | |
| 3942 void SetAt(intptr_t index, int32_t value) const { | |
| 3943 ASSERT((index >= 0) && (index < Length())); | |
| 3944 raw_ptr()->data_[index] = value; | |
| 3945 } | |
| 3946 | |
| 3947 static intptr_t data_offset() { | |
| 3948 return length_offset() + kWordSize; | |
| 3949 } | |
| 3950 | |
| 3951 static intptr_t InstanceSize() { | |
| 3952 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_)); | |
| 3953 return 0; | |
| 3954 } | |
| 3955 | |
| 3956 static intptr_t InstanceSize(intptr_t len) { | |
| 3957 intptr_t data_size = len * kBytesPerElement; | |
| 3958 return RoundedAllocationSize(sizeof(RawInt32Array) + data_size); | |
| 3959 } | |
| 3960 | |
| 3961 static RawInt32Array* New(intptr_t len, | |
| 3962 Heap::Space space = Heap::kNew); | |
| 3963 static RawInt32Array* New(const int32_t* data, | |
| 3964 intptr_t len, | |
| 3965 Heap::Space space = Heap::kNew); | |
| 3966 | |
| 3967 private: | |
| 3968 static const intptr_t kBytesPerElement = 4; | |
| 3969 | |
| 3970 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 3971 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 3972 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 3973 } | |
| 3974 | |
| 3975 HEAP_OBJECT_IMPLEMENTATION(Int32Array, ByteArray); | |
| 3976 friend class ByteArray; | |
| 3977 friend class Class; | |
| 3978 }; | |
| 3979 | |
| 3980 | |
| 3981 class Uint32Array : public ByteArray { | |
| 3982 public: | |
| 3983 intptr_t ByteLength() const { | |
| 3984 return Length() * kBytesPerElement; | |
| 3985 } | |
| 3986 | |
| 3987 uint32_t At(intptr_t index) const { | |
| 3988 ASSERT((index >= 0) && (index < Length())); | |
| 3989 return raw_ptr()->data_[index]; | |
| 3990 } | |
| 3991 | |
| 3992 void SetAt(intptr_t index, uint32_t value) const { | |
| 3993 ASSERT((index >= 0) && (index < Length())); | |
| 3994 raw_ptr()->data_[index] = value; | |
| 3995 } | |
| 3996 | |
| 3997 static intptr_t data_offset() { | |
| 3998 return length_offset() + kWordSize; | |
| 3999 } | |
| 4000 | |
| 4001 static intptr_t InstanceSize() { | |
| 4002 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_)); | |
| 4003 return 0; | |
| 4004 } | |
| 4005 | |
| 4006 static intptr_t InstanceSize(intptr_t len) { | |
| 4007 intptr_t data_size = len * kBytesPerElement; | |
| 4008 return RoundedAllocationSize(sizeof(RawUint32Array) + data_size); | |
| 4009 } | |
| 4010 | |
| 4011 static RawUint32Array* New(intptr_t len, | |
| 4012 Heap::Space space = Heap::kNew); | |
| 4013 static RawUint32Array* New(const uint32_t* data, | |
| 4014 intptr_t len, | |
| 4015 Heap::Space space = Heap::kNew); | |
| 4016 | |
| 4017 private: | |
| 4018 static const intptr_t kBytesPerElement = 4; | |
| 4019 | |
| 4020 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4021 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4022 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 4023 } | |
| 4024 | |
| 4025 HEAP_OBJECT_IMPLEMENTATION(Uint32Array, ByteArray); | |
| 4026 friend class ByteArray; | |
| 4027 friend class Class; | |
| 4028 }; | |
| 4029 | |
| 4030 | |
| 4031 class Int64Array : public ByteArray { | |
| 4032 public: | |
| 4033 intptr_t ByteLength() const { | |
| 4034 return Length() * kBytesPerElement; | |
| 4035 } | |
| 4036 | |
| 4037 int64_t At(intptr_t index) const { | |
| 4038 ASSERT((index >= 0) && (index < Length())); | |
| 4039 return raw_ptr()->data_[index]; | |
| 4040 } | |
| 4041 | |
| 4042 void SetAt(intptr_t index, int64_t value) const { | |
| 4043 ASSERT((index >= 0) && (index < Length())); | |
| 4044 raw_ptr()->data_[index] = value; | |
| 4045 } | |
| 4046 | |
| 4047 static intptr_t data_offset() { | |
| 4048 return length_offset() + kWordSize; | |
| 4049 } | |
| 4050 | |
| 4051 static intptr_t InstanceSize() { | |
| 4052 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_)); | |
| 4053 return 0; | |
| 4054 } | |
| 4055 | |
| 4056 static intptr_t InstanceSize(intptr_t len) { | |
| 4057 intptr_t data_size = len * kBytesPerElement; | |
| 4058 return RoundedAllocationSize(sizeof(RawInt64Array) + data_size); | |
| 4059 } | |
| 4060 | |
| 4061 static RawInt64Array* New(intptr_t len, | |
| 4062 Heap::Space space = Heap::kNew); | |
| 4063 static RawInt64Array* New(const int64_t* data, | |
| 4064 intptr_t len, | |
| 4065 Heap::Space space = Heap::kNew); | |
| 4066 | |
| 4067 private: | |
| 4068 static const intptr_t kBytesPerElement = 8; | |
| 4069 | |
| 4070 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4071 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4072 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 4073 } | |
| 4074 | |
| 4075 HEAP_OBJECT_IMPLEMENTATION(Int64Array, ByteArray); | |
| 4076 friend class ByteArray; | |
| 4077 friend class Class; | |
| 4078 }; | |
| 4079 | |
| 4080 | |
| 4081 class Uint64Array : public ByteArray { | |
| 4082 public: | |
| 4083 intptr_t ByteLength() const { | |
| 4084 return Length() * sizeof(uint64_t); | |
| 4085 } | |
| 4086 | |
| 4087 uint64_t At(intptr_t index) const { | |
| 4088 ASSERT((index >= 0) && (index < Length())); | |
| 4089 return raw_ptr()->data_[index]; | |
| 4090 } | |
| 4091 | |
| 4092 void SetAt(intptr_t index, uint64_t value) const { | |
| 4093 ASSERT((index >= 0) && (index < Length())); | |
| 4094 raw_ptr()->data_[index] = value; | |
| 4095 } | |
| 4096 | |
| 4097 static intptr_t data_offset() { | |
| 4098 return length_offset() + kWordSize; | |
| 4099 } | |
| 4100 | |
| 4101 static intptr_t InstanceSize() { | |
| 4102 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_)); | |
| 4103 return 0; | |
| 4104 } | |
| 4105 | |
| 4106 static intptr_t InstanceSize(intptr_t len) { | |
| 4107 intptr_t data_size = len * kBytesPerElement; | |
| 4108 return RoundedAllocationSize(sizeof(RawUint64Array) + data_size); | |
| 4109 } | |
| 4110 | |
| 4111 static RawUint64Array* New(intptr_t len, | |
| 4112 Heap::Space space = Heap::kNew); | |
| 4113 static RawUint64Array* New(const uint64_t* data, | |
| 4114 intptr_t len, | |
| 4115 Heap::Space space = Heap::kNew); | |
| 4116 | |
| 4117 private: | |
| 4118 static const intptr_t kBytesPerElement = 8; | |
| 4119 | |
| 4120 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4121 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4122 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 4123 } | |
| 4124 | |
| 4125 HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray); | |
| 4126 friend class ByteArray; | |
| 4127 friend class Class; | |
| 4128 }; | |
| 4129 | |
| 4130 | |
| 4131 class Float32Array : public ByteArray { | |
| 4132 public: | |
| 4133 intptr_t ByteLength() const { | |
| 4134 return Length() * kBytesPerElement; | |
| 4135 } | |
| 4136 | |
| 4137 float At(intptr_t index) const { | |
| 4138 ASSERT((index >= 0) && (index < Length())); | |
| 4139 return raw_ptr()->data_[index]; | |
| 4140 } | |
| 4141 | |
| 4142 void SetAt(intptr_t index, float value) const { | |
| 4143 ASSERT((index >= 0) && (index < Length())); | |
| 4144 raw_ptr()->data_[index] = value; | |
| 4145 } | |
| 4146 | |
| 4147 static intptr_t data_offset() { | |
| 4148 return length_offset() + kWordSize; | |
| 4149 } | |
| 4150 | |
| 4151 static intptr_t InstanceSize() { | |
| 4152 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_)); | |
| 4153 return 0; | |
| 4154 } | |
| 4155 | |
| 4156 static intptr_t InstanceSize(intptr_t len) { | |
| 4157 intptr_t data_size = len * kBytesPerElement; | |
| 4158 return RoundedAllocationSize(sizeof(RawFloat32Array) + data_size); | |
| 4159 } | |
| 4160 | |
| 4161 static RawFloat32Array* New(intptr_t len, | |
| 4162 Heap::Space space = Heap::kNew); | |
| 4163 static RawFloat32Array* New(const float* data, | |
| 4164 intptr_t len, | |
| 4165 Heap::Space space = Heap::kNew); | |
| 4166 | |
| 4167 private: | |
| 4168 static const intptr_t kBytesPerElement = 4; | |
| 4169 | |
| 4170 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4171 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4172 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 4173 } | |
| 4174 | |
| 4175 HEAP_OBJECT_IMPLEMENTATION(Float32Array, ByteArray); | |
| 4176 friend class ByteArray; | |
| 4177 friend class Class; | |
| 4178 }; | |
| 4179 | |
| 4180 | |
| 4181 class Float64Array : public ByteArray { | |
| 4182 public: | |
| 4183 intptr_t ByteLength() const { | |
| 4184 return Length() * kBytesPerElement; | |
| 4185 } | |
| 4186 | |
| 4187 double At(intptr_t index) const { | |
| 4188 ASSERT((index >= 0) && (index < Length())); | |
| 4189 return raw_ptr()->data_[index]; | |
| 4190 } | |
| 4191 | |
| 4192 void SetAt(intptr_t index, double value) const { | |
| 4193 ASSERT((index >= 0) && (index < Length())); | |
| 4194 raw_ptr()->data_[index] = value; | |
| 4195 } | |
| 4196 | |
| 4197 static intptr_t InstanceSize() { | |
| 4198 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_)); | |
| 4199 return 0; | |
| 4200 } | |
| 4201 | |
| 4202 static intptr_t data_offset() { | |
| 4203 return length_offset() + kWordSize; | |
| 4204 } | |
| 4205 | |
| 4206 static intptr_t InstanceSize(intptr_t len) { | |
| 4207 intptr_t data_size = len * kBytesPerElement; | |
| 4208 return RoundedAllocationSize(sizeof(RawFloat64Array) + data_size); | |
| 4209 } | |
| 4210 | |
| 4211 static RawFloat64Array* New(intptr_t len, | |
| 4212 Heap::Space space = Heap::kNew); | |
| 4213 static RawFloat64Array* New(const double* data, | |
| 4214 intptr_t len, | |
| 4215 Heap::Space space = Heap::kNew); | |
| 4216 | |
| 4217 private: | |
| 4218 static const intptr_t kBytesPerElement = 8; | |
| 4219 | |
| 4220 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4221 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4222 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
| 4223 } | |
| 4224 | |
| 4225 HEAP_OBJECT_IMPLEMENTATION(Float64Array, ByteArray); | |
| 4226 friend class ByteArray; | |
| 4227 friend class Class; | |
| 4228 }; | |
| 4229 | |
| 4230 | |
| 4231 class ExternalInt8Array : public ByteArray { | |
| 4232 public: | |
| 4233 intptr_t ByteLength() const { | |
| 4234 return Length() * kBytesPerElement; | |
| 4235 } | |
| 4236 | |
| 4237 int8_t At(intptr_t index) const { | |
| 4238 ASSERT((index >= 0) && (index < Length())); | |
| 4239 return raw_ptr()->external_data_->data()[index]; | |
| 4240 } | |
| 4241 | |
| 4242 void SetAt(intptr_t index, int8_t value) const { | |
| 4243 ASSERT((index >= 0) && (index < Length())); | |
| 4244 raw_ptr()->external_data_->data()[index] = value; | |
| 4245 } | 3775 } |
| 4246 | 3776 |
| 4247 void* GetPeer() const { | 3777 void* GetPeer() const { |
| 4248 return raw_ptr()->external_data_->peer(); | 3778 return raw_ptr()->external_data_->peer(); |
| 4249 } | 3779 } |
| 4250 | 3780 |
| 4251 static intptr_t InstanceSize() { | 3781 template<typename T> |
| 4252 return RoundedAllocationSize(sizeof(RawExternalInt8Array)); | 3782 T At(intptr_t byte_offset) const { |
| 3783 T* addr = Addr<T>(byte_offset); |
| 3784 ASSERT(Utils::IsAligned(reinterpret_cast<intptr_t>(addr), sizeof(T))); |
| 3785 return *addr; |
| 4253 } | 3786 } |
| 4254 | 3787 |
| 4255 static RawExternalInt8Array* New(int8_t* data, | 3788 template<typename T> |
| 3789 void SetAt(intptr_t byte_offset, T value) const { |
| 3790 T* addr = Addr<T>(byte_offset); |
| 3791 ASSERT(Utils::IsAligned(reinterpret_cast<intptr_t>(addr), sizeof(T))); |
| 3792 *addr = value; |
| 3793 } |
| 3794 |
| 3795 template<typename T> |
| 3796 T UnalignedAt(intptr_t byte_offset) const { |
| 3797 T result; |
| 3798 memmove(&result, Addr<T>(byte_offset), sizeof(T)); |
| 3799 return result; |
| 3800 } |
| 3801 |
| 3802 template<typename T> |
| 3803 void SetUnalignedAt(intptr_t byte_offset, T value) const { |
| 3804 memmove(Addr<T>(byte_offset), &value, sizeof(T)); |
| 3805 } |
| 3806 |
| 3807 static intptr_t InstanceSize() { |
| 3808 return RoundedAllocationSize(sizeof(RawExternalByteArray)); |
| 3809 } |
| 3810 |
| 3811 static RawExternalByteArray* New(uint8_t* data, |
| 4256 intptr_t len, | 3812 intptr_t len, |
| 4257 void* peer, | 3813 void* peer, |
| 4258 Dart_PeerFinalizer callback, | 3814 Dart_PeerFinalizer callback, |
| 4259 Heap::Space space = Heap::kNew); | 3815 Heap::Space space = Heap::kNew); |
| 4260 | 3816 |
| 4261 private: | 3817 private: |
| 4262 static const intptr_t kBytesPerElement = 1; | |
| 4263 | |
| 4264 uint8_t* ByteAddr(intptr_t byte_offset) const { | 3818 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4265 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 3819 return Addr<uint8_t>(byte_offset); |
| 4266 uint8_t* data = | |
| 4267 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4268 return data + byte_offset; | |
| 4269 } | 3820 } |
| 4270 | 3821 |
| 4271 void SetExternalData(ExternalByteArrayData<int8_t>* data) { | 3822 template<typename T> |
| 3823 T* Addr(intptr_t byte_offset) const { |
| 3824 intptr_t limit = byte_offset + sizeof(T); |
| 3825 // TODO(iposva): Determine if we should throw an exception here. |
| 3826 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 3827 uint8_t* addr = &raw_ptr()->external_data_->data()[byte_offset]; |
| 3828 return reinterpret_cast<T*>(addr); |
| 3829 } |
| 3830 |
| 3831 void SetLength(intptr_t value) const { |
| 3832 raw_ptr()->length_ = Smi::New(value); |
| 3833 } |
| 3834 |
| 3835 void SetExternalData(ExternalByteArrayData* data) const { |
| 4272 raw_ptr()->external_data_ = data; | 3836 raw_ptr()->external_data_ = data; |
| 4273 } | 3837 } |
| 4274 | 3838 |
| 4275 HEAP_OBJECT_IMPLEMENTATION(ExternalInt8Array, ByteArray); | 3839 static void Finalize(Dart_Handle handle, void* peer); |
| 4276 friend class ByteArray; | 3840 |
| 3841 HEAP_OBJECT_IMPLEMENTATION(ExternalByteArray, ByteArray); |
| 4277 friend class Class; | 3842 friend class Class; |
| 4278 }; | 3843 }; |
| 4279 | 3844 |
| 4280 | |
| 4281 class ExternalUint8Array : public ByteArray { | |
| 4282 public: | |
| 4283 intptr_t ByteLength() const { | |
| 4284 return Length() * kBytesPerElement; | |
| 4285 } | |
| 4286 | |
| 4287 uint8_t At(intptr_t index) const { | |
| 4288 ASSERT((index >= 0) && (index < Length())); | |
| 4289 return raw_ptr()->external_data_->data()[index]; | |
| 4290 } | |
| 4291 | |
| 4292 void SetAt(intptr_t index, uint8_t value) const { | |
| 4293 ASSERT((index >= 0) && (index < Length())); | |
| 4294 raw_ptr()->external_data_->data()[index] = value; | |
| 4295 } | |
| 4296 | |
| 4297 void* GetPeer() const { | |
| 4298 return raw_ptr()->external_data_->peer(); | |
| 4299 } | |
| 4300 | |
| 4301 static intptr_t InstanceSize() { | |
| 4302 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); | |
| 4303 } | |
| 4304 | |
| 4305 static RawExternalUint8Array* New(uint8_t* data, | |
| 4306 intptr_t len, | |
| 4307 void* peer, | |
| 4308 Dart_PeerFinalizer callback, | |
| 4309 Heap::Space space = Heap::kNew); | |
| 4310 | |
| 4311 private: | |
| 4312 static const intptr_t kBytesPerElement = 1; | |
| 4313 | |
| 4314 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4315 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4316 uint8_t* data = | |
| 4317 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4318 return data + byte_offset; | |
| 4319 } | |
| 4320 | |
| 4321 void SetExternalData(ExternalByteArrayData<uint8_t>* data) { | |
| 4322 raw_ptr()->external_data_ = data; | |
| 4323 } | |
| 4324 | |
| 4325 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray); | |
| 4326 friend class ByteArray; | |
| 4327 friend class Class; | |
| 4328 }; | |
| 4329 | |
| 4330 | |
| 4331 class ExternalInt16Array : public ByteArray { | |
| 4332 public: | |
| 4333 intptr_t ByteLength() const { | |
| 4334 return Length() * kBytesPerElement; | |
| 4335 } | |
| 4336 | |
| 4337 int16_t At(intptr_t index) const { | |
| 4338 ASSERT((index >= 0) && (index < Length())); | |
| 4339 return raw_ptr()->external_data_->data()[index]; | |
| 4340 } | |
| 4341 | |
| 4342 void SetAt(intptr_t index, int16_t value) const { | |
| 4343 ASSERT((index >= 0) && (index < Length())); | |
| 4344 raw_ptr()->external_data_->data()[index] = value; | |
| 4345 } | |
| 4346 | |
| 4347 void* GetPeer() const { | |
| 4348 return raw_ptr()->external_data_->peer(); | |
| 4349 } | |
| 4350 | |
| 4351 static intptr_t InstanceSize() { | |
| 4352 return RoundedAllocationSize(sizeof(RawExternalInt16Array)); | |
| 4353 } | |
| 4354 | |
| 4355 static RawExternalInt16Array* New(int16_t* data, | |
| 4356 intptr_t len, | |
| 4357 void* peer, | |
| 4358 Dart_PeerFinalizer callback, | |
| 4359 Heap::Space space = Heap::kNew); | |
| 4360 | |
| 4361 private: | |
| 4362 static const intptr_t kBytesPerElement = 2; | |
| 4363 | |
| 4364 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4365 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4366 uint8_t* data = | |
| 4367 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4368 return data + byte_offset; | |
| 4369 } | |
| 4370 | |
| 4371 void SetExternalData(ExternalByteArrayData<int16_t>* data) { | |
| 4372 raw_ptr()->external_data_ = data; | |
| 4373 } | |
| 4374 | |
| 4375 HEAP_OBJECT_IMPLEMENTATION(ExternalInt16Array, ByteArray); | |
| 4376 friend class ByteArray; | |
| 4377 friend class Class; | |
| 4378 }; | |
| 4379 | |
| 4380 | |
| 4381 class ExternalUint16Array : public ByteArray { | |
| 4382 public: | |
| 4383 intptr_t ByteLength() const { | |
| 4384 return Length() * kBytesPerElement; | |
| 4385 } | |
| 4386 | |
| 4387 int16_t At(intptr_t index) const { | |
| 4388 ASSERT((index >= 0) && (index < Length())); | |
| 4389 return raw_ptr()->external_data_->data()[index]; | |
| 4390 } | |
| 4391 | |
| 4392 void SetAt(intptr_t index, int16_t value) const { | |
| 4393 ASSERT((index >= 0) && (index < Length())); | |
| 4394 raw_ptr()->external_data_->data()[index] = value; | |
| 4395 } | |
| 4396 | |
| 4397 void* GetPeer() const { | |
| 4398 return raw_ptr()->external_data_->peer(); | |
| 4399 } | |
| 4400 | |
| 4401 static intptr_t InstanceSize() { | |
| 4402 return RoundedAllocationSize(sizeof(RawExternalUint16Array)); | |
| 4403 } | |
| 4404 | |
| 4405 static RawExternalUint16Array* New(uint16_t* data, | |
| 4406 intptr_t len, | |
| 4407 void* peer, | |
| 4408 Dart_PeerFinalizer callback, | |
| 4409 Heap::Space space = Heap::kNew); | |
| 4410 | |
| 4411 private: | |
| 4412 static const intptr_t kBytesPerElement = 2; | |
| 4413 | |
| 4414 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4415 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4416 uint8_t* data = | |
| 4417 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4418 return data + byte_offset; | |
| 4419 } | |
| 4420 | |
| 4421 void SetExternalData(ExternalByteArrayData<uint16_t>* data) { | |
| 4422 raw_ptr()->external_data_ = data; | |
| 4423 } | |
| 4424 | |
| 4425 HEAP_OBJECT_IMPLEMENTATION(ExternalUint16Array, ByteArray); | |
| 4426 friend class ByteArray; | |
| 4427 friend class Class; | |
| 4428 }; | |
| 4429 | |
| 4430 | |
| 4431 class ExternalInt32Array : public ByteArray { | |
| 4432 public: | |
| 4433 intptr_t ByteLength() const { | |
| 4434 return Length() * kBytesPerElement; | |
| 4435 } | |
| 4436 | |
| 4437 int32_t At(intptr_t index) const { | |
| 4438 ASSERT((index >= 0) && (index < Length())); | |
| 4439 return raw_ptr()->external_data_->data()[index]; | |
| 4440 } | |
| 4441 | |
| 4442 void SetAt(intptr_t index, int32_t value) const { | |
| 4443 ASSERT((index >= 0) && (index < Length())); | |
| 4444 raw_ptr()->external_data_->data()[index] = value; | |
| 4445 } | |
| 4446 | |
| 4447 void* GetPeer() const { | |
| 4448 return raw_ptr()->external_data_->peer(); | |
| 4449 } | |
| 4450 | |
| 4451 static intptr_t InstanceSize() { | |
| 4452 return RoundedAllocationSize(sizeof(RawExternalInt32Array)); | |
| 4453 } | |
| 4454 | |
| 4455 static RawExternalInt32Array* New(int32_t* data, | |
| 4456 intptr_t len, | |
| 4457 void* peer, | |
| 4458 Dart_PeerFinalizer callback, | |
| 4459 Heap::Space space = Heap::kNew); | |
| 4460 | |
| 4461 private: | |
| 4462 static const intptr_t kBytesPerElement = 4; | |
| 4463 | |
| 4464 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4465 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4466 uint8_t* data = | |
| 4467 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4468 return data + byte_offset; | |
| 4469 } | |
| 4470 | |
| 4471 void SetExternalData(ExternalByteArrayData<int32_t>* data) { | |
| 4472 raw_ptr()->external_data_ = data; | |
| 4473 } | |
| 4474 | |
| 4475 HEAP_OBJECT_IMPLEMENTATION(ExternalInt32Array, ByteArray); | |
| 4476 friend class ByteArray; | |
| 4477 friend class Class; | |
| 4478 }; | |
| 4479 | |
| 4480 | |
| 4481 class ExternalUint32Array : public ByteArray { | |
| 4482 public: | |
| 4483 intptr_t ByteLength() const { | |
| 4484 return Length() * kBytesPerElement; | |
| 4485 } | |
| 4486 | |
| 4487 int32_t At(intptr_t index) const { | |
| 4488 ASSERT((index >= 0) && (index < Length())); | |
| 4489 return raw_ptr()->external_data_->data()[index]; | |
| 4490 } | |
| 4491 | |
| 4492 void SetAt(intptr_t index, int32_t value) const { | |
| 4493 ASSERT((index >= 0) && (index < Length())); | |
| 4494 raw_ptr()->external_data_->data()[index] = value; | |
| 4495 } | |
| 4496 | |
| 4497 void* GetPeer() const { | |
| 4498 return raw_ptr()->external_data_->peer(); | |
| 4499 } | |
| 4500 | |
| 4501 static intptr_t InstanceSize() { | |
| 4502 return RoundedAllocationSize(sizeof(RawExternalUint32Array)); | |
| 4503 } | |
| 4504 | |
| 4505 static RawExternalUint32Array* New(uint32_t* data, | |
| 4506 intptr_t len, | |
| 4507 void* peer, | |
| 4508 Dart_PeerFinalizer callback, | |
| 4509 Heap::Space space = Heap::kNew); | |
| 4510 | |
| 4511 private: | |
| 4512 static const intptr_t kBytesPerElement = 4; | |
| 4513 | |
| 4514 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4515 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4516 uint8_t* data = | |
| 4517 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4518 return data + byte_offset; | |
| 4519 } | |
| 4520 | |
| 4521 void SetExternalData(ExternalByteArrayData<uint32_t>* data) { | |
| 4522 raw_ptr()->external_data_ = data; | |
| 4523 } | |
| 4524 | |
| 4525 HEAP_OBJECT_IMPLEMENTATION(ExternalUint32Array, ByteArray); | |
| 4526 friend class ByteArray; | |
| 4527 friend class Class; | |
| 4528 }; | |
| 4529 | |
| 4530 | |
| 4531 class ExternalInt64Array : public ByteArray { | |
| 4532 public: | |
| 4533 intptr_t ByteLength() const { | |
| 4534 return Length() * kBytesPerElement; | |
| 4535 } | |
| 4536 | |
| 4537 int64_t At(intptr_t index) const { | |
| 4538 ASSERT((index >= 0) && (index < Length())); | |
| 4539 return raw_ptr()->external_data_->data()[index]; | |
| 4540 } | |
| 4541 | |
| 4542 void SetAt(intptr_t index, int64_t value) const { | |
| 4543 ASSERT((index >= 0) && (index < Length())); | |
| 4544 raw_ptr()->external_data_->data()[index] = value; | |
| 4545 } | |
| 4546 | |
| 4547 void* GetPeer() const { | |
| 4548 return raw_ptr()->external_data_->peer(); | |
| 4549 } | |
| 4550 | |
| 4551 static intptr_t InstanceSize() { | |
| 4552 return RoundedAllocationSize(sizeof(RawExternalInt64Array)); | |
| 4553 } | |
| 4554 | |
| 4555 static RawExternalInt64Array* New(int64_t* data, | |
| 4556 intptr_t len, | |
| 4557 void* peer, | |
| 4558 Dart_PeerFinalizer callback, | |
| 4559 Heap::Space space = Heap::kNew); | |
| 4560 | |
| 4561 private: | |
| 4562 static const intptr_t kBytesPerElement = 8; | |
| 4563 | |
| 4564 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4565 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4566 uint8_t* data = | |
| 4567 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4568 return data + byte_offset; | |
| 4569 } | |
| 4570 | |
| 4571 void SetExternalData(ExternalByteArrayData<int64_t>* data) { | |
| 4572 raw_ptr()->external_data_ = data; | |
| 4573 } | |
| 4574 | |
| 4575 HEAP_OBJECT_IMPLEMENTATION(ExternalInt64Array, ByteArray); | |
| 4576 friend class ByteArray; | |
| 4577 friend class Class; | |
| 4578 }; | |
| 4579 | |
| 4580 | |
| 4581 class ExternalUint64Array : public ByteArray { | |
| 4582 public: | |
| 4583 intptr_t ByteLength() const { | |
| 4584 return Length() * kBytesPerElement; | |
| 4585 } | |
| 4586 | |
| 4587 int64_t At(intptr_t index) const { | |
| 4588 ASSERT((index >= 0) && (index < Length())); | |
| 4589 return raw_ptr()->external_data_->data()[index]; | |
| 4590 } | |
| 4591 | |
| 4592 void SetAt(intptr_t index, int64_t value) const { | |
| 4593 ASSERT((index >= 0) && (index < Length())); | |
| 4594 raw_ptr()->external_data_->data()[index] = value; | |
| 4595 } | |
| 4596 | |
| 4597 void* GetPeer() const { | |
| 4598 return raw_ptr()->external_data_->peer(); | |
| 4599 } | |
| 4600 | |
| 4601 static intptr_t InstanceSize() { | |
| 4602 return RoundedAllocationSize(sizeof(RawExternalUint64Array)); | |
| 4603 } | |
| 4604 | |
| 4605 static RawExternalUint64Array* New(uint64_t* data, | |
| 4606 intptr_t len, | |
| 4607 void* peer, | |
| 4608 Dart_PeerFinalizer callback, | |
| 4609 Heap::Space space = Heap::kNew); | |
| 4610 | |
| 4611 private: | |
| 4612 static const intptr_t kBytesPerElement = 8; | |
| 4613 | |
| 4614 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4615 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4616 uint8_t* data = | |
| 4617 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4618 return data + byte_offset; | |
| 4619 } | |
| 4620 | |
| 4621 void SetExternalData(ExternalByteArrayData<uint64_t>* data) { | |
| 4622 raw_ptr()->external_data_ = data; | |
| 4623 } | |
| 4624 | |
| 4625 HEAP_OBJECT_IMPLEMENTATION(ExternalUint64Array, ByteArray); | |
| 4626 friend class ByteArray; | |
| 4627 friend class Class; | |
| 4628 }; | |
| 4629 | |
| 4630 | |
| 4631 class ExternalFloat32Array : public ByteArray { | |
| 4632 public: | |
| 4633 intptr_t ByteLength() const { | |
| 4634 return Length() * kBytesPerElement; | |
| 4635 } | |
| 4636 | |
| 4637 float At(intptr_t index) const { | |
| 4638 ASSERT((index >= 0) && (index < Length())); | |
| 4639 return raw_ptr()->external_data_->data()[index]; | |
| 4640 } | |
| 4641 | |
| 4642 void SetAt(intptr_t index, float value) const { | |
| 4643 ASSERT((index >= 0) && (index < Length())); | |
| 4644 raw_ptr()->external_data_->data()[index] = value; | |
| 4645 } | |
| 4646 | |
| 4647 void* GetPeer() const { | |
| 4648 return raw_ptr()->external_data_->peer(); | |
| 4649 } | |
| 4650 | |
| 4651 static intptr_t InstanceSize() { | |
| 4652 return RoundedAllocationSize(sizeof(RawExternalFloat32Array)); | |
| 4653 } | |
| 4654 | |
| 4655 static RawExternalFloat32Array* New(float* data, | |
| 4656 intptr_t len, | |
| 4657 void* peer, | |
| 4658 Dart_PeerFinalizer callback, | |
| 4659 Heap::Space space = Heap::kNew); | |
| 4660 | |
| 4661 private: | |
| 4662 static const intptr_t kBytesPerElement = 4; | |
| 4663 | |
| 4664 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4665 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4666 uint8_t* data = | |
| 4667 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4668 return data + byte_offset; | |
| 4669 } | |
| 4670 | |
| 4671 void SetExternalData(ExternalByteArrayData<float>* data) { | |
| 4672 raw_ptr()->external_data_ = data; | |
| 4673 } | |
| 4674 | |
| 4675 HEAP_OBJECT_IMPLEMENTATION(ExternalFloat32Array, ByteArray); | |
| 4676 friend class ByteArray; | |
| 4677 friend class Class; | |
| 4678 }; | |
| 4679 | |
| 4680 | |
| 4681 class ExternalFloat64Array : public ByteArray { | |
| 4682 public: | |
| 4683 intptr_t ByteLength() const { | |
| 4684 return Length() * kBytesPerElement; | |
| 4685 } | |
| 4686 | |
| 4687 double At(intptr_t index) const { | |
| 4688 ASSERT((index >= 0) && (index < Length())); | |
| 4689 return raw_ptr()->external_data_->data()[index]; | |
| 4690 } | |
| 4691 | |
| 4692 void SetAt(intptr_t index, double value) const { | |
| 4693 ASSERT((index >= 0) && (index < Length())); | |
| 4694 raw_ptr()->external_data_->data()[index] = value; | |
| 4695 } | |
| 4696 | |
| 4697 void* GetPeer() const { | |
| 4698 return raw_ptr()->external_data_->peer(); | |
| 4699 } | |
| 4700 | |
| 4701 static intptr_t InstanceSize() { | |
| 4702 return RoundedAllocationSize(sizeof(RawExternalFloat64Array)); | |
| 4703 } | |
| 4704 | |
| 4705 static RawExternalFloat64Array* New(double* data, | |
| 4706 intptr_t len, | |
| 4707 void* peer, | |
| 4708 Dart_PeerFinalizer callback, | |
| 4709 Heap::Space space = Heap::kNew); | |
| 4710 | |
| 4711 private: | |
| 4712 static const intptr_t kBytesPerElement = 8; | |
| 4713 | |
| 4714 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 4715 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
| 4716 uint8_t* data = | |
| 4717 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 4718 return data + byte_offset; | |
| 4719 } | |
| 4720 | |
| 4721 void SetExternalData(ExternalByteArrayData<double>* data) { | |
| 4722 raw_ptr()->external_data_ = data; | |
| 4723 } | |
| 4724 | |
| 4725 HEAP_OBJECT_IMPLEMENTATION(ExternalFloat64Array, ByteArray); | |
| 4726 friend class ByteArray; | |
| 4727 friend class Class; | |
| 4728 }; | |
| 4729 | |
| 4730 | 3845 |
| 4731 class Closure : public Instance { | 3846 class Closure : public Instance { |
| 4732 public: | 3847 public: |
| 4733 RawFunction* function() const { return raw_ptr()->function_; } | 3848 RawFunction* function() const { return raw_ptr()->function_; } |
| 4734 static intptr_t function_offset() { | 3849 static intptr_t function_offset() { |
| 4735 return OFFSET_OF(RawClosure, function_); | 3850 return OFFSET_OF(RawClosure, function_); |
| 4736 } | 3851 } |
| 4737 | 3852 |
| 4738 RawContext* context() const { return raw_ptr()->context_; } | 3853 RawContext* context() const { return raw_ptr()->context_; } |
| 4739 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } | 3854 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4953 } | 4068 } |
| 4954 | 4069 |
| 4955 | 4070 |
| 4956 intptr_t Stackmap::SizeInBits() const { | 4071 intptr_t Stackmap::SizeInBits() const { |
| 4957 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); | 4072 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); |
| 4958 } | 4073 } |
| 4959 | 4074 |
| 4960 } // namespace dart | 4075 } // namespace dart |
| 4961 | 4076 |
| 4962 #endif // VM_OBJECT_H_ | 4077 #endif // VM_OBJECT_H_ |
| OLD | NEW |