| 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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 static RawClass* New(const String& name, | 826 static RawClass* New(const String& name, |
| 827 const Script& script, | 827 const Script& script, |
| 828 intptr_t token_pos); | 828 intptr_t token_pos); |
| 829 static RawClass* NewNativeWrapper(const Library& library, | 829 static RawClass* NewNativeWrapper(const Library& library, |
| 830 const String& name, | 830 const String& name, |
| 831 int num_fields); | 831 int num_fields); |
| 832 | 832 |
| 833 // Allocate the raw string classes. | 833 // Allocate the raw string classes. |
| 834 static RawClass* NewStringClass(intptr_t class_id); | 834 static RawClass* NewStringClass(intptr_t class_id); |
| 835 | 835 |
| 836 // Allocate the raw TypedData classes. |
| 837 static RawClass* NewTypedDataClass(intptr_t class_id); |
| 838 |
| 839 // Allocate the raw ExternalTypedData classes. |
| 840 static RawClass* NewExternalTypedDataClass(intptr_t class_id); |
| 841 |
| 836 // Allocate a class representing a function signature described by | 842 // Allocate a class representing a function signature described by |
| 837 // signature_function, which must be a closure function or a signature | 843 // signature_function, which must be a closure function or a signature |
| 838 // function. | 844 // function. |
| 839 // The class may be type parameterized unless the signature_function is in a | 845 // The class may be type parameterized unless the signature_function is in a |
| 840 // static scope. In that case, the type parameters are copied from the owner | 846 // static scope. In that case, the type parameters are copied from the owner |
| 841 // class of signature_function. | 847 // class of signature_function. |
| 842 // A null signature function may be passed in and patched later. See below. | 848 // A null signature function may be passed in and patched later. See below. |
| 843 static RawClass* NewSignatureClass(const String& name, | 849 static RawClass* NewSignatureClass(const String& name, |
| 844 const Function& signature_function, | 850 const Function& signature_function, |
| 845 const Script& script, | 851 const Script& script, |
| (...skipping 3996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4842 | 4848 |
| 4843 FINAL_HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); | 4849 FINAL_HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); |
| 4844 friend class Array; | 4850 friend class Array; |
| 4845 friend class Class; | 4851 friend class Class; |
| 4846 }; | 4852 }; |
| 4847 | 4853 |
| 4848 | 4854 |
| 4849 class Float32x4 : public Instance { | 4855 class Float32x4 : public Instance { |
| 4850 public: | 4856 public: |
| 4851 static RawFloat32x4* New(float value0, float value1, float value2, | 4857 static RawFloat32x4* New(float value0, float value1, float value2, |
| 4852 float value3, Heap::Space space = Heap::kNew); | 4858 float value3, Heap::Space space = Heap::kNew); |
| 4853 static RawFloat32x4* New(simd_value_t value, Heap::Space space = Heap::kNew); | 4859 static RawFloat32x4* New(simd_value_t value, Heap::Space space = Heap::kNew); |
| 4854 | 4860 |
| 4855 float x() const; | 4861 float x() const; |
| 4856 float y() const; | 4862 float y() const; |
| 4857 float z() const; | 4863 float z() const; |
| 4858 float w() const; | 4864 float w() const; |
| 4859 | 4865 |
| 4860 void set_x(float x) const; | 4866 void set_x(float x) const; |
| 4861 void set_y(float y) const; | 4867 void set_y(float y) const; |
| 4862 void set_z(float z) const; | 4868 void set_z(float z) const; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4875 | 4881 |
| 4876 private: | 4882 private: |
| 4877 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float32x4, Instance); | 4883 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float32x4, Instance); |
| 4878 friend class Class; | 4884 friend class Class; |
| 4879 }; | 4885 }; |
| 4880 | 4886 |
| 4881 | 4887 |
| 4882 class Uint32x4 : public Instance { | 4888 class Uint32x4 : public Instance { |
| 4883 public: | 4889 public: |
| 4884 static RawUint32x4* New(uint32_t value0, uint32_t value1, uint32_t value2, | 4890 static RawUint32x4* New(uint32_t value0, uint32_t value1, uint32_t value2, |
| 4885 uint32_t value3, Heap::Space space = Heap::kNew); | 4891 uint32_t value3, Heap::Space space = Heap::kNew); |
| 4886 static RawUint32x4* New(simd_value_t value, Heap::Space space = Heap::kNew); | 4892 static RawUint32x4* New(simd_value_t value, Heap::Space space = Heap::kNew); |
| 4887 | 4893 |
| 4888 uint32_t x() const; | 4894 uint32_t x() const; |
| 4889 uint32_t y() const; | 4895 uint32_t y() const; |
| 4890 uint32_t z() const; | 4896 uint32_t z() const; |
| 4891 uint32_t w() const; | 4897 uint32_t w() const; |
| 4892 | 4898 |
| 4893 void set_x(uint32_t x) const; | 4899 void set_x(uint32_t x) const; |
| 4894 void set_y(uint32_t y) const; | 4900 void set_y(uint32_t y) const; |
| 4895 void set_z(uint32_t z) const; | 4901 void set_z(uint32_t z) const; |
| 4896 void set_w(uint32_t w) const; | 4902 void set_w(uint32_t w) const; |
| 4897 | 4903 |
| 4898 simd_value_t value() const; | 4904 simd_value_t value() const; |
| 4899 void set_value(simd_value_t value) const; | 4905 void set_value(simd_value_t value) const; |
| 4900 | 4906 |
| 4901 static intptr_t InstanceSize() { | 4907 static intptr_t InstanceSize() { |
| 4902 return RoundedAllocationSize(sizeof(RawUint32x4)); | 4908 return RoundedAllocationSize(sizeof(RawUint32x4)); |
| 4903 } | 4909 } |
| 4904 | 4910 |
| 4905 static intptr_t value_offset() { | 4911 static intptr_t value_offset() { |
| 4906 return OFFSET_OF(RawUint32x4, value_); | 4912 return OFFSET_OF(RawUint32x4, value_); |
| 4907 } | 4913 } |
| 4908 | 4914 |
| 4909 private: | 4915 private: |
| 4910 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint32x4, Instance); | 4916 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint32x4, Instance); |
| 4911 friend class Class; | 4917 friend class Class; |
| 4912 }; | 4918 }; |
| 4913 | 4919 |
| 4914 | 4920 |
| 4921 class TypedData : public Instance { |
| 4922 public: |
| 4923 intptr_t Length() const { |
| 4924 ASSERT(!IsNull()); |
| 4925 return Smi::Value(raw_ptr()->length_); |
| 4926 } |
| 4927 |
| 4928 intptr_t ElementSizeInBytes() const { |
| 4929 intptr_t cid = raw()->GetClassId(); |
| 4930 return ElementSizeInBytes(cid); |
| 4931 } |
| 4932 |
| 4933 intptr_t LengthInBytes() const { |
| 4934 intptr_t cid = raw()->GetClassId(); |
| 4935 return (ElementSizeInBytes(cid) * Length()); |
| 4936 } |
| 4937 |
| 4938 #define TYPED_GETTER_SETTER(name, type) \ |
| 4939 type Get##name(intptr_t byte_offset) const { \ |
| 4940 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \ |
| 4941 } \ |
| 4942 void Set##name(intptr_t byte_offset, type value) const { \ |
| 4943 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \ |
| 4944 } |
| 4945 TYPED_GETTER_SETTER(Int8, int8_t) |
| 4946 TYPED_GETTER_SETTER(Uint8, uint8_t) |
| 4947 TYPED_GETTER_SETTER(Int16, int16_t) |
| 4948 TYPED_GETTER_SETTER(Uint16, uint16_t) |
| 4949 TYPED_GETTER_SETTER(Int32, int32_t) |
| 4950 TYPED_GETTER_SETTER(Uint32, uint32_t) |
| 4951 TYPED_GETTER_SETTER(Int64, int64_t) |
| 4952 TYPED_GETTER_SETTER(Uint64, uint64_t) |
| 4953 TYPED_GETTER_SETTER(Float32, float) |
| 4954 TYPED_GETTER_SETTER(Float64, double) |
| 4955 |
| 4956 static intptr_t length_offset() { |
| 4957 return OFFSET_OF(RawTypedData, length_); |
| 4958 } |
| 4959 |
| 4960 static intptr_t InstanceSize() { |
| 4961 ASSERT(sizeof(RawTypedData) == OFFSET_OF(RawTypedData, data_)); |
| 4962 return 0; |
| 4963 } |
| 4964 |
| 4965 static intptr_t InstanceSize(intptr_t lengthInBytes) { |
| 4966 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax); |
| 4967 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes); |
| 4968 } |
| 4969 |
| 4970 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 4971 ASSERT(RawObject::IsTypedDataClassId(class_id)); |
| 4972 return element_size[class_id - kTypedDataInt8ArrayCid]; |
| 4973 } |
| 4974 |
| 4975 static RawTypedData* New(intptr_t class_id, |
| 4976 intptr_t len, |
| 4977 Heap::Space space = Heap::kNew); |
| 4978 |
| 4979 protected: |
| 4980 void SetLength(intptr_t value) const { |
| 4981 raw_ptr()->length_ = Smi::New(value); |
| 4982 } |
| 4983 |
| 4984 private: |
| 4985 static const intptr_t element_size[]; |
| 4986 |
| 4987 void* DataAddr(intptr_t byte_offset) const { |
| 4988 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes())); |
| 4989 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset); |
| 4990 } |
| 4991 |
| 4992 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); |
| 4993 friend class Class; |
| 4994 friend class ExternalTypedData; |
| 4995 }; |
| 4996 |
| 4997 |
| 4998 class ExternalTypedData : public Instance { |
| 4999 public: |
| 5000 intptr_t Length() const { |
| 5001 ASSERT(!IsNull()); |
| 5002 return Smi::Value(raw_ptr()->length_); |
| 5003 } |
| 5004 |
| 5005 intptr_t ElementSizeInBytes() const { |
| 5006 intptr_t cid = raw()->GetClassId(); |
| 5007 return ElementSizeInBytes(cid); |
| 5008 } |
| 5009 |
| 5010 intptr_t LengthInBytes() const { |
| 5011 intptr_t cid = raw()->GetClassId(); |
| 5012 return (ElementSizeInBytes(cid) * Length()); |
| 5013 } |
| 5014 |
| 5015 #define TYPED_GETTER_SETTER(name, type) \ |
| 5016 type Get##name(intptr_t byte_offset) const { \ |
| 5017 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \ |
| 5018 } \ |
| 5019 void Set##name(intptr_t byte_offset, type value) const { \ |
| 5020 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \ |
| 5021 } |
| 5022 TYPED_GETTER_SETTER(Int8, int8_t) |
| 5023 TYPED_GETTER_SETTER(Uint8, uint8_t) |
| 5024 TYPED_GETTER_SETTER(Int16, int16_t) |
| 5025 TYPED_GETTER_SETTER(Uint16, uint16_t) |
| 5026 TYPED_GETTER_SETTER(Int32, int32_t) |
| 5027 TYPED_GETTER_SETTER(Uint32, uint32_t) |
| 5028 TYPED_GETTER_SETTER(Int64, int64_t) |
| 5029 TYPED_GETTER_SETTER(Uint64, uint64_t) |
| 5030 TYPED_GETTER_SETTER(Float32, float) |
| 5031 TYPED_GETTER_SETTER(Float64, double) |
| 5032 |
| 5033 FinalizablePersistentHandle* AddFinalizer( |
| 5034 void* peer, Dart_WeakPersistentHandleFinalizer callback) const; |
| 5035 |
| 5036 static intptr_t length_offset() { |
| 5037 return OFFSET_OF(RawExternalTypedData, length_); |
| 5038 } |
| 5039 |
| 5040 static intptr_t data_offset() { |
| 5041 return OFFSET_OF(RawExternalTypedData, data_); |
| 5042 } |
| 5043 |
| 5044 static intptr_t InstanceSize() { |
| 5045 return RoundedAllocationSize(sizeof(RawExternalTypedData)); |
| 5046 } |
| 5047 |
| 5048 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 5049 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); |
| 5050 return TypedData::element_size[class_id - kExternalTypedDataInt8ArrayCid]; |
| 5051 } |
| 5052 |
| 5053 static RawExternalTypedData* New(intptr_t class_id, |
| 5054 uint8_t* data, |
| 5055 intptr_t len, |
| 5056 Heap::Space space = Heap::kNew); |
| 5057 |
| 5058 protected: |
| 5059 void SetLength(intptr_t value) const { |
| 5060 raw_ptr()->length_ = Smi::New(value); |
| 5061 } |
| 5062 |
| 5063 void SetData(uint8_t* data) const { |
| 5064 raw_ptr()->data_ = data; |
| 5065 } |
| 5066 |
| 5067 void SetPeer(void* peer) const { |
| 5068 raw_ptr()->peer_ = peer; |
| 5069 } |
| 5070 |
| 5071 private: |
| 5072 void* DataAddr(intptr_t byte_offset) const { |
| 5073 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes())); |
| 5074 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset); |
| 5075 } |
| 5076 |
| 5077 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); |
| 5078 friend class Class; |
| 5079 }; |
| 5080 |
| 5081 |
| 4915 class ByteArray : public Instance { | 5082 class ByteArray : public Instance { |
| 4916 public: | 5083 public: |
| 4917 intptr_t Length() const { | 5084 intptr_t Length() const { |
| 4918 ASSERT(!IsNull()); | 5085 ASSERT(!IsNull()); |
| 4919 return Smi::Value(raw_ptr()->length_); | 5086 return Smi::Value(raw_ptr()->length_); |
| 4920 } | 5087 } |
| 4921 | 5088 |
| 4922 static intptr_t length_offset() { | 5089 static intptr_t length_offset() { |
| 4923 return OFFSET_OF(RawByteArray, length_); | 5090 return OFFSET_OF(RawByteArray, length_); |
| 4924 } | 5091 } |
| (...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6647 | 6814 |
| 6648 | 6815 |
| 6649 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 6816 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 6650 intptr_t index) { | 6817 intptr_t index) { |
| 6651 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 6818 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 6652 } | 6819 } |
| 6653 | 6820 |
| 6654 } // namespace dart | 6821 } // namespace dart |
| 6655 | 6822 |
| 6656 #endif // VM_OBJECT_H_ | 6823 #endif // VM_OBJECT_H_ |
| OLD | NEW |