| 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 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1150                     bound_error, |  1150                     bound_error, | 
|  1151                     bound_trail, |  1151                     bound_trail, | 
|  1152                     space); |  1152                     space); | 
|  1153   } |  1153   } | 
|  1154  |  1154  | 
|  1155   // Check if this is the top level class. |  1155   // Check if this is the top level class. | 
|  1156   bool IsTopLevel() const; |  1156   bool IsTopLevel() const; | 
|  1157  |  1157  | 
|  1158   bool IsPrivate() const; |  1158   bool IsPrivate() const; | 
|  1159  |  1159  | 
 |  1160   // Returns an array of instance and static fields defined by this class. | 
|  1160   RawArray* fields() const { return raw_ptr()->fields_; } |  1161   RawArray* fields() const { return raw_ptr()->fields_; } | 
|  1161   void SetFields(const Array& value) const; |  1162   void SetFields(const Array& value) const; | 
|  1162   void AddField(const Field& field) const; |  1163   void AddField(const Field& field) const; | 
|  1163   void AddFields(const GrowableArray<const Field*>& fields) const; |  1164   void AddFields(const GrowableArray<const Field*>& fields) const; | 
|  1164  |  1165  | 
|  1165   // Returns an array of all fields of this class and its superclasses indexed |  1166   // Returns an array of all instance fields of this class and its superclasses | 
|  1166   // by offset in words. |  1167   // indexed by offset in words. | 
|  1167   RawArray* OffsetToFieldMap() const; |  1168   RawArray* OffsetToFieldMap() const; | 
|  1168  |  1169  | 
|  1169   // Returns true if non-static fields are defined. |  1170   // Returns true if non-static fields are defined. | 
|  1170   bool HasInstanceFields() const; |  1171   bool HasInstanceFields() const; | 
|  1171  |  1172  | 
|  1172   // TODO(koda): Unite w/ hash table. |  1173   // TODO(koda): Unite w/ hash table. | 
|  1173   RawArray* functions() const { return raw_ptr()->functions_; } |  1174   RawArray* functions() const { return raw_ptr()->functions_; } | 
|  1174   void SetFunctions(const Array& value) const; |  1175   void SetFunctions(const Array& value) const; | 
|  1175   void AddFunction(const Function& function) const; |  1176   void AddFunction(const Function& function) const; | 
|  1176   void RemoveFunction(const Function& function) const; |  1177   void RemoveFunction(const Function& function) const; | 
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1395  |  1396  | 
|  1396   bool TraceAllocation(Isolate* isolate) const; |  1397   bool TraceAllocation(Isolate* isolate) const; | 
|  1397   void SetTraceAllocation(bool trace_allocation) const; |  1398   void SetTraceAllocation(bool trace_allocation) const; | 
|  1398  |  1399  | 
|  1399   bool ValidatePostFinalizePatch(const Class& orig_class, Error* error) const; |  1400   bool ValidatePostFinalizePatch(const Class& orig_class, Error* error) const; | 
|  1400   void ReplaceEnum(const Class& old_enum) const; |  1401   void ReplaceEnum(const Class& old_enum) const; | 
|  1401   void CopyStaticFieldValues(const Class& old_cls) const; |  1402   void CopyStaticFieldValues(const Class& old_cls) const; | 
|  1402   void PatchFieldsAndFunctions() const; |  1403   void PatchFieldsAndFunctions() const; | 
|  1403   void CopyCanonicalConstants(const Class& old_cls) const; |  1404   void CopyCanonicalConstants(const Class& old_cls) const; | 
|  1404   void CopyCanonicalType(const Class& old_cls) const; |  1405   void CopyCanonicalType(const Class& old_cls) const; | 
|  1405   bool CanReload(const Class& replacement) const; |  1406   void CheckReload(const Class& replacement, | 
 |  1407                    IsolateReloadContext* context) const; | 
|  1406  |  1408  | 
|  1407  private: |  1409  private: | 
 |  1410   bool CanReloadFinalized(const Class& replacement, | 
 |  1411                           IsolateReloadContext* context) const; | 
 |  1412   bool CanReloadPreFinalized(const Class& replacement, | 
 |  1413                              IsolateReloadContext* context) const; | 
 |  1414  | 
 |  1415   // Tells whether instances need morphing for reload. | 
 |  1416   bool RequiresInstanceMorphing(const Class& replacement) const; | 
 |  1417  | 
|  1408   template <class FakeObject> static RawClass* NewCommon(intptr_t index); |  1418   template <class FakeObject> static RawClass* NewCommon(intptr_t index); | 
|  1409  |  1419  | 
|  1410   enum MemberKind { |  1420   enum MemberKind { | 
|  1411     kAny = 0, |  1421     kAny = 0, | 
|  1412     kStatic, |  1422     kStatic, | 
|  1413     kInstance, |  1423     kInstance, | 
|  1414     kInstanceAllowAbstract, |  1424     kInstanceAllowAbstract, | 
|  1415     kConstructor, |  1425     kConstructor, | 
|  1416     kFactory, |  1426     kFactory, | 
|  1417   }; |  1427   }; | 
| (...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2963  |  2973  | 
|  2964   // Returns a field cloned from 'this'. 'this' is set as the |  2974   // Returns a field cloned from 'this'. 'this' is set as the | 
|  2965   // original field of result. |  2975   // original field of result. | 
|  2966   RawField* CloneFromOriginal() const; |  2976   RawField* CloneFromOriginal() const; | 
|  2967  |  2977  | 
|  2968   RawString* name() const { return raw_ptr()->name_; } |  2978   RawString* name() const { return raw_ptr()->name_; } | 
|  2969   RawString* UserVisibleName() const;  // Same as scrubbed name. |  2979   RawString* UserVisibleName() const;  // Same as scrubbed name. | 
|  2970   virtual RawString* DictionaryName() const { return name(); } |  2980   virtual RawString* DictionaryName() const { return name(); } | 
|  2971  |  2981  | 
|  2972   bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } |  2982   bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } | 
 |  2983   bool is_instance() const { return !is_static(); } | 
|  2973   bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } |  2984   bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } | 
|  2974   bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } |  2985   bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } | 
|  2975   bool is_reflectable() const { |  2986   bool is_reflectable() const { | 
|  2976     return ReflectableBit::decode(raw_ptr()->kind_bits_); |  2987     return ReflectableBit::decode(raw_ptr()->kind_bits_); | 
|  2977   } |  2988   } | 
|  2978   void set_is_reflectable(bool value) const { |  2989   void set_is_reflectable(bool value) const { | 
|  2979     ASSERT(IsOriginal()); |  2990     ASSERT(IsOriginal()); | 
|  2980     set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_)); |  2991     set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_)); | 
|  2981   } |  2992   } | 
|  2982   bool is_double_initialized() const { |  2993   bool is_double_initialized() const { | 
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3728                                   const char* class_name, |  3739                                   const char* class_name, | 
|  3729                                   const char* function_name); |  3740                                   const char* function_name); | 
|  3730  |  3741  | 
|  3731   // Character used to indicate a private identifier. |  3742   // Character used to indicate a private identifier. | 
|  3732   static const char kPrivateIdentifierStart  = '_'; |  3743   static const char kPrivateIdentifierStart  = '_'; | 
|  3733  |  3744  | 
|  3734   // Character used to separate private identifiers from |  3745   // Character used to separate private identifiers from | 
|  3735   // the library-specific key. |  3746   // the library-specific key. | 
|  3736   static const char kPrivateKeySeparator = '@'; |  3747   static const char kPrivateKeySeparator = '@'; | 
|  3737  |  3748  | 
|  3738   bool CanReload(const Library& replacement) const; |  3749   void CheckReload(const Library& replacement, | 
 |  3750                    IsolateReloadContext* context) const; | 
|  3739  |  3751  | 
|  3740  private: |  3752  private: | 
|  3741   static const int kInitialImportsCapacity = 4; |  3753   static const int kInitialImportsCapacity = 4; | 
|  3742   static const int kImportsCapacityIncrement = 8; |  3754   static const int kImportsCapacityIncrement = 8; | 
|  3743  |  3755  | 
|  3744   static RawLibrary* New(); |  3756   static RawLibrary* New(); | 
|  3745  |  3757  | 
|  3746   void set_num_imports(intptr_t value) const; |  3758   void set_num_imports(intptr_t value) const; | 
|  3747   bool HasExports() const; |  3759   bool HasExports() const; | 
|  3748   RawArray* loaded_scripts() const { return raw_ptr()->loaded_scripts_; } |  3760   RawArray* loaded_scripts() const { return raw_ptr()->loaded_scripts_; } | 
| (...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  5323   RawObject** FieldAddrAtOffset(intptr_t offset) const { |  5335   RawObject** FieldAddrAtOffset(intptr_t offset) const { | 
|  5324     ASSERT(IsValidFieldOffset(offset)); |  5336     ASSERT(IsValidFieldOffset(offset)); | 
|  5325     return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); |  5337     return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); | 
|  5326   } |  5338   } | 
|  5327   RawObject** FieldAddr(const Field& field) const { |  5339   RawObject** FieldAddr(const Field& field) const { | 
|  5328     return FieldAddrAtOffset(field.Offset()); |  5340     return FieldAddrAtOffset(field.Offset()); | 
|  5329   } |  5341   } | 
|  5330   RawObject** NativeFieldsAddr() const { |  5342   RawObject** NativeFieldsAddr() const { | 
|  5331     return FieldAddrAtOffset(sizeof(RawObject)); |  5343     return FieldAddrAtOffset(sizeof(RawObject)); | 
|  5332   } |  5344   } | 
|  5333  |  | 
|  5334   void SetFieldAtOffset(intptr_t offset, const Object& value) const { |  5345   void SetFieldAtOffset(intptr_t offset, const Object& value) const { | 
|  5335     StorePointer(FieldAddrAtOffset(offset), value.raw()); |  5346     StorePointer(FieldAddrAtOffset(offset), value.raw()); | 
|  5336   } |  5347   } | 
|  5337   bool IsValidFieldOffset(intptr_t offset) const; |  5348   bool IsValidFieldOffset(intptr_t offset) const; | 
|  5338  |  5349  | 
|  5339   static intptr_t NextFieldOffset() { |  5350   static intptr_t NextFieldOffset() { | 
|  5340     return sizeof(RawInstance); |  5351     return sizeof(RawInstance); | 
|  5341   } |  5352   } | 
|  5342  |  5353  | 
 |  5354   // The follwoing raw methods are used for morphing. | 
 |  5355   // They are needed due to the extraction of the class in IsValidFieldOffset. | 
 |  5356   RawObject** RawFieldAddrAtOffset(intptr_t offset) const { | 
 |  5357     return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); | 
 |  5358   } | 
 |  5359   RawObject* RawGetFieldAtOffset(intptr_t offset) const { | 
 |  5360     return *RawFieldAddrAtOffset(offset); | 
 |  5361   } | 
 |  5362   void RawSetFieldAtOffset(intptr_t offset, const Object& value) const { | 
 |  5363     StorePointer(RawFieldAddrAtOffset(offset), value.raw()); | 
 |  5364   } | 
 |  5365  | 
|  5343   // TODO(iposva): Determine if this gets in the way of Smi. |  5366   // TODO(iposva): Determine if this gets in the way of Smi. | 
|  5344   HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |  5367   HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 
|  5345   friend class ByteBuffer; |  5368   friend class ByteBuffer; | 
|  5346   friend class Class; |  5369   friend class Class; | 
|  5347   friend class Closure; |  5370   friend class Closure; | 
|  5348   friend class DeferredObject; |  5371   friend class DeferredObject; | 
|  5349   friend class RegExp; |  5372   friend class RegExp; | 
|  5350   friend class SnapshotWriter; |  5373   friend class SnapshotWriter; | 
|  5351   friend class StubCode; |  5374   friend class StubCode; | 
|  5352   friend class TypedDataView; |  5375   friend class TypedDataView; | 
|  5353   friend class InstanceSerializationCluster; |  5376   friend class InstanceSerializationCluster; | 
|  5354   friend class InstanceDeserializationCluster; |  5377   friend class InstanceDeserializationCluster; | 
|  5355   friend class ClassDeserializationCluster;  // vtable |  5378   friend class ClassDeserializationCluster;  // vtable | 
 |  5379   friend class InstanceMorpher; | 
|  5356 }; |  5380 }; | 
|  5357  |  5381  | 
|  5358  |  5382  | 
|  5359 class LibraryPrefix : public Instance { |  5383 class LibraryPrefix : public Instance { | 
|  5360  public: |  5384  public: | 
|  5361   RawString* name() const { return raw_ptr()->name_; } |  5385   RawString* name() const { return raw_ptr()->name_; } | 
|  5362   virtual RawString* DictionaryName() const { return name(); } |  5386   virtual RawString* DictionaryName() const { return name(); } | 
|  5363  |  5387  | 
|  5364   RawArray* imports() const { return raw_ptr()->imports_; } |  5388   RawArray* imports() const { return raw_ptr()->imports_; } | 
|  5365   intptr_t num_imports() const { return raw_ptr()->num_imports_; } |  5389   intptr_t num_imports() const { return raw_ptr()->num_imports_; } | 
| (...skipping 3155 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  8521     Heap* isolate_heap = isolate->heap(); |  8545     Heap* isolate_heap = isolate->heap(); | 
|  8522     Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |  8546     Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 
|  8523     ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || |  8547     ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || | 
|  8524            vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); |  8548            vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); | 
|  8525   } |  8549   } | 
|  8526 #endif |  8550 #endif | 
|  8527 } |  8551 } | 
|  8528  |  8552  | 
|  8529  |  8553  | 
|  8530 intptr_t Field::Offset() const { |  8554 intptr_t Field::Offset() const { | 
|  8531   ASSERT(!is_static());  // Valid only for dart instance fields. |  8555   ASSERT(is_instance());  // Valid only for dart instance fields. | 
|  8532   intptr_t value = Smi::Value(raw_ptr()->value_.offset_); |  8556   intptr_t value = Smi::Value(raw_ptr()->value_.offset_); | 
|  8533   return (value * kWordSize); |  8557   return (value * kWordSize); | 
|  8534 } |  8558 } | 
|  8535  |  8559  | 
|  8536  |  8560  | 
|  8537 void Field::SetOffset(intptr_t offset_in_bytes) const { |  8561 void Field::SetOffset(intptr_t offset_in_bytes) const { | 
|  8538   ASSERT(!is_static());  // Valid only for dart instance fields. |  8562   ASSERT(is_instance());  // Valid only for dart instance fields. | 
|  8539   ASSERT(kWordSize != 0); |  8563   ASSERT(kWordSize != 0); | 
|  8540   StorePointer(&raw_ptr()->value_.offset_, |  8564   StorePointer(&raw_ptr()->value_.offset_, | 
|  8541                Smi::New(offset_in_bytes / kWordSize)); |  8565                Smi::New(offset_in_bytes / kWordSize)); | 
|  8542 } |  8566 } | 
|  8543  |  8567  | 
|  8544  |  8568  | 
|  8545 RawInstance* Field::StaticValue() const { |  8569 RawInstance* Field::StaticValue() const { | 
|  8546   ASSERT(is_static());  // Valid only for static dart fields. |  8570   ASSERT(is_static());  // Valid only for static dart fields. | 
|  8547   return raw_ptr()->value_.static_value_; |  8571   return raw_ptr()->value_.static_value_; | 
|  8548 } |  8572 } | 
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  8701  |  8725  | 
|  8702 inline void TypeArguments::SetHash(intptr_t value) const { |  8726 inline void TypeArguments::SetHash(intptr_t value) const { | 
|  8703   // This is only safe because we create a new Smi, which does not cause |  8727   // This is only safe because we create a new Smi, which does not cause | 
|  8704   // heap allocation. |  8728   // heap allocation. | 
|  8705   StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |  8729   StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 
|  8706 } |  8730 } | 
|  8707  |  8731  | 
|  8708 }  // namespace dart |  8732 }  // namespace dart | 
|  8709  |  8733  | 
|  8710 #endif  // VM_OBJECT_H_ |  8734 #endif  // VM_OBJECT_H_ | 
| OLD | NEW |