| 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 6931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6942 return 0; | 6942 return 0; |
| 6943 } | 6943 } |
| 6944 | 6944 |
| 6945 static intptr_t InstanceSize(intptr_t lengthInBytes) { | 6945 static intptr_t InstanceSize(intptr_t lengthInBytes) { |
| 6946 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax); | 6946 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax); |
| 6947 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes); | 6947 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes); |
| 6948 } | 6948 } |
| 6949 | 6949 |
| 6950 static intptr_t ElementSizeInBytes(intptr_t class_id) { | 6950 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 6951 ASSERT(RawObject::IsTypedDataClassId(class_id)); | 6951 ASSERT(RawObject::IsTypedDataClassId(class_id)); |
| 6952 return element_size[ElementType(class_id)]; | 6952 return element_size(ElementType(class_id)); |
| 6953 } | 6953 } |
| 6954 | 6954 |
| 6955 static TypedDataElementType ElementType(intptr_t class_id) { | 6955 static TypedDataElementType ElementType(intptr_t class_id) { |
| 6956 ASSERT(RawObject::IsTypedDataClassId(class_id)); | 6956 ASSERT(RawObject::IsTypedDataClassId(class_id)); |
| 6957 return static_cast<TypedDataElementType>( | 6957 return static_cast<TypedDataElementType>( |
| 6958 class_id - kTypedDataInt8ArrayCid); | 6958 class_id - kTypedDataInt8ArrayCid); |
| 6959 } | 6959 } |
| 6960 | 6960 |
| 6961 static intptr_t MaxElements(intptr_t class_id) { | 6961 static intptr_t MaxElements(intptr_t class_id) { |
| 6962 ASSERT(RawObject::IsTypedDataClassId(class_id)); | 6962 ASSERT(RawObject::IsTypedDataClassId(class_id)); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7023 } | 7023 } |
| 7024 | 7024 |
| 7025 static RawTypedData* EmptyUint32Array(Isolate* isolate); | 7025 static RawTypedData* EmptyUint32Array(Isolate* isolate); |
| 7026 | 7026 |
| 7027 protected: | 7027 protected: |
| 7028 void SetLength(intptr_t value) const { | 7028 void SetLength(intptr_t value) const { |
| 7029 StoreSmi(&raw_ptr()->length_, Smi::New(value)); | 7029 StoreSmi(&raw_ptr()->length_, Smi::New(value)); |
| 7030 } | 7030 } |
| 7031 | 7031 |
| 7032 private: | 7032 private: |
| 7033 static const intptr_t element_size[]; | 7033 static intptr_t element_size(intptr_t index) { |
| 7034 ASSERT(0 <= index && index < kNumElementSizes); |
| 7035 intptr_t size = element_size_table[index]; |
| 7036 ASSERT(size != 0); |
| 7037 return size; |
| 7038 } |
| 7039 static const intptr_t kNumElementSizes = |
| 7040 kTypedDataFloat64x2ArrayCid - kTypedDataInt8ArrayCid + 1; |
| 7041 static const intptr_t element_size_table[kNumElementSizes]; |
| 7034 | 7042 |
| 7035 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); | 7043 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); |
| 7036 friend class Class; | 7044 friend class Class; |
| 7037 friend class ExternalTypedData; | 7045 friend class ExternalTypedData; |
| 7038 friend class TypedDataView; | 7046 friend class TypedDataView; |
| 7039 }; | 7047 }; |
| 7040 | 7048 |
| 7041 | 7049 |
| 7042 class ExternalTypedData : public Instance { | 7050 class ExternalTypedData : public Instance { |
| 7043 public: | 7051 public: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7100 static intptr_t data_offset() { | 7108 static intptr_t data_offset() { |
| 7101 return OFFSET_OF(RawExternalTypedData, data_); | 7109 return OFFSET_OF(RawExternalTypedData, data_); |
| 7102 } | 7110 } |
| 7103 | 7111 |
| 7104 static intptr_t InstanceSize() { | 7112 static intptr_t InstanceSize() { |
| 7105 return RoundedAllocationSize(sizeof(RawExternalTypedData)); | 7113 return RoundedAllocationSize(sizeof(RawExternalTypedData)); |
| 7106 } | 7114 } |
| 7107 | 7115 |
| 7108 static intptr_t ElementSizeInBytes(intptr_t class_id) { | 7116 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 7109 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); | 7117 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); |
| 7110 return TypedData::element_size[ElementType(class_id)]; | 7118 return TypedData::element_size(ElementType(class_id)); |
| 7111 } | 7119 } |
| 7112 | 7120 |
| 7113 static TypedDataElementType ElementType(intptr_t class_id) { | 7121 static TypedDataElementType ElementType(intptr_t class_id) { |
| 7114 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); | 7122 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); |
| 7115 return static_cast<TypedDataElementType>( | 7123 return static_cast<TypedDataElementType>( |
| 7116 class_id - kExternalTypedDataInt8ArrayCid); | 7124 class_id - kExternalTypedDataInt8ArrayCid); |
| 7117 } | 7125 } |
| 7118 | 7126 |
| 7119 static intptr_t MaxElements(intptr_t class_id) { | 7127 static intptr_t MaxElements(intptr_t class_id) { |
| 7120 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); | 7128 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7193 return kWordSize * kOffsetInBytesOffset; | 7201 return kWordSize * kOffsetInBytesOffset; |
| 7194 } | 7202 } |
| 7195 | 7203 |
| 7196 static intptr_t length_offset() { | 7204 static intptr_t length_offset() { |
| 7197 return kWordSize * kLengthOffset; | 7205 return kWordSize * kLengthOffset; |
| 7198 } | 7206 } |
| 7199 | 7207 |
| 7200 static intptr_t ElementSizeInBytes(intptr_t class_id) { | 7208 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 7201 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); | 7209 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); |
| 7202 return (class_id == kByteDataViewCid) ? | 7210 return (class_id == kByteDataViewCid) ? |
| 7203 TypedData::element_size[kTypedDataInt8ArrayCid] : | 7211 1 : TypedData::element_size(class_id - kTypedDataInt8ArrayViewCid); |
| 7204 TypedData::element_size[class_id - kTypedDataInt8ArrayViewCid]; | |
| 7205 } | 7212 } |
| 7206 | 7213 |
| 7207 private: | 7214 private: |
| 7208 enum { | 7215 enum { |
| 7209 kDataOffset = 1, | 7216 kDataOffset = 1, |
| 7210 kOffsetInBytesOffset = 2, | 7217 kOffsetInBytesOffset = 2, |
| 7211 kLengthOffset = 3, | 7218 kLengthOffset = 3, |
| 7212 }; | 7219 }; |
| 7213 }; | 7220 }; |
| 7214 | 7221 |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7806 | 7813 |
| 7807 | 7814 |
| 7808 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7815 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 7809 intptr_t index) { | 7816 intptr_t index) { |
| 7810 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7817 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 7811 } | 7818 } |
| 7812 | 7819 |
| 7813 } // namespace dart | 7820 } // namespace dart |
| 7814 | 7821 |
| 7815 #endif // VM_OBJECT_H_ | 7822 #endif // VM_OBJECT_H_ |
| OLD | NEW |