| 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 3231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3242 private: | 3242 private: |
| 3243 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 3243 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); |
| 3244 friend class Class; | 3244 friend class Class; |
| 3245 }; | 3245 }; |
| 3246 | 3246 |
| 3247 | 3247 |
| 3248 class ByteArray : public Instance { | 3248 class ByteArray : public Instance { |
| 3249 public: | 3249 public: |
| 3250 virtual intptr_t Length() const; | 3250 virtual intptr_t Length() const; |
| 3251 | 3251 |
| 3252 static void Copy(uint8_t* dst, |
| 3253 const ByteArray& src, |
| 3254 intptr_t src_offset, |
| 3255 intptr_t length); |
| 3256 |
| 3257 static void Copy(const ByteArray& dst, |
| 3258 intptr_t dst_offset, |
| 3259 const uint8_t* src, |
| 3260 intptr_t length); |
| 3261 |
| 3262 static void Copy(const ByteArray& dst, |
| 3263 intptr_t dst_offset, |
| 3264 const ByteArray& src, |
| 3265 intptr_t src_offset, |
| 3266 intptr_t length); |
| 3267 |
| 3252 private: | 3268 private: |
| 3269 virtual uint8_t* ByteAddr(intptr_t byte_offset) const; |
| 3270 |
| 3253 HEAP_OBJECT_IMPLEMENTATION(ByteArray, Instance); | 3271 HEAP_OBJECT_IMPLEMENTATION(ByteArray, Instance); |
| 3254 friend class Class; | 3272 friend class Class; |
| 3255 }; | 3273 }; |
| 3256 | 3274 |
| 3257 | 3275 |
| 3258 class InternalByteArray : public ByteArray { | 3276 class InternalByteArray : public ByteArray { |
| 3259 public: | 3277 public: |
| 3260 intptr_t Length() const { | 3278 intptr_t Length() const { |
| 3261 ASSERT(!IsNull()); | 3279 ASSERT(!IsNull()); |
| 3262 return Smi::Value(raw_ptr()->length_); | 3280 return Smi::Value(raw_ptr()->length_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3306 return RoundedAllocationSize(sizeof(RawInternalByteArray) + len); | 3324 return RoundedAllocationSize(sizeof(RawInternalByteArray) + len); |
| 3307 } | 3325 } |
| 3308 | 3326 |
| 3309 static RawInternalByteArray* New(intptr_t len, | 3327 static RawInternalByteArray* New(intptr_t len, |
| 3310 Heap::Space space = Heap::kNew); | 3328 Heap::Space space = Heap::kNew); |
| 3311 static RawInternalByteArray* New(const uint8_t* data, | 3329 static RawInternalByteArray* New(const uint8_t* data, |
| 3312 intptr_t len, | 3330 intptr_t len, |
| 3313 Heap::Space space = Heap::kNew); | 3331 Heap::Space space = Heap::kNew); |
| 3314 | 3332 |
| 3315 private: | 3333 private: |
| 3334 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 3335 return Addr<uint8_t>(byte_offset); |
| 3336 } |
| 3337 |
| 3316 template<typename T> | 3338 template<typename T> |
| 3317 T* Addr(intptr_t byte_offset) const { | 3339 T* Addr(intptr_t byte_offset) const { |
| 3318 intptr_t limit = byte_offset + sizeof(T); | 3340 intptr_t limit = byte_offset + sizeof(T); |
| 3319 // TODO(iposva): Determine if we should throw an exception here. | 3341 // TODO(iposva): Determine if we should throw an exception here. |
| 3320 ASSERT((byte_offset >= 0) && (limit <= Length())); | 3342 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 3321 uint8_t* addr = &raw_ptr()->data()[byte_offset]; | 3343 uint8_t* addr = &raw_ptr()->data()[byte_offset]; |
| 3322 return reinterpret_cast<T*>(addr); | 3344 return reinterpret_cast<T*>(addr); |
| 3323 } | 3345 } |
| 3324 | 3346 |
| 3325 void SetLength(intptr_t value) { | 3347 void SetLength(intptr_t value) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3366 | 3388 |
| 3367 static intptr_t InstanceSize() { | 3389 static intptr_t InstanceSize() { |
| 3368 return RoundedAllocationSize(sizeof(RawExternalByteArray)); | 3390 return RoundedAllocationSize(sizeof(RawExternalByteArray)); |
| 3369 } | 3391 } |
| 3370 | 3392 |
| 3371 static RawExternalByteArray* New(uint8_t* data, | 3393 static RawExternalByteArray* New(uint8_t* data, |
| 3372 intptr_t len, | 3394 intptr_t len, |
| 3373 Heap::Space space = Heap::kNew); | 3395 Heap::Space space = Heap::kNew); |
| 3374 | 3396 |
| 3375 private: | 3397 private: |
| 3398 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 3399 return Addr<uint8_t>(byte_offset); |
| 3400 } |
| 3401 |
| 3376 template<typename T> | 3402 template<typename T> |
| 3377 T* Addr(intptr_t byte_offset) const { | 3403 T* Addr(intptr_t byte_offset) const { |
| 3378 intptr_t limit = byte_offset + sizeof(T); | 3404 intptr_t limit = byte_offset + sizeof(T); |
| 3379 // TODO(iposva): Determine if we should throw an exception here. | 3405 // TODO(iposva): Determine if we should throw an exception here. |
| 3380 ASSERT((byte_offset >= 0) && (limit <= Length())); | 3406 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 3381 uint8_t* addr = &raw_ptr()->data_[byte_offset]; | 3407 uint8_t* addr = &raw_ptr()->data_[byte_offset]; |
| 3382 return reinterpret_cast<T*>(addr); | 3408 return reinterpret_cast<T*>(addr); |
| 3383 } | 3409 } |
| 3384 | 3410 |
| 3385 void SetLength(intptr_t value) { | 3411 void SetLength(intptr_t value) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3601 } | 3627 } |
| 3602 | 3628 |
| 3603 | 3629 |
| 3604 void Context::SetAt(intptr_t index, const Instance& value) const { | 3630 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 3605 StorePointer(InstanceAddr(index), value.raw()); | 3631 StorePointer(InstanceAddr(index), value.raw()); |
| 3606 } | 3632 } |
| 3607 | 3633 |
| 3608 } // namespace dart | 3634 } // namespace dart |
| 3609 | 3635 |
| 3610 #endif // VM_OBJECT_H_ | 3636 #endif // VM_OBJECT_H_ |
| OLD | NEW |