| 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_RAW_OBJECT_H_ | 5 #ifndef VM_RAW_OBJECT_H_ |
| 6 #define VM_RAW_OBJECT_H_ | 6 #define VM_RAW_OBJECT_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/token.h" | 10 #include "vm/token.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 V(ExternalUint8ClampedArray) \ | 80 V(ExternalUint8ClampedArray) \ |
| 81 V(ExternalInt16Array) \ | 81 V(ExternalInt16Array) \ |
| 82 V(ExternalUint16Array) \ | 82 V(ExternalUint16Array) \ |
| 83 V(ExternalInt32Array) \ | 83 V(ExternalInt32Array) \ |
| 84 V(ExternalUint32Array) \ | 84 V(ExternalUint32Array) \ |
| 85 V(ExternalInt64Array) \ | 85 V(ExternalInt64Array) \ |
| 86 V(ExternalUint64Array) \ | 86 V(ExternalUint64Array) \ |
| 87 V(ExternalFloat32x4Array) \ | 87 V(ExternalFloat32x4Array) \ |
| 88 V(ExternalFloat32Array) \ | 88 V(ExternalFloat32Array) \ |
| 89 V(ExternalFloat64Array) \ | 89 V(ExternalFloat64Array) \ |
| 90 V(TypedData) \ |
| 91 V(ExternalTypedData) \ |
| 90 V(Stacktrace) \ | 92 V(Stacktrace) \ |
| 91 V(JSRegExp) \ | 93 V(JSRegExp) \ |
| 92 V(WeakProperty) \ | 94 V(WeakProperty) \ |
| 93 V(DartFunction) \ | 95 V(DartFunction) \ |
| 94 V(Float32x4) \ | 96 V(Float32x4) \ |
| 95 V(Uint32x4) \ | 97 V(Uint32x4) \ |
| 96 | 98 |
| 97 | 99 |
| 98 #define CLASS_LIST_STRINGS(V) \ | 100 #define CLASS_LIST_STRINGS(V) \ |
| 99 V(String) \ | 101 V(String) \ |
| 100 V(OneByteString) \ | 102 V(OneByteString) \ |
| 101 V(TwoByteString) \ | 103 V(TwoByteString) \ |
| 102 V(ExternalOneByteString) \ | 104 V(ExternalOneByteString) \ |
| 103 V(ExternalTwoByteString) | 105 V(ExternalTwoByteString) |
| 104 | 106 |
| 107 #define CLASS_LIST_TYPED_DATA(V) \ |
| 108 V(Int8Array) \ |
| 109 V(Uint8Array) \ |
| 110 V(Uint8ClampedArray) \ |
| 111 V(Int16Array) \ |
| 112 V(Uint16Array) \ |
| 113 V(Int32Array) \ |
| 114 V(Uint32Array) \ |
| 115 V(Int64Array) \ |
| 116 V(Uint64Array) \ |
| 117 V(Float32Array) \ |
| 118 V(Float64Array) \ |
| 119 |
| 105 #define CLASS_LIST_FOR_HANDLES(V) \ | 120 #define CLASS_LIST_FOR_HANDLES(V) \ |
| 106 CLASS_LIST_NO_OBJECT_OR_STRING(V) \ | 121 CLASS_LIST_NO_OBJECT_OR_STRING(V) \ |
| 107 V(String) | 122 V(String) |
| 108 | 123 |
| 109 #define CLASS_LIST_NO_OBJECT(V) \ | 124 #define CLASS_LIST_NO_OBJECT(V) \ |
| 110 CLASS_LIST_NO_OBJECT_OR_STRING(V) \ | 125 CLASS_LIST_NO_OBJECT_OR_STRING(V) \ |
| 111 CLASS_LIST_STRINGS(V) | 126 CLASS_LIST_STRINGS(V) |
| 112 | 127 |
| 113 #define CLASS_LIST(V) \ | 128 #define CLASS_LIST(V) \ |
| 114 V(Object) \ | 129 V(Object) \ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 enum ClassId { | 141 enum ClassId { |
| 127 // Illegal class id. | 142 // Illegal class id. |
| 128 kIllegalCid = 0, | 143 kIllegalCid = 0, |
| 129 | 144 |
| 130 // List of Ids for predefined classes. | 145 // List of Ids for predefined classes. |
| 131 #define DEFINE_OBJECT_KIND(clazz) \ | 146 #define DEFINE_OBJECT_KIND(clazz) \ |
| 132 k##clazz##Cid, | 147 k##clazz##Cid, |
| 133 CLASS_LIST(DEFINE_OBJECT_KIND) | 148 CLASS_LIST(DEFINE_OBJECT_KIND) |
| 134 #undef DEFINE_OBJECT_KIND | 149 #undef DEFINE_OBJECT_KIND |
| 135 | 150 |
| 151 #define DEFINE_OBJECT_KIND(clazz) \ |
| 152 kTypedData##clazz##Cid, |
| 153 CLASS_LIST_TYPED_DATA(DEFINE_OBJECT_KIND) |
| 154 #undef DEFINE_OBJECT_KIND |
| 155 |
| 156 #define DEFINE_OBJECT_KIND(clazz) \ |
| 157 kExternalTypedData##clazz##Cid, |
| 158 CLASS_LIST_TYPED_DATA(DEFINE_OBJECT_KIND) |
| 159 #undef DEFINE_OBJECT_KIND |
| 160 |
| 136 // The following entries do not describe a predefined class, but instead | 161 // The following entries do not describe a predefined class, but instead |
| 137 // are class indexes for pre-allocated instance (Null, dynamic and Void). | 162 // are class indexes for pre-allocated instance (Null, dynamic and Void). |
| 138 kNullCid, | 163 kNullCid, |
| 139 kDynamicCid, | 164 kDynamicCid, |
| 140 kVoidCid, | 165 kVoidCid, |
| 141 | 166 |
| 142 // The following entry does not describe a real class, but instead it is an | 167 // The following entry does not describe a real class, but instead it is an |
| 143 // id which is used to identify free list elements in the heap. | 168 // id which is used to identify free list elements in the heap. |
| 144 kFreeListElement, | 169 kFreeListElement, |
| 145 | 170 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 static bool IsErrorClassId(intptr_t index); | 379 static bool IsErrorClassId(intptr_t index); |
| 355 static bool IsNumberClassId(intptr_t index); | 380 static bool IsNumberClassId(intptr_t index); |
| 356 static bool IsIntegerClassId(intptr_t index); | 381 static bool IsIntegerClassId(intptr_t index); |
| 357 static bool IsStringClassId(intptr_t index); | 382 static bool IsStringClassId(intptr_t index); |
| 358 static bool IsOneByteStringClassId(intptr_t index); | 383 static bool IsOneByteStringClassId(intptr_t index); |
| 359 static bool IsTwoByteStringClassId(intptr_t index); | 384 static bool IsTwoByteStringClassId(intptr_t index); |
| 360 static bool IsExternalStringClassId(intptr_t index); | 385 static bool IsExternalStringClassId(intptr_t index); |
| 361 static bool IsBuiltinListClassId(intptr_t index); | 386 static bool IsBuiltinListClassId(intptr_t index); |
| 362 static bool IsByteArrayClassId(intptr_t index); | 387 static bool IsByteArrayClassId(intptr_t index); |
| 363 static bool IsExternalByteArrayClassId(intptr_t index); | 388 static bool IsExternalByteArrayClassId(intptr_t index); |
| 389 static bool IsTypedDataClassId(intptr_t index); |
| 390 static bool IsExternalTypedDataClassId(intptr_t index); |
| 391 |
| 392 static intptr_t NumberOfTypedDataClasses(); |
| 364 | 393 |
| 365 private: | 394 private: |
| 366 uword tags_; // Various object tags (bits). | 395 uword tags_; // Various object tags (bits). |
| 367 | 396 |
| 368 class FreeBit : public BitField<bool, kFreeBit, 1> {}; | 397 class FreeBit : public BitField<bool, kFreeBit, 1> {}; |
| 369 | 398 |
| 370 class MarkBit : public BitField<bool, kMarkBit, 1> {}; | 399 class MarkBit : public BitField<bool, kMarkBit, 1> {}; |
| 371 | 400 |
| 372 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; | 401 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; |
| 373 | 402 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 389 | 418 |
| 390 intptr_t GetClassId() const { | 419 intptr_t GetClassId() const { |
| 391 uword tags = ptr()->tags_; | 420 uword tags = ptr()->tags_; |
| 392 return ClassIdTag::decode(tags); | 421 return ClassIdTag::decode(tags); |
| 393 } | 422 } |
| 394 | 423 |
| 395 friend class Api; | 424 friend class Api; |
| 396 friend class Array; | 425 friend class Array; |
| 397 friend class FreeListElement; | 426 friend class FreeListElement; |
| 398 friend class GCMarker; | 427 friend class GCMarker; |
| 428 friend class ExternalTypedData; |
| 399 friend class Heap; | 429 friend class Heap; |
| 400 friend class HeapProfiler; | 430 friend class HeapProfiler; |
| 401 friend class HeapProfilerRootVisitor; | 431 friend class HeapProfilerRootVisitor; |
| 402 friend class HeapTrace; | 432 friend class HeapTrace; |
| 403 friend class HeapTraceDebugObjectVisitor; | 433 friend class HeapTraceDebugObjectVisitor; |
| 404 friend class HeapTraceHandleVisitor; | 434 friend class HeapTraceHandleVisitor; |
| 405 friend class HeapTraceVisitor; | 435 friend class HeapTraceVisitor; |
| 406 friend class MarkingVisitor; | 436 friend class MarkingVisitor; |
| 407 friend class Object; | 437 friend class Object; |
| 438 friend class RawExternalTypedData; |
| 408 friend class RawInstructions; | 439 friend class RawInstructions; |
| 409 friend class RawInstance; | 440 friend class RawInstance; |
| 441 friend class RawTypedData; |
| 410 friend class Scavenger; | 442 friend class Scavenger; |
| 411 friend class SnapshotReader; | 443 friend class SnapshotReader; |
| 412 friend class SnapshotWriter; | 444 friend class SnapshotWriter; |
| 413 friend class String; | 445 friend class String; |
| 446 friend class TypedData; |
| 414 | 447 |
| 415 DISALLOW_ALLOCATION(); | 448 DISALLOW_ALLOCATION(); |
| 416 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); | 449 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); |
| 417 }; | 450 }; |
| 418 | 451 |
| 419 | 452 |
| 420 class RawClass : public RawObject { | 453 class RawClass : public RawObject { |
| 421 public: | 454 public: |
| 422 enum ClassState { | 455 enum ClassState { |
| 423 kAllocated, // Initial state. | 456 kAllocated, // Initial state. |
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 #define RawIntPtrArray RawInt32Array | 1380 #define RawIntPtrArray RawInt32Array |
| 1348 #define IntPtrArray Int32Array | 1381 #define IntPtrArray Int32Array |
| 1349 #elif defined(ARCH_IS_64_BIT) | 1382 #elif defined(ARCH_IS_64_BIT) |
| 1350 #define RawIntPtrArray RawInt64Array | 1383 #define RawIntPtrArray RawInt64Array |
| 1351 #define IntPtrArray Int64Array | 1384 #define IntPtrArray Int64Array |
| 1352 #else | 1385 #else |
| 1353 #error Architecture is not 32-bit or 64-bit. | 1386 #error Architecture is not 32-bit or 64-bit. |
| 1354 #endif // ARCH_IS_32_BIT | 1387 #endif // ARCH_IS_32_BIT |
| 1355 | 1388 |
| 1356 | 1389 |
| 1390 class RawTypedData : public RawInstance { |
| 1391 RAW_HEAP_OBJECT_IMPLEMENTATION(TypedData); |
| 1392 |
| 1393 protected: |
| 1394 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| 1395 RawSmi* length_; |
| 1396 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| 1397 |
| 1398 // Variable length data follows here. |
| 1399 uint8_t data_[0]; |
| 1400 }; |
| 1401 |
| 1402 |
| 1403 class RawExternalTypedData : public RawInstance { |
| 1404 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData); |
| 1405 |
| 1406 protected: |
| 1407 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| 1408 RawSmi* length_; |
| 1409 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| 1410 |
| 1411 uint8_t* data_; |
| 1412 void* peer_; |
| 1413 }; |
| 1414 |
| 1415 |
| 1357 class RawByteArray : public RawInstance { | 1416 class RawByteArray : public RawInstance { |
| 1358 RAW_HEAP_OBJECT_IMPLEMENTATION(ByteArray); | 1417 RAW_HEAP_OBJECT_IMPLEMENTATION(ByteArray); |
| 1359 | 1418 |
| 1360 protected: | 1419 protected: |
| 1361 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } | 1420 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| 1362 RawSmi* length_; | 1421 RawSmi* length_; |
| 1363 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } | 1422 RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->length_); } |
| 1364 }; | 1423 }; |
| 1365 | 1424 |
| 1366 | 1425 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 kExternalUint8ClampedArrayCid == kByteArrayCid + 15 && | 1796 kExternalUint8ClampedArrayCid == kByteArrayCid + 15 && |
| 1738 kExternalInt16ArrayCid == kByteArrayCid + 16 && | 1797 kExternalInt16ArrayCid == kByteArrayCid + 16 && |
| 1739 kExternalUint16ArrayCid == kByteArrayCid + 17 && | 1798 kExternalUint16ArrayCid == kByteArrayCid + 17 && |
| 1740 kExternalInt32ArrayCid == kByteArrayCid + 18 && | 1799 kExternalInt32ArrayCid == kByteArrayCid + 18 && |
| 1741 kExternalUint32ArrayCid == kByteArrayCid + 19 && | 1800 kExternalUint32ArrayCid == kByteArrayCid + 19 && |
| 1742 kExternalInt64ArrayCid == kByteArrayCid + 20 && | 1801 kExternalInt64ArrayCid == kByteArrayCid + 20 && |
| 1743 kExternalUint64ArrayCid == kByteArrayCid + 21 && | 1802 kExternalUint64ArrayCid == kByteArrayCid + 21 && |
| 1744 kExternalFloat32x4ArrayCid == kByteArrayCid + 22 && | 1803 kExternalFloat32x4ArrayCid == kByteArrayCid + 22 && |
| 1745 kExternalFloat32ArrayCid == kByteArrayCid + 23 && | 1804 kExternalFloat32ArrayCid == kByteArrayCid + 23 && |
| 1746 kExternalFloat64ArrayCid == kByteArrayCid + 24 && | 1805 kExternalFloat64ArrayCid == kByteArrayCid + 24 && |
| 1747 kStacktraceCid == kByteArrayCid + 25); | 1806 kTypedDataCid == kByteArrayCid + 25); |
| 1748 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); | 1807 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); |
| 1749 } | 1808 } |
| 1750 | 1809 |
| 1810 |
| 1751 inline bool RawObject::IsExternalByteArrayClassId(intptr_t index) { | 1811 inline bool RawObject::IsExternalByteArrayClassId(intptr_t index) { |
| 1752 // Make sure this function is updated when new ByteArray types are added. | 1812 // Make sure this function is updated when new ByteArray types are added. |
| 1753 ASSERT(kExternalUint8ArrayCid == kExternalInt8ArrayCid + 1 && | 1813 ASSERT(kExternalUint8ArrayCid == kExternalInt8ArrayCid + 1 && |
| 1754 kExternalUint8ClampedArrayCid == kExternalInt8ArrayCid + 2 && | 1814 kExternalUint8ClampedArrayCid == kExternalInt8ArrayCid + 2 && |
| 1755 kExternalInt16ArrayCid == kExternalInt8ArrayCid + 3 && | 1815 kExternalInt16ArrayCid == kExternalInt8ArrayCid + 3 && |
| 1756 kExternalUint16ArrayCid == kExternalInt8ArrayCid + 4 && | 1816 kExternalUint16ArrayCid == kExternalInt8ArrayCid + 4 && |
| 1757 kExternalInt32ArrayCid == kExternalInt8ArrayCid + 5 && | 1817 kExternalInt32ArrayCid == kExternalInt8ArrayCid + 5 && |
| 1758 kExternalUint32ArrayCid == kExternalInt8ArrayCid + 6 && | 1818 kExternalUint32ArrayCid == kExternalInt8ArrayCid + 6 && |
| 1759 kExternalInt64ArrayCid == kExternalInt8ArrayCid + 7 && | 1819 kExternalInt64ArrayCid == kExternalInt8ArrayCid + 7 && |
| 1760 kExternalUint64ArrayCid == kExternalInt8ArrayCid + 8 && | 1820 kExternalUint64ArrayCid == kExternalInt8ArrayCid + 8 && |
| 1761 kExternalFloat32x4ArrayCid == kExternalInt8ArrayCid + 9 && | 1821 kExternalFloat32x4ArrayCid == kExternalInt8ArrayCid + 9 && |
| 1762 kExternalFloat32ArrayCid == kExternalInt8ArrayCid + 10 && | 1822 kExternalFloat32ArrayCid == kExternalInt8ArrayCid + 10 && |
| 1763 kExternalFloat64ArrayCid == kExternalInt8ArrayCid + 11 && | 1823 kExternalFloat64ArrayCid == kExternalInt8ArrayCid + 11 && |
| 1764 kStacktraceCid == kExternalInt8ArrayCid + 12); | 1824 kTypedDataCid == kExternalInt8ArrayCid + 12); |
| 1765 return (index >= kExternalInt8ArrayCid && index <= kExternalFloat64ArrayCid); | 1825 return (index >= kExternalInt8ArrayCid && index <= kExternalFloat64ArrayCid); |
| 1766 } | 1826 } |
| 1767 | 1827 |
| 1828 |
| 1829 inline bool RawObject::IsTypedDataClassId(intptr_t index) { |
| 1830 // Make sure this is updated when new TypedData types are added. |
| 1831 ASSERT(kTypedDataUint8ArrayCid == kTypedDataInt8ArrayCid + 1 && |
| 1832 kTypedDataUint8ClampedArrayCid == kTypedDataInt8ArrayCid + 2 && |
| 1833 kTypedDataInt16ArrayCid == kTypedDataInt8ArrayCid + 3 && |
| 1834 kTypedDataUint16ArrayCid == kTypedDataInt8ArrayCid + 4 && |
| 1835 kTypedDataInt32ArrayCid == kTypedDataInt8ArrayCid + 5 && |
| 1836 kTypedDataUint32ArrayCid == kTypedDataInt8ArrayCid + 6 && |
| 1837 kTypedDataInt64ArrayCid == kTypedDataInt8ArrayCid + 7 && |
| 1838 kTypedDataUint64ArrayCid == kTypedDataInt8ArrayCid + 8 && |
| 1839 kTypedDataFloat32ArrayCid == kTypedDataInt8ArrayCid + 9 && |
| 1840 kTypedDataFloat64ArrayCid == kTypedDataInt8ArrayCid + 10 && |
| 1841 kExternalTypedDataInt8ArrayCid == kTypedDataInt8ArrayCid + 11); |
| 1842 return (index >= kTypedDataInt8ArrayCid && |
| 1843 index <= kTypedDataFloat64ArrayCid); |
| 1844 } |
| 1845 |
| 1846 |
| 1847 inline bool RawObject::IsExternalTypedDataClassId(intptr_t index) { |
| 1848 // Make sure this is updated when new ExternalTypedData types are added. |
| 1849 ASSERT((kExternalTypedDataUint8ArrayCid == |
| 1850 kExternalTypedDataInt8ArrayCid + 1) && |
| 1851 (kExternalTypedDataUint8ClampedArrayCid == |
| 1852 kExternalTypedDataInt8ArrayCid + 2) && |
| 1853 (kExternalTypedDataInt16ArrayCid == |
| 1854 kExternalTypedDataInt8ArrayCid + 3) && |
| 1855 (kExternalTypedDataUint16ArrayCid == |
| 1856 kExternalTypedDataInt8ArrayCid + 4) && |
| 1857 (kExternalTypedDataInt32ArrayCid == |
| 1858 kExternalTypedDataInt8ArrayCid + 5) && |
| 1859 (kExternalTypedDataUint32ArrayCid == |
| 1860 kExternalTypedDataInt8ArrayCid + 6) && |
| 1861 (kExternalTypedDataInt64ArrayCid == |
| 1862 kExternalTypedDataInt8ArrayCid + 7) && |
| 1863 (kExternalTypedDataUint64ArrayCid == |
| 1864 kExternalTypedDataInt8ArrayCid + 8) && |
| 1865 (kExternalTypedDataFloat32ArrayCid == |
| 1866 kExternalTypedDataInt8ArrayCid + 9) && |
| 1867 (kExternalTypedDataFloat64ArrayCid == |
| 1868 kExternalTypedDataInt8ArrayCid + 10) && |
| 1869 (kNullCid == kExternalTypedDataInt8ArrayCid + 11)); |
| 1870 return (index >= kExternalTypedDataInt8ArrayCid && |
| 1871 index <= kExternalTypedDataFloat64ArrayCid); |
| 1872 } |
| 1873 |
| 1874 |
| 1875 inline intptr_t RawObject::NumberOfTypedDataClasses() { |
| 1876 // Make sure this is updated when new TypedData types are added. |
| 1877 ASSERT(kExternalTypedDataInt8ArrayCid == kTypedDataInt8ArrayCid + 11); |
| 1878 ASSERT(kNullCid == kExternalTypedDataInt8ArrayCid + 11); |
| 1879 return (kNullCid - kTypedDataInt8ArrayCid); |
| 1880 } |
| 1881 |
| 1768 } // namespace dart | 1882 } // namespace dart |
| 1769 | 1883 |
| 1770 #endif // VM_RAW_OBJECT_H_ | 1884 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |