| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 V(TypeParameter) \ | 52 V(TypeParameter) \ |
| 53 V(Number) \ | 53 V(Number) \ |
| 54 V(Integer) \ | 54 V(Integer) \ |
| 55 V(Smi) \ | 55 V(Smi) \ |
| 56 V(Mint) \ | 56 V(Mint) \ |
| 57 V(Bigint) \ | 57 V(Bigint) \ |
| 58 V(Double) \ | 58 V(Double) \ |
| 59 V(String) \ | 59 V(String) \ |
| 60 V(OneByteString) \ | 60 V(OneByteString) \ |
| 61 V(TwoByteString) \ | 61 V(TwoByteString) \ |
| 62 V(FourByteString) \ | |
| 63 V(ExternalOneByteString) \ | 62 V(ExternalOneByteString) \ |
| 64 V(ExternalTwoByteString) \ | 63 V(ExternalTwoByteString) \ |
| 65 V(ExternalFourByteString) \ | |
| 66 V(Bool) \ | 64 V(Bool) \ |
| 67 V(Array) \ | 65 V(Array) \ |
| 68 V(ImmutableArray) \ | 66 V(ImmutableArray) \ |
| 69 V(GrowableObjectArray) \ | 67 V(GrowableObjectArray) \ |
| 70 V(ByteArray) \ | 68 V(ByteArray) \ |
| 71 V(Int8Array) \ | 69 V(Int8Array) \ |
| 72 V(Uint8Array) \ | 70 V(Uint8Array) \ |
| 73 V(Int16Array) \ | 71 V(Int16Array) \ |
| 74 V(Uint16Array) \ | 72 V(Uint16Array) \ |
| 75 V(Int32Array) \ | 73 V(Int32Array) \ |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 class RawTwoByteString : public RawString { | 1116 class RawTwoByteString : public RawString { |
| 1119 RAW_HEAP_OBJECT_IMPLEMENTATION(TwoByteString); | 1117 RAW_HEAP_OBJECT_IMPLEMENTATION(TwoByteString); |
| 1120 | 1118 |
| 1121 // Variable length data follows here. | 1119 // Variable length data follows here. |
| 1122 uint16_t data_[0]; | 1120 uint16_t data_[0]; |
| 1123 | 1121 |
| 1124 friend class SnapshotReader; | 1122 friend class SnapshotReader; |
| 1125 }; | 1123 }; |
| 1126 | 1124 |
| 1127 | 1125 |
| 1128 class RawFourByteString : public RawString { | |
| 1129 RAW_HEAP_OBJECT_IMPLEMENTATION(FourByteString); | |
| 1130 | |
| 1131 // Variable length data follows here. | |
| 1132 uint32_t data_[0]; | |
| 1133 | |
| 1134 friend class SnapshotReader; | |
| 1135 }; | |
| 1136 | |
| 1137 | |
| 1138 template<typename T> | 1126 template<typename T> |
| 1139 class ExternalStringData { | 1127 class ExternalStringData { |
| 1140 public: | 1128 public: |
| 1141 ExternalStringData(const T* data, void* peer, Dart_PeerFinalizer callback) : | 1129 ExternalStringData(const T* data, void* peer, Dart_PeerFinalizer callback) : |
| 1142 data_(data), peer_(peer), callback_(callback) { | 1130 data_(data), peer_(peer), callback_(callback) { |
| 1143 } | 1131 } |
| 1144 ~ExternalStringData() { | 1132 ~ExternalStringData() { |
| 1145 if (callback_ != NULL) (*callback_)(peer_); | 1133 if (callback_ != NULL) (*callback_)(peer_); |
| 1146 } | 1134 } |
| 1147 | 1135 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1168 | 1156 |
| 1169 | 1157 |
| 1170 class RawExternalTwoByteString : public RawString { | 1158 class RawExternalTwoByteString : public RawString { |
| 1171 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString); | 1159 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString); |
| 1172 | 1160 |
| 1173 ExternalStringData<uint16_t>* external_data_; | 1161 ExternalStringData<uint16_t>* external_data_; |
| 1174 friend class Api; | 1162 friend class Api; |
| 1175 }; | 1163 }; |
| 1176 | 1164 |
| 1177 | 1165 |
| 1178 class RawExternalFourByteString : public RawString { | |
| 1179 RAW_HEAP_OBJECT_IMPLEMENTATION(ExternalFourByteString); | |
| 1180 | |
| 1181 ExternalStringData<uint32_t>* external_data_; | |
| 1182 friend class Api; | |
| 1183 }; | |
| 1184 | |
| 1185 | |
| 1186 class RawBool : public RawInstance { | 1166 class RawBool : public RawInstance { |
| 1187 RAW_HEAP_OBJECT_IMPLEMENTATION(Bool); | 1167 RAW_HEAP_OBJECT_IMPLEMENTATION(Bool); |
| 1188 | 1168 |
| 1189 bool value_; | 1169 bool value_; |
| 1190 }; | 1170 }; |
| 1191 | 1171 |
| 1192 | 1172 |
| 1193 class RawArray : public RawInstance { | 1173 class RawArray : public RawInstance { |
| 1194 RAW_HEAP_OBJECT_IMPLEMENTATION(Array); | 1174 RAW_HEAP_OBJECT_IMPLEMENTATION(Array); |
| 1195 | 1175 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 return reinterpret_cast<RawObject**>(&ptr()->pattern_); | 1446 return reinterpret_cast<RawObject**>(&ptr()->pattern_); |
| 1467 } | 1447 } |
| 1468 | 1448 |
| 1469 intptr_t type_; // Uninitialized, simple or complex. | 1449 intptr_t type_; // Uninitialized, simple or complex. |
| 1470 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 1450 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
| 1471 | 1451 |
| 1472 // Variable length data follows here. | 1452 // Variable length data follows here. |
| 1473 uint8_t data_[0]; | 1453 uint8_t data_[0]; |
| 1474 }; | 1454 }; |
| 1475 | 1455 |
| 1456 |
| 1476 class RawWeakProperty : public RawInstance { | 1457 class RawWeakProperty : public RawInstance { |
| 1477 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); | 1458 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); |
| 1478 | 1459 |
| 1479 RawObject** from() { | 1460 RawObject** from() { |
| 1480 return reinterpret_cast<RawObject**>(&ptr()->key_); | 1461 return reinterpret_cast<RawObject**>(&ptr()->key_); |
| 1481 } | 1462 } |
| 1482 RawObject* key_; | 1463 RawObject* key_; |
| 1483 RawObject* value_; | 1464 RawObject* value_; |
| 1484 RawObject** to() { | 1465 RawObject** to() { |
| 1485 return reinterpret_cast<RawObject**>(&ptr()->value_); | 1466 return reinterpret_cast<RawObject**>(&ptr()->value_); |
| 1486 } | 1467 } |
| 1487 | 1468 |
| 1488 friend class GCMarker; | 1469 friend class GCMarker; |
| 1489 friend class MarkingVisitor; | 1470 friend class MarkingVisitor; |
| 1490 friend class Scavenger; | 1471 friend class Scavenger; |
| 1491 friend class ScavengerVisitor; | 1472 friend class ScavengerVisitor; |
| 1492 }; | 1473 }; |
| 1493 | 1474 |
| 1475 |
| 1494 // Class Id predicates. | 1476 // Class Id predicates. |
| 1495 | 1477 |
| 1496 inline bool RawObject::IsErrorClassId(intptr_t index) { | 1478 inline bool RawObject::IsErrorClassId(intptr_t index) { |
| 1497 // Make sure this function is updated when new Error types are added. | 1479 // Make sure this function is updated when new Error types are added. |
| 1498 ASSERT(kApiErrorCid == kErrorCid + 1 && | 1480 ASSERT(kApiErrorCid == kErrorCid + 1 && |
| 1499 kLanguageErrorCid == kErrorCid + 2 && | 1481 kLanguageErrorCid == kErrorCid + 2 && |
| 1500 kUnhandledExceptionCid == kErrorCid + 3 && | 1482 kUnhandledExceptionCid == kErrorCid + 3 && |
| 1501 kUnwindErrorCid == kErrorCid + 4 && | 1483 kUnwindErrorCid == kErrorCid + 4 && |
| 1502 kInstanceCid == kErrorCid + 5); | 1484 kInstanceCid == kErrorCid + 5); |
| 1503 return (index >= kErrorCid && index < kInstanceCid); | 1485 return (index >= kErrorCid && index < kInstanceCid); |
| 1504 } | 1486 } |
| 1505 | 1487 |
| 1488 |
| 1506 inline bool RawObject::IsNumberClassId(intptr_t index) { | 1489 inline bool RawObject::IsNumberClassId(intptr_t index) { |
| 1507 // Make sure this function is updated when new Number types are added. | 1490 // Make sure this function is updated when new Number types are added. |
| 1508 ASSERT(kIntegerCid == kNumberCid + 1 && | 1491 ASSERT(kIntegerCid == kNumberCid + 1 && |
| 1509 kSmiCid == kNumberCid + 2 && | 1492 kSmiCid == kNumberCid + 2 && |
| 1510 kMintCid == kNumberCid + 3 && | 1493 kMintCid == kNumberCid + 3 && |
| 1511 kBigintCid == kNumberCid + 4 && | 1494 kBigintCid == kNumberCid + 4 && |
| 1512 kDoubleCid == kNumberCid + 5 && | 1495 kDoubleCid == kNumberCid + 5 && |
| 1513 kStringCid == kNumberCid + 6); | 1496 kStringCid == kNumberCid + 6); |
| 1514 return (index >= kNumberCid && index < kStringCid); | 1497 return (index >= kNumberCid && index < kStringCid); |
| 1515 } | 1498 } |
| 1516 | 1499 |
| 1500 |
| 1517 inline bool RawObject::IsIntegerClassId(intptr_t index) { | 1501 inline bool RawObject::IsIntegerClassId(intptr_t index) { |
| 1518 // Make sure this function is updated when new Integer types are added. | 1502 // Make sure this function is updated when new Integer types are added. |
| 1519 ASSERT(kSmiCid == kIntegerCid + 1 && | 1503 ASSERT(kSmiCid == kIntegerCid + 1 && |
| 1520 kMintCid == kIntegerCid + 2 && | 1504 kMintCid == kIntegerCid + 2 && |
| 1521 kBigintCid == kIntegerCid + 3 && | 1505 kBigintCid == kIntegerCid + 3 && |
| 1522 kDoubleCid == kIntegerCid + 4); | 1506 kDoubleCid == kIntegerCid + 4); |
| 1523 return (index >= kIntegerCid && index < kDoubleCid); | 1507 return (index >= kIntegerCid && index < kDoubleCid); |
| 1524 } | 1508 } |
| 1525 | 1509 |
| 1510 |
| 1526 inline bool RawObject::IsStringClassId(intptr_t index) { | 1511 inline bool RawObject::IsStringClassId(intptr_t index) { |
| 1527 // Make sure this function is updated when new StringCid types are added. | 1512 // Make sure this function is updated when new StringCid types are added. |
| 1528 ASSERT(kOneByteStringCid == kStringCid + 1 && | 1513 ASSERT(kOneByteStringCid == kStringCid + 1 && |
| 1529 kTwoByteStringCid == kStringCid + 2 && | 1514 kTwoByteStringCid == kStringCid + 2 && |
| 1530 kFourByteStringCid == kStringCid + 3 && | 1515 kExternalOneByteStringCid == kStringCid + 3 && |
| 1531 kExternalOneByteStringCid == kStringCid + 4 && | 1516 kExternalTwoByteStringCid == kStringCid + 4 && |
| 1532 kExternalTwoByteStringCid == kStringCid + 5 && | 1517 kBoolCid == kStringCid + 5); |
| 1533 kExternalFourByteStringCid == kStringCid + 6 && | |
| 1534 kBoolCid == kStringCid + 7); | |
| 1535 return (index >= kStringCid && index < kBoolCid); | 1518 return (index >= kStringCid && index < kBoolCid); |
| 1536 } | 1519 } |
| 1537 | 1520 |
| 1521 |
| 1538 inline bool RawObject::IsOneByteStringClassId(intptr_t index) { | 1522 inline bool RawObject::IsOneByteStringClassId(intptr_t index) { |
| 1539 // Make sure this function is updated when new StringCid types are added. | 1523 // Make sure this function is updated when new StringCid types are added. |
| 1540 ASSERT(kOneByteStringCid == kStringCid + 1 && | 1524 ASSERT(kOneByteStringCid == kStringCid + 1 && |
| 1541 kTwoByteStringCid == kStringCid + 2 && | 1525 kTwoByteStringCid == kStringCid + 2 && |
| 1542 kFourByteStringCid == kStringCid + 3 && | 1526 kExternalOneByteStringCid == kStringCid + 3 && |
| 1543 kExternalOneByteStringCid == kStringCid + 4 && | 1527 kExternalTwoByteStringCid == kStringCid + 4 && |
| 1544 kExternalTwoByteStringCid == kStringCid + 5 && | 1528 kBoolCid == kStringCid + 5); |
| 1545 kExternalFourByteStringCid == kStringCid + 6 && | |
| 1546 kBoolCid == kStringCid + 7); | |
| 1547 return (index == kOneByteStringCid || index == kExternalOneByteStringCid); | 1529 return (index == kOneByteStringCid || index == kExternalOneByteStringCid); |
| 1548 } | 1530 } |
| 1549 | 1531 |
| 1532 |
| 1550 inline bool RawObject::IsTwoByteStringClassId(intptr_t index) { | 1533 inline bool RawObject::IsTwoByteStringClassId(intptr_t index) { |
| 1551 // Make sure this function is updated when new StringCid types are added. | 1534 // Make sure this function is updated when new StringCid types are added. |
| 1552 ASSERT(kOneByteStringCid == kStringCid + 1 && | 1535 ASSERT(kOneByteStringCid == kStringCid + 1 && |
| 1553 kTwoByteStringCid == kStringCid + 2 && | 1536 kTwoByteStringCid == kStringCid + 2 && |
| 1554 kFourByteStringCid == kStringCid + 3 && | 1537 kExternalOneByteStringCid == kStringCid + 3 && |
| 1555 kExternalOneByteStringCid == kStringCid + 4 && | 1538 kExternalTwoByteStringCid == kStringCid + 4 && |
| 1556 kExternalTwoByteStringCid == kStringCid + 5 && | 1539 kBoolCid == kStringCid + 5); |
| 1557 kExternalFourByteStringCid == kStringCid + 6 && | |
| 1558 kBoolCid == kStringCid + 7); | |
| 1559 return (index == kOneByteStringCid || | 1540 return (index == kOneByteStringCid || |
| 1560 index == kTwoByteStringCid || | 1541 index == kTwoByteStringCid || |
| 1561 index == kExternalOneByteStringCid || | 1542 index == kExternalOneByteStringCid || |
| 1562 index == kExternalTwoByteStringCid); | 1543 index == kExternalTwoByteStringCid); |
| 1563 } | 1544 } |
| 1564 | 1545 |
| 1546 |
| 1565 inline bool RawObject::IsExternalStringClassId(intptr_t index) { | 1547 inline bool RawObject::IsExternalStringClassId(intptr_t index) { |
| 1566 // Make sure this function is updated when new StringCid types are added. | 1548 // Make sure this function is updated when new StringCid types are added. |
| 1567 ASSERT(kOneByteStringCid == kStringCid + 1 && | 1549 ASSERT(kOneByteStringCid == kStringCid + 1 && |
| 1568 kTwoByteStringCid == kStringCid + 2 && | 1550 kTwoByteStringCid == kStringCid + 2 && |
| 1569 kFourByteStringCid == kStringCid + 3 && | 1551 kExternalOneByteStringCid == kStringCid + 3 && |
| 1570 kExternalOneByteStringCid == kStringCid + 4 && | 1552 kExternalTwoByteStringCid == kStringCid + 4 && |
| 1571 kExternalTwoByteStringCid == kStringCid + 5 && | 1553 kBoolCid == kStringCid + 5); |
| 1572 kExternalFourByteStringCid == kStringCid + 6 && | |
| 1573 kBoolCid == kStringCid + 7); | |
| 1574 return (index == kExternalOneByteStringCid || | 1554 return (index == kExternalOneByteStringCid || |
| 1575 index == kExternalTwoByteStringCid || | 1555 index == kExternalTwoByteStringCid); |
| 1576 index == kExternalFourByteStringCid); | |
| 1577 } | 1556 } |
| 1578 | 1557 |
| 1558 |
| 1579 inline bool RawObject::IsBuiltinListClassId(intptr_t index) { | 1559 inline bool RawObject::IsBuiltinListClassId(intptr_t index) { |
| 1580 // Make sure this function is updated when new builtin List types are added. | 1560 // Make sure this function is updated when new builtin List types are added. |
| 1581 ASSERT(kImmutableArrayCid == kArrayCid + 1 && | 1561 ASSERT(kImmutableArrayCid == kArrayCid + 1 && |
| 1582 kGrowableObjectArrayCid == kArrayCid + 2 && | 1562 kGrowableObjectArrayCid == kArrayCid + 2 && |
| 1583 kByteArrayCid == kArrayCid + 3); | 1563 kByteArrayCid == kArrayCid + 3); |
| 1584 return (index >= kArrayCid && index < kByteArrayCid) || | 1564 return (index >= kArrayCid && index < kByteArrayCid) || |
| 1585 IsByteArrayClassId(index); | 1565 IsByteArrayClassId(index); |
| 1586 } | 1566 } |
| 1587 | 1567 |
| 1568 |
| 1588 inline bool RawObject::IsByteArrayClassId(intptr_t index) { | 1569 inline bool RawObject::IsByteArrayClassId(intptr_t index) { |
| 1589 // Make sure this function is updated when new ByteArray types are added. | 1570 // Make sure this function is updated when new ByteArray types are added. |
| 1590 ASSERT(kInt8ArrayCid == kByteArrayCid + 1 && | 1571 ASSERT(kInt8ArrayCid == kByteArrayCid + 1 && |
| 1591 kUint8ArrayCid == kByteArrayCid + 2 && | 1572 kUint8ArrayCid == kByteArrayCid + 2 && |
| 1592 kInt16ArrayCid == kByteArrayCid + 3 && | 1573 kInt16ArrayCid == kByteArrayCid + 3 && |
| 1593 kUint16ArrayCid == kByteArrayCid + 4 && | 1574 kUint16ArrayCid == kByteArrayCid + 4 && |
| 1594 kInt32ArrayCid == kByteArrayCid + 5 && | 1575 kInt32ArrayCid == kByteArrayCid + 5 && |
| 1595 kUint32ArrayCid == kByteArrayCid + 6 && | 1576 kUint32ArrayCid == kByteArrayCid + 6 && |
| 1596 kInt64ArrayCid == kByteArrayCid + 7 && | 1577 kInt64ArrayCid == kByteArrayCid + 7 && |
| 1597 kUint64ArrayCid == kByteArrayCid + 8 && | 1578 kUint64ArrayCid == kByteArrayCid + 8 && |
| 1598 kFloat32ArrayCid == kByteArrayCid + 9 && | 1579 kFloat32ArrayCid == kByteArrayCid + 9 && |
| 1599 kFloat64ArrayCid == kByteArrayCid + 10 && | 1580 kFloat64ArrayCid == kByteArrayCid + 10 && |
| 1600 kExternalInt8ArrayCid == kByteArrayCid + 11 && | 1581 kExternalInt8ArrayCid == kByteArrayCid + 11 && |
| 1601 kExternalUint8ArrayCid == kByteArrayCid + 12 && | 1582 kExternalUint8ArrayCid == kByteArrayCid + 12 && |
| 1602 kExternalInt16ArrayCid == kByteArrayCid + 13 && | 1583 kExternalInt16ArrayCid == kByteArrayCid + 13 && |
| 1603 kExternalUint16ArrayCid == kByteArrayCid + 14 && | 1584 kExternalUint16ArrayCid == kByteArrayCid + 14 && |
| 1604 kExternalInt32ArrayCid == kByteArrayCid + 15 && | 1585 kExternalInt32ArrayCid == kByteArrayCid + 15 && |
| 1605 kExternalUint32ArrayCid == kByteArrayCid + 16 && | 1586 kExternalUint32ArrayCid == kByteArrayCid + 16 && |
| 1606 kExternalInt64ArrayCid == kByteArrayCid + 17 && | 1587 kExternalInt64ArrayCid == kByteArrayCid + 17 && |
| 1607 kExternalUint64ArrayCid == kByteArrayCid + 18 && | 1588 kExternalUint64ArrayCid == kByteArrayCid + 18 && |
| 1608 kExternalFloat32ArrayCid == kByteArrayCid + 19 && | 1589 kExternalFloat32ArrayCid == kByteArrayCid + 19 && |
| 1609 kExternalFloat64ArrayCid == kByteArrayCid + 20 && | 1590 kExternalFloat64ArrayCid == kByteArrayCid + 20 && |
| 1610 kStacktraceCid == kByteArrayCid + 21); | 1591 kStacktraceCid == kByteArrayCid + 21); |
| 1611 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); | 1592 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); |
| 1612 } | 1593 } |
| 1613 | 1594 |
| 1614 } // namespace dart | 1595 } // namespace dart |
| 1615 | 1596 |
| 1616 #endif // VM_RAW_OBJECT_H_ | 1597 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |