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