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