| 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 3414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3425 } | 3425 } |
| 3426 void SetFieldAtOffset(intptr_t offset, const Object& value) const { | 3426 void SetFieldAtOffset(intptr_t offset, const Object& value) const { |
| 3427 StorePointer(FieldAddrAtOffset(offset), value.raw()); | 3427 StorePointer(FieldAddrAtOffset(offset), value.raw()); |
| 3428 } | 3428 } |
| 3429 bool IsValidFieldOffset(int offset) const; | 3429 bool IsValidFieldOffset(int offset) const; |
| 3430 | 3430 |
| 3431 // TODO(iposva): Determine if this gets in the way of Smi. | 3431 // TODO(iposva): Determine if this gets in the way of Smi. |
| 3432 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 3432 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
| 3433 friend class Class; | 3433 friend class Class; |
| 3434 friend class Closure; | 3434 friend class Closure; |
| 3435 friend class TypedDataView; |
| 3435 }; | 3436 }; |
| 3436 | 3437 |
| 3437 | 3438 |
| 3438 // AbstractType is an abstract superclass. | 3439 // AbstractType is an abstract superclass. |
| 3439 // Subclasses of AbstractType are Type and TypeParameter. | 3440 // Subclasses of AbstractType are Type and TypeParameter. |
| 3440 class AbstractType : public Instance { | 3441 class AbstractType : public Instance { |
| 3441 public: | 3442 public: |
| 3442 virtual bool IsFinalized() const; | 3443 virtual bool IsFinalized() const; |
| 3443 virtual bool IsBeingFinalized() const; | 3444 virtual bool IsBeingFinalized() const; |
| 3444 virtual bool IsMalformed() const; | 3445 virtual bool IsMalformed() const; |
| (...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5085 static RawTypedData* New(intptr_t class_id, | 5086 static RawTypedData* New(intptr_t class_id, |
| 5086 intptr_t len, | 5087 intptr_t len, |
| 5087 Heap::Space space = Heap::kNew); | 5088 Heap::Space space = Heap::kNew); |
| 5088 | 5089 |
| 5089 static void Copy(const TypedData& dst, | 5090 static void Copy(const TypedData& dst, |
| 5090 intptr_t dst_offset_in_bytes, | 5091 intptr_t dst_offset_in_bytes, |
| 5091 const TypedData& src, | 5092 const TypedData& src, |
| 5092 intptr_t src_offset_in_bytes, | 5093 intptr_t src_offset_in_bytes, |
| 5093 intptr_t length_in_bytes); | 5094 intptr_t length_in_bytes); |
| 5094 | 5095 |
| 5096 static bool IsTypedData(const Instance& obj) { |
| 5097 ASSERT(!obj.IsNull()); |
| 5098 intptr_t cid = obj.raw()->GetClassId(); |
| 5099 return RawObject::IsTypedDataClassId(cid); |
| 5100 } |
| 5101 |
| 5095 protected: | 5102 protected: |
| 5096 void SetLength(intptr_t value) const { | 5103 void SetLength(intptr_t value) const { |
| 5097 raw_ptr()->length_ = Smi::New(value); | 5104 raw_ptr()->length_ = Smi::New(value); |
| 5098 } | 5105 } |
| 5099 | 5106 |
| 5100 private: | 5107 private: |
| 5101 static const intptr_t element_size[]; | 5108 static const intptr_t element_size[]; |
| 5102 | 5109 |
| 5103 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); | 5110 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); |
| 5104 friend class Class; | 5111 friend class Class; |
| 5105 friend class ExternalTypedData; | 5112 friend class ExternalTypedData; |
| 5113 friend class TypedDataView; |
| 5106 }; | 5114 }; |
| 5107 | 5115 |
| 5108 | 5116 |
| 5109 class ExternalTypedData : public Instance { | 5117 class ExternalTypedData : public Instance { |
| 5110 public: | 5118 public: |
| 5111 intptr_t Length() const { | 5119 intptr_t Length() const { |
| 5112 ASSERT(!IsNull()); | 5120 ASSERT(!IsNull()); |
| 5113 return Smi::Value(raw_ptr()->length_); | 5121 return Smi::Value(raw_ptr()->length_); |
| 5114 } | 5122 } |
| 5115 | 5123 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5180 uint8_t* data, | 5188 uint8_t* data, |
| 5181 intptr_t len, | 5189 intptr_t len, |
| 5182 Heap::Space space = Heap::kNew); | 5190 Heap::Space space = Heap::kNew); |
| 5183 | 5191 |
| 5184 static void Copy(const ExternalTypedData& dst, | 5192 static void Copy(const ExternalTypedData& dst, |
| 5185 intptr_t dst_offset_in_bytes, | 5193 intptr_t dst_offset_in_bytes, |
| 5186 const ExternalTypedData& src, | 5194 const ExternalTypedData& src, |
| 5187 intptr_t src_offset_in_bytes, | 5195 intptr_t src_offset_in_bytes, |
| 5188 intptr_t length_in_bytes); | 5196 intptr_t length_in_bytes); |
| 5189 | 5197 |
| 5198 static bool IsExternalTypedData(const Instance& obj) { |
| 5199 ASSERT(!obj.IsNull()); |
| 5200 intptr_t cid = obj.raw()->GetClassId(); |
| 5201 return RawObject::IsExternalTypedDataClassId(cid); |
| 5202 } |
| 5203 |
| 5190 protected: | 5204 protected: |
| 5191 void SetLength(intptr_t value) const { | 5205 void SetLength(intptr_t value) const { |
| 5192 raw_ptr()->length_ = Smi::New(value); | 5206 raw_ptr()->length_ = Smi::New(value); |
| 5193 } | 5207 } |
| 5194 | 5208 |
| 5195 void SetData(uint8_t* data) const { | 5209 void SetData(uint8_t* data) const { |
| 5196 raw_ptr()->data_ = data; | 5210 raw_ptr()->data_ = data; |
| 5197 } | 5211 } |
| 5198 | 5212 |
| 5199 void SetPeer(void* peer) const { | 5213 void SetPeer(void* peer) const { |
| 5200 raw_ptr()->peer_ = peer; | 5214 raw_ptr()->peer_ = peer; |
| 5201 } | 5215 } |
| 5202 | 5216 |
| 5203 private: | 5217 private: |
| 5204 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); | 5218 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); |
| 5205 friend class Class; | 5219 friend class Class; |
| 5206 }; | 5220 }; |
| 5207 | 5221 |
| 5208 | 5222 |
| 5223 class TypedDataView : public AllStatic { |
| 5224 public: |
| 5225 static intptr_t ElementSizeInBytes(const Instance& view_obj) { |
| 5226 ASSERT(!view_obj.IsNull()); |
| 5227 intptr_t cid = view_obj.raw()->GetClassId(); |
| 5228 return ElementSizeInBytes(cid); |
| 5229 } |
| 5230 |
| 5231 static RawInstance* Data(const Instance& view_obj) { |
| 5232 ASSERT(!view_obj.IsNull()); |
| 5233 return *reinterpret_cast<RawInstance**>(view_obj.raw_ptr() + kDataOffset); |
| 5234 } |
| 5235 |
| 5236 static RawSmi* OffsetInBytes(const Instance& view_obj) { |
| 5237 ASSERT(!view_obj.IsNull()); |
| 5238 return *reinterpret_cast<RawSmi**>( |
| 5239 view_obj.raw_ptr() + kOffsetInBytesOffset); |
| 5240 } |
| 5241 |
| 5242 static RawSmi* Length(const Instance& view_obj) { |
| 5243 ASSERT(!view_obj.IsNull()); |
| 5244 return *reinterpret_cast<RawSmi**>(view_obj.raw_ptr() + kLengthOffset); |
| 5245 } |
| 5246 |
| 5247 static bool IsExternalTypedDataView(const Instance& view_obj) { |
| 5248 const Instance& data = Instance::Handle(Data(view_obj)); |
| 5249 intptr_t cid = data.raw()->GetClassId(); |
| 5250 ASSERT(RawObject::IsTypedDataClassId(cid) || |
| 5251 RawObject::IsExternalTypedDataClassId(cid)); |
| 5252 return RawObject::IsExternalTypedDataClassId(cid); |
| 5253 } |
| 5254 |
| 5255 static intptr_t NumberOfFields() { |
| 5256 return (kLengthOffset - kTypeArguments); |
| 5257 } |
| 5258 |
| 5259 static intptr_t data_offset() { |
| 5260 return kWordSize * kDataOffset; |
| 5261 } |
| 5262 |
| 5263 static intptr_t offset_in_bytes_offset() { |
| 5264 return kWordSize * kOffsetInBytesOffset; |
| 5265 } |
| 5266 |
| 5267 static intptr_t length_offset() { |
| 5268 return kWordSize * kLengthOffset; |
| 5269 } |
| 5270 |
| 5271 static intptr_t ElementSizeInBytes(intptr_t class_id) { |
| 5272 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); |
| 5273 return (class_id == kByteDataViewCid) ? |
| 5274 TypedData::element_size[kTypedDataInt8ArrayCid] : |
| 5275 TypedData::element_size[class_id - kTypedDataInt8ArrayViewCid]; |
| 5276 } |
| 5277 |
| 5278 private: |
| 5279 enum { |
| 5280 kTypeArguments = 1, |
| 5281 kDataOffset = 2, |
| 5282 kOffsetInBytesOffset = 3, |
| 5283 kLengthOffset = 4, |
| 5284 }; |
| 5285 }; |
| 5286 |
| 5287 |
| 5209 // DartFunction represents the abstract Dart class 'Function'. | 5288 // DartFunction represents the abstract Dart class 'Function'. |
| 5210 class DartFunction : public Instance { | 5289 class DartFunction : public Instance { |
| 5211 private: | 5290 private: |
| 5212 FINAL_HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); | 5291 FINAL_HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); |
| 5213 friend class Class; | 5292 friend class Class; |
| 5214 friend class Instance; | 5293 friend class Instance; |
| 5215 }; | 5294 }; |
| 5216 | 5295 |
| 5217 | 5296 |
| 5218 class Closure : public AllStatic { | 5297 class Closure : public AllStatic { |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5569 | 5648 |
| 5570 | 5649 |
| 5571 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 5650 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 5572 intptr_t index) { | 5651 intptr_t index) { |
| 5573 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 5652 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 5574 } | 5653 } |
| 5575 | 5654 |
| 5576 } // namespace dart | 5655 } // namespace dart |
| 5577 | 5656 |
| 5578 #endif // VM_OBJECT_H_ | 5657 #endif // VM_OBJECT_H_ |
| OLD | NEW |