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 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5318 RawObject** FieldAddrAtOffset(intptr_t offset) const { | 5330 RawObject** FieldAddrAtOffset(intptr_t offset) const { |
5319 ASSERT(IsValidFieldOffset(offset)); | 5331 ASSERT(IsValidFieldOffset(offset)); |
5320 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); | 5332 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); |
5321 } | 5333 } |
5322 RawObject** FieldAddr(const Field& field) const { | 5334 RawObject** FieldAddr(const Field& field) const { |
5323 return FieldAddrAtOffset(field.Offset()); | 5335 return FieldAddrAtOffset(field.Offset()); |
5324 } | 5336 } |
5325 RawObject** NativeFieldsAddr() const { | 5337 RawObject** NativeFieldsAddr() const { |
5326 return FieldAddrAtOffset(sizeof(RawObject)); | 5338 return FieldAddrAtOffset(sizeof(RawObject)); |
5327 } | 5339 } |
5328 | |
5329 void SetFieldAtOffset(intptr_t offset, const Object& value) const { | 5340 void SetFieldAtOffset(intptr_t offset, const Object& value) const { |
5330 StorePointer(FieldAddrAtOffset(offset), value.raw()); | 5341 StorePointer(FieldAddrAtOffset(offset), value.raw()); |
5331 } | 5342 } |
5332 bool IsValidFieldOffset(intptr_t offset) const; | 5343 bool IsValidFieldOffset(intptr_t offset) const; |
5333 | 5344 |
5334 static intptr_t NextFieldOffset() { | 5345 static intptr_t NextFieldOffset() { |
5335 return sizeof(RawInstance); | 5346 return sizeof(RawInstance); |
5336 } | 5347 } |
5337 | 5348 |
| 5349 // The follwoing raw methods are used for morphing. |
| 5350 // They are needed due to the extraction of the class in IsValidFieldOffset. |
| 5351 RawObject** RawFieldAddrAtOffset(intptr_t offset) const { |
| 5352 return reinterpret_cast<RawObject**>(raw_value() - kHeapObjectTag + offset); |
| 5353 } |
| 5354 RawObject* RawGetFieldAtOffset(intptr_t offset) const { |
| 5355 return *RawFieldAddrAtOffset(offset); |
| 5356 } |
| 5357 void RawSetFieldAtOffset(intptr_t offset, const Object& value) const { |
| 5358 StorePointer(RawFieldAddrAtOffset(offset), value.raw()); |
| 5359 } |
| 5360 |
5338 // TODO(iposva): Determine if this gets in the way of Smi. | 5361 // TODO(iposva): Determine if this gets in the way of Smi. |
5339 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 5362 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
5340 friend class ByteBuffer; | 5363 friend class ByteBuffer; |
5341 friend class Class; | 5364 friend class Class; |
5342 friend class Closure; | 5365 friend class Closure; |
5343 friend class DeferredObject; | 5366 friend class DeferredObject; |
5344 friend class RegExp; | 5367 friend class RegExp; |
5345 friend class SnapshotWriter; | 5368 friend class SnapshotWriter; |
5346 friend class StubCode; | 5369 friend class StubCode; |
5347 friend class TypedDataView; | 5370 friend class TypedDataView; |
5348 friend class InstanceSerializationCluster; | 5371 friend class InstanceSerializationCluster; |
5349 friend class InstanceDeserializationCluster; | 5372 friend class InstanceDeserializationCluster; |
5350 friend class ClassDeserializationCluster; // vtable | 5373 friend class ClassDeserializationCluster; // vtable |
| 5374 friend class InstanceMorpher; |
5351 }; | 5375 }; |
5352 | 5376 |
5353 | 5377 |
5354 class LibraryPrefix : public Instance { | 5378 class LibraryPrefix : public Instance { |
5355 public: | 5379 public: |
5356 RawString* name() const { return raw_ptr()->name_; } | 5380 RawString* name() const { return raw_ptr()->name_; } |
5357 virtual RawString* DictionaryName() const { return name(); } | 5381 virtual RawString* DictionaryName() const { return name(); } |
5358 | 5382 |
5359 RawArray* imports() const { return raw_ptr()->imports_; } | 5383 RawArray* imports() const { return raw_ptr()->imports_; } |
5360 intptr_t num_imports() const { return raw_ptr()->num_imports_; } | 5384 intptr_t num_imports() const { return raw_ptr()->num_imports_; } |
(...skipping 3117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8478 Heap* isolate_heap = isolate->heap(); | 8502 Heap* isolate_heap = isolate->heap(); |
8479 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 8503 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
8480 ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || | 8504 ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || |
8481 vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); | 8505 vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); |
8482 } | 8506 } |
8483 #endif | 8507 #endif |
8484 } | 8508 } |
8485 | 8509 |
8486 | 8510 |
8487 intptr_t Field::Offset() const { | 8511 intptr_t Field::Offset() const { |
8488 ASSERT(!is_static()); // Valid only for dart instance fields. | 8512 ASSERT(is_instance()); // Valid only for dart instance fields. |
8489 intptr_t value = Smi::Value(raw_ptr()->value_.offset_); | 8513 intptr_t value = Smi::Value(raw_ptr()->value_.offset_); |
8490 return (value * kWordSize); | 8514 return (value * kWordSize); |
8491 } | 8515 } |
8492 | 8516 |
8493 | 8517 |
8494 void Field::SetOffset(intptr_t offset_in_bytes) const { | 8518 void Field::SetOffset(intptr_t offset_in_bytes) const { |
8495 ASSERT(!is_static()); // Valid only for dart instance fields. | 8519 ASSERT(is_instance()); // Valid only for dart instance fields. |
8496 ASSERT(kWordSize != 0); | 8520 ASSERT(kWordSize != 0); |
8497 StorePointer(&raw_ptr()->value_.offset_, | 8521 StorePointer(&raw_ptr()->value_.offset_, |
8498 Smi::New(offset_in_bytes / kWordSize)); | 8522 Smi::New(offset_in_bytes / kWordSize)); |
8499 } | 8523 } |
8500 | 8524 |
8501 | 8525 |
8502 RawInstance* Field::StaticValue() const { | 8526 RawInstance* Field::StaticValue() const { |
8503 ASSERT(is_static()); // Valid only for static dart fields. | 8527 ASSERT(is_static()); // Valid only for static dart fields. |
8504 return raw_ptr()->value_.static_value_; | 8528 return raw_ptr()->value_.static_value_; |
8505 } | 8529 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8658 | 8682 |
8659 inline void TypeArguments::SetHash(intptr_t value) const { | 8683 inline void TypeArguments::SetHash(intptr_t value) const { |
8660 // This is only safe because we create a new Smi, which does not cause | 8684 // This is only safe because we create a new Smi, which does not cause |
8661 // heap allocation. | 8685 // heap allocation. |
8662 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 8686 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
8663 } | 8687 } |
8664 | 8688 |
8665 } // namespace dart | 8689 } // namespace dart |
8666 | 8690 |
8667 #endif // VM_OBJECT_H_ | 8691 #endif // VM_OBJECT_H_ |
OLD | NEW |