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 5227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5238 // An instance cannot be canonicalized if it still contains non-canonical | 5238 // An instance cannot be canonicalized if it still contains non-canonical |
5239 // instances in its fields. | 5239 // instances in its fields. |
5240 // Returns error in error_str, pass NULL if an error cannot occur. | 5240 // Returns error in error_str, pass NULL if an error cannot occur. |
5241 virtual RawInstance* CheckAndCanonicalize(Thread* thread, | 5241 virtual RawInstance* CheckAndCanonicalize(Thread* thread, |
5242 const char** error_str) const; | 5242 const char** error_str) const; |
5243 | 5243 |
5244 // Returns true if all fields are OK for canonicalization. | 5244 // Returns true if all fields are OK for canonicalization. |
5245 virtual bool CheckAndCanonicalizeFields(Thread* thread, | 5245 virtual bool CheckAndCanonicalizeFields(Thread* thread, |
5246 const char** error_str) const; | 5246 const char** error_str) const; |
5247 | 5247 |
| 5248 #if defined(DEBUG) |
| 5249 // Check if instance is canonical. |
| 5250 virtual bool CheckIsCanonical(Thread* thread) const; |
| 5251 #endif // DEBUG |
| 5252 |
5248 RawObject* GetField(const Field& field) const { | 5253 RawObject* GetField(const Field& field) const { |
5249 return *FieldAddr(field); | 5254 return *FieldAddr(field); |
5250 } | 5255 } |
5251 | 5256 |
5252 void SetField(const Field& field, const Object& value) const { | 5257 void SetField(const Field& field, const Object& value) const { |
5253 field.RecordStore(value); | 5258 field.RecordStore(value); |
5254 StorePointer(FieldAddr(field), value.raw()); | 5259 StorePointer(FieldAddr(field), value.raw()); |
5255 } | 5260 } |
5256 | 5261 |
5257 RawAbstractType* GetType() const; | 5262 RawAbstractType* GetType() const; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5472 const Class& new_owner, TrailPtr trail = NULL) const; | 5477 const Class& new_owner, TrailPtr trail = NULL) const; |
5473 | 5478 |
5474 virtual RawInstance* CheckAndCanonicalize(Thread* thread, | 5479 virtual RawInstance* CheckAndCanonicalize(Thread* thread, |
5475 const char** error_str) const { | 5480 const char** error_str) const { |
5476 return Canonicalize(); | 5481 return Canonicalize(); |
5477 } | 5482 } |
5478 | 5483 |
5479 // Return the canonical version of this type. | 5484 // Return the canonical version of this type. |
5480 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; | 5485 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; |
5481 | 5486 |
| 5487 #if defined(DEBUG) |
| 5488 // Check if abstract type is canonical. |
| 5489 virtual bool CheckIsCanonical(Thread* thread) const { |
| 5490 UNREACHABLE(); |
| 5491 return false; |
| 5492 } |
| 5493 #endif // DEBUG |
| 5494 |
5482 // Return the object associated with the receiver in the trail or | 5495 // Return the object associated with the receiver in the trail or |
5483 // AbstractType::null() if the receiver is not contained in the trail. | 5496 // AbstractType::null() if the receiver is not contained in the trail. |
5484 RawAbstractType* OnlyBuddyInTrail(TrailPtr trail) const; | 5497 RawAbstractType* OnlyBuddyInTrail(TrailPtr trail) const; |
5485 | 5498 |
5486 // If the trail is null, allocate a trail, add the pair <receiver, buddy> to | 5499 // If the trail is null, allocate a trail, add the pair <receiver, buddy> to |
5487 // the trail. The receiver may only be added once with its only buddy. | 5500 // the trail. The receiver may only be added once with its only buddy. |
5488 void AddOnlyBuddyToTrail(TrailPtr* trail, const AbstractType& buddy) const; | 5501 void AddOnlyBuddyToTrail(TrailPtr* trail, const AbstractType& buddy) const; |
5489 | 5502 |
5490 // Return true if the receiver is contained in the trail. | 5503 // Return true if the receiver is contained in the trail. |
5491 // Otherwise, if the trail is null, allocate a trail, then add the receiver to | 5504 // Otherwise, if the trail is null, allocate a trail, then add the receiver to |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5663 const TypeArguments& instantiator_type_arguments, | 5676 const TypeArguments& instantiator_type_arguments, |
5664 Error* bound_error, | 5677 Error* bound_error, |
5665 TrailPtr instantiation_trail, | 5678 TrailPtr instantiation_trail, |
5666 TrailPtr bound_trail, | 5679 TrailPtr bound_trail, |
5667 Heap::Space space) const; | 5680 Heap::Space space) const; |
5668 virtual RawAbstractType* CloneUnfinalized() const; | 5681 virtual RawAbstractType* CloneUnfinalized() const; |
5669 virtual RawAbstractType* CloneUninstantiated( | 5682 virtual RawAbstractType* CloneUninstantiated( |
5670 const Class& new_owner, | 5683 const Class& new_owner, |
5671 TrailPtr trail = NULL) const; | 5684 TrailPtr trail = NULL) const; |
5672 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; | 5685 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; |
| 5686 #if defined(DEBUG) |
| 5687 // Check if type is canonical. |
| 5688 virtual bool CheckIsCanonical(Thread* thread) const; |
| 5689 #endif // DEBUG |
5673 virtual RawString* EnumerateURIs() const; | 5690 virtual RawString* EnumerateURIs() const; |
5674 | 5691 |
5675 virtual intptr_t Hash() const; | 5692 virtual intptr_t Hash() const; |
5676 | 5693 |
5677 static intptr_t InstanceSize() { | 5694 static intptr_t InstanceSize() { |
5678 return RoundedAllocationSize(sizeof(RawType)); | 5695 return RoundedAllocationSize(sizeof(RawType)); |
5679 } | 5696 } |
5680 | 5697 |
5681 // The type of the literal 'null'. | 5698 // The type of the literal 'null'. |
5682 static RawType* NullType(); | 5699 static RawType* NullType(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5791 virtual RawTypeRef* InstantiateFrom( | 5808 virtual RawTypeRef* InstantiateFrom( |
5792 const TypeArguments& instantiator_type_arguments, | 5809 const TypeArguments& instantiator_type_arguments, |
5793 Error* bound_error, | 5810 Error* bound_error, |
5794 TrailPtr instantiation_trail, | 5811 TrailPtr instantiation_trail, |
5795 TrailPtr bound_trail, | 5812 TrailPtr bound_trail, |
5796 Heap::Space space) const; | 5813 Heap::Space space) const; |
5797 virtual RawTypeRef* CloneUninstantiated( | 5814 virtual RawTypeRef* CloneUninstantiated( |
5798 const Class& new_owner, | 5815 const Class& new_owner, |
5799 TrailPtr trail = NULL) const; | 5816 TrailPtr trail = NULL) const; |
5800 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; | 5817 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; |
| 5818 #if defined(DEBUG) |
| 5819 // Check if typeref is canonical. |
| 5820 virtual bool CheckIsCanonical(Thread* thread) const; |
| 5821 #endif // DEBUG |
5801 virtual RawString* EnumerateURIs() const; | 5822 virtual RawString* EnumerateURIs() const; |
5802 | 5823 |
5803 virtual intptr_t Hash() const; | 5824 virtual intptr_t Hash() const; |
5804 | 5825 |
5805 static intptr_t InstanceSize() { | 5826 static intptr_t InstanceSize() { |
5806 return RoundedAllocationSize(sizeof(RawTypeRef)); | 5827 return RoundedAllocationSize(sizeof(RawTypeRef)); |
5807 } | 5828 } |
5808 | 5829 |
5809 static RawTypeRef* New(const AbstractType& type); | 5830 static RawTypeRef* New(const AbstractType& type); |
5810 | 5831 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5866 Error* bound_error, | 5887 Error* bound_error, |
5867 TrailPtr instantiation_trail, | 5888 TrailPtr instantiation_trail, |
5868 TrailPtr bound_trail, | 5889 TrailPtr bound_trail, |
5869 Heap::Space space) const; | 5890 Heap::Space space) const; |
5870 virtual RawAbstractType* CloneUnfinalized() const; | 5891 virtual RawAbstractType* CloneUnfinalized() const; |
5871 virtual RawAbstractType* CloneUninstantiated( | 5892 virtual RawAbstractType* CloneUninstantiated( |
5872 const Class& new_owner, TrailPtr trail = NULL) const; | 5893 const Class& new_owner, TrailPtr trail = NULL) const; |
5873 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const { | 5894 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const { |
5874 return raw(); | 5895 return raw(); |
5875 } | 5896 } |
| 5897 #if defined(DEBUG) |
| 5898 // Check if type parameter is canonical. |
| 5899 virtual bool CheckIsCanonical(Thread* thread) const { |
| 5900 return true; |
| 5901 } |
| 5902 #endif // DEBUG |
5876 virtual RawString* EnumerateURIs() const; | 5903 virtual RawString* EnumerateURIs() const; |
5877 | 5904 |
5878 virtual intptr_t Hash() const; | 5905 virtual intptr_t Hash() const; |
5879 | 5906 |
5880 static intptr_t InstanceSize() { | 5907 static intptr_t InstanceSize() { |
5881 return RoundedAllocationSize(sizeof(RawTypeParameter)); | 5908 return RoundedAllocationSize(sizeof(RawTypeParameter)); |
5882 } | 5909 } |
5883 | 5910 |
5884 static RawTypeParameter* New(const Class& parameterized_class, | 5911 static RawTypeParameter* New(const Class& parameterized_class, |
5885 intptr_t index, | 5912 intptr_t index, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5956 Error* bound_error, | 5983 Error* bound_error, |
5957 TrailPtr instantiation_trail, | 5984 TrailPtr instantiation_trail, |
5958 TrailPtr bound_trail, | 5985 TrailPtr bound_trail, |
5959 Heap::Space space) const; | 5986 Heap::Space space) const; |
5960 virtual RawAbstractType* CloneUnfinalized() const; | 5987 virtual RawAbstractType* CloneUnfinalized() const; |
5961 virtual RawAbstractType* CloneUninstantiated( | 5988 virtual RawAbstractType* CloneUninstantiated( |
5962 const Class& new_owner, TrailPtr trail = NULL) const; | 5989 const Class& new_owner, TrailPtr trail = NULL) const; |
5963 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const { | 5990 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const { |
5964 return raw(); | 5991 return raw(); |
5965 } | 5992 } |
| 5993 #if defined(DEBUG) |
| 5994 // Check if bounded type is canonical. |
| 5995 virtual bool CheckIsCanonical(Thread* thread) const { |
| 5996 return true; |
| 5997 } |
| 5998 #endif // DEBUG |
5966 virtual RawString* EnumerateURIs() const; | 5999 virtual RawString* EnumerateURIs() const; |
5967 | 6000 |
5968 virtual intptr_t Hash() const; | 6001 virtual intptr_t Hash() const; |
5969 | 6002 |
5970 static intptr_t InstanceSize() { | 6003 static intptr_t InstanceSize() { |
5971 return RoundedAllocationSize(sizeof(RawBoundedType)); | 6004 return RoundedAllocationSize(sizeof(RawBoundedType)); |
5972 } | 6005 } |
5973 | 6006 |
5974 static RawBoundedType* New(const AbstractType& type, | 6007 static RawBoundedType* New(const AbstractType& type, |
5975 const AbstractType& bound, | 6008 const AbstractType& bound, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6044 | 6077 |
6045 class Number : public Instance { | 6078 class Number : public Instance { |
6046 public: | 6079 public: |
6047 // TODO(iposva): Add more useful Number methods. | 6080 // TODO(iposva): Add more useful Number methods. |
6048 RawString* ToString(Heap::Space space) const; | 6081 RawString* ToString(Heap::Space space) const; |
6049 | 6082 |
6050 // Numbers are canonicalized differently from other instances/strings. | 6083 // Numbers are canonicalized differently from other instances/strings. |
6051 virtual RawInstance* CheckAndCanonicalize(Thread* thread, | 6084 virtual RawInstance* CheckAndCanonicalize(Thread* thread, |
6052 const char** error_str) const; | 6085 const char** error_str) const; |
6053 | 6086 |
| 6087 #if defined(DEBUG) |
| 6088 // Check if number is canonical. |
| 6089 virtual bool CheckIsCanonical(Thread* thread) const; |
| 6090 #endif // DEBUG |
| 6091 |
6054 private: | 6092 private: |
6055 OBJECT_IMPLEMENTATION(Number, Instance); | 6093 OBJECT_IMPLEMENTATION(Number, Instance); |
6056 | 6094 |
6057 friend class Class; | 6095 friend class Class; |
6058 }; | 6096 }; |
6059 | 6097 |
6060 | 6098 |
6061 class Integer : public Number { | 6099 class Integer : public Number { |
6062 public: | 6100 public: |
6063 static RawInteger* New(const String& str, Heap::Space space = Heap::kNew); | 6101 static RawInteger* New(const String& str, Heap::Space space = Heap::kNew); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6520 virtual bool Equals(const Instance& other) const; | 6558 virtual bool Equals(const Instance& other) const; |
6521 | 6559 |
6522 intptr_t CompareTo(const String& other) const; | 6560 intptr_t CompareTo(const String& other) const; |
6523 | 6561 |
6524 bool StartsWith(const String& other) const; | 6562 bool StartsWith(const String& other) const; |
6525 | 6563 |
6526 // Strings are canonicalized using the symbol table. | 6564 // Strings are canonicalized using the symbol table. |
6527 virtual RawInstance* CheckAndCanonicalize(Thread* thread, | 6565 virtual RawInstance* CheckAndCanonicalize(Thread* thread, |
6528 const char** error_str) const; | 6566 const char** error_str) const; |
6529 | 6567 |
| 6568 #if defined(DEBUG) |
| 6569 // Check if string is canonical. |
| 6570 virtual bool CheckIsCanonical(Thread* thread) const; |
| 6571 #endif // DEBUG |
| 6572 |
6530 bool IsSymbol() const { return raw()->IsCanonical(); } | 6573 bool IsSymbol() const { return raw()->IsCanonical(); } |
6531 | 6574 |
6532 bool IsOneByteString() const { | 6575 bool IsOneByteString() const { |
6533 return raw()->GetClassId() == kOneByteStringCid; | 6576 return raw()->GetClassId() == kOneByteStringCid; |
6534 } | 6577 } |
6535 | 6578 |
6536 bool IsTwoByteString() const { | 6579 bool IsTwoByteString() const { |
6537 return raw()->GetClassId() == kTwoByteStringCid; | 6580 return raw()->GetClassId() == kTwoByteStringCid; |
6538 } | 6581 } |
6539 | 6582 |
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8658 | 8701 |
8659 inline void TypeArguments::SetHash(intptr_t value) const { | 8702 inline void TypeArguments::SetHash(intptr_t value) const { |
8660 // This is only safe because we create a new Smi, which does not cause | 8703 // This is only safe because we create a new Smi, which does not cause |
8661 // heap allocation. | 8704 // heap allocation. |
8662 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 8705 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
8663 } | 8706 } |
8664 | 8707 |
8665 } // namespace dart | 8708 } // namespace dart |
8666 | 8709 |
8667 #endif // VM_OBJECT_H_ | 8710 #endif // VM_OBJECT_H_ |
OLD | NEW |