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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 V(ExternalInt8Array) \ | 79 V(ExternalInt8Array) \ |
80 V(ExternalUint8Array) \ | 80 V(ExternalUint8Array) \ |
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(ExternalFloat32Array) \ | 87 V(ExternalFloat32Array) \ |
88 V(ExternalFloat64Array) \ | 88 V(ExternalFloat64Array) \ |
89 V(Closure) \ | |
90 V(Stacktrace) \ | 89 V(Stacktrace) \ |
91 V(JSRegExp) \ | 90 V(JSRegExp) \ |
| 91 V(Closure) \ |
92 | 92 |
93 #define CLASS_LIST(V) \ | 93 #define CLASS_LIST(V) \ |
94 V(Object) \ | 94 V(Object) \ |
95 CLASS_LIST_NO_OBJECT(V) | 95 CLASS_LIST_NO_OBJECT(V) |
96 | 96 |
97 | 97 |
98 // Forward declarations. | 98 // Forward declarations. |
99 class Isolate; | 99 class Isolate; |
100 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 100 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
101 class Raw##clazz; | 101 class Raw##clazz; |
102 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 102 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
103 #undef DEFINE_FORWARD_DECLARATION | 103 #undef DEFINE_FORWARD_DECLARATION |
104 | 104 |
105 | 105 |
106 enum ObjectKind { | 106 enum ClassId { |
107 kIllegalObjectKind = 0, | 107 // Illegal class id. |
| 108 kIllegalCid = 0, |
| 109 |
| 110 // List of Ids for predefined classes. |
108 #define DEFINE_OBJECT_KIND(clazz) \ | 111 #define DEFINE_OBJECT_KIND(clazz) \ |
109 k##clazz, | 112 k##clazz##Cid, |
110 CLASS_LIST(DEFINE_OBJECT_KIND) | 113 CLASS_LIST(DEFINE_OBJECT_KIND) |
111 #undef DEFINE_OBJECT_KIND | 114 #undef DEFINE_OBJECT_KIND |
112 // The following entry does not describe a real object, but instead it | 115 |
113 // identifies free list elements in the heap. | 116 // The following entries do not describe a predefined class, but instead |
| 117 // are class indexes for pre-allocated instance (Null, Dynamic and Void). |
| 118 kNullCid, |
| 119 kDynamicCid, |
| 120 kVoidCid, |
| 121 |
| 122 // The following entry does not describe a real class, but instead it is an |
| 123 // id which is used to identify free list elements in the heap. |
114 kFreeListElement, | 124 kFreeListElement, |
115 // The following entries do not describe a real object, but instead are used | 125 |
116 // to allocate class indexes for pre-allocated instance classes such as the | 126 kNumPredefinedCids, |
117 // Null, Void, Dynamic and other similar classes. | |
118 kNullClassId, | |
119 kDynamicClassId, | |
120 kVoidClassId, | |
121 kNumPredefinedKinds = 100 | |
122 }; | 127 }; |
123 | 128 |
124 enum ObjectAlignment { | 129 enum ObjectAlignment { |
125 // Alignment offsets are used to determine object age. | 130 // Alignment offsets are used to determine object age. |
126 kNewObjectAlignmentOffset = kWordSize, | 131 kNewObjectAlignmentOffset = kWordSize, |
127 kOldObjectAlignmentOffset = 0, | 132 kOldObjectAlignmentOffset = 0, |
128 // Object sizes are aligned to kObjectAlignment. | 133 // Object sizes are aligned to kObjectAlignment. |
129 kObjectAlignment = 2 * kWordSize, | 134 kObjectAlignment = 2 * kWordSize, |
130 kObjectAlignmentLog2 = kWordSizeLog2 + 1, | 135 kObjectAlignmentLog2 = kWordSizeLog2 + 1, |
131 kObjectAlignmentMask = kObjectAlignment - 1, | 136 kObjectAlignmentMask = kObjectAlignment - 1, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 304 } |
300 | 305 |
301 static bool IsCreatedFromSnapshot(intptr_t value) { | 306 static bool IsCreatedFromSnapshot(intptr_t value) { |
302 return CreatedFromSnapshotTag::decode(value); | 307 return CreatedFromSnapshotTag::decode(value); |
303 } | 308 } |
304 | 309 |
305 static bool IsCanonical(intptr_t value) { | 310 static bool IsCanonical(intptr_t value) { |
306 return CanonicalObjectTag::decode(value); | 311 return CanonicalObjectTag::decode(value); |
307 } | 312 } |
308 | 313 |
309 // ObjectKind predicates. | 314 // Class Id predicates. |
310 static bool IsErrorClassId(intptr_t index); | 315 static bool IsErrorClassId(intptr_t index); |
311 static bool IsNumberClassId(intptr_t index); | 316 static bool IsNumberClassId(intptr_t index); |
312 static bool IsIntegerClassId(intptr_t index); | 317 static bool IsIntegerClassId(intptr_t index); |
313 static bool IsStringClassId(intptr_t index); | 318 static bool IsStringClassId(intptr_t index); |
314 static bool IsOneByteStringClassId(intptr_t index); | 319 static bool IsOneByteStringClassId(intptr_t index); |
315 static bool IsTwoByteStringClassId(intptr_t index); | 320 static bool IsTwoByteStringClassId(intptr_t index); |
316 static bool IsExternalStringClassId(intptr_t index); | 321 static bool IsExternalStringClassId(intptr_t index); |
317 static bool IsBuiltinListClassId(intptr_t index); | 322 static bool IsBuiltinListClassId(intptr_t index); |
318 static bool IsByteArrayClassId(intptr_t index); | 323 static bool IsByteArrayClassId(intptr_t index); |
319 | 324 |
(...skipping 19 matching lines...) Expand all Loading... |
339 reinterpret_cast<uword>(this) - kHeapObjectTag); | 344 reinterpret_cast<uword>(this) - kHeapObjectTag); |
340 } | 345 } |
341 | 346 |
342 intptr_t SizeFromClass() const; | 347 intptr_t SizeFromClass() const; |
343 | 348 |
344 intptr_t GetClassId() const { | 349 intptr_t GetClassId() const { |
345 uword tags = ptr()->tags_; | 350 uword tags = ptr()->tags_; |
346 return ClassIdTag::decode(tags); | 351 return ClassIdTag::decode(tags); |
347 } | 352 } |
348 | 353 |
349 ObjectKind GetObjectKind() const; | |
350 | |
351 friend class Api; | 354 friend class Api; |
352 friend class Array; | 355 friend class Array; |
353 friend class FreeListElement; | 356 friend class FreeListElement; |
354 friend class Heap; | 357 friend class Heap; |
355 friend class HeapProfiler; | 358 friend class HeapProfiler; |
356 friend class HeapProfilerRootVisitor; | 359 friend class HeapProfilerRootVisitor; |
357 friend class MarkingVisitor; | 360 friend class MarkingVisitor; |
358 friend class Object; | 361 friend class Object; |
359 friend class RawInstructions; | 362 friend class RawInstructions; |
360 friend class RawInstance; | 363 friend class RawInstance; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 RawArray* functions_cache_; // See class FunctionsCache. | 395 RawArray* functions_cache_; // See class FunctionsCache. |
393 RawArray* constants_; // Canonicalized values of this class. | 396 RawArray* constants_; // Canonicalized values of this class. |
394 RawArray* canonical_types_; // Canonicalized types of this class. | 397 RawArray* canonical_types_; // Canonicalized types of this class. |
395 RawCode* allocation_stub_; // Stub code for allocation of instances. | 398 RawCode* allocation_stub_; // Stub code for allocation of instances. |
396 RawObject** to() { | 399 RawObject** to() { |
397 return reinterpret_cast<RawObject**>(&ptr()->allocation_stub_); | 400 return reinterpret_cast<RawObject**>(&ptr()->allocation_stub_); |
398 } | 401 } |
399 | 402 |
400 cpp_vtable handle_vtable_; | 403 cpp_vtable handle_vtable_; |
401 intptr_t instance_size_; // Size if fixed length or 0 if variable length. | 404 intptr_t instance_size_; // Size if fixed length or 0 if variable length. |
402 ObjectKind instance_kind_; | |
403 intptr_t id_; // Class Id, also index in the class table. | 405 intptr_t id_; // Class Id, also index in the class table. |
404 intptr_t type_arguments_instance_field_offset_; // May be kNoTypeArguments. | 406 intptr_t type_arguments_instance_field_offset_; // May be kNoTypeArguments. |
405 intptr_t next_field_offset_; // Offset of the next instance field. | 407 intptr_t next_field_offset_; // Offset of the next instance field. |
406 intptr_t num_native_fields_; // Number of native fields in class. | 408 intptr_t num_native_fields_; // Number of native fields in class. |
407 intptr_t token_pos_; | 409 intptr_t token_pos_; |
408 int8_t class_state_; // Of type ClassState. | 410 int8_t class_state_; // Of type ClassState. |
409 bool is_const_; | 411 bool is_const_; |
410 bool is_interface_; | 412 bool is_interface_; |
411 | 413 |
412 friend class Object; | 414 friend class Object; |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 return reinterpret_cast<RawObject**>(&ptr()->pattern_); | 1487 return reinterpret_cast<RawObject**>(&ptr()->pattern_); |
1486 } | 1488 } |
1487 | 1489 |
1488 intptr_t type_; // Uninitialized, simple or complex. | 1490 intptr_t type_; // Uninitialized, simple or complex. |
1489 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 1491 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
1490 | 1492 |
1491 // Variable length data follows here. | 1493 // Variable length data follows here. |
1492 uint8_t data_[0]; | 1494 uint8_t data_[0]; |
1493 }; | 1495 }; |
1494 | 1496 |
1495 // ObjectKind predicates. | 1497 // Class Id predicates. |
1496 | 1498 |
1497 inline bool RawObject::IsErrorClassId(intptr_t index) { | 1499 inline bool RawObject::IsErrorClassId(intptr_t index) { |
1498 // Make sure this function is updated when new Error types are added. | 1500 // Make sure this function is updated when new Error types are added. |
1499 ASSERT(kApiError == kError + 1 && | 1501 ASSERT(kApiErrorCid == kErrorCid + 1 && |
1500 kLanguageError == kError + 2 && | 1502 kLanguageErrorCid == kErrorCid + 2 && |
1501 kUnhandledException == kError + 3 && | 1503 kUnhandledExceptionCid == kErrorCid + 3 && |
1502 kUnwindError == kError + 4 && | 1504 kUnwindErrorCid == kErrorCid + 4 && |
1503 kInstance == kError + 5); | 1505 kInstanceCid == kErrorCid + 5); |
1504 return (index >= kError && index < kInstance); | 1506 return (index >= kErrorCid && index < kInstanceCid); |
1505 } | 1507 } |
1506 | 1508 |
1507 inline bool RawObject::IsNumberClassId(intptr_t index) { | 1509 inline bool RawObject::IsNumberClassId(intptr_t index) { |
1508 // Make sure this function is updated when new Number types are added. | 1510 // Make sure this function is updated when new Number types are added. |
1509 ASSERT(kInteger == kNumber + 1 && | 1511 ASSERT(kIntegerCid == kNumberCid + 1 && |
1510 kSmi == kNumber + 2 && | 1512 kSmiCid == kNumberCid + 2 && |
1511 kMint == kNumber + 3 && | 1513 kMintCid == kNumberCid + 3 && |
1512 kBigint == kNumber + 4 && | 1514 kBigintCid == kNumberCid + 4 && |
1513 kDouble == kNumber + 5 && | 1515 kDoubleCid == kNumberCid + 5 && |
1514 kString == kNumber + 6); | 1516 kStringCid == kNumberCid + 6); |
1515 return (index >= kNumber && index < kString); | 1517 return (index >= kNumberCid && index < kStringCid); |
1516 } | 1518 } |
1517 | 1519 |
1518 inline bool RawObject::IsIntegerClassId(intptr_t index) { | 1520 inline bool RawObject::IsIntegerClassId(intptr_t index) { |
1519 // Make sure this function is updated when new Integer types are added. | 1521 // Make sure this function is updated when new Integer types are added. |
1520 ASSERT(kSmi == kInteger + 1 && | 1522 ASSERT(kSmiCid == kIntegerCid + 1 && |
1521 kMint == kInteger + 2 && | 1523 kMintCid == kIntegerCid + 2 && |
1522 kBigint == kInteger + 3 && | 1524 kBigintCid == kIntegerCid + 3 && |
1523 kDouble == kInteger + 4); | 1525 kDoubleCid == kIntegerCid + 4); |
1524 return (index >= kInteger && index < kDouble); | 1526 return (index >= kIntegerCid && index < kDoubleCid); |
1525 } | 1527 } |
1526 | 1528 |
1527 inline bool RawObject::IsStringClassId(intptr_t index) { | 1529 inline bool RawObject::IsStringClassId(intptr_t index) { |
1528 // Make sure this function is updated when new String types are added. | 1530 // Make sure this function is updated when new StringCid types are added. |
1529 ASSERT(kOneByteString == kString + 1 && | 1531 ASSERT(kOneByteStringCid == kStringCid + 1 && |
1530 kTwoByteString == kString + 2 && | 1532 kTwoByteStringCid == kStringCid + 2 && |
1531 kFourByteString == kString + 3 && | 1533 kFourByteStringCid == kStringCid + 3 && |
1532 kExternalOneByteString == kString + 4 && | 1534 kExternalOneByteStringCid == kStringCid + 4 && |
1533 kExternalTwoByteString == kString + 5 && | 1535 kExternalTwoByteStringCid == kStringCid + 5 && |
1534 kExternalFourByteString == kString + 6 && | 1536 kExternalFourByteStringCid == kStringCid + 6 && |
1535 kBool == kString + 7); | 1537 kBoolCid == kStringCid + 7); |
1536 return (index >= kString && index < kBool); | 1538 return (index >= kStringCid && index < kBoolCid); |
1537 } | 1539 } |
1538 | 1540 |
1539 inline bool RawObject::IsOneByteStringClassId(intptr_t index) { | 1541 inline bool RawObject::IsOneByteStringClassId(intptr_t index) { |
1540 // Make sure this function is updated when new String types are added. | 1542 // Make sure this function is updated when new StringCid types are added. |
1541 ASSERT(kOneByteString == kString + 1 && | 1543 ASSERT(kOneByteStringCid == kStringCid + 1 && |
1542 kTwoByteString == kString + 2 && | 1544 kTwoByteStringCid == kStringCid + 2 && |
1543 kFourByteString == kString + 3 && | 1545 kFourByteStringCid == kStringCid + 3 && |
1544 kExternalOneByteString == kString + 4 && | 1546 kExternalOneByteStringCid == kStringCid + 4 && |
1545 kExternalTwoByteString == kString + 5 && | 1547 kExternalTwoByteStringCid == kStringCid + 5 && |
1546 kExternalFourByteString == kString + 6 && | 1548 kExternalFourByteStringCid == kStringCid + 6 && |
1547 kBool == kString + 7); | 1549 kBoolCid == kStringCid + 7); |
1548 return (index == kOneByteString || | 1550 return (index == kOneByteStringCid || index == kExternalOneByteStringCid); |
1549 index == kExternalOneByteString); | |
1550 } | 1551 } |
1551 | 1552 |
1552 inline bool RawObject::IsTwoByteStringClassId(intptr_t index) { | 1553 inline bool RawObject::IsTwoByteStringClassId(intptr_t index) { |
1553 // Make sure this function is updated when new String types are added. | 1554 // Make sure this function is updated when new StringCid types are added. |
1554 ASSERT(kOneByteString == kString + 1 && | 1555 ASSERT(kOneByteStringCid == kStringCid + 1 && |
1555 kTwoByteString == kString + 2 && | 1556 kTwoByteStringCid == kStringCid + 2 && |
1556 kFourByteString == kString + 3 && | 1557 kFourByteStringCid == kStringCid + 3 && |
1557 kExternalOneByteString == kString + 4 && | 1558 kExternalOneByteStringCid == kStringCid + 4 && |
1558 kExternalTwoByteString == kString + 5 && | 1559 kExternalTwoByteStringCid == kStringCid + 5 && |
1559 kExternalFourByteString == kString + 6 && | 1560 kExternalFourByteStringCid == kStringCid + 6 && |
1560 kBool == kString + 7); | 1561 kBoolCid == kStringCid + 7); |
1561 return (index == kOneByteString || | 1562 return (index == kOneByteStringCid || |
1562 index == kTwoByteString || | 1563 index == kTwoByteStringCid || |
1563 index == kExternalOneByteString || | 1564 index == kExternalOneByteStringCid || |
1564 index == kExternalTwoByteString); | 1565 index == kExternalTwoByteStringCid); |
1565 } | 1566 } |
1566 | 1567 |
1567 inline bool RawObject::IsExternalStringClassId(intptr_t index) { | 1568 inline bool RawObject::IsExternalStringClassId(intptr_t index) { |
1568 // Make sure this function is updated when new String types are added. | 1569 // Make sure this function is updated when new StringCid types are added. |
1569 ASSERT(kOneByteString == kString + 1 && | 1570 ASSERT(kOneByteStringCid == kStringCid + 1 && |
1570 kTwoByteString == kString + 2 && | 1571 kTwoByteStringCid == kStringCid + 2 && |
1571 kFourByteString == kString + 3 && | 1572 kFourByteStringCid == kStringCid + 3 && |
1572 kExternalOneByteString == kString + 4 && | 1573 kExternalOneByteStringCid == kStringCid + 4 && |
1573 kExternalTwoByteString == kString + 5 && | 1574 kExternalTwoByteStringCid == kStringCid + 5 && |
1574 kExternalFourByteString == kString + 6 && | 1575 kExternalFourByteStringCid == kStringCid + 6 && |
1575 kBool == kString + 7); | 1576 kBoolCid == kStringCid + 7); |
1576 return (index == kExternalOneByteString || | 1577 return (index == kExternalOneByteStringCid || |
1577 index == kExternalTwoByteString || | 1578 index == kExternalTwoByteStringCid || |
1578 index == kExternalFourByteString); | 1579 index == kExternalFourByteStringCid); |
1579 } | 1580 } |
1580 | 1581 |
1581 inline bool RawObject::IsBuiltinListClassId(intptr_t index) { | 1582 inline bool RawObject::IsBuiltinListClassId(intptr_t index) { |
1582 // Make sure this function is updated when new builtin List types are added. | 1583 // Make sure this function is updated when new builtin List types are added. |
1583 ASSERT(kImmutableArray == kArray + 1 && | 1584 ASSERT(kImmutableArrayCid == kArrayCid + 1 && |
1584 kGrowableObjectArray == kArray + 2 && | 1585 kGrowableObjectArrayCid == kArrayCid + 2 && |
1585 kByteArray == kArray + 3); | 1586 kByteArrayCid == kArrayCid + 3); |
1586 return (index >= kArray && index < kByteArray) || IsByteArrayClassId(index); | 1587 return (index >= kArrayCid && index < kByteArrayCid) || |
| 1588 IsByteArrayClassId(index); |
1587 } | 1589 } |
1588 | 1590 |
1589 inline bool RawObject::IsByteArrayClassId(intptr_t index) { | 1591 inline bool RawObject::IsByteArrayClassId(intptr_t index) { |
1590 // Make sure this function is updated when new ByteArray types are added. | 1592 // Make sure this function is updated when new ByteArray types are added. |
1591 ASSERT(kInt8Array == kByteArray + 1 && | 1593 ASSERT(kInt8ArrayCid == kByteArrayCid + 1 && |
1592 kUint8Array == kByteArray + 2 && | 1594 kUint8ArrayCid == kByteArrayCid + 2 && |
1593 kInt16Array == kByteArray + 3 && | 1595 kInt16ArrayCid == kByteArrayCid + 3 && |
1594 kUint16Array == kByteArray + 4 && | 1596 kUint16ArrayCid == kByteArrayCid + 4 && |
1595 kInt32Array == kByteArray + 5 && | 1597 kInt32ArrayCid == kByteArrayCid + 5 && |
1596 kUint32Array == kByteArray + 6 && | 1598 kUint32ArrayCid == kByteArrayCid + 6 && |
1597 kInt64Array == kByteArray + 7 && | 1599 kInt64ArrayCid == kByteArrayCid + 7 && |
1598 kUint64Array == kByteArray + 8 && | 1600 kUint64ArrayCid == kByteArrayCid + 8 && |
1599 kFloat32Array == kByteArray + 9 && | 1601 kFloat32ArrayCid == kByteArrayCid + 9 && |
1600 kFloat64Array == kByteArray + 10 && | 1602 kFloat64ArrayCid == kByteArrayCid + 10 && |
1601 kExternalInt8Array == kByteArray + 11 && | 1603 kExternalInt8ArrayCid == kByteArrayCid + 11 && |
1602 kExternalUint8Array == kByteArray + 12 && | 1604 kExternalUint8ArrayCid == kByteArrayCid + 12 && |
1603 kExternalInt16Array == kByteArray + 13 && | 1605 kExternalInt16ArrayCid == kByteArrayCid + 13 && |
1604 kExternalUint16Array == kByteArray + 14 && | 1606 kExternalUint16ArrayCid == kByteArrayCid + 14 && |
1605 kExternalInt32Array == kByteArray + 15 && | 1607 kExternalInt32ArrayCid == kByteArrayCid + 15 && |
1606 kExternalUint32Array == kByteArray + 16 && | 1608 kExternalUint32ArrayCid == kByteArrayCid + 16 && |
1607 kExternalInt64Array == kByteArray + 17 && | 1609 kExternalInt64ArrayCid == kByteArrayCid + 17 && |
1608 kExternalUint64Array == kByteArray + 18 && | 1610 kExternalUint64ArrayCid == kByteArrayCid + 18 && |
1609 kExternalFloat32Array == kByteArray + 19 && | 1611 kExternalFloat32ArrayCid == kByteArrayCid + 19 && |
1610 kExternalFloat64Array == kByteArray + 20 && | 1612 kExternalFloat64ArrayCid == kByteArrayCid + 20 && |
1611 kClosure == kByteArray + 21); | 1613 kStacktraceCid == kByteArrayCid + 21); |
1612 return (index >= kByteArray && index <= kClosure); | 1614 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); |
1613 } | 1615 } |
1614 | 1616 |
1615 } // namespace dart | 1617 } // namespace dart |
1616 | 1618 |
1617 #endif // VM_RAW_OBJECT_H_ | 1619 #endif // VM_RAW_OBJECT_H_ |
OLD | NEW |