| 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 12 matching lines...) Expand all Loading... |
| 23 // Forward declarations. | 23 // Forward declarations. |
| 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
| 25 class clazz; | 25 class clazz; |
| 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
| 27 #undef DEFINE_FORWARD_DECLARATION | 27 #undef DEFINE_FORWARD_DECLARATION |
| 28 class Api; | 28 class Api; |
| 29 class Assembler; | 29 class Assembler; |
| 30 class Closure; | 30 class Closure; |
| 31 class Code; | 31 class Code; |
| 32 class DeoptInstr; | 32 class DeoptInstr; |
| 33 class FinalizablePersistentHandle; |
| 33 class LocalScope; | 34 class LocalScope; |
| 34 class Symbols; | 35 class Symbols; |
| 35 | 36 |
| 36 #if defined(DEBUG) | 37 #if defined(DEBUG) |
| 37 #define CHECK_HANDLE() CheckHandle(); | 38 #define CHECK_HANDLE() CheckHandle(); |
| 38 #else | 39 #else |
| 39 #define CHECK_HANDLE() | 40 #define CHECK_HANDLE() |
| 40 #endif | 41 #endif |
| 41 | 42 |
| 42 #define BASE_OBJECT_IMPLEMENTATION(object, super) \ | 43 #define BASE_OBJECT_IMPLEMENTATION(object, super) \ |
| (...skipping 1845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 Object& obj_; | 1889 Object& obj_; |
| 1889 intptr_t cur_token_pos_; | 1890 intptr_t cur_token_pos_; |
| 1890 Token::Kind cur_token_kind_; | 1891 Token::Kind cur_token_kind_; |
| 1891 intptr_t cur_token_obj_index_; | 1892 intptr_t cur_token_obj_index_; |
| 1892 }; | 1893 }; |
| 1893 | 1894 |
| 1894 private: | 1895 private: |
| 1895 void SetPrivateKey(const String& value) const; | 1896 void SetPrivateKey(const String& value) const; |
| 1896 | 1897 |
| 1897 static RawTokenStream* New(); | 1898 static RawTokenStream* New(); |
| 1898 static void DataFinalizer(void *peer); | 1899 static void DataFinalizer(Dart_Handle handle, void *peer); |
| 1899 | 1900 |
| 1900 FINAL_HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); | 1901 FINAL_HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); |
| 1901 friend class Class; | 1902 friend class Class; |
| 1902 }; | 1903 }; |
| 1903 | 1904 |
| 1904 | 1905 |
| 1905 class Script : public Object { | 1906 class Script : public Object { |
| 1906 public: | 1907 public: |
| 1907 RawString* url() const { return raw_ptr()->url_; } | 1908 RawString* url() const { return raw_ptr()->url_; } |
| 1908 bool HasSource() const; | 1909 bool HasSource() const; |
| (...skipping 2834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4743 ASSERT(!IsNull()); | 4744 ASSERT(!IsNull()); |
| 4744 return Smi::Value(raw_ptr()->length_); | 4745 return Smi::Value(raw_ptr()->length_); |
| 4745 } | 4746 } |
| 4746 | 4747 |
| 4747 static intptr_t length_offset() { | 4748 static intptr_t length_offset() { |
| 4748 return OFFSET_OF(RawByteArray, length_); | 4749 return OFFSET_OF(RawByteArray, length_); |
| 4749 } | 4750 } |
| 4750 | 4751 |
| 4751 virtual intptr_t ByteLength() const; | 4752 virtual intptr_t ByteLength() const; |
| 4752 | 4753 |
| 4754 virtual void* GetPeer() const { return NULL; } |
| 4755 |
| 4756 FinalizablePersistentHandle* AddFinalizer( |
| 4757 void* peer, Dart_WeakPersistentHandleFinalizer callback) const; |
| 4758 |
| 4753 static void Copy(void* dst, | 4759 static void Copy(void* dst, |
| 4754 const ByteArray& src, | 4760 const ByteArray& src, |
| 4755 intptr_t src_offset, | 4761 intptr_t src_offset, |
| 4756 intptr_t length); | 4762 intptr_t length); |
| 4757 | 4763 |
| 4758 static void Copy(const ByteArray& dst, | 4764 static void Copy(const ByteArray& dst, |
| 4759 intptr_t dst_offset, | 4765 intptr_t dst_offset, |
| 4760 const void* src, | 4766 const void* src, |
| 4761 intptr_t length); | 4767 intptr_t length); |
| 4762 | 4768 |
| 4763 static void Copy(const ByteArray& dst, | 4769 static void Copy(const ByteArray& dst, |
| 4764 intptr_t dst_offset, | 4770 intptr_t dst_offset, |
| 4765 const ByteArray& src, | 4771 const ByteArray& src, |
| 4766 intptr_t src_offset, | 4772 intptr_t src_offset, |
| 4767 intptr_t length); | 4773 intptr_t length); |
| 4768 | 4774 |
| 4769 protected: | 4775 protected: |
| 4770 virtual uint8_t* ByteAddr(intptr_t byte_offset) const; | 4776 virtual uint8_t* ByteAddr(intptr_t byte_offset) const; |
| 4777 virtual void SetPeer(void* peer) const { } |
| 4771 | 4778 |
| 4772 template<typename HandleT, typename RawT> | 4779 template<typename HandleT, typename RawT> |
| 4773 static RawT* NewImpl(intptr_t class_id, | 4780 static RawT* NewImpl(intptr_t class_id, |
| 4774 intptr_t len, | 4781 intptr_t len, |
| 4775 Heap::Space space); | 4782 Heap::Space space); |
| 4776 | 4783 |
| 4777 template<typename HandleT, typename RawT, typename ElementT> | 4784 template<typename HandleT, typename RawT, typename ElementT> |
| 4778 static RawT* NewImpl(intptr_t class_id, | 4785 static RawT* NewImpl(intptr_t class_id, |
| 4779 const ElementT* data, | 4786 const ElementT* data, |
| 4780 intptr_t len, | 4787 intptr_t len, |
| 4781 Heap::Space space); | 4788 Heap::Space space); |
| 4782 | 4789 |
| 4783 template<typename HandleT, typename RawT, typename ElementT> | 4790 template<typename HandleT, typename RawT, typename ElementT> |
| 4784 static RawT* NewExternalImpl(intptr_t class_id, | 4791 static RawT* NewExternalImpl(intptr_t class_id, |
| 4785 ElementT* data, | 4792 ElementT* data, |
| 4786 intptr_t len, | 4793 intptr_t len, |
| 4787 void* peer, | |
| 4788 Dart_PeerFinalizer callback, | |
| 4789 Heap::Space space); | 4794 Heap::Space space); |
| 4790 | 4795 |
| 4791 template<typename HandleT, typename RawT, typename ElementT> | 4796 template<typename HandleT, typename RawT, typename ElementT> |
| 4792 static RawT* ReadFromImpl(SnapshotReader* reader, | 4797 static RawT* ReadFromImpl(SnapshotReader* reader, |
| 4793 intptr_t object_id, | 4798 intptr_t object_id, |
| 4794 intptr_t tags, | 4799 intptr_t tags, |
| 4795 Snapshot::Kind kind); | 4800 Snapshot::Kind kind); |
| 4796 | 4801 |
| 4797 void SetLength(intptr_t value) const { | 4802 void SetLength(intptr_t value) const { |
| 4798 raw_ptr()->length_ = Smi::New(value); | 4803 raw_ptr()->length_ = Smi::New(value); |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5378 | 5383 |
| 5379 | 5384 |
| 5380 class ExternalInt8Array : public ByteArray { | 5385 class ExternalInt8Array : public ByteArray { |
| 5381 public: | 5386 public: |
| 5382 intptr_t ByteLength() const { | 5387 intptr_t ByteLength() const { |
| 5383 return Length() * kBytesPerElement; | 5388 return Length() * kBytesPerElement; |
| 5384 } | 5389 } |
| 5385 | 5390 |
| 5386 int8_t At(intptr_t index) const { | 5391 int8_t At(intptr_t index) const { |
| 5387 ASSERT((index >= 0) && (index < Length())); | 5392 ASSERT((index >= 0) && (index < Length())); |
| 5388 return raw_ptr()->external_data_->data()[index]; | 5393 return raw_ptr()->data_[index]; |
| 5389 } | 5394 } |
| 5390 | 5395 |
| 5391 void SetAt(intptr_t index, int8_t value) const { | 5396 void SetAt(intptr_t index, int8_t value) const { |
| 5392 ASSERT((index >= 0) && (index < Length())); | 5397 ASSERT((index >= 0) && (index < Length())); |
| 5393 raw_ptr()->external_data_->data()[index] = value; | 5398 raw_ptr()->data_[index] = value; |
| 5394 } | 5399 } |
| 5395 | 5400 |
| 5396 void* GetData() const { | 5401 int8_t* GetData() const { |
| 5397 return raw_ptr()->external_data_->data(); | 5402 return raw_ptr()->data_; |
| 5398 } | 5403 } |
| 5399 | 5404 |
| 5400 void* GetPeer() const { | 5405 void* GetPeer() const { |
| 5401 return raw_ptr()->external_data_->peer(); | 5406 return raw_ptr()->peer_; |
| 5402 } | 5407 } |
| 5403 | 5408 |
| 5404 static const intptr_t kBytesPerElement = 1; | 5409 static const intptr_t kBytesPerElement = 1; |
| 5405 | 5410 |
| 5406 // Since external arrays may be serialized to non-external ones, | 5411 // Since external arrays may be serialized to non-external ones, |
| 5407 // enforce the same maximum element count. | 5412 // enforce the same maximum element count. |
| 5408 static const intptr_t kMaxElements = Int8Array::kMaxElements; | 5413 static const intptr_t kMaxElements = Int8Array::kMaxElements; |
| 5409 | 5414 |
| 5410 static intptr_t InstanceSize() { | 5415 static intptr_t InstanceSize() { |
| 5411 return RoundedAllocationSize(sizeof(RawExternalInt8Array)); | 5416 return RoundedAllocationSize(sizeof(RawExternalInt8Array)); |
| 5412 } | 5417 } |
| 5413 | 5418 |
| 5419 static intptr_t data_offset() { |
| 5420 return OFFSET_OF(RawExternalInt8Array, data_); |
| 5421 } |
| 5422 |
| 5414 static RawExternalInt8Array* New(int8_t* data, | 5423 static RawExternalInt8Array* New(int8_t* data, |
| 5415 intptr_t len, | 5424 intptr_t len, |
| 5416 void* peer, | |
| 5417 Dart_PeerFinalizer callback, | |
| 5418 Heap::Space space = Heap::kNew); | 5425 Heap::Space space = Heap::kNew); |
| 5419 | 5426 |
| 5420 private: | 5427 private: |
| 5421 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5428 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5422 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5429 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5423 uint8_t* data = | 5430 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5424 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5425 return data + byte_offset; | 5431 return data + byte_offset; |
| 5426 } | 5432 } |
| 5427 | 5433 |
| 5428 void SetExternalData(ExternalByteArrayData<int8_t>* data) { | 5434 void SetData(int8_t* data) const { |
| 5429 raw_ptr()->external_data_ = data; | 5435 raw_ptr()->data_ = data; |
| 5436 } |
| 5437 |
| 5438 void SetPeer(void* peer) const { |
| 5439 raw_ptr()->peer_ = peer; |
| 5430 } | 5440 } |
| 5431 | 5441 |
| 5432 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt8Array, ByteArray); | 5442 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt8Array, ByteArray); |
| 5433 friend class ByteArray; | 5443 friend class ByteArray; |
| 5434 friend class Class; | 5444 friend class Class; |
| 5435 }; | 5445 }; |
| 5436 | 5446 |
| 5437 | 5447 |
| 5438 class ExternalUint8Array : public ByteArray { | 5448 class ExternalUint8Array : public ByteArray { |
| 5439 public: | 5449 public: |
| 5440 intptr_t ByteLength() const { | 5450 intptr_t ByteLength() const { |
| 5441 return Length() * kBytesPerElement; | 5451 return Length() * kBytesPerElement; |
| 5442 } | 5452 } |
| 5443 | 5453 |
| 5444 uint8_t At(intptr_t index) const { | 5454 uint8_t At(intptr_t index) const { |
| 5445 ASSERT((index >= 0) && (index < Length())); | 5455 ASSERT((index >= 0) && (index < Length())); |
| 5446 return raw_ptr()->external_data_->data()[index]; | 5456 return raw_ptr()->data_[index]; |
| 5447 } | 5457 } |
| 5448 | 5458 |
| 5449 void SetAt(intptr_t index, uint8_t value) const { | 5459 void SetAt(intptr_t index, uint8_t value) const { |
| 5450 ASSERT((index >= 0) && (index < Length())); | 5460 ASSERT((index >= 0) && (index < Length())); |
| 5451 raw_ptr()->external_data_->data()[index] = value; | 5461 raw_ptr()->data_[index] = value; |
| 5452 } | 5462 } |
| 5453 | 5463 |
| 5454 void* GetData() const { | 5464 uint8_t* GetData() const { |
| 5455 return raw_ptr()->external_data_->data(); | 5465 return raw_ptr()->data_; |
| 5456 } | 5466 } |
| 5457 | 5467 |
| 5458 void* GetPeer() const { | 5468 void* GetPeer() const { |
| 5459 return raw_ptr()->external_data_->peer(); | 5469 return raw_ptr()->peer_; |
| 5460 } | 5470 } |
| 5461 | 5471 |
| 5462 static const intptr_t kBytesPerElement = 1; | 5472 static const intptr_t kBytesPerElement = 1; |
| 5463 | 5473 |
| 5464 // Since external arrays may be serialized to non-external ones, | 5474 // Since external arrays may be serialized to non-external ones, |
| 5465 // enforce the same maximum element count. | 5475 // enforce the same maximum element count. |
| 5466 static const intptr_t kMaxElements = Uint8Array::kMaxElements; | 5476 static const intptr_t kMaxElements = Uint8Array::kMaxElements; |
| 5467 | 5477 |
| 5468 static intptr_t InstanceSize() { | 5478 static intptr_t InstanceSize() { |
| 5469 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); | 5479 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); |
| 5470 } | 5480 } |
| 5471 | 5481 |
| 5472 static intptr_t external_data_offset() { | 5482 static intptr_t data_offset() { |
| 5473 return OFFSET_OF(RawExternalUint8Array, external_data_); | 5483 return OFFSET_OF(RawExternalUint8Array, data_); |
| 5474 } | 5484 } |
| 5475 | 5485 |
| 5476 static RawExternalUint8Array* New(uint8_t* data, | 5486 static RawExternalUint8Array* New(uint8_t* data, |
| 5477 intptr_t len, | 5487 intptr_t len, |
| 5478 void* peer, | |
| 5479 Dart_PeerFinalizer callback, | |
| 5480 Heap::Space space = Heap::kNew); | 5488 Heap::Space space = Heap::kNew); |
| 5481 | 5489 |
| 5482 private: | 5490 private: |
| 5483 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5491 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5484 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5492 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5485 uint8_t* data = | 5493 uint8_t* data = |
| 5486 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 5494 reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5487 return data + byte_offset; | 5495 return data + byte_offset; |
| 5488 } | 5496 } |
| 5489 | 5497 |
| 5490 void SetExternalData(ExternalByteArrayData<uint8_t>* data) { | 5498 void SetData(uint8_t* data) const { |
| 5491 raw_ptr()->external_data_ = data; | 5499 raw_ptr()->data_ = data; |
| 5500 } |
| 5501 |
| 5502 void SetPeer(void* peer) const { |
| 5503 raw_ptr()->peer_ = peer; |
| 5492 } | 5504 } |
| 5493 | 5505 |
| 5494 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray); | 5506 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray); |
| 5495 friend class ByteArray; | 5507 friend class ByteArray; |
| 5496 friend class Class; | 5508 friend class Class; |
| 5497 friend class TokenStream; | 5509 friend class TokenStream; |
| 5498 }; | 5510 }; |
| 5499 | 5511 |
| 5500 | 5512 |
| 5501 class ExternalUint8ClampedArray : public ExternalUint8Array { | 5513 class ExternalUint8ClampedArray : public ExternalUint8Array { |
| 5502 public: | 5514 public: |
| 5503 static RawExternalUint8ClampedArray* New(uint8_t* data, | 5515 static RawExternalUint8ClampedArray* New(uint8_t* data, |
| 5504 intptr_t len, | 5516 intptr_t len, |
| 5505 void* peer, | |
| 5506 Dart_PeerFinalizer callback, | |
| 5507 Heap::Space space = Heap::kNew); | 5517 Heap::Space space = Heap::kNew); |
| 5508 | 5518 |
| 5509 private: | 5519 private: |
| 5510 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint8ClampedArray, | 5520 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint8ClampedArray, |
| 5511 ExternalUint8Array); | 5521 ExternalUint8Array); |
| 5512 friend class Class; | 5522 friend class Class; |
| 5513 }; | 5523 }; |
| 5514 | 5524 |
| 5515 | 5525 |
| 5516 class ExternalInt16Array : public ByteArray { | 5526 class ExternalInt16Array : public ByteArray { |
| 5517 public: | 5527 public: |
| 5518 intptr_t ByteLength() const { | 5528 intptr_t ByteLength() const { |
| 5519 return Length() * kBytesPerElement; | 5529 return Length() * kBytesPerElement; |
| 5520 } | 5530 } |
| 5521 | 5531 |
| 5522 int16_t At(intptr_t index) const { | 5532 int16_t At(intptr_t index) const { |
| 5523 ASSERT((index >= 0) && (index < Length())); | 5533 ASSERT((index >= 0) && (index < Length())); |
| 5524 return raw_ptr()->external_data_->data()[index]; | 5534 return raw_ptr()->data_[index]; |
| 5525 } | 5535 } |
| 5526 | 5536 |
| 5527 void SetAt(intptr_t index, int16_t value) const { | 5537 void SetAt(intptr_t index, int16_t value) const { |
| 5528 ASSERT((index >= 0) && (index < Length())); | 5538 ASSERT((index >= 0) && (index < Length())); |
| 5529 raw_ptr()->external_data_->data()[index] = value; | 5539 raw_ptr()->data_[index] = value; |
| 5530 } | 5540 } |
| 5531 | 5541 |
| 5532 void* GetData() const { | 5542 int16_t* GetData() const { |
| 5533 return raw_ptr()->external_data_->data(); | 5543 return raw_ptr()->data_; |
| 5534 } | 5544 } |
| 5535 | 5545 |
| 5536 void* GetPeer() const { | 5546 void* GetPeer() const { |
| 5537 return raw_ptr()->external_data_->peer(); | 5547 return raw_ptr()->peer_; |
| 5538 } | 5548 } |
| 5539 | 5549 |
| 5540 static const intptr_t kBytesPerElement = 2; | 5550 static const intptr_t kBytesPerElement = 2; |
| 5541 | 5551 |
| 5542 // Since external arrays may be serialized to non-external ones, | 5552 // Since external arrays may be serialized to non-external ones, |
| 5543 // enforce the same maximum element count. | 5553 // enforce the same maximum element count. |
| 5544 static const intptr_t kMaxElements = Int16Array::kMaxElements; | 5554 static const intptr_t kMaxElements = Int16Array::kMaxElements; |
| 5545 | 5555 |
| 5546 static intptr_t InstanceSize() { | 5556 static intptr_t InstanceSize() { |
| 5547 return RoundedAllocationSize(sizeof(RawExternalInt16Array)); | 5557 return RoundedAllocationSize(sizeof(RawExternalInt16Array)); |
| 5548 } | 5558 } |
| 5549 | 5559 |
| 5550 static RawExternalInt16Array* New(int16_t* data, | 5560 static RawExternalInt16Array* New(int16_t* data, |
| 5551 intptr_t len, | 5561 intptr_t len, |
| 5552 void* peer, | |
| 5553 Dart_PeerFinalizer callback, | |
| 5554 Heap::Space space = Heap::kNew); | 5562 Heap::Space space = Heap::kNew); |
| 5555 | 5563 |
| 5556 private: | 5564 private: |
| 5557 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5565 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5558 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5566 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5559 uint8_t* data = | 5567 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5560 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5561 return data + byte_offset; | 5568 return data + byte_offset; |
| 5562 } | 5569 } |
| 5563 | 5570 |
| 5564 void SetExternalData(ExternalByteArrayData<int16_t>* data) { | 5571 void SetData(int16_t* data) const { |
| 5565 raw_ptr()->external_data_ = data; | 5572 raw_ptr()->data_ = data; |
| 5573 } |
| 5574 |
| 5575 void SetPeer(void* peer) const { |
| 5576 raw_ptr()->peer_ = peer; |
| 5566 } | 5577 } |
| 5567 | 5578 |
| 5568 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt16Array, ByteArray); | 5579 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt16Array, ByteArray); |
| 5569 friend class ByteArray; | 5580 friend class ByteArray; |
| 5570 friend class Class; | 5581 friend class Class; |
| 5571 }; | 5582 }; |
| 5572 | 5583 |
| 5573 | 5584 |
| 5574 class ExternalUint16Array : public ByteArray { | 5585 class ExternalUint16Array : public ByteArray { |
| 5575 public: | 5586 public: |
| 5576 intptr_t ByteLength() const { | 5587 intptr_t ByteLength() const { |
| 5577 return Length() * kBytesPerElement; | 5588 return Length() * kBytesPerElement; |
| 5578 } | 5589 } |
| 5579 | 5590 |
| 5580 int16_t At(intptr_t index) const { | 5591 int16_t At(intptr_t index) const { |
| 5581 ASSERT((index >= 0) && (index < Length())); | 5592 ASSERT((index >= 0) && (index < Length())); |
| 5582 return raw_ptr()->external_data_->data()[index]; | 5593 return raw_ptr()->data_[index]; |
| 5583 } | 5594 } |
| 5584 | 5595 |
| 5585 void SetAt(intptr_t index, int16_t value) const { | 5596 void SetAt(intptr_t index, int16_t value) const { |
| 5586 ASSERT((index >= 0) && (index < Length())); | 5597 ASSERT((index >= 0) && (index < Length())); |
| 5587 raw_ptr()->external_data_->data()[index] = value; | 5598 raw_ptr()->data_[index] = value; |
| 5588 } | 5599 } |
| 5589 | 5600 |
| 5590 void* GetData() const { | 5601 uint16_t* GetData() const { |
| 5591 return raw_ptr()->external_data_->data(); | 5602 return raw_ptr()->data_; |
| 5592 } | 5603 } |
| 5593 | 5604 |
| 5594 void* GetPeer() const { | 5605 void* GetPeer() const { |
| 5595 return raw_ptr()->external_data_->peer(); | 5606 return raw_ptr()->peer_; |
| 5596 } | 5607 } |
| 5597 | 5608 |
| 5598 static const intptr_t kBytesPerElement = 2; | 5609 static const intptr_t kBytesPerElement = 2; |
| 5599 | 5610 |
| 5600 // Since external arrays may be serialized to non-external ones, | 5611 // Since external arrays may be serialized to non-external ones, |
| 5601 // enforce the same maximum element count. | 5612 // enforce the same maximum element count. |
| 5602 static const intptr_t kMaxElements = Uint16Array::kMaxElements; | 5613 static const intptr_t kMaxElements = Uint16Array::kMaxElements; |
| 5603 | 5614 |
| 5604 static intptr_t InstanceSize() { | 5615 static intptr_t InstanceSize() { |
| 5605 return RoundedAllocationSize(sizeof(RawExternalUint16Array)); | 5616 return RoundedAllocationSize(sizeof(RawExternalUint16Array)); |
| 5606 } | 5617 } |
| 5607 | 5618 |
| 5608 static RawExternalUint16Array* New(uint16_t* data, | 5619 static RawExternalUint16Array* New(uint16_t* data, |
| 5609 intptr_t len, | 5620 intptr_t len, |
| 5610 void* peer, | |
| 5611 Dart_PeerFinalizer callback, | |
| 5612 Heap::Space space = Heap::kNew); | 5621 Heap::Space space = Heap::kNew); |
| 5613 | 5622 |
| 5614 private: | 5623 private: |
| 5615 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5624 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5616 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5625 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5617 uint8_t* data = | 5626 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5618 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5619 return data + byte_offset; | 5627 return data + byte_offset; |
| 5620 } | 5628 } |
| 5621 | 5629 |
| 5622 void SetExternalData(ExternalByteArrayData<uint16_t>* data) { | 5630 void SetData(uint16_t* data) const { |
| 5623 raw_ptr()->external_data_ = data; | 5631 raw_ptr()->data_ = data; |
| 5632 } |
| 5633 |
| 5634 void SetPeer(void* peer) const { |
| 5635 raw_ptr()->peer_ = peer; |
| 5624 } | 5636 } |
| 5625 | 5637 |
| 5626 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint16Array, ByteArray); | 5638 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint16Array, ByteArray); |
| 5627 friend class ByteArray; | 5639 friend class ByteArray; |
| 5628 friend class Class; | 5640 friend class Class; |
| 5629 }; | 5641 }; |
| 5630 | 5642 |
| 5631 | 5643 |
| 5632 class ExternalInt32Array : public ByteArray { | 5644 class ExternalInt32Array : public ByteArray { |
| 5633 public: | 5645 public: |
| 5634 intptr_t ByteLength() const { | 5646 intptr_t ByteLength() const { |
| 5635 return Length() * kBytesPerElement; | 5647 return Length() * kBytesPerElement; |
| 5636 } | 5648 } |
| 5637 | 5649 |
| 5638 int32_t At(intptr_t index) const { | 5650 int32_t At(intptr_t index) const { |
| 5639 ASSERT((index >= 0) && (index < Length())); | 5651 ASSERT((index >= 0) && (index < Length())); |
| 5640 return raw_ptr()->external_data_->data()[index]; | 5652 return raw_ptr()->data_[index]; |
| 5641 } | 5653 } |
| 5642 | 5654 |
| 5643 void SetAt(intptr_t index, int32_t value) const { | 5655 void SetAt(intptr_t index, int32_t value) const { |
| 5644 ASSERT((index >= 0) && (index < Length())); | 5656 ASSERT((index >= 0) && (index < Length())); |
| 5645 raw_ptr()->external_data_->data()[index] = value; | 5657 raw_ptr()->data_[index] = value; |
| 5646 } | 5658 } |
| 5647 | 5659 |
| 5648 void* GetData() const { | 5660 int32_t* GetData() const { |
| 5649 return raw_ptr()->external_data_->data(); | 5661 return raw_ptr()->data_; |
| 5650 } | 5662 } |
| 5651 | 5663 |
| 5652 void* GetPeer() const { | 5664 void* GetPeer() const { |
| 5653 return raw_ptr()->external_data_->peer(); | 5665 return raw_ptr()->peer_; |
| 5654 } | 5666 } |
| 5655 | 5667 |
| 5656 static const intptr_t kBytesPerElement = 4; | 5668 static const intptr_t kBytesPerElement = 4; |
| 5657 | 5669 |
| 5658 // Since external arrays may be serialized to non-external ones, | 5670 // Since external arrays may be serialized to non-external ones, |
| 5659 // enforce the same maximum element count. | 5671 // enforce the same maximum element count. |
| 5660 static const intptr_t kMaxElements = Int32Array::kMaxElements; | 5672 static const intptr_t kMaxElements = Int32Array::kMaxElements; |
| 5661 | 5673 |
| 5662 static intptr_t InstanceSize() { | 5674 static intptr_t InstanceSize() { |
| 5663 return RoundedAllocationSize(sizeof(RawExternalInt32Array)); | 5675 return RoundedAllocationSize(sizeof(RawExternalInt32Array)); |
| 5664 } | 5676 } |
| 5665 | 5677 |
| 5666 static RawExternalInt32Array* New(int32_t* data, | 5678 static RawExternalInt32Array* New(int32_t* data, |
| 5667 intptr_t len, | 5679 intptr_t len, |
| 5668 void* peer, | |
| 5669 Dart_PeerFinalizer callback, | |
| 5670 Heap::Space space = Heap::kNew); | 5680 Heap::Space space = Heap::kNew); |
| 5671 | 5681 |
| 5672 private: | 5682 private: |
| 5673 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5683 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5674 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5684 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5675 uint8_t* data = | 5685 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5676 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5677 return data + byte_offset; | 5686 return data + byte_offset; |
| 5678 } | 5687 } |
| 5679 | 5688 |
| 5680 void SetExternalData(ExternalByteArrayData<int32_t>* data) { | 5689 void SetData(int32_t* data) const { |
| 5681 raw_ptr()->external_data_ = data; | 5690 raw_ptr()->data_ = data; |
| 5691 } |
| 5692 |
| 5693 void SetPeer(void* peer) const { |
| 5694 raw_ptr()->peer_ = peer; |
| 5682 } | 5695 } |
| 5683 | 5696 |
| 5684 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt32Array, ByteArray); | 5697 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt32Array, ByteArray); |
| 5685 friend class ByteArray; | 5698 friend class ByteArray; |
| 5686 friend class Class; | 5699 friend class Class; |
| 5687 }; | 5700 }; |
| 5688 | 5701 |
| 5689 | 5702 |
| 5690 class ExternalUint32Array : public ByteArray { | 5703 class ExternalUint32Array : public ByteArray { |
| 5691 public: | 5704 public: |
| 5692 intptr_t ByteLength() const { | 5705 intptr_t ByteLength() const { |
| 5693 return Length() * kBytesPerElement; | 5706 return Length() * kBytesPerElement; |
| 5694 } | 5707 } |
| 5695 | 5708 |
| 5696 int32_t At(intptr_t index) const { | 5709 int32_t At(intptr_t index) const { |
| 5697 ASSERT((index >= 0) && (index < Length())); | 5710 ASSERT((index >= 0) && (index < Length())); |
| 5698 return raw_ptr()->external_data_->data()[index]; | 5711 return raw_ptr()->data_[index]; |
| 5699 } | 5712 } |
| 5700 | 5713 |
| 5701 void SetAt(intptr_t index, int32_t value) const { | 5714 void SetAt(intptr_t index, int32_t value) const { |
| 5702 ASSERT((index >= 0) && (index < Length())); | 5715 ASSERT((index >= 0) && (index < Length())); |
| 5703 raw_ptr()->external_data_->data()[index] = value; | 5716 raw_ptr()->data_[index] = value; |
| 5704 } | 5717 } |
| 5705 | 5718 |
| 5706 void* GetData() const { | 5719 uint32_t* GetData() const { |
| 5707 return raw_ptr()->external_data_->data(); | 5720 return raw_ptr()->data_; |
| 5708 } | 5721 } |
| 5709 | 5722 |
| 5710 void* GetPeer() const { | 5723 void* GetPeer() const { |
| 5711 return raw_ptr()->external_data_->peer(); | 5724 return raw_ptr()->peer_; |
| 5712 } | 5725 } |
| 5713 | 5726 |
| 5714 static const intptr_t kBytesPerElement = 4; | 5727 static const intptr_t kBytesPerElement = 4; |
| 5715 | 5728 |
| 5716 // Since external arrays may be serialized to non-external ones, | 5729 // Since external arrays may be serialized to non-external ones, |
| 5717 // enforce the same maximum element count. | 5730 // enforce the same maximum element count. |
| 5718 static const intptr_t kMaxElements = Uint32Array::kMaxElements; | 5731 static const intptr_t kMaxElements = Uint32Array::kMaxElements; |
| 5719 | 5732 |
| 5720 static intptr_t InstanceSize() { | 5733 static intptr_t InstanceSize() { |
| 5721 return RoundedAllocationSize(sizeof(RawExternalUint32Array)); | 5734 return RoundedAllocationSize(sizeof(RawExternalUint32Array)); |
| 5722 } | 5735 } |
| 5723 | 5736 |
| 5724 static RawExternalUint32Array* New(uint32_t* data, | 5737 static RawExternalUint32Array* New(uint32_t* data, |
| 5725 intptr_t len, | 5738 intptr_t len, |
| 5726 void* peer, | |
| 5727 Dart_PeerFinalizer callback, | |
| 5728 Heap::Space space = Heap::kNew); | 5739 Heap::Space space = Heap::kNew); |
| 5729 | 5740 |
| 5730 private: | 5741 private: |
| 5731 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5742 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5732 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5743 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5733 uint8_t* data = | 5744 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5734 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5735 return data + byte_offset; | 5745 return data + byte_offset; |
| 5736 } | 5746 } |
| 5737 | 5747 |
| 5738 void SetExternalData(ExternalByteArrayData<uint32_t>* data) { | 5748 void SetData(uint32_t* data) const { |
| 5739 raw_ptr()->external_data_ = data; | 5749 raw_ptr()->data_ = data; |
| 5750 } |
| 5751 |
| 5752 void SetPeer(void* peer) const { |
| 5753 raw_ptr()->peer_ = peer; |
| 5740 } | 5754 } |
| 5741 | 5755 |
| 5742 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint32Array, ByteArray); | 5756 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint32Array, ByteArray); |
| 5743 friend class ByteArray; | 5757 friend class ByteArray; |
| 5744 friend class Class; | 5758 friend class Class; |
| 5745 }; | 5759 }; |
| 5746 | 5760 |
| 5747 | 5761 |
| 5748 class ExternalInt64Array : public ByteArray { | 5762 class ExternalInt64Array : public ByteArray { |
| 5749 public: | 5763 public: |
| 5750 intptr_t ByteLength() const { | 5764 intptr_t ByteLength() const { |
| 5751 return Length() * kBytesPerElement; | 5765 return Length() * kBytesPerElement; |
| 5752 } | 5766 } |
| 5753 | 5767 |
| 5754 int64_t At(intptr_t index) const { | 5768 int64_t At(intptr_t index) const { |
| 5755 ASSERT((index >= 0) && (index < Length())); | 5769 ASSERT((index >= 0) && (index < Length())); |
| 5756 return raw_ptr()->external_data_->data()[index]; | 5770 return raw_ptr()->data_[index]; |
| 5757 } | 5771 } |
| 5758 | 5772 |
| 5759 void SetAt(intptr_t index, int64_t value) const { | 5773 void SetAt(intptr_t index, int64_t value) const { |
| 5760 ASSERT((index >= 0) && (index < Length())); | 5774 ASSERT((index >= 0) && (index < Length())); |
| 5761 raw_ptr()->external_data_->data()[index] = value; | 5775 raw_ptr()->data_[index] = value; |
| 5762 } | 5776 } |
| 5763 | 5777 |
| 5764 void* GetData() const { | 5778 int64_t* GetData() const { |
| 5765 return raw_ptr()->external_data_->data(); | 5779 return raw_ptr()->data_; |
| 5766 } | 5780 } |
| 5767 | 5781 |
| 5768 void* GetPeer() const { | 5782 void* GetPeer() const { |
| 5769 return raw_ptr()->external_data_->peer(); | 5783 return raw_ptr()->peer_; |
| 5770 } | 5784 } |
| 5771 | 5785 |
| 5772 static const intptr_t kBytesPerElement = 8; | 5786 static const intptr_t kBytesPerElement = 8; |
| 5773 | 5787 |
| 5774 // Since external arrays may be serialized to non-external ones, | 5788 // Since external arrays may be serialized to non-external ones, |
| 5775 // enforce the same maximum element count. | 5789 // enforce the same maximum element count. |
| 5776 static const intptr_t kMaxElements = Int64Array::kMaxElements; | 5790 static const intptr_t kMaxElements = Int64Array::kMaxElements; |
| 5777 | 5791 |
| 5778 static intptr_t InstanceSize() { | 5792 static intptr_t InstanceSize() { |
| 5779 return RoundedAllocationSize(sizeof(RawExternalInt64Array)); | 5793 return RoundedAllocationSize(sizeof(RawExternalInt64Array)); |
| 5780 } | 5794 } |
| 5781 | 5795 |
| 5782 static RawExternalInt64Array* New(int64_t* data, | 5796 static RawExternalInt64Array* New(int64_t* data, |
| 5783 intptr_t len, | 5797 intptr_t len, |
| 5784 void* peer, | |
| 5785 Dart_PeerFinalizer callback, | |
| 5786 Heap::Space space = Heap::kNew); | 5798 Heap::Space space = Heap::kNew); |
| 5787 | 5799 |
| 5788 private: | 5800 private: |
| 5789 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5801 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5790 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5802 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5791 uint8_t* data = | 5803 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5792 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5793 return data + byte_offset; | 5804 return data + byte_offset; |
| 5794 } | 5805 } |
| 5795 | 5806 |
| 5796 void SetExternalData(ExternalByteArrayData<int64_t>* data) { | 5807 void SetData(int64_t* data) const { |
| 5797 raw_ptr()->external_data_ = data; | 5808 raw_ptr()->data_ = data; |
| 5809 } |
| 5810 |
| 5811 void SetPeer(void* peer) const { |
| 5812 raw_ptr()->peer_ = peer; |
| 5798 } | 5813 } |
| 5799 | 5814 |
| 5800 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt64Array, ByteArray); | 5815 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt64Array, ByteArray); |
| 5801 friend class ByteArray; | 5816 friend class ByteArray; |
| 5802 friend class Class; | 5817 friend class Class; |
| 5803 }; | 5818 }; |
| 5804 | 5819 |
| 5805 | 5820 |
| 5806 class ExternalUint64Array : public ByteArray { | 5821 class ExternalUint64Array : public ByteArray { |
| 5807 public: | 5822 public: |
| 5808 intptr_t ByteLength() const { | 5823 intptr_t ByteLength() const { |
| 5809 return Length() * kBytesPerElement; | 5824 return Length() * kBytesPerElement; |
| 5810 } | 5825 } |
| 5811 | 5826 |
| 5812 int64_t At(intptr_t index) const { | 5827 int64_t At(intptr_t index) const { |
| 5813 ASSERT((index >= 0) && (index < Length())); | 5828 ASSERT((index >= 0) && (index < Length())); |
| 5814 return raw_ptr()->external_data_->data()[index]; | 5829 return raw_ptr()->data_[index]; |
| 5815 } | 5830 } |
| 5816 | 5831 |
| 5817 void SetAt(intptr_t index, int64_t value) const { | 5832 void SetAt(intptr_t index, int64_t value) const { |
| 5818 ASSERT((index >= 0) && (index < Length())); | 5833 ASSERT((index >= 0) && (index < Length())); |
| 5819 raw_ptr()->external_data_->data()[index] = value; | 5834 raw_ptr()->data_[index] = value; |
| 5820 } | 5835 } |
| 5821 | 5836 |
| 5822 void* GetData() const { | 5837 uint64_t* GetData() const { |
| 5823 return raw_ptr()->external_data_->data(); | 5838 return raw_ptr()->data_; |
| 5824 } | 5839 } |
| 5825 | 5840 |
| 5826 void* GetPeer() const { | 5841 void* GetPeer() const { |
| 5827 return raw_ptr()->external_data_->peer(); | 5842 return raw_ptr()->peer_; |
| 5828 } | 5843 } |
| 5829 | 5844 |
| 5830 static const intptr_t kBytesPerElement = 8; | 5845 static const intptr_t kBytesPerElement = 8; |
| 5831 | 5846 |
| 5832 // Since external arrays may be serialized to non-external ones, | 5847 // Since external arrays may be serialized to non-external ones, |
| 5833 // enforce the same maximum element count. | 5848 // enforce the same maximum element count. |
| 5834 static const intptr_t kMaxElements = Uint64Array::kMaxElements; | 5849 static const intptr_t kMaxElements = Uint64Array::kMaxElements; |
| 5835 | 5850 |
| 5836 static intptr_t InstanceSize() { | 5851 static intptr_t InstanceSize() { |
| 5837 return RoundedAllocationSize(sizeof(RawExternalUint64Array)); | 5852 return RoundedAllocationSize(sizeof(RawExternalUint64Array)); |
| 5838 } | 5853 } |
| 5839 | 5854 |
| 5840 static RawExternalUint64Array* New(uint64_t* data, | 5855 static RawExternalUint64Array* New(uint64_t* data, |
| 5841 intptr_t len, | 5856 intptr_t len, |
| 5842 void* peer, | |
| 5843 Dart_PeerFinalizer callback, | |
| 5844 Heap::Space space = Heap::kNew); | 5857 Heap::Space space = Heap::kNew); |
| 5845 | 5858 |
| 5846 private: | 5859 private: |
| 5847 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5860 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5848 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5861 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5849 uint8_t* data = | 5862 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5850 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5851 return data + byte_offset; | 5863 return data + byte_offset; |
| 5852 } | 5864 } |
| 5853 | 5865 |
| 5854 void SetExternalData(ExternalByteArrayData<uint64_t>* data) { | 5866 void SetData(uint64_t* data) const { |
| 5855 raw_ptr()->external_data_ = data; | 5867 raw_ptr()->data_ = data; |
| 5868 } |
| 5869 |
| 5870 void SetPeer(void* peer) const { |
| 5871 raw_ptr()->peer_ = peer; |
| 5856 } | 5872 } |
| 5857 | 5873 |
| 5858 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint64Array, ByteArray); | 5874 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint64Array, ByteArray); |
| 5859 friend class ByteArray; | 5875 friend class ByteArray; |
| 5860 friend class Class; | 5876 friend class Class; |
| 5861 }; | 5877 }; |
| 5862 | 5878 |
| 5863 | 5879 |
| 5864 class ExternalFloat32Array : public ByteArray { | 5880 class ExternalFloat32Array : public ByteArray { |
| 5865 public: | 5881 public: |
| 5866 intptr_t ByteLength() const { | 5882 intptr_t ByteLength() const { |
| 5867 return Length() * kBytesPerElement; | 5883 return Length() * kBytesPerElement; |
| 5868 } | 5884 } |
| 5869 | 5885 |
| 5870 float At(intptr_t index) const { | 5886 float At(intptr_t index) const { |
| 5871 ASSERT((index >= 0) && (index < Length())); | 5887 ASSERT((index >= 0) && (index < Length())); |
| 5872 return raw_ptr()->external_data_->data()[index]; | 5888 return raw_ptr()->data_[index]; |
| 5873 } | 5889 } |
| 5874 | 5890 |
| 5875 void SetAt(intptr_t index, float value) const { | 5891 void SetAt(intptr_t index, float value) const { |
| 5876 ASSERT((index >= 0) && (index < Length())); | 5892 ASSERT((index >= 0) && (index < Length())); |
| 5877 raw_ptr()->external_data_->data()[index] = value; | 5893 raw_ptr()->data_[index] = value; |
| 5878 } | 5894 } |
| 5879 | 5895 |
| 5880 void* GetData() const { | 5896 float* GetData() const { |
| 5881 return raw_ptr()->external_data_->data(); | 5897 return raw_ptr()->data_; |
| 5882 } | 5898 } |
| 5883 | 5899 |
| 5884 void* GetPeer() const { | 5900 void* GetPeer() const { |
| 5885 return raw_ptr()->external_data_->peer(); | 5901 return raw_ptr()->peer_; |
| 5886 } | 5902 } |
| 5887 | 5903 |
| 5888 static const intptr_t kBytesPerElement = 4; | 5904 static const intptr_t kBytesPerElement = 4; |
| 5889 | 5905 |
| 5890 // Since external arrays may be serialized to non-external ones, | 5906 // Since external arrays may be serialized to non-external ones, |
| 5891 // enforce the same maximum element count. | 5907 // enforce the same maximum element count. |
| 5892 static const intptr_t kMaxElements = Float32Array::kMaxElements; | 5908 static const intptr_t kMaxElements = Float32Array::kMaxElements; |
| 5893 | 5909 |
| 5894 static intptr_t InstanceSize() { | 5910 static intptr_t InstanceSize() { |
| 5895 return RoundedAllocationSize(sizeof(RawExternalFloat32Array)); | 5911 return RoundedAllocationSize(sizeof(RawExternalFloat32Array)); |
| 5896 } | 5912 } |
| 5897 | 5913 |
| 5898 static RawExternalFloat32Array* New(float* data, | 5914 static RawExternalFloat32Array* New(float* data, |
| 5899 intptr_t len, | 5915 intptr_t len, |
| 5900 void* peer, | |
| 5901 Dart_PeerFinalizer callback, | |
| 5902 Heap::Space space = Heap::kNew); | 5916 Heap::Space space = Heap::kNew); |
| 5903 | 5917 |
| 5904 private: | 5918 private: |
| 5905 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5919 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5906 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5920 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5907 uint8_t* data = | 5921 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5908 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5909 return data + byte_offset; | 5922 return data + byte_offset; |
| 5910 } | 5923 } |
| 5911 | 5924 |
| 5912 void SetExternalData(ExternalByteArrayData<float>* data) { | 5925 void SetData(float* data) const { |
| 5913 raw_ptr()->external_data_ = data; | 5926 raw_ptr()->data_ = data; |
| 5927 } |
| 5928 |
| 5929 void SetPeer(void* peer) const { |
| 5930 raw_ptr()->peer_ = peer; |
| 5914 } | 5931 } |
| 5915 | 5932 |
| 5916 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat32Array, ByteArray); | 5933 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat32Array, ByteArray); |
| 5917 friend class ByteArray; | 5934 friend class ByteArray; |
| 5918 friend class Class; | 5935 friend class Class; |
| 5919 }; | 5936 }; |
| 5920 | 5937 |
| 5921 | 5938 |
| 5922 class ExternalFloat64Array : public ByteArray { | 5939 class ExternalFloat64Array : public ByteArray { |
| 5923 public: | 5940 public: |
| 5924 intptr_t ByteLength() const { | 5941 intptr_t ByteLength() const { |
| 5925 return Length() * kBytesPerElement; | 5942 return Length() * kBytesPerElement; |
| 5926 } | 5943 } |
| 5927 | 5944 |
| 5928 double At(intptr_t index) const { | 5945 double At(intptr_t index) const { |
| 5929 ASSERT((index >= 0) && (index < Length())); | 5946 ASSERT((index >= 0) && (index < Length())); |
| 5930 return raw_ptr()->external_data_->data()[index]; | 5947 return raw_ptr()->data_[index]; |
| 5931 } | 5948 } |
| 5932 | 5949 |
| 5933 void SetAt(intptr_t index, double value) const { | 5950 void SetAt(intptr_t index, double value) const { |
| 5934 ASSERT((index >= 0) && (index < Length())); | 5951 ASSERT((index >= 0) && (index < Length())); |
| 5935 raw_ptr()->external_data_->data()[index] = value; | 5952 raw_ptr()->data_[index] = value; |
| 5936 } | 5953 } |
| 5937 | 5954 |
| 5938 void* GetData() const { | 5955 double* GetData() const { |
| 5939 return raw_ptr()->external_data_->data(); | 5956 return raw_ptr()->data_; |
| 5940 } | 5957 } |
| 5941 | 5958 |
| 5942 void* GetPeer() const { | 5959 void* GetPeer() const { |
| 5943 return raw_ptr()->external_data_->peer(); | 5960 return raw_ptr()->peer_; |
| 5944 } | 5961 } |
| 5945 | 5962 |
| 5946 static const intptr_t kBytesPerElement = 8; | 5963 static const intptr_t kBytesPerElement = 8; |
| 5947 | 5964 |
| 5948 // Since external arrays may be serialized to non-external ones, | 5965 // Since external arrays may be serialized to non-external ones, |
| 5949 // enforce the same maximum element count. | 5966 // enforce the same maximum element count. |
| 5950 static const intptr_t kMaxElements = Float64Array::kMaxElements; | 5967 static const intptr_t kMaxElements = Float64Array::kMaxElements; |
| 5951 | 5968 |
| 5952 static intptr_t InstanceSize() { | 5969 static intptr_t InstanceSize() { |
| 5953 return RoundedAllocationSize(sizeof(RawExternalFloat64Array)); | 5970 return RoundedAllocationSize(sizeof(RawExternalFloat64Array)); |
| 5954 } | 5971 } |
| 5955 | 5972 |
| 5956 static RawExternalFloat64Array* New(double* data, | 5973 static RawExternalFloat64Array* New(double* data, |
| 5957 intptr_t len, | 5974 intptr_t len, |
| 5958 void* peer, | |
| 5959 Dart_PeerFinalizer callback, | |
| 5960 Heap::Space space = Heap::kNew); | 5975 Heap::Space space = Heap::kNew); |
| 5961 | 5976 |
| 5962 private: | 5977 private: |
| 5963 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5978 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5964 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5979 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5965 uint8_t* data = | 5980 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 5966 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | |
| 5967 return data + byte_offset; | 5981 return data + byte_offset; |
| 5968 } | 5982 } |
| 5969 | 5983 |
| 5970 void SetExternalData(ExternalByteArrayData<double>* data) { | 5984 void SetData(double* data) const { |
| 5971 raw_ptr()->external_data_ = data; | 5985 raw_ptr()->data_ = data; |
| 5986 } |
| 5987 |
| 5988 void SetPeer(void* peer) const { |
| 5989 raw_ptr()->peer_ = peer; |
| 5972 } | 5990 } |
| 5973 | 5991 |
| 5974 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat64Array, ByteArray); | 5992 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat64Array, ByteArray); |
| 5975 friend class ByteArray; | 5993 friend class ByteArray; |
| 5976 friend class Class; | 5994 friend class Class; |
| 5977 }; | 5995 }; |
| 5978 | 5996 |
| 5979 | 5997 |
| 5980 // DartFunction represents the abstract Dart class 'Function'. | 5998 // DartFunction represents the abstract Dart class 'Function'. |
| 5981 class DartFunction : public Instance { | 5999 class DartFunction : public Instance { |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6322 | 6340 |
| 6323 | 6341 |
| 6324 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 6342 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 6325 intptr_t index) { | 6343 intptr_t index) { |
| 6326 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 6344 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 6327 } | 6345 } |
| 6328 | 6346 |
| 6329 } // namespace dart | 6347 } // namespace dart |
| 6330 | 6348 |
| 6331 #endif // VM_OBJECT_H_ | 6349 #endif // VM_OBJECT_H_ |
| OLD | NEW |