| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 294 } |
| 295 | 295 |
| 296 static bool IsCreatedFromSnapshot(intptr_t value) { | 296 static bool IsCreatedFromSnapshot(intptr_t value) { |
| 297 return CreatedFromSnapshotTag::decode(value); | 297 return CreatedFromSnapshotTag::decode(value); |
| 298 } | 298 } |
| 299 | 299 |
| 300 static bool IsCanonical(intptr_t value) { | 300 static bool IsCanonical(intptr_t value) { |
| 301 return CanonicalObjectTag::decode(value); | 301 return CanonicalObjectTag::decode(value); |
| 302 } | 302 } |
| 303 | 303 |
| 304 // ObjectKind predicates. |
| 305 static bool IsErrorClassIndex(intptr_t index); |
| 306 static bool IsNumberClassIndex(intptr_t index); |
| 307 static bool IsIntegerClassIndex(intptr_t index); |
| 308 static bool IsStringClassIndex(intptr_t index); |
| 309 static bool IsOneByteStringClassIndex(intptr_t index); |
| 310 static bool IsTwoByteStringClassIndex(intptr_t index); |
| 311 static bool IsExternalStringClassIndex(intptr_t index); |
| 312 static bool IsBuiltinListClassIndex(intptr_t index); |
| 313 static bool IsByteArrayClassIndex(intptr_t index); |
| 314 |
| 304 protected: | 315 protected: |
| 305 RawClass* class_; | 316 RawClass* class_; |
| 306 uword tags_; // Various object tags (bits). | 317 uword tags_; // Various object tags (bits). |
| 307 | 318 |
| 308 private: | 319 private: |
| 309 class FreeBit : public BitField<bool, kFreeBit, 1> {}; | 320 class FreeBit : public BitField<bool, kFreeBit, 1> {}; |
| 310 | 321 |
| 311 class MarkBit : public BitField<bool, kMarkBit, 1> {}; | 322 class MarkBit : public BitField<bool, kMarkBit, 1> {}; |
| 312 | 323 |
| 313 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; | 324 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; |
| 314 | 325 |
| 315 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; | 326 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; |
| 316 | 327 |
| 317 RawObject* ptr() const { | 328 RawObject* ptr() const { |
| 318 ASSERT(IsHeapObject()); | 329 ASSERT(IsHeapObject()); |
| 319 return reinterpret_cast<RawObject*>( | 330 return reinterpret_cast<RawObject*>( |
| 320 reinterpret_cast<uword>(this) - kHeapObjectTag); | 331 reinterpret_cast<uword>(this) - kHeapObjectTag); |
| 321 } | 332 } |
| 322 | 333 |
| 323 intptr_t SizeFromClass() const; | 334 intptr_t SizeFromClass() const; |
| 324 | 335 |
| 336 intptr_t GetClassIndex() const { |
| 337 uword tags = ptr()->tags_; |
| 338 return ClassTag::decode(tags); |
| 339 } |
| 340 |
| 341 friend class Api; |
| 342 friend class Array; |
| 325 friend class Heap; | 343 friend class Heap; |
| 344 friend class MarkingVisitor; |
| 326 friend class Object; | 345 friend class Object; |
| 327 friend class Array; | |
| 328 friend class RawInstructions; | 346 friend class RawInstructions; |
| 347 friend class SnapshotReader; |
| 329 friend class SnapshotWriter; | 348 friend class SnapshotWriter; |
| 330 friend class SnapshotReader; | |
| 331 friend class MarkingVisitor; | |
| 332 | 349 |
| 333 DISALLOW_ALLOCATION(); | 350 DISALLOW_ALLOCATION(); |
| 334 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); | 351 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); |
| 335 }; | 352 }; |
| 336 | 353 |
| 337 | 354 |
| 338 class RawClass : public RawObject { | 355 class RawClass : public RawObject { |
| 339 public: | 356 public: |
| 340 enum ClassState { | 357 enum ClassState { |
| 341 kAllocated, // Initial state. | 358 kAllocated, // Initial state. |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 return reinterpret_cast<RawObject**>(&ptr()->pattern_); | 1371 return reinterpret_cast<RawObject**>(&ptr()->pattern_); |
| 1355 } | 1372 } |
| 1356 | 1373 |
| 1357 intptr_t type_; // Uninitialized, simple or complex. | 1374 intptr_t type_; // Uninitialized, simple or complex. |
| 1358 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 1375 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
| 1359 | 1376 |
| 1360 // Variable length data follows here. | 1377 // Variable length data follows here. |
| 1361 uint8_t data_[0]; | 1378 uint8_t data_[0]; |
| 1362 }; | 1379 }; |
| 1363 | 1380 |
| 1381 // ObjectKind predicates. |
| 1382 |
| 1383 inline bool RawObject::IsErrorClassIndex(intptr_t index) { |
| 1384 // Make sure this function is updated when new Error types are added. |
| 1385 ASSERT(kApiError == kError + 1 && |
| 1386 kLanguageError == kError + 2 && |
| 1387 kUnhandledException == kError + 3 && |
| 1388 kUnwindError == kError + 4 && |
| 1389 kInstance == kError + 5); |
| 1390 return (index >= kError && index < kInstance); |
| 1391 } |
| 1392 |
| 1393 inline bool RawObject::IsNumberClassIndex(intptr_t index) { |
| 1394 // Make sure this function is updated when new Number types are added. |
| 1395 ASSERT(kInteger == kNumber + 1 && |
| 1396 kSmi == kNumber + 2 && |
| 1397 kMint == kNumber + 3 && |
| 1398 kBigint == kNumber + 4 && |
| 1399 kDouble == kNumber + 5 && |
| 1400 kString == kNumber + 6); |
| 1401 return (index >= kNumber && index < kString); |
| 1402 } |
| 1403 |
| 1404 inline bool RawObject::IsIntegerClassIndex(intptr_t index) { |
| 1405 // Make sure this function is updated when new Integer types are added. |
| 1406 ASSERT(kSmi == kInteger + 1 && |
| 1407 kMint == kInteger + 2 && |
| 1408 kBigint == kInteger + 3 && |
| 1409 kDouble == kInteger + 4); |
| 1410 return (index >= kInteger && index < kDouble); |
| 1411 } |
| 1412 |
| 1413 inline bool RawObject::IsStringClassIndex(intptr_t index) { |
| 1414 // Make sure this function is updated when new String types are added. |
| 1415 ASSERT(kOneByteString == kString + 1 && |
| 1416 kTwoByteString == kString + 2 && |
| 1417 kFourByteString == kString + 3 && |
| 1418 kExternalOneByteString == kString + 4 && |
| 1419 kExternalTwoByteString == kString + 5 && |
| 1420 kExternalFourByteString == kString + 6 && |
| 1421 kBool == kString + 7); |
| 1422 return (index >= kString && index < kBool); |
| 1423 } |
| 1424 |
| 1425 inline bool RawObject::IsOneByteStringClassIndex(intptr_t index) { |
| 1426 // Make sure this function is updated when new String types are added. |
| 1427 ASSERT(kOneByteString == kString + 1 && |
| 1428 kTwoByteString == kString + 2 && |
| 1429 kFourByteString == kString + 3 && |
| 1430 kExternalOneByteString == kString + 4 && |
| 1431 kExternalTwoByteString == kString + 5 && |
| 1432 kExternalFourByteString == kString + 6 && |
| 1433 kBool == kString + 7); |
| 1434 return (index == kOneByteString || |
| 1435 index == kExternalOneByteString); |
| 1436 } |
| 1437 |
| 1438 inline bool RawObject::IsTwoByteStringClassIndex(intptr_t index) { |
| 1439 // Make sure this function is updated when new String types are added. |
| 1440 ASSERT(kOneByteString == kString + 1 && |
| 1441 kTwoByteString == kString + 2 && |
| 1442 kFourByteString == kString + 3 && |
| 1443 kExternalOneByteString == kString + 4 && |
| 1444 kExternalTwoByteString == kString + 5 && |
| 1445 kExternalFourByteString == kString + 6 && |
| 1446 kBool == kString + 7); |
| 1447 return (index == kOneByteString || |
| 1448 index == kTwoByteString || |
| 1449 index == kExternalOneByteString || |
| 1450 index == kExternalTwoByteString); |
| 1451 } |
| 1452 |
| 1453 inline bool RawObject::IsExternalStringClassIndex(intptr_t index) { |
| 1454 // Make sure this function is updated when new String types are added. |
| 1455 ASSERT(kOneByteString == kString + 1 && |
| 1456 kTwoByteString == kString + 2 && |
| 1457 kFourByteString == kString + 3 && |
| 1458 kExternalOneByteString == kString + 4 && |
| 1459 kExternalTwoByteString == kString + 5 && |
| 1460 kExternalFourByteString == kString + 6 && |
| 1461 kBool == kString + 7); |
| 1462 return (index == kExternalOneByteString || |
| 1463 index == kExternalTwoByteString || |
| 1464 index == kExternalFourByteString); |
| 1465 } |
| 1466 |
| 1467 inline bool RawObject::IsBuiltinListClassIndex(intptr_t index) { |
| 1468 // Make sure this function is updated when new builtin List types are added. |
| 1469 ASSERT(kImmutableArray == kArray + 1 && |
| 1470 kGrowableObjectArray == kArray + 2 && |
| 1471 kByteArray == kArray + 3); |
| 1472 return (index >= kArray && index < kByteArray); |
| 1473 } |
| 1474 |
| 1475 inline bool RawObject::IsByteArrayClassIndex(intptr_t index) { |
| 1476 // Make sure this function is updated when new ByteArray types are added. |
| 1477 ASSERT(kInt8Array == kByteArray + 1 && |
| 1478 kUint8Array == kByteArray + 2 && |
| 1479 kInt16Array == kByteArray + 3 && |
| 1480 kUint16Array == kByteArray + 4 && |
| 1481 kInt32Array == kByteArray + 5 && |
| 1482 kUint32Array == kByteArray + 6 && |
| 1483 kInt64Array == kByteArray + 7 && |
| 1484 kUint64Array == kByteArray + 8 && |
| 1485 kFloat32Array == kByteArray + 9 && |
| 1486 kFloat64Array == kByteArray + 10 && |
| 1487 kExternalInt8Array == kByteArray + 11 && |
| 1488 kExternalUint8Array == kByteArray + 12 && |
| 1489 kExternalInt16Array == kByteArray + 13 && |
| 1490 kExternalUint16Array == kByteArray + 14 && |
| 1491 kExternalInt32Array == kByteArray + 15 && |
| 1492 kExternalUint32Array == kByteArray + 16 && |
| 1493 kExternalInt64Array == kByteArray + 17 && |
| 1494 kExternalUint64Array == kByteArray + 18 && |
| 1495 kExternalFloat32Array == kByteArray + 19 && |
| 1496 kExternalFloat64Array == kByteArray + 20 && |
| 1497 kClosure == kByteArray + 21); |
| 1498 return (index >= kByteArray && index <= kClosure); |
| 1499 } |
| 1500 |
| 1364 } // namespace dart | 1501 } // namespace dart |
| 1365 | 1502 |
| 1366 #endif // VM_RAW_OBJECT_H_ | 1503 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |