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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 // Returns the cached canonical type of this class, i.e. the canonical type | 1044 // Returns the cached canonical type of this class, i.e. the canonical type |
1045 // whose type class is this class and whose type arguments are the | 1045 // whose type class is this class and whose type arguments are the |
1046 // uninstantiated type parameters declared by this class if it is generic, | 1046 // uninstantiated type parameters declared by this class if it is generic, |
1047 // e.g. Map<K, V>. | 1047 // e.g. Map<K, V>. |
1048 // Returns Type::null() if the canonical type is not cached yet. | 1048 // Returns Type::null() if the canonical type is not cached yet. |
1049 RawType* CanonicalType() const; | 1049 RawType* CanonicalType() const; |
1050 | 1050 |
1051 // Caches the canonical type of this class. | 1051 // Caches the canonical type of this class. |
1052 void SetCanonicalType(const Type& type) const; | 1052 void SetCanonicalType(const Type& type) const; |
1053 | 1053 |
1054 static intptr_t canonical_types_offset() { | 1054 static intptr_t canonical_type_offset() { |
1055 return OFFSET_OF(RawClass, canonical_types_); | 1055 return OFFSET_OF(RawClass, canonical_type_); |
1056 } | 1056 } |
1057 | 1057 |
1058 // The super type of this class, Object type if not explicitly specified. | 1058 // The super type of this class, Object type if not explicitly specified. |
1059 // Note that the super type may be bounded, as in this example: | 1059 // Note that the super type may be bounded, as in this example: |
1060 // class C<T> extends S<T> { }; class S<T extends num> { }; | 1060 // class C<T> extends S<T> { }; class S<T extends num> { }; |
1061 RawAbstractType* super_type() const { return raw_ptr()->super_type_; } | 1061 RawAbstractType* super_type() const { return raw_ptr()->super_type_; } |
1062 void set_super_type(const AbstractType& value) const; | 1062 void set_super_type(const AbstractType& value) const; |
1063 static intptr_t super_type_offset() { | 1063 static intptr_t super_type_offset() { |
1064 return OFFSET_OF(RawClass, super_type_); | 1064 return OFFSET_OF(RawClass, super_type_); |
1065 } | 1065 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 // The methods above are more efficient than this generic one. | 1214 // The methods above are more efficient than this generic one. |
1215 RawInstance* LookupCanonicalInstance(Zone* zone, | 1215 RawInstance* LookupCanonicalInstance(Zone* zone, |
1216 const Instance& value) const; | 1216 const Instance& value) const; |
1217 | 1217 |
1218 RawInstance* InsertCanonicalConstant(Zone* zone, | 1218 RawInstance* InsertCanonicalConstant(Zone* zone, |
1219 const Instance& constant) const; | 1219 const Instance& constant) const; |
1220 void InsertCanonicalNumber(Zone* zone, | 1220 void InsertCanonicalNumber(Zone* zone, |
1221 intptr_t index, | 1221 intptr_t index, |
1222 const Number& constant) const; | 1222 const Number& constant) const; |
1223 | 1223 |
1224 intptr_t FindCanonicalTypeIndex(const AbstractType& needle) const; | |
1225 RawAbstractType* CanonicalTypeFromIndex(intptr_t idx) const; | |
1226 | |
1227 void RehashConstants(Zone* zone) const; | 1224 void RehashConstants(Zone* zone) const; |
1228 | 1225 |
1229 static intptr_t InstanceSize() { | 1226 static intptr_t InstanceSize() { |
1230 return RoundedAllocationSize(sizeof(RawClass)); | 1227 return RoundedAllocationSize(sizeof(RawClass)); |
1231 } | 1228 } |
1232 | 1229 |
1233 bool is_implemented() const { | 1230 bool is_implemented() const { |
1234 return ImplementedBit::decode(raw_ptr()->state_bits_); | 1231 return ImplementedBit::decode(raw_ptr()->state_bits_); |
1235 } | 1232 } |
1236 void set_is_implemented() const; | 1233 void set_is_implemented() const; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 void set_dependent_code(const Array& array) const; | 1393 void set_dependent_code(const Array& array) const; |
1397 | 1394 |
1398 bool TraceAllocation(Isolate* isolate) const; | 1395 bool TraceAllocation(Isolate* isolate) const; |
1399 void SetTraceAllocation(bool trace_allocation) const; | 1396 void SetTraceAllocation(bool trace_allocation) const; |
1400 | 1397 |
1401 bool ValidatePostFinalizePatch(const Class& orig_class, Error* error) const; | 1398 bool ValidatePostFinalizePatch(const Class& orig_class, Error* error) const; |
1402 void ReplaceEnum(const Class& old_enum) const; | 1399 void ReplaceEnum(const Class& old_enum) const; |
1403 void CopyStaticFieldValues(const Class& old_cls) const; | 1400 void CopyStaticFieldValues(const Class& old_cls) const; |
1404 void PatchFieldsAndFunctions() const; | 1401 void PatchFieldsAndFunctions() const; |
1405 void CopyCanonicalConstants(const Class& old_cls) const; | 1402 void CopyCanonicalConstants(const Class& old_cls) const; |
1406 void CopyCanonicalTypes(const Class& old_cls) const; | 1403 void CopyCanonicalType(const Class& old_cls) const; |
1407 bool CanReload(const Class& replacement) const; | 1404 bool CanReload(const Class& replacement) const; |
1408 | 1405 |
1409 private: | 1406 private: |
1410 template <class FakeObject> static RawClass* NewCommon(intptr_t index); | 1407 template <class FakeObject> static RawClass* NewCommon(intptr_t index); |
1411 | 1408 |
1412 enum MemberKind { | 1409 enum MemberKind { |
1413 kAny = 0, | 1410 kAny = 0, |
1414 kStatic, | 1411 kStatic, |
1415 kInstance, | 1412 kInstance, |
1416 kInstanceAllowAbstract, | 1413 kInstanceAllowAbstract, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 class EnumBit : public BitField<uint16_t, bool, kEnumBit, 1> {}; | 1455 class EnumBit : public BitField<uint16_t, bool, kEnumBit, 1> {}; |
1459 class IsAllocatedBit : public BitField<uint16_t, bool, kIsAllocatedBit, 1> {}; | 1456 class IsAllocatedBit : public BitField<uint16_t, bool, kIsAllocatedBit, 1> {}; |
1460 | 1457 |
1461 void set_name(const String& value) const; | 1458 void set_name(const String& value) const; |
1462 void set_user_name(const String& value) const; | 1459 void set_user_name(const String& value) const; |
1463 RawString* GenerateUserVisibleName() const; | 1460 RawString* GenerateUserVisibleName() const; |
1464 void set_state_bits(intptr_t bits) const; | 1461 void set_state_bits(intptr_t bits) const; |
1465 | 1462 |
1466 void set_constants(const Array& value) const; | 1463 void set_constants(const Array& value) const; |
1467 | 1464 |
1468 void set_canonical_types(const Object& value) const; | 1465 void set_canonical_type(const Type& value) const; |
1469 RawObject* canonical_types() const; | 1466 RawType* canonical_type() const; |
1470 | 1467 |
1471 RawArray* invocation_dispatcher_cache() const; | 1468 RawArray* invocation_dispatcher_cache() const; |
1472 void set_invocation_dispatcher_cache(const Array& cache) const; | 1469 void set_invocation_dispatcher_cache(const Array& cache) const; |
1473 RawFunction* CreateInvocationDispatcher(const String& target_name, | 1470 RawFunction* CreateInvocationDispatcher(const String& target_name, |
1474 const Array& args_desc, | 1471 const Array& args_desc, |
1475 RawFunction::Kind kind) const; | 1472 RawFunction::Kind kind) const; |
1476 | 1473 |
1477 void CalculateFieldOffsets() const; | 1474 void CalculateFieldOffsets() const; |
1478 | 1475 |
1479 // functions_hash_table is in use iff there are at least this many functions. | 1476 // functions_hash_table is in use iff there are at least this many functions. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 static bool TypeTestNonRecursive( | 1520 static bool TypeTestNonRecursive( |
1524 const Class& cls, | 1521 const Class& cls, |
1525 TypeTestKind test_kind, | 1522 TypeTestKind test_kind, |
1526 const TypeArguments& type_arguments, | 1523 const TypeArguments& type_arguments, |
1527 const Class& other, | 1524 const Class& other, |
1528 const TypeArguments& other_type_arguments, | 1525 const TypeArguments& other_type_arguments, |
1529 Error* bound_error, | 1526 Error* bound_error, |
1530 TrailPtr bound_trail, | 1527 TrailPtr bound_trail, |
1531 Heap::Space space); | 1528 Heap::Space space); |
1532 | 1529 |
1533 // Returns AbstractType::null() if type not found. | |
1534 RawAbstractType* LookupCanonicalType(Zone* zone, | |
1535 const AbstractType& type, | |
1536 intptr_t* index) const; | |
1537 | |
1538 // Returns canonical type. Thread safe. | |
1539 RawAbstractType* LookupOrAddCanonicalType(const AbstractType& type, | |
1540 intptr_t start_index) const; | |
1541 | |
1542 FINAL_HEAP_OBJECT_IMPLEMENTATION(Class, Object); | 1530 FINAL_HEAP_OBJECT_IMPLEMENTATION(Class, Object); |
1543 friend class AbstractType; | 1531 friend class AbstractType; |
1544 friend class Instance; | 1532 friend class Instance; |
1545 friend class Object; | 1533 friend class Object; |
1546 friend class Type; | 1534 friend class Type; |
1547 friend class Intrinsifier; | 1535 friend class Intrinsifier; |
1548 friend class Precompiler; | 1536 friend class Precompiler; |
1549 }; | 1537 }; |
1550 | 1538 |
1551 | 1539 |
(...skipping 25 matching lines...) Expand all Loading... |
1577 static RawUnresolvedClass* New(); | 1565 static RawUnresolvedClass* New(); |
1578 | 1566 |
1579 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); | 1567 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); |
1580 friend class Class; | 1568 friend class Class; |
1581 }; | 1569 }; |
1582 | 1570 |
1583 | 1571 |
1584 // A TypeArguments is an array of AbstractType. | 1572 // A TypeArguments is an array of AbstractType. |
1585 class TypeArguments : public Object { | 1573 class TypeArguments : public Object { |
1586 public: | 1574 public: |
| 1575 // We use 30 bits for the hash code so hashes in a snapshot taken on a |
| 1576 // 64-bit architecture stay in Smi range when loaded on a 32-bit |
| 1577 // architecture. |
| 1578 static const intptr_t kHashBits = 30; |
| 1579 |
1587 intptr_t Length() const; | 1580 intptr_t Length() const; |
1588 RawAbstractType* TypeAt(intptr_t index) const; | 1581 RawAbstractType* TypeAt(intptr_t index) const; |
1589 static intptr_t type_at_offset(intptr_t index) { | 1582 static intptr_t type_at_offset(intptr_t index) { |
1590 return OFFSET_OF_RETURNED_VALUE( | 1583 return OFFSET_OF_RETURNED_VALUE( |
1591 RawTypeArguments, types) + index * kWordSize; | 1584 RawTypeArguments, types) + index * kWordSize; |
1592 } | 1585 } |
1593 void SetTypeAt(intptr_t index, const AbstractType& value) const; | 1586 void SetTypeAt(intptr_t index, const AbstractType& value) const; |
1594 | 1587 |
1595 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>". | 1588 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>". |
1596 RawString* Name() const { | 1589 RawString* Name() const { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 1714 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
1722 | 1715 |
1723 static intptr_t InstanceSize() { | 1716 static intptr_t InstanceSize() { |
1724 ASSERT(sizeof(RawTypeArguments) == | 1717 ASSERT(sizeof(RawTypeArguments) == |
1725 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types)); | 1718 OFFSET_OF_RETURNED_VALUE(RawTypeArguments, types)); |
1726 return 0; | 1719 return 0; |
1727 } | 1720 } |
1728 | 1721 |
1729 static intptr_t InstanceSize(intptr_t len) { | 1722 static intptr_t InstanceSize(intptr_t len) { |
1730 // Ensure that the types() is not adding to the object size, which includes | 1723 // Ensure that the types() is not adding to the object size, which includes |
1731 // 2 fields: instantiations_ and length_. | 1724 // 3 fields: instantiations_, length_ and hash_. |
1732 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (2 * kWordSize))); | 1725 ASSERT(sizeof(RawTypeArguments) == |
| 1726 (sizeof(RawObject) + (kNumFields * kWordSize))); |
1733 ASSERT(0 <= len && len <= kMaxElements); | 1727 ASSERT(0 <= len && len <= kMaxElements); |
1734 return RoundedAllocationSize( | 1728 return RoundedAllocationSize( |
1735 sizeof(RawTypeArguments) + (len * kBytesPerElement)); | 1729 sizeof(RawTypeArguments) + (len * kBytesPerElement)); |
1736 } | 1730 } |
1737 | 1731 |
1738 intptr_t Hash() const; | 1732 intptr_t Hash() const; |
1739 | 1733 |
1740 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); | 1734 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); |
1741 | 1735 |
1742 private: | 1736 private: |
| 1737 intptr_t ComputeHash() const; |
| 1738 void SetHash(intptr_t value) const; |
| 1739 |
1743 // Check if the subvector of length 'len' starting at 'from_index' of this | 1740 // Check if the subvector of length 'len' starting at 'from_index' of this |
1744 // type argument vector consists solely of DynamicType. | 1741 // type argument vector consists solely of DynamicType. |
1745 // If raw_instantiated is true, consider each type parameter to be first | 1742 // If raw_instantiated is true, consider each type parameter to be first |
1746 // instantiated from a vector of dynamic types. | 1743 // instantiated from a vector of dynamic types. |
1747 bool IsDynamicTypes(bool raw_instantiated, | 1744 bool IsDynamicTypes(bool raw_instantiated, |
1748 intptr_t from_index, | 1745 intptr_t from_index, |
1749 intptr_t len) const; | 1746 intptr_t len) const; |
1750 | 1747 |
1751 // Check the subtype or 'more specific' relationship, considering only a | 1748 // Check the subtype or 'more specific' relationship, considering only a |
1752 // subvector of length 'len' starting at 'from_index'. | 1749 // subvector of length 'len' starting at 'from_index'. |
1753 bool TypeTest(TypeTestKind test_kind, | 1750 bool TypeTest(TypeTestKind test_kind, |
1754 const TypeArguments& other, | 1751 const TypeArguments& other, |
1755 intptr_t from_index, | 1752 intptr_t from_index, |
1756 intptr_t len, | 1753 intptr_t len, |
1757 Error* bound_error, | 1754 Error* bound_error, |
1758 TrailPtr bound_trail, | 1755 TrailPtr bound_trail, |
1759 Heap::Space space) const; | 1756 Heap::Space space) const; |
1760 | 1757 |
1761 // Return the internal or public name of a subvector of this type argument | 1758 // Return the internal or public name of a subvector of this type argument |
1762 // vector, e.g. "<T, dynamic, List<T>, int>". | 1759 // vector, e.g. "<T, dynamic, List<T>, int>". |
1763 RawString* SubvectorName(intptr_t from_index, | 1760 RawString* SubvectorName(intptr_t from_index, |
1764 intptr_t len, | 1761 intptr_t len, |
1765 NameVisibility name_visibility) const; | 1762 NameVisibility name_visibility) const; |
1766 | 1763 |
1767 RawArray* instantiations() const; | 1764 RawArray* instantiations() const; |
1768 void set_instantiations(const Array& value) const; | 1765 void set_instantiations(const Array& value) const; |
1769 RawAbstractType* const* TypeAddr(intptr_t index) const; | 1766 RawAbstractType* const* TypeAddr(intptr_t index) const; |
1770 void SetLength(intptr_t value) const; | 1767 void SetLength(intptr_t value) const; |
| 1768 // Number of fields in the raw object=3 (instantiations_, length_ and hash_). |
| 1769 static const int kNumFields = 3; |
1771 | 1770 |
1772 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeArguments, Object); | 1771 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeArguments, Object); |
1773 friend class AbstractType; | 1772 friend class AbstractType; |
1774 friend class Class; | 1773 friend class Class; |
1775 }; | 1774 }; |
1776 | 1775 |
1777 | 1776 |
1778 class PatchClass : public Object { | 1777 class PatchClass : public Object { |
1779 public: | 1778 public: |
1780 RawClass* patched_class() const { return raw_ptr()->patched_class_; } | 1779 RawClass* patched_class() const { return raw_ptr()->patched_class_; } |
(...skipping 3658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5439 | 5438 |
5440 FINAL_HEAP_OBJECT_IMPLEMENTATION(LibraryPrefix, Instance); | 5439 FINAL_HEAP_OBJECT_IMPLEMENTATION(LibraryPrefix, Instance); |
5441 friend class Class; | 5440 friend class Class; |
5442 }; | 5441 }; |
5443 | 5442 |
5444 | 5443 |
5445 // AbstractType is an abstract superclass. | 5444 // AbstractType is an abstract superclass. |
5446 // Subclasses of AbstractType are Type and TypeParameter. | 5445 // Subclasses of AbstractType are Type and TypeParameter. |
5447 class AbstractType : public Instance { | 5446 class AbstractType : public Instance { |
5448 public: | 5447 public: |
| 5448 // We use 30 bits for the hash code so hashes in a snapshot taken on a |
| 5449 // 64-bit architecture stay in Smi range when loaded on a 32-bit |
| 5450 // architecture. |
| 5451 static const intptr_t kHashBits = 30; |
| 5452 |
5449 virtual bool IsFinalized() const; | 5453 virtual bool IsFinalized() const; |
5450 virtual void SetIsFinalized() const; | 5454 virtual void SetIsFinalized() const; |
5451 virtual bool IsBeingFinalized() const; | 5455 virtual bool IsBeingFinalized() const; |
5452 virtual void SetIsBeingFinalized() const; | 5456 virtual void SetIsBeingFinalized() const; |
5453 virtual bool IsMalformed() const; | 5457 virtual bool IsMalformed() const; |
5454 virtual bool IsMalbounded() const; | 5458 virtual bool IsMalbounded() const; |
5455 virtual bool IsMalformedOrMalbounded() const; | 5459 virtual bool IsMalformedOrMalbounded() const; |
5456 virtual RawLanguageError* error() const; | 5460 virtual RawLanguageError* error() const; |
5457 virtual void set_error(const LanguageError& value) const; | 5461 virtual void set_error(const LanguageError& value) const; |
5458 virtual bool IsResolved() const; | 5462 virtual bool IsResolved() const; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5757 | 5761 |
5758 // The finalized type of the given non-parameterized class. | 5762 // The finalized type of the given non-parameterized class. |
5759 static RawType* NewNonParameterizedType(const Class& type_class); | 5763 static RawType* NewNonParameterizedType(const Class& type_class); |
5760 | 5764 |
5761 static RawType* New(const Object& clazz, | 5765 static RawType* New(const Object& clazz, |
5762 const TypeArguments& arguments, | 5766 const TypeArguments& arguments, |
5763 TokenPosition token_pos, | 5767 TokenPosition token_pos, |
5764 Heap::Space space = Heap::kOld); | 5768 Heap::Space space = Heap::kOld); |
5765 | 5769 |
5766 private: | 5770 private: |
| 5771 intptr_t ComputeHash() const; |
| 5772 void SetHash(intptr_t value) const; |
| 5773 |
5767 void set_token_pos(TokenPosition token_pos) const; | 5774 void set_token_pos(TokenPosition token_pos) const; |
5768 void set_type_state(int8_t state) const; | 5775 void set_type_state(int8_t state) const; |
5769 | 5776 |
5770 static RawType* New(Heap::Space space = Heap::kOld); | 5777 static RawType* New(Heap::Space space = Heap::kOld); |
5771 | 5778 |
5772 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); | 5779 FINAL_HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); |
5773 friend class Class; | 5780 friend class Class; |
5774 friend class TypeArguments; | 5781 friend class TypeArguments; |
5775 }; | 5782 }; |
5776 | 5783 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5907 return RoundedAllocationSize(sizeof(RawTypeParameter)); | 5914 return RoundedAllocationSize(sizeof(RawTypeParameter)); |
5908 } | 5915 } |
5909 | 5916 |
5910 static RawTypeParameter* New(const Class& parameterized_class, | 5917 static RawTypeParameter* New(const Class& parameterized_class, |
5911 intptr_t index, | 5918 intptr_t index, |
5912 const String& name, | 5919 const String& name, |
5913 const AbstractType& bound, | 5920 const AbstractType& bound, |
5914 TokenPosition token_pos); | 5921 TokenPosition token_pos); |
5915 | 5922 |
5916 private: | 5923 private: |
| 5924 intptr_t ComputeHash() const; |
| 5925 void SetHash(intptr_t value) const; |
| 5926 |
5917 void set_parameterized_class(const Class& value) const; | 5927 void set_parameterized_class(const Class& value) const; |
5918 void set_name(const String& value) const; | 5928 void set_name(const String& value) const; |
5919 void set_token_pos(TokenPosition token_pos) const; | 5929 void set_token_pos(TokenPosition token_pos) const; |
5920 void set_type_state(int8_t state) const; | 5930 void set_type_state(int8_t state) const; |
5921 | 5931 |
5922 static RawTypeParameter* New(); | 5932 static RawTypeParameter* New(); |
5923 | 5933 |
5924 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); | 5934 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); |
5925 friend class Class; | 5935 friend class Class; |
5926 }; | 5936 }; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5992 | 6002 |
5993 static intptr_t InstanceSize() { | 6003 static intptr_t InstanceSize() { |
5994 return RoundedAllocationSize(sizeof(RawBoundedType)); | 6004 return RoundedAllocationSize(sizeof(RawBoundedType)); |
5995 } | 6005 } |
5996 | 6006 |
5997 static RawBoundedType* New(const AbstractType& type, | 6007 static RawBoundedType* New(const AbstractType& type, |
5998 const AbstractType& bound, | 6008 const AbstractType& bound, |
5999 const TypeParameter& type_parameter); | 6009 const TypeParameter& type_parameter); |
6000 | 6010 |
6001 private: | 6011 private: |
| 6012 intptr_t ComputeHash() const; |
| 6013 void SetHash(intptr_t value) const; |
| 6014 |
6002 void set_type(const AbstractType& value) const; | 6015 void set_type(const AbstractType& value) const; |
6003 void set_bound(const AbstractType& value) const; | 6016 void set_bound(const AbstractType& value) const; |
6004 void set_type_parameter(const TypeParameter& value) const; | 6017 void set_type_parameter(const TypeParameter& value) const; |
6005 | 6018 |
6006 static RawBoundedType* New(); | 6019 static RawBoundedType* New(); |
6007 | 6020 |
6008 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType); | 6021 FINAL_HEAP_OBJECT_IMPLEMENTATION(BoundedType, AbstractType); |
6009 friend class Class; | 6022 friend class Class; |
6010 }; | 6023 }; |
6011 | 6024 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6406 | 6419 |
6407 FINAL_HEAP_OBJECT_IMPLEMENTATION(Double, Number); | 6420 FINAL_HEAP_OBJECT_IMPLEMENTATION(Double, Number); |
6408 friend class Class; | 6421 friend class Class; |
6409 friend class Number; | 6422 friend class Number; |
6410 }; | 6423 }; |
6411 | 6424 |
6412 | 6425 |
6413 // String may not be '\0' terminated. | 6426 // String may not be '\0' terminated. |
6414 class String : public Instance { | 6427 class String : public Instance { |
6415 public: | 6428 public: |
6416 // We use 30 bits for the hash code so that we consistently use a | 6429 // We use 30 bits for the hash code so hashes in a snapshot taken on a |
6417 // 32bit Smi representation for the hash code on all architectures. | 6430 // 64-bit architecture stay in Smi range when loaded on a 32-bit |
| 6431 // architecture. |
6418 static const intptr_t kHashBits = 30; | 6432 static const intptr_t kHashBits = 30; |
6419 | 6433 |
6420 static const intptr_t kOneByteChar = 1; | 6434 static const intptr_t kOneByteChar = 1; |
6421 static const intptr_t kTwoByteChar = 2; | 6435 static const intptr_t kTwoByteChar = 2; |
6422 | 6436 |
6423 // All strings share the same maximum element count to keep things | 6437 // All strings share the same maximum element count to keep things |
6424 // simple. We choose a value that will prevent integer overflow for | 6438 // simple. We choose a value that will prevent integer overflow for |
6425 // 2 byte strings, since it is the worst case. | 6439 // 2 byte strings, since it is the worst case. |
6426 static const intptr_t kSizeofRawString = | 6440 static const intptr_t kSizeofRawString = |
6427 sizeof(RawInstance) + (2 * kWordSize); | 6441 sizeof(RawInstance) + (2 * kWordSize); |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7186 static RawBool* New(bool value); | 7200 static RawBool* New(bool value); |
7187 | 7201 |
7188 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bool, Instance); | 7202 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bool, Instance); |
7189 friend class Class; | 7203 friend class Class; |
7190 friend class Object; // To initialize the true and false values. | 7204 friend class Object; // To initialize the true and false values. |
7191 }; | 7205 }; |
7192 | 7206 |
7193 | 7207 |
7194 class Array : public Instance { | 7208 class Array : public Instance { |
7195 public: | 7209 public: |
| 7210 // We use 30 bits for the hash code so hashes in a snapshot taken on a |
| 7211 // 64-bit architecture stay in Smi range when loaded on a 32-bit |
| 7212 // architecture. |
| 7213 static const intptr_t kHashBits = 30; |
| 7214 |
7196 intptr_t Length() const { | 7215 intptr_t Length() const { |
7197 ASSERT(!IsNull()); | 7216 ASSERT(!IsNull()); |
7198 return Smi::Value(raw_ptr()->length_); | 7217 return Smi::Value(raw_ptr()->length_); |
7199 } | 7218 } |
7200 static intptr_t length_offset() { return OFFSET_OF(RawArray, length_); } | 7219 static intptr_t length_offset() { return OFFSET_OF(RawArray, length_); } |
7201 static intptr_t data_offset() { | 7220 static intptr_t data_offset() { |
7202 return OFFSET_OF_RETURNED_VALUE(RawArray, data); | 7221 return OFFSET_OF_RETURNED_VALUE(RawArray, data); |
7203 } | 7222 } |
7204 static intptr_t element_offset(intptr_t index) { | 7223 static intptr_t element_offset(intptr_t index) { |
7205 return OFFSET_OF_RETURNED_VALUE(RawArray, data) + kWordSize * index; | 7224 return OFFSET_OF_RETURNED_VALUE(RawArray, data) + kWordSize * index; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7553 } | 7572 } |
7554 | 7573 |
7555 private: | 7574 private: |
7556 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float64x2, Instance); | 7575 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float64x2, Instance); |
7557 friend class Class; | 7576 friend class Class; |
7558 }; | 7577 }; |
7559 | 7578 |
7560 | 7579 |
7561 class TypedData : public Instance { | 7580 class TypedData : public Instance { |
7562 public: | 7581 public: |
| 7582 // We use 30 bits for the hash code so hashes in a snapshot taken on a |
| 7583 // 64-bit architecture stay in Smi range when loaded on a 32-bit |
| 7584 // architecture. |
| 7585 static const intptr_t kHashBits = 30; |
| 7586 |
7563 intptr_t Length() const { | 7587 intptr_t Length() const { |
7564 ASSERT(!IsNull()); | 7588 ASSERT(!IsNull()); |
7565 return Smi::Value(raw_ptr()->length_); | 7589 return Smi::Value(raw_ptr()->length_); |
7566 } | 7590 } |
7567 | 7591 |
7568 intptr_t ElementSizeInBytes() const { | 7592 intptr_t ElementSizeInBytes() const { |
7569 intptr_t cid = raw()->GetClassId(); | 7593 intptr_t cid = raw()->GetClassId(); |
7570 return ElementSizeInBytes(cid); | 7594 return ElementSizeInBytes(cid); |
7571 } | 7595 } |
7572 | 7596 |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8599 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) { | 8623 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) { |
8600 return array.At((index * kEntryLength) + kClassIdIndex); | 8624 return array.At((index * kEntryLength) + kClassIdIndex); |
8601 } | 8625 } |
8602 | 8626 |
8603 | 8627 |
8604 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 8628 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
8605 intptr_t index) { | 8629 intptr_t index) { |
8606 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 8630 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
8607 } | 8631 } |
8608 | 8632 |
| 8633 |
| 8634 inline intptr_t Type::Hash() const { |
| 8635 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8636 if (result != 0) { |
| 8637 return result; |
| 8638 } |
| 8639 return ComputeHash(); |
| 8640 } |
| 8641 |
| 8642 |
| 8643 inline void Type::SetHash(intptr_t value) const { |
| 8644 // This is only safe because we create a new Smi, which does not cause |
| 8645 // heap allocation. |
| 8646 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8647 } |
| 8648 |
| 8649 |
| 8650 inline intptr_t TypeParameter::Hash() const { |
| 8651 ASSERT(IsFinalized()); |
| 8652 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8653 if (result != 0) { |
| 8654 return result; |
| 8655 } |
| 8656 return ComputeHash(); |
| 8657 } |
| 8658 |
| 8659 |
| 8660 inline void TypeParameter::SetHash(intptr_t value) const { |
| 8661 // This is only safe because we create a new Smi, which does not cause |
| 8662 // heap allocation. |
| 8663 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8664 } |
| 8665 |
| 8666 |
| 8667 inline intptr_t BoundedType::Hash() const { |
| 8668 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8669 if (result != 0) { |
| 8670 return result; |
| 8671 } |
| 8672 return ComputeHash(); |
| 8673 } |
| 8674 |
| 8675 |
| 8676 inline void BoundedType::SetHash(intptr_t value) const { |
| 8677 // This is only safe because we create a new Smi, which does not cause |
| 8678 // heap allocation. |
| 8679 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8680 } |
| 8681 |
| 8682 |
| 8683 inline intptr_t TypeArguments::Hash() const { |
| 8684 if (IsNull()) return 0; |
| 8685 intptr_t result = Smi::Value(raw_ptr()->hash_); |
| 8686 if (result != 0) { |
| 8687 return result; |
| 8688 } |
| 8689 return ComputeHash(); |
| 8690 } |
| 8691 |
| 8692 |
| 8693 inline void TypeArguments::SetHash(intptr_t value) const { |
| 8694 // This is only safe because we create a new Smi, which does not cause |
| 8695 // heap allocation. |
| 8696 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
| 8697 } |
| 8698 |
8609 } // namespace dart | 8699 } // namespace dart |
8610 | 8700 |
8611 #endif // VM_OBJECT_H_ | 8701 #endif // VM_OBJECT_H_ |
OLD | NEW |