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