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 2863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2874 | 2874 |
2875 FINAL_HEAP_OBJECT_IMPLEMENTATION(RedirectionData, Object); | 2875 FINAL_HEAP_OBJECT_IMPLEMENTATION(RedirectionData, Object); |
2876 friend class Class; | 2876 friend class Class; |
2877 friend class Function; | 2877 friend class Function; |
2878 friend class HeapProfiler; | 2878 friend class HeapProfiler; |
2879 }; | 2879 }; |
2880 | 2880 |
2881 | 2881 |
2882 class Field : public Object { | 2882 class Field : public Object { |
2883 public: | 2883 public: |
| 2884 RawField* Original() const; |
| 2885 void SetOriginal(const Field& value) const; |
| 2886 bool IsOriginal() const { |
| 2887 if (IsNull()) { |
| 2888 return true; |
| 2889 } |
| 2890 NoSafepointScope no_safepoint; |
| 2891 return !raw_ptr()->owner_->IsField(); |
| 2892 } |
| 2893 |
| 2894 // Returns a field cloned from 'this'. 'this' is set as the |
| 2895 // original field of result. |
| 2896 RawField* CloneFromOriginal() const; |
| 2897 |
2884 RawString* name() const { return raw_ptr()->name_; } | 2898 RawString* name() const { return raw_ptr()->name_; } |
2885 RawString* UserVisibleName() const; // Same as scrubbed name. | 2899 RawString* UserVisibleName() const; // Same as scrubbed name. |
2886 virtual RawString* DictionaryName() const { return name(); } | 2900 virtual RawString* DictionaryName() const { return name(); } |
2887 | 2901 |
2888 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } | 2902 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } |
2889 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } | 2903 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } |
2890 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } | 2904 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } |
2891 bool is_reflectable() const { | 2905 bool is_reflectable() const { |
2892 return ReflectableBit::decode(raw_ptr()->kind_bits_); | 2906 return ReflectableBit::decode(raw_ptr()->kind_bits_); |
2893 } | 2907 } |
2894 void set_is_reflectable(bool value) const { | 2908 void set_is_reflectable(bool value) const { |
| 2909 ASSERT(IsOriginal()); |
2895 set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_)); | 2910 set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_)); |
2896 } | 2911 } |
2897 bool is_double_initialized() const { | 2912 bool is_double_initialized() const { |
2898 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); | 2913 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); |
2899 } | 2914 } |
2900 // Called in parser after allocating field, immutable property otherwise. | 2915 // Called in parser after allocating field, immutable property otherwise. |
2901 // Marks fields that are initialized with a simple double constant. | 2916 // Marks fields that are initialized with a simple double constant. |
2902 void set_is_double_initialized(bool value) const { | 2917 void set_is_double_initialized(bool value) const { |
2903 ASSERT(Thread::Current()->IsMutatorThread()); | 2918 ASSERT(Thread::Current()->IsMutatorThread()); |
| 2919 ASSERT(IsOriginal()); |
2904 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); | 2920 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); |
2905 } | 2921 } |
2906 | 2922 |
2907 inline intptr_t Offset() const; | 2923 inline intptr_t Offset() const; |
2908 // Called during class finalization. | 2924 // Called during class finalization. |
2909 inline void SetOffset(intptr_t offset_in_bytes) const; | 2925 inline void SetOffset(intptr_t offset_in_bytes) const; |
2910 | 2926 |
2911 inline RawInstance* StaticValue() const; | 2927 inline RawInstance* StaticValue() const; |
2912 inline void SetStaticValue(const Instance& value, | 2928 inline void SetStaticValue(const Instance& value, |
2913 bool save_initial_value = false) const; | 2929 bool save_initial_value = false) const; |
2914 | 2930 |
2915 RawClass* owner() const; | 2931 RawClass* Owner() const; |
2916 RawClass* origin() const; // Either mixin class, or same as owner(). | 2932 RawClass* Origin() const; // Either mixin class, or same as owner(). |
2917 RawScript* script() const; | 2933 RawScript* Script() const; |
2918 RawObject* RawOwner() const { return raw_ptr()->owner_; } | 2934 RawObject* RawOwner() const; |
2919 | 2935 |
2920 RawAbstractType* type() const { return raw_ptr()->type_; } | 2936 RawAbstractType* type() const { return raw_ptr()->type_; } |
2921 // Used by class finalizer, otherwise initialized in constructor. | 2937 // Used by class finalizer, otherwise initialized in constructor. |
2922 void SetFieldType(const AbstractType& value) const; | 2938 void SetFieldType(const AbstractType& value) const; |
2923 | 2939 |
2924 static intptr_t InstanceSize() { | 2940 static intptr_t InstanceSize() { |
2925 return RoundedAllocationSize(sizeof(RawField)); | 2941 return RoundedAllocationSize(sizeof(RawField)); |
2926 } | 2942 } |
2927 | 2943 |
2928 static RawField* New(const String& name, | 2944 static RawField* New(const String& name, |
2929 bool is_static, | 2945 bool is_static, |
2930 bool is_final, | 2946 bool is_final, |
2931 bool is_const, | 2947 bool is_const, |
2932 bool is_reflectable, | 2948 bool is_reflectable, |
2933 const Class& owner, | 2949 const Class& owner, |
2934 const AbstractType& type, | 2950 const AbstractType& type, |
2935 TokenPosition token_pos); | 2951 TokenPosition token_pos); |
2936 | 2952 |
2937 static RawField* NewTopLevel(const String& name, | 2953 static RawField* NewTopLevel(const String& name, |
2938 bool is_final, | 2954 bool is_final, |
2939 bool is_const, | 2955 bool is_const, |
2940 const Object& owner, | 2956 const Object& owner, |
2941 TokenPosition token_pos); | 2957 TokenPosition token_pos); |
2942 | 2958 |
2943 // Allocate new field object, clone values from this field. The | 2959 // Allocate new field object, clone values from this field. The |
2944 // owner of the clone is new_owner. | 2960 // owner of the clone is new_owner. |
2945 RawField* Clone(const Class& new_owner) const; | 2961 RawField* Clone(const Class& new_owner) const; |
| 2962 // Allocate new field object, clone values from this field. The |
| 2963 // original is specified. |
| 2964 RawField* Clone(const Field& original) const; |
2946 | 2965 |
2947 static intptr_t instance_field_offset() { | 2966 static intptr_t instance_field_offset() { |
2948 return OFFSET_OF(RawField, value_.offset_); | 2967 return OFFSET_OF(RawField, value_.offset_); |
2949 } | 2968 } |
2950 static intptr_t static_value_offset() { | 2969 static intptr_t static_value_offset() { |
2951 return OFFSET_OF(RawField, value_.static_value_); | 2970 return OFFSET_OF(RawField, value_.static_value_); |
2952 } | 2971 } |
2953 | 2972 |
2954 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); } | 2973 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); } |
2955 | 2974 |
2956 TokenPosition token_pos() const { return raw_ptr()->token_pos_; } | 2975 TokenPosition token_pos() const { return raw_ptr()->token_pos_; } |
2957 | 2976 |
2958 bool has_initializer() const { | 2977 bool has_initializer() const { |
2959 return HasInitializerBit::decode(raw_ptr()->kind_bits_); | 2978 return HasInitializerBit::decode(raw_ptr()->kind_bits_); |
2960 } | 2979 } |
2961 // Called by parser after allocating field. | 2980 // Called by parser after allocating field. |
2962 void set_has_initializer(bool has_initializer) const { | 2981 void set_has_initializer(bool has_initializer) const { |
| 2982 ASSERT(IsOriginal()); |
2963 ASSERT(Thread::Current()->IsMutatorThread()); | 2983 ASSERT(Thread::Current()->IsMutatorThread()); |
2964 set_kind_bits(HasInitializerBit::update(has_initializer, | 2984 set_kind_bits(HasInitializerBit::update(has_initializer, |
2965 raw_ptr()->kind_bits_)); | 2985 raw_ptr()->kind_bits_)); |
2966 } | 2986 } |
2967 | 2987 |
2968 // Return class id that any non-null value read from this field is guaranteed | 2988 // Return class id that any non-null value read from this field is guaranteed |
2969 // to have or kDynamicCid if such class id is not known. | 2989 // to have or kDynamicCid if such class id is not known. |
2970 // Stores to this field must update this information hence the name. | 2990 // Stores to this field must update this information hence the name. |
2971 intptr_t guarded_cid() const { return raw_ptr()->guarded_cid_; } | 2991 intptr_t guarded_cid() const { return raw_ptr()->guarded_cid_; } |
2972 | 2992 |
(...skipping 30 matching lines...) Expand all Loading... |
3003 intptr_t UnboxedFieldCid() const { | 3023 intptr_t UnboxedFieldCid() const { |
3004 return guarded_cid(); | 3024 return guarded_cid(); |
3005 } | 3025 } |
3006 | 3026 |
3007 bool is_unboxing_candidate() const { | 3027 bool is_unboxing_candidate() const { |
3008 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_); | 3028 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_); |
3009 } | 3029 } |
3010 // Default 'true', set to false once optimizing compiler determines it should | 3030 // Default 'true', set to false once optimizing compiler determines it should |
3011 // be boxed. | 3031 // be boxed. |
3012 void set_is_unboxing_candidate(bool b) const { | 3032 void set_is_unboxing_candidate(bool b) const { |
| 3033 ASSERT(IsOriginal()); |
3013 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_)); | 3034 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_)); |
3014 } | 3035 } |
3015 | 3036 |
3016 static bool IsExternalizableCid(intptr_t cid) { | 3037 static bool IsExternalizableCid(intptr_t cid) { |
3017 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); | 3038 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); |
3018 } | 3039 } |
3019 | 3040 |
3020 enum { | 3041 enum { |
3021 kUnknownLengthOffset = -1, | 3042 kUnknownLengthOffset = -1, |
3022 kUnknownFixedLength = -1, | 3043 kUnknownFixedLength = -1, |
(...skipping 5404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8427 | 8448 |
8428 | 8449 |
8429 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 8450 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
8430 intptr_t index) { | 8451 intptr_t index) { |
8431 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 8452 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
8432 } | 8453 } |
8433 | 8454 |
8434 } // namespace dart | 8455 } // namespace dart |
8435 | 8456 |
8436 #endif // VM_OBJECT_H_ | 8457 #endif // VM_OBJECT_H_ |
OLD | NEW |