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 5016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5027 intptr_t Length() const { | 5027 intptr_t Length() const { |
| 5028 ASSERT(!IsNull()); | 5028 ASSERT(!IsNull()); |
| 5029 return Smi::Value(raw_ptr()->length_); | 5029 return Smi::Value(raw_ptr()->length_); |
| 5030 } | 5030 } |
| 5031 | 5031 |
| 5032 intptr_t ElementSizeInBytes() const { | 5032 intptr_t ElementSizeInBytes() const { |
| 5033 intptr_t cid = raw()->GetClassId(); | 5033 intptr_t cid = raw()->GetClassId(); |
| 5034 return ElementSizeInBytes(cid); | 5034 return ElementSizeInBytes(cid); |
| 5035 } | 5035 } |
| 5036 | 5036 |
| 5037 | |
| 5038 TypeDataElementType ElementType() const { | |
| 5039 intptr_t cid = raw()->GetClassId(); | |
| 5040 return ElementType(cid); | |
| 5041 } | |
| 5042 | |
| 5037 intptr_t LengthInBytes() const { | 5043 intptr_t LengthInBytes() const { |
| 5038 intptr_t cid = raw()->GetClassId(); | 5044 intptr_t cid = raw()->GetClassId(); |
| 5039 return (ElementSizeInBytes(cid) * Length()); | 5045 return (ElementSizeInBytes(cid) * Length()); |
| 5040 } | 5046 } |
| 5041 | 5047 |
| 5042 void* DataAddr(intptr_t byte_offset) const { | 5048 void* DataAddr(intptr_t byte_offset) const { |
| 5043 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes())); | 5049 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes())); |
| 5044 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset); | 5050 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset); |
| 5045 } | 5051 } |
| 5046 | 5052 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 5076 return 0; | 5082 return 0; |
| 5077 } | 5083 } |
| 5078 | 5084 |
| 5079 static intptr_t InstanceSize(intptr_t lengthInBytes) { | 5085 static intptr_t InstanceSize(intptr_t lengthInBytes) { |
| 5080 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax); | 5086 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax); |
| 5081 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes); | 5087 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes); |
| 5082 } | 5088 } |
| 5083 | 5089 |
| 5084 static intptr_t ElementSizeInBytes(intptr_t class_id) { | 5090 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 5085 ASSERT(RawObject::IsTypedDataClassId(class_id)); | 5091 ASSERT(RawObject::IsTypedDataClassId(class_id)); |
| 5086 return element_size[class_id - kTypedDataInt8ArrayCid]; | 5092 return element_size[class_id - kTypedDataInt8ArrayCid]; |
|
siva
2013/04/19 17:38:40
you could use your new ElementType() here instead
kustermann
2013/04/19 19:21:54
Done.
kustermann
2013/04/19 19:21:54
Done.
| |
| 5087 } | 5093 } |
| 5088 | 5094 |
| 5095 static TypeDataElementType ElementType(intptr_t class_id) { | |
| 5096 ASSERT(RawObject::IsTypedDataClassId(class_id)); | |
| 5097 return static_cast<TypeDataElementType>( | |
| 5098 class_id - kTypedDataInt8ArrayCid); | |
| 5099 } | |
| 5100 | |
| 5089 static intptr_t MaxElements(intptr_t class_id) { | 5101 static intptr_t MaxElements(intptr_t class_id) { |
| 5090 ASSERT(RawObject::IsTypedDataClassId(class_id)); | 5102 ASSERT(RawObject::IsTypedDataClassId(class_id)); |
| 5091 return (kSmiMax / ElementSizeInBytes(class_id)); | 5103 return (kSmiMax / ElementSizeInBytes(class_id)); |
| 5092 } | 5104 } |
| 5093 | 5105 |
| 5094 static RawTypedData* New(intptr_t class_id, | 5106 static RawTypedData* New(intptr_t class_id, |
| 5095 intptr_t len, | 5107 intptr_t len, |
| 5096 Heap::Space space = Heap::kNew); | 5108 Heap::Space space = Heap::kNew); |
| 5097 | 5109 |
| 5098 static void Copy(const TypedData& dst, | 5110 static void Copy(const TypedData& dst, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 5127 intptr_t Length() const { | 5139 intptr_t Length() const { |
| 5128 ASSERT(!IsNull()); | 5140 ASSERT(!IsNull()); |
| 5129 return Smi::Value(raw_ptr()->length_); | 5141 return Smi::Value(raw_ptr()->length_); |
| 5130 } | 5142 } |
| 5131 | 5143 |
| 5132 intptr_t ElementSizeInBytes() const { | 5144 intptr_t ElementSizeInBytes() const { |
| 5133 intptr_t cid = raw()->GetClassId(); | 5145 intptr_t cid = raw()->GetClassId(); |
| 5134 return ElementSizeInBytes(cid); | 5146 return ElementSizeInBytes(cid); |
| 5135 } | 5147 } |
| 5136 | 5148 |
| 5149 TypeDataElementType ElementType() const { | |
| 5150 intptr_t cid = raw()->GetClassId(); | |
| 5151 return ElementType(cid); | |
| 5152 } | |
| 5153 | |
| 5137 intptr_t LengthInBytes() const { | 5154 intptr_t LengthInBytes() const { |
| 5138 intptr_t cid = raw()->GetClassId(); | 5155 intptr_t cid = raw()->GetClassId(); |
| 5139 return (ElementSizeInBytes(cid) * Length()); | 5156 return (ElementSizeInBytes(cid) * Length()); |
| 5140 } | 5157 } |
| 5141 | 5158 |
| 5142 void* GetPeer() const { | 5159 void* GetPeer() const { |
| 5143 return raw_ptr()->peer_; | 5160 return raw_ptr()->peer_; |
| 5144 } | 5161 } |
| 5145 | 5162 |
| 5146 void* DataAddr(intptr_t byte_offset) const { | 5163 void* DataAddr(intptr_t byte_offset) const { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 5177 static intptr_t data_offset() { | 5194 static intptr_t data_offset() { |
| 5178 return OFFSET_OF(RawExternalTypedData, data_); | 5195 return OFFSET_OF(RawExternalTypedData, data_); |
| 5179 } | 5196 } |
| 5180 | 5197 |
| 5181 static intptr_t InstanceSize() { | 5198 static intptr_t InstanceSize() { |
| 5182 return RoundedAllocationSize(sizeof(RawExternalTypedData)); | 5199 return RoundedAllocationSize(sizeof(RawExternalTypedData)); |
| 5183 } | 5200 } |
| 5184 | 5201 |
| 5185 static intptr_t ElementSizeInBytes(intptr_t class_id) { | 5202 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 5186 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); | 5203 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); |
| 5187 return TypedData::element_size[class_id - kExternalTypedDataInt8ArrayCid]; | 5204 return TypedData::element_size[class_id - kExternalTypedDataInt8ArrayCid]; |
|
siva
2013/04/19 17:38:40
Ditto comment about using the new ElementType
kustermann
2013/04/19 19:21:54
Done.
| |
| 5188 } | 5205 } |
| 5189 | 5206 |
| 5207 static TypeDataElementType ElementType(intptr_t class_id) { | |
| 5208 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); | |
| 5209 return static_cast<TypeDataElementType>( | |
| 5210 class_id - kExternalTypedDataInt8ArrayCid); | |
| 5211 } | |
| 5212 | |
| 5190 static intptr_t MaxElements(intptr_t class_id) { | 5213 static intptr_t MaxElements(intptr_t class_id) { |
| 5191 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); | 5214 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); |
| 5192 return (kSmiMax / ElementSizeInBytes(class_id)); | 5215 return (kSmiMax / ElementSizeInBytes(class_id)); |
| 5193 } | 5216 } |
| 5194 | 5217 |
| 5195 static RawExternalTypedData* New(intptr_t class_id, | 5218 static RawExternalTypedData* New(intptr_t class_id, |
| 5196 uint8_t* data, | 5219 uint8_t* data, |
| 5197 intptr_t len, | 5220 intptr_t len, |
| 5198 Heap::Space space = Heap::kNew); | 5221 Heap::Space space = Heap::kNew); |
| 5199 | 5222 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 5221 void SetPeer(void* peer) const { | 5244 void SetPeer(void* peer) const { |
| 5222 raw_ptr()->peer_ = peer; | 5245 raw_ptr()->peer_ = peer; |
| 5223 } | 5246 } |
| 5224 | 5247 |
| 5225 private: | 5248 private: |
| 5226 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); | 5249 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); |
| 5227 friend class Class; | 5250 friend class Class; |
| 5228 }; | 5251 }; |
| 5229 | 5252 |
| 5230 | 5253 |
| 5254 template <typename DstType, typename SrcType> | |
| 5255 void TypedArrayCopyData(const DstType& dst, intptr_t dst_offset_in_bytes, | |
| 5256 const SrcType& src, intptr_t src_offset_in_bytes, | |
| 5257 intptr_t length_in_bytes) { | |
| 5258 ASSERT(dst.ElementType() == src.ElementType()); | |
| 5259 ASSERT(Utils::RangeCheck(src_offset_in_bytes, | |
| 5260 length_in_bytes, | |
| 5261 src.LengthInBytes())); | |
| 5262 ASSERT(Utils::RangeCheck(dst_offset_in_bytes, | |
| 5263 length_in_bytes, | |
| 5264 dst.LengthInBytes())); | |
| 5265 { | |
| 5266 NoGCScope no_gc; | |
| 5267 if (length_in_bytes > 0) { | |
| 5268 memmove(dst.DataAddr(dst_offset_in_bytes), | |
| 5269 src.DataAddr(src_offset_in_bytes), | |
| 5270 length_in_bytes); | |
| 5271 } | |
| 5272 } | |
| 5273 } | |
|
siva
2013/04/19 17:38:40
Why not make this the static function of class Typ
kustermann
2013/04/19 19:21:54
Done.
| |
| 5274 | |
| 5275 | |
| 5231 class TypedDataView : public AllStatic { | 5276 class TypedDataView : public AllStatic { |
| 5232 public: | 5277 public: |
| 5233 static intptr_t ElementSizeInBytes(const Instance& view_obj) { | 5278 static intptr_t ElementSizeInBytes(const Instance& view_obj) { |
| 5234 ASSERT(!view_obj.IsNull()); | 5279 ASSERT(!view_obj.IsNull()); |
| 5235 intptr_t cid = view_obj.raw()->GetClassId(); | 5280 intptr_t cid = view_obj.raw()->GetClassId(); |
| 5236 return ElementSizeInBytes(cid); | 5281 return ElementSizeInBytes(cid); |
| 5237 } | 5282 } |
| 5238 | 5283 |
| 5239 static RawInstance* Data(const Instance& view_obj) { | 5284 static RawInstance* Data(const Instance& view_obj) { |
| 5240 ASSERT(!view_obj.IsNull()); | 5285 ASSERT(!view_obj.IsNull()); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5656 | 5701 |
| 5657 | 5702 |
| 5658 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 5703 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 5659 intptr_t index) { | 5704 intptr_t index) { |
| 5660 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 5705 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 5661 } | 5706 } |
| 5662 | 5707 |
| 5663 } // namespace dart | 5708 } // namespace dart |
| 5664 | 5709 |
| 5665 #endif // VM_OBJECT_H_ | 5710 #endif // VM_OBJECT_H_ |
| OLD | NEW |