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 4547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4558 | 4558 |
4559 void SetAt(intptr_t index, int8_t value) const { | 4559 void SetAt(intptr_t index, int8_t value) const { |
4560 ASSERT((index >= 0) && (index < Length())); | 4560 ASSERT((index >= 0) && (index < Length())); |
4561 raw_ptr()->data_[index] = value; | 4561 raw_ptr()->data_[index] = value; |
4562 } | 4562 } |
4563 | 4563 |
4564 static const intptr_t kBytesPerElement = 1; | 4564 static const intptr_t kBytesPerElement = 1; |
4565 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4565 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4566 | 4566 |
4567 static intptr_t data_offset() { | 4567 static intptr_t data_offset() { |
4568 return length_offset() + kWordSize; | 4568 return OFFSET_OF(RawInt8Array, data_); |
4569 } | 4569 } |
4570 | 4570 |
4571 static intptr_t InstanceSize() { | 4571 static intptr_t InstanceSize() { |
4572 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_)); | 4572 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_)); |
4573 return 0; | 4573 return 0; |
4574 } | 4574 } |
4575 | 4575 |
4576 static intptr_t InstanceSize(intptr_t len) { | 4576 static intptr_t InstanceSize(intptr_t len) { |
4577 ASSERT(0 <= len && len <= kMaxElements); | 4577 ASSERT(0 <= len && len <= kMaxElements); |
4578 return RoundedAllocationSize( | 4578 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4610 | 4610 |
4611 void SetAt(intptr_t index, uint8_t value) const { | 4611 void SetAt(intptr_t index, uint8_t value) const { |
4612 ASSERT((index >= 0) && (index < Length())); | 4612 ASSERT((index >= 0) && (index < Length())); |
4613 raw_ptr()->data_[index] = value; | 4613 raw_ptr()->data_[index] = value; |
4614 } | 4614 } |
4615 | 4615 |
4616 static const intptr_t kBytesPerElement = 1; | 4616 static const intptr_t kBytesPerElement = 1; |
4617 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4617 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4618 | 4618 |
4619 static intptr_t data_offset() { | 4619 static intptr_t data_offset() { |
4620 return length_offset() + kWordSize; | 4620 return OFFSET_OF(RawUint8Array, data_); |
4621 } | 4621 } |
4622 | 4622 |
4623 static intptr_t InstanceSize() { | 4623 static intptr_t InstanceSize() { |
4624 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_)); | 4624 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_)); |
4625 return 0; | 4625 return 0; |
4626 } | 4626 } |
4627 | 4627 |
4628 static intptr_t InstanceSize(intptr_t len) { | 4628 static intptr_t InstanceSize(intptr_t len) { |
4629 ASSERT(0 <= len && len <= kMaxElements); | 4629 ASSERT(0 <= len && len <= kMaxElements); |
4630 return RoundedAllocationSize( | 4630 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4662 | 4662 |
4663 void SetAt(intptr_t index, int16_t value) const { | 4663 void SetAt(intptr_t index, int16_t value) const { |
4664 ASSERT((index >= 0) && (index < Length())); | 4664 ASSERT((index >= 0) && (index < Length())); |
4665 raw_ptr()->data_[index] = value; | 4665 raw_ptr()->data_[index] = value; |
4666 } | 4666 } |
4667 | 4667 |
4668 static const intptr_t kBytesPerElement = 2; | 4668 static const intptr_t kBytesPerElement = 2; |
4669 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4669 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4670 | 4670 |
4671 static intptr_t data_offset() { | 4671 static intptr_t data_offset() { |
4672 return length_offset() + kWordSize; | 4672 return OFFSET_OF(RawInt16Array, data_); |
4673 } | 4673 } |
4674 | 4674 |
4675 static intptr_t InstanceSize() { | 4675 static intptr_t InstanceSize() { |
4676 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_)); | 4676 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_)); |
4677 return 0; | 4677 return 0; |
4678 } | 4678 } |
4679 | 4679 |
4680 static intptr_t InstanceSize(intptr_t len) { | 4680 static intptr_t InstanceSize(intptr_t len) { |
4681 ASSERT(0 <= len && len <= kMaxElements); | 4681 ASSERT(0 <= len && len <= kMaxElements); |
4682 return RoundedAllocationSize( | 4682 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4714 | 4714 |
4715 void SetAt(intptr_t index, uint16_t value) const { | 4715 void SetAt(intptr_t index, uint16_t value) const { |
4716 ASSERT((index >= 0) && (index < Length())); | 4716 ASSERT((index >= 0) && (index < Length())); |
4717 raw_ptr()->data_[index] = value; | 4717 raw_ptr()->data_[index] = value; |
4718 } | 4718 } |
4719 | 4719 |
4720 static const intptr_t kBytesPerElement = 2; | 4720 static const intptr_t kBytesPerElement = 2; |
4721 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4721 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4722 | 4722 |
4723 static intptr_t data_offset() { | 4723 static intptr_t data_offset() { |
4724 return length_offset() + kWordSize; | 4724 return OFFSET_OF(RawUint16Array, data_); |
4725 } | 4725 } |
4726 | 4726 |
4727 static intptr_t InstanceSize() { | 4727 static intptr_t InstanceSize() { |
4728 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_)); | 4728 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_)); |
4729 return 0; | 4729 return 0; |
4730 } | 4730 } |
4731 | 4731 |
4732 static intptr_t InstanceSize(intptr_t len) { | 4732 static intptr_t InstanceSize(intptr_t len) { |
4733 ASSERT(0 <= len && len <= kMaxElements); | 4733 ASSERT(0 <= len && len <= kMaxElements); |
4734 return RoundedAllocationSize( | 4734 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4766 | 4766 |
4767 void SetAt(intptr_t index, int32_t value) const { | 4767 void SetAt(intptr_t index, int32_t value) const { |
4768 ASSERT((index >= 0) && (index < Length())); | 4768 ASSERT((index >= 0) && (index < Length())); |
4769 raw_ptr()->data_[index] = value; | 4769 raw_ptr()->data_[index] = value; |
4770 } | 4770 } |
4771 | 4771 |
4772 static const intptr_t kBytesPerElement = 4; | 4772 static const intptr_t kBytesPerElement = 4; |
4773 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4773 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4774 | 4774 |
4775 static intptr_t data_offset() { | 4775 static intptr_t data_offset() { |
4776 return length_offset() + kWordSize; | 4776 return OFFSET_OF(RawInt32Array, data_); |
4777 } | 4777 } |
4778 | 4778 |
4779 static intptr_t InstanceSize() { | 4779 static intptr_t InstanceSize() { |
4780 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_)); | 4780 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_)); |
4781 return 0; | 4781 return 0; |
4782 } | 4782 } |
4783 | 4783 |
4784 static intptr_t InstanceSize(intptr_t len) { | 4784 static intptr_t InstanceSize(intptr_t len) { |
4785 ASSERT(0 <= len && len <= kMaxElements); | 4785 ASSERT(0 <= len && len <= kMaxElements); |
4786 return RoundedAllocationSize( | 4786 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4818 | 4818 |
4819 void SetAt(intptr_t index, uint32_t value) const { | 4819 void SetAt(intptr_t index, uint32_t value) const { |
4820 ASSERT((index >= 0) && (index < Length())); | 4820 ASSERT((index >= 0) && (index < Length())); |
4821 raw_ptr()->data_[index] = value; | 4821 raw_ptr()->data_[index] = value; |
4822 } | 4822 } |
4823 | 4823 |
4824 static const intptr_t kBytesPerElement = 4; | 4824 static const intptr_t kBytesPerElement = 4; |
4825 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4825 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4826 | 4826 |
4827 static intptr_t data_offset() { | 4827 static intptr_t data_offset() { |
4828 return length_offset() + kWordSize; | 4828 return OFFSET_OF(RawUint32Array, data_); |
4829 } | 4829 } |
4830 | 4830 |
4831 static intptr_t InstanceSize() { | 4831 static intptr_t InstanceSize() { |
4832 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_)); | 4832 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_)); |
4833 return 0; | 4833 return 0; |
4834 } | 4834 } |
4835 | 4835 |
4836 static intptr_t InstanceSize(intptr_t len) { | 4836 static intptr_t InstanceSize(intptr_t len) { |
4837 ASSERT(0 <= len && len <= kMaxElements); | 4837 ASSERT(0 <= len && len <= kMaxElements); |
4838 return RoundedAllocationSize( | 4838 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4870 | 4870 |
4871 void SetAt(intptr_t index, int64_t value) const { | 4871 void SetAt(intptr_t index, int64_t value) const { |
4872 ASSERT((index >= 0) && (index < Length())); | 4872 ASSERT((index >= 0) && (index < Length())); |
4873 raw_ptr()->data_[index] = value; | 4873 raw_ptr()->data_[index] = value; |
4874 } | 4874 } |
4875 | 4875 |
4876 static const intptr_t kBytesPerElement = 8; | 4876 static const intptr_t kBytesPerElement = 8; |
4877 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4877 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4878 | 4878 |
4879 static intptr_t data_offset() { | 4879 static intptr_t data_offset() { |
4880 return length_offset() + kWordSize; | 4880 return OFFSET_OF(RawInt64Array, data_); |
4881 } | 4881 } |
4882 | 4882 |
4883 static intptr_t InstanceSize() { | 4883 static intptr_t InstanceSize() { |
4884 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_)); | 4884 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_)); |
4885 return 0; | 4885 return 0; |
4886 } | 4886 } |
4887 | 4887 |
4888 static intptr_t InstanceSize(intptr_t len) { | 4888 static intptr_t InstanceSize(intptr_t len) { |
4889 ASSERT(0 <= len && len <= kMaxElements); | 4889 ASSERT(0 <= len && len <= kMaxElements); |
4890 return RoundedAllocationSize( | 4890 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4922 | 4922 |
4923 void SetAt(intptr_t index, uint64_t value) const { | 4923 void SetAt(intptr_t index, uint64_t value) const { |
4924 ASSERT((index >= 0) && (index < Length())); | 4924 ASSERT((index >= 0) && (index < Length())); |
4925 raw_ptr()->data_[index] = value; | 4925 raw_ptr()->data_[index] = value; |
4926 } | 4926 } |
4927 | 4927 |
4928 static const intptr_t kBytesPerElement = 8; | 4928 static const intptr_t kBytesPerElement = 8; |
4929 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4929 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4930 | 4930 |
4931 static intptr_t data_offset() { | 4931 static intptr_t data_offset() { |
4932 return length_offset() + kWordSize; | 4932 return OFFSET_OF(RawUint64Array, data_); |
4933 } | 4933 } |
4934 | 4934 |
4935 static intptr_t InstanceSize() { | 4935 static intptr_t InstanceSize() { |
4936 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_)); | 4936 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_)); |
4937 return 0; | 4937 return 0; |
4938 } | 4938 } |
4939 | 4939 |
4940 static intptr_t InstanceSize(intptr_t len) { | 4940 static intptr_t InstanceSize(intptr_t len) { |
4941 ASSERT(0 <= len && len <= kMaxElements); | 4941 ASSERT(0 <= len && len <= kMaxElements); |
4942 return RoundedAllocationSize( | 4942 return RoundedAllocationSize( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4974 | 4974 |
4975 void SetAt(intptr_t index, float value) const { | 4975 void SetAt(intptr_t index, float value) const { |
4976 ASSERT((index >= 0) && (index < Length())); | 4976 ASSERT((index >= 0) && (index < Length())); |
4977 raw_ptr()->data_[index] = value; | 4977 raw_ptr()->data_[index] = value; |
4978 } | 4978 } |
4979 | 4979 |
4980 static const intptr_t kBytesPerElement = 4; | 4980 static const intptr_t kBytesPerElement = 4; |
4981 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 4981 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
4982 | 4982 |
4983 static intptr_t data_offset() { | 4983 static intptr_t data_offset() { |
4984 return length_offset() + kWordSize; | 4984 return OFFSET_OF(RawFloat32Array, data_); |
4985 } | 4985 } |
4986 | 4986 |
4987 static intptr_t InstanceSize() { | 4987 static intptr_t InstanceSize() { |
4988 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_)); | 4988 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_)); |
4989 return 0; | 4989 return 0; |
4990 } | 4990 } |
4991 | 4991 |
4992 static intptr_t InstanceSize(intptr_t len) { | 4992 static intptr_t InstanceSize(intptr_t len) { |
4993 ASSERT(0 <= len && len <= kMaxElements); | 4993 ASSERT(0 <= len && len <= kMaxElements); |
4994 return RoundedAllocationSize( | 4994 return RoundedAllocationSize( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5031 | 5031 |
5032 static const intptr_t kBytesPerElement = 8; | 5032 static const intptr_t kBytesPerElement = 8; |
5033 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 5033 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
5034 | 5034 |
5035 static intptr_t InstanceSize() { | 5035 static intptr_t InstanceSize() { |
5036 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_)); | 5036 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_)); |
5037 return 0; | 5037 return 0; |
5038 } | 5038 } |
5039 | 5039 |
5040 static intptr_t data_offset() { | 5040 static intptr_t data_offset() { |
5041 return length_offset() + kWordSize; | 5041 return OFFSET_OF(RawFloat64Array, data_); |
5042 } | 5042 } |
5043 | 5043 |
5044 static intptr_t InstanceSize(intptr_t len) { | 5044 static intptr_t InstanceSize(intptr_t len) { |
5045 ASSERT(0 <= len && len <= kMaxElements); | 5045 ASSERT(0 <= len && len <= kMaxElements); |
5046 return RoundedAllocationSize( | 5046 return RoundedAllocationSize( |
5047 sizeof(RawFloat64Array) + (len * kBytesPerElement)); | 5047 sizeof(RawFloat64Array) + (len * kBytesPerElement)); |
5048 } | 5048 } |
5049 | 5049 |
5050 static RawFloat64Array* New(intptr_t len, | 5050 static RawFloat64Array* New(intptr_t len, |
5051 Heap::Space space = Heap::kNew); | 5051 Heap::Space space = Heap::kNew); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5150 static const intptr_t kBytesPerElement = 1; | 5150 static const intptr_t kBytesPerElement = 1; |
5151 | 5151 |
5152 // Since external arrays may be serialized to non-external ones, | 5152 // Since external arrays may be serialized to non-external ones, |
5153 // enforce the same maximum element count. | 5153 // enforce the same maximum element count. |
5154 static const intptr_t kMaxElements = Uint8Array::kMaxElements; | 5154 static const intptr_t kMaxElements = Uint8Array::kMaxElements; |
5155 | 5155 |
5156 static intptr_t InstanceSize() { | 5156 static intptr_t InstanceSize() { |
5157 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); | 5157 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); |
5158 } | 5158 } |
5159 | 5159 |
| 5160 static intptr_t external_data_offset() { |
| 5161 return OFFSET_OF(RawExternalUint8Array, external_data_); |
| 5162 } |
| 5163 |
5160 static RawExternalUint8Array* New(uint8_t* data, | 5164 static RawExternalUint8Array* New(uint8_t* data, |
5161 intptr_t len, | 5165 intptr_t len, |
5162 void* peer, | 5166 void* peer, |
5163 Dart_PeerFinalizer callback, | 5167 Dart_PeerFinalizer callback, |
5164 Heap::Space space = Heap::kNew); | 5168 Heap::Space space = Heap::kNew); |
5165 | 5169 |
5166 private: | 5170 private: |
5167 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5171 uint8_t* ByteAddr(intptr_t byte_offset) const { |
5168 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5172 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
5169 uint8_t* data = | 5173 uint8_t* data = |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5971 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5975 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5972 return false; | 5976 return false; |
5973 } | 5977 } |
5974 } | 5978 } |
5975 return true; | 5979 return true; |
5976 } | 5980 } |
5977 | 5981 |
5978 } // namespace dart | 5982 } // namespace dart |
5979 | 5983 |
5980 #endif // VM_OBJECT_H_ | 5984 #endif // VM_OBJECT_H_ |
OLD | NEW |