Chromium Code Reviews| 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 Field* OriginalAsHandle(Zone* zone = NULL) const { | |
| 2886 if (zone == NULL) { | |
| 2887 zone = Thread::Current()->zone(); | |
| 2888 } | |
| 2889 return &Field::ZoneHandle(zone, Original()); | |
| 2890 } | |
|
siva
2016/02/25 23:38:33
Can this function be moved to the callers (e.g ast
srdjan
2016/02/26 00:40:43
Removed function.
| |
| 2891 void SetOriginal(const Field& value) const; | |
| 2892 bool IsOriginal() const { | |
| 2893 return Original() == this->raw(); | |
|
siva
2016/02/25 23:38:33
Wouldn't it be easier to just do:
{
if (IsNull()
srdjan
2016/02/26 00:40:43
Adapted:
bool IsOriginal() const {
if (IsNul
| |
| 2894 } | |
| 2895 | |
| 2896 // Returns ZoneHandle of a field cloned from 'this'. 'this' is set as the | |
| 2897 // original field of result. | |
| 2898 Field* CloneFromOriginal() const; | |
|
siva
2016/02/25 23:38:33
RawField* CloneFromOriginal() const;
(See comment
srdjan
2016/02/26 00:40:43
Returning RawField*
| |
| 2899 | |
| 2884 RawString* name() const { return raw_ptr()->name_; } | 2900 RawString* name() const { return raw_ptr()->name_; } |
| 2885 RawString* UserVisibleName() const; // Same as scrubbed name. | 2901 RawString* UserVisibleName() const; // Same as scrubbed name. |
| 2886 virtual RawString* DictionaryName() const { return name(); } | 2902 virtual RawString* DictionaryName() const { return name(); } |
| 2887 | 2903 |
| 2888 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } | 2904 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } |
| 2889 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } | 2905 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } |
| 2890 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } | 2906 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } |
| 2891 bool is_reflectable() const { | 2907 bool is_reflectable() const { |
| 2892 return ReflectableBit::decode(raw_ptr()->kind_bits_); | 2908 return ReflectableBit::decode(raw_ptr()->kind_bits_); |
| 2893 } | 2909 } |
| 2894 void set_is_reflectable(bool value) const { | 2910 void set_is_reflectable(bool value) const { |
| 2911 ASSERT(IsOriginal()); | |
| 2895 set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_)); | 2912 set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_)); |
| 2896 } | 2913 } |
| 2897 bool is_double_initialized() const { | 2914 bool is_double_initialized() const { |
| 2898 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); | 2915 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); |
| 2899 } | 2916 } |
| 2900 // Called in parser after allocating field, immutable property otherwise. | 2917 // Called in parser after allocating field, immutable property otherwise. |
| 2901 // Marks fields that are initialized with a simple double constant. | 2918 // Marks fields that are initialized with a simple double constant. |
| 2902 void set_is_double_initialized(bool value) const { | 2919 void set_is_double_initialized(bool value) const { |
| 2903 ASSERT(Thread::Current()->IsMutatorThread()); | 2920 ASSERT(Thread::Current()->IsMutatorThread()); |
| 2921 ASSERT(IsOriginal()); | |
| 2904 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); | 2922 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); |
| 2905 } | 2923 } |
| 2906 | 2924 |
| 2907 inline intptr_t Offset() const; | 2925 inline intptr_t Offset() const; |
| 2908 // Called during class finalization. | 2926 // Called during class finalization. |
| 2909 inline void SetOffset(intptr_t offset_in_bytes) const; | 2927 inline void SetOffset(intptr_t offset_in_bytes) const; |
| 2910 | 2928 |
| 2911 inline RawInstance* StaticValue() const; | 2929 inline RawInstance* StaticValue() const; |
| 2912 inline void SetStaticValue(const Instance& value, | 2930 inline void SetStaticValue(const Instance& value, |
| 2913 bool save_initial_value = false) const; | 2931 bool save_initial_value = false) const; |
| 2914 | 2932 |
| 2915 RawClass* owner() const; | 2933 RawClass* Owner() const; |
| 2916 RawClass* origin() const; // Either mixin class, or same as owner(). | 2934 RawClass* Origin() const; // Either mixin class, or same as owner(). |
| 2917 RawScript* script() const; | 2935 RawScript* Script() const; |
| 2918 RawObject* RawOwner() const { return raw_ptr()->owner_; } | 2936 RawObject* RawOwner() const; |
| 2919 | 2937 |
| 2920 RawAbstractType* type() const { return raw_ptr()->type_; } | 2938 RawAbstractType* type() const { return raw_ptr()->type_; } |
| 2921 // Used by class finalizer, otherwise initialized in constructor. | 2939 // Used by class finalizer, otherwise initialized in constructor. |
| 2922 void SetFieldType(const AbstractType& value) const; | 2940 void SetFieldType(const AbstractType& value) const; |
| 2923 | 2941 |
| 2924 static intptr_t InstanceSize() { | 2942 static intptr_t InstanceSize() { |
| 2925 return RoundedAllocationSize(sizeof(RawField)); | 2943 return RoundedAllocationSize(sizeof(RawField)); |
| 2926 } | 2944 } |
| 2927 | 2945 |
| 2928 static RawField* New(const String& name, | 2946 static RawField* New(const String& name, |
| 2929 bool is_static, | 2947 bool is_static, |
| 2930 bool is_final, | 2948 bool is_final, |
| 2931 bool is_const, | 2949 bool is_const, |
| 2932 bool is_reflectable, | 2950 bool is_reflectable, |
| 2933 const Class& owner, | 2951 const Class& owner, |
| 2934 const AbstractType& type, | 2952 const AbstractType& type, |
| 2935 TokenPosition token_pos); | 2953 TokenPosition token_pos); |
| 2936 | 2954 |
| 2937 static RawField* NewTopLevel(const String& name, | 2955 static RawField* NewTopLevel(const String& name, |
| 2938 bool is_final, | 2956 bool is_final, |
| 2939 bool is_const, | 2957 bool is_const, |
| 2940 const Object& owner, | 2958 const Object& owner, |
| 2941 TokenPosition token_pos); | 2959 TokenPosition token_pos); |
| 2942 | 2960 |
| 2943 // Allocate new field object, clone values from this field. The | 2961 // Allocate new field object, clone values from this field. The |
| 2944 // owner of the clone is new_owner. | 2962 // owner of the clone is new_owner. |
| 2945 RawField* Clone(const Class& new_owner) const; | 2963 RawField* Clone(const Class& new_owner) const; |
| 2964 // Allocate new field object, clone values from this field. The | |
| 2965 // original is specified. | |
| 2966 RawField* Clone(const Field& original) const; | |
| 2946 | 2967 |
| 2947 static intptr_t instance_field_offset() { | 2968 static intptr_t instance_field_offset() { |
| 2948 return OFFSET_OF(RawField, value_.offset_); | 2969 return OFFSET_OF(RawField, value_.offset_); |
| 2949 } | 2970 } |
| 2950 static intptr_t static_value_offset() { | 2971 static intptr_t static_value_offset() { |
| 2951 return OFFSET_OF(RawField, value_.static_value_); | 2972 return OFFSET_OF(RawField, value_.static_value_); |
| 2952 } | 2973 } |
| 2953 | 2974 |
| 2954 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); } | 2975 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); } |
| 2955 | 2976 |
| 2956 TokenPosition token_pos() const { return raw_ptr()->token_pos_; } | 2977 TokenPosition token_pos() const { return raw_ptr()->token_pos_; } |
| 2957 | 2978 |
| 2958 bool has_initializer() const { | 2979 bool has_initializer() const { |
| 2959 return HasInitializerBit::decode(raw_ptr()->kind_bits_); | 2980 return HasInitializerBit::decode(raw_ptr()->kind_bits_); |
| 2960 } | 2981 } |
| 2961 // Called by parser after allocating field. | 2982 // Called by parser after allocating field. |
| 2962 void set_has_initializer(bool has_initializer) const { | 2983 void set_has_initializer(bool has_initializer) const { |
| 2984 ASSERT(IsOriginal()); | |
| 2963 ASSERT(Thread::Current()->IsMutatorThread()); | 2985 ASSERT(Thread::Current()->IsMutatorThread()); |
| 2964 set_kind_bits(HasInitializerBit::update(has_initializer, | 2986 set_kind_bits(HasInitializerBit::update(has_initializer, |
| 2965 raw_ptr()->kind_bits_)); | 2987 raw_ptr()->kind_bits_)); |
| 2966 } | 2988 } |
| 2967 | 2989 |
| 2968 // Return class id that any non-null value read from this field is guaranteed | 2990 // 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. | 2991 // to have or kDynamicCid if such class id is not known. |
| 2970 // Stores to this field must update this information hence the name. | 2992 // Stores to this field must update this information hence the name. |
| 2971 intptr_t guarded_cid() const { return raw_ptr()->guarded_cid_; } | 2993 intptr_t guarded_cid() const { return raw_ptr()->guarded_cid_; } |
| 2972 | 2994 |
| 2973 void set_guarded_cid(intptr_t cid) const { | 2995 void set_guarded_cid(intptr_t cid) const { |
| 2996 ASSERT(IsOriginal()); | |
| 2974 ASSERT(Thread::Current()->IsMutatorThread()); | 2997 ASSERT(Thread::Current()->IsMutatorThread()); |
| 2975 StoreNonPointer(&raw_ptr()->guarded_cid_, cid); | 2998 StoreNonPointer(&raw_ptr()->guarded_cid_, cid); |
| 2976 } | 2999 } |
| 2977 static intptr_t guarded_cid_offset() { | 3000 static intptr_t guarded_cid_offset() { |
| 2978 return OFFSET_OF(RawField, guarded_cid_); | 3001 return OFFSET_OF(RawField, guarded_cid_); |
| 2979 } | 3002 } |
| 2980 // Return the list length that any list stored in this field is guaranteed | 3003 // Return the list length that any list stored in this field is guaranteed |
| 2981 // to have. If length is kUnknownFixedLength the length has not | 3004 // to have. If length is kUnknownFixedLength the length has not |
| 2982 // been determined. If length is kNoFixedLength this field has multiple | 3005 // been determined. If length is kNoFixedLength this field has multiple |
| 2983 // list lengths associated with it and cannot be predicted. | 3006 // list lengths associated with it and cannot be predicted. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 3003 intptr_t UnboxedFieldCid() const { | 3026 intptr_t UnboxedFieldCid() const { |
| 3004 return guarded_cid(); | 3027 return guarded_cid(); |
| 3005 } | 3028 } |
| 3006 | 3029 |
| 3007 bool is_unboxing_candidate() const { | 3030 bool is_unboxing_candidate() const { |
| 3008 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_); | 3031 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_); |
| 3009 } | 3032 } |
| 3010 // Default 'true', set to false once optimizing compiler determines it should | 3033 // Default 'true', set to false once optimizing compiler determines it should |
| 3011 // be boxed. | 3034 // be boxed. |
| 3012 void set_is_unboxing_candidate(bool b) const { | 3035 void set_is_unboxing_candidate(bool b) const { |
| 3036 ASSERT(IsOriginal()); | |
| 3013 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_)); | 3037 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_)); |
| 3014 } | 3038 } |
| 3015 | 3039 |
| 3016 static bool IsExternalizableCid(intptr_t cid) { | 3040 static bool IsExternalizableCid(intptr_t cid) { |
| 3017 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); | 3041 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); |
| 3018 } | 3042 } |
| 3019 | 3043 |
| 3020 enum { | 3044 enum { |
| 3021 kUnknownLengthOffset = -1, | 3045 kUnknownLengthOffset = -1, |
| 3022 kUnknownFixedLength = -1, | 3046 kUnknownFixedLength = -1, |
| 3023 kNoFixedLength = -2, | 3047 kNoFixedLength = -2, |
| 3024 }; | 3048 }; |
| 3025 // Returns false if any value read from this field is guaranteed to be | 3049 // Returns false if any value read from this field is guaranteed to be |
| 3026 // not null. | 3050 // not null. |
| 3027 // Internally we is_nullable_ field contains either kNullCid (nullable) or | 3051 // Internally we is_nullable_ field contains either kNullCid (nullable) or |
| 3028 // any other value (non-nullable) instead of boolean. This is done to simplify | 3052 // any other value (non-nullable) instead of boolean. This is done to simplify |
| 3029 // guarding sequence in the generated code. | 3053 // guarding sequence in the generated code. |
| 3030 bool is_nullable() const { | 3054 bool is_nullable() const { |
| 3031 return raw_ptr()->is_nullable_ == kNullCid; | 3055 return raw_ptr()->is_nullable_ == kNullCid; |
| 3032 } | 3056 } |
| 3033 void set_is_nullable(bool val) const { | 3057 void set_is_nullable(bool val) const { |
| 3058 ASSERT(IsOriginal()); | |
| 3034 ASSERT(Thread::Current()->IsMutatorThread()); | 3059 ASSERT(Thread::Current()->IsMutatorThread()); |
| 3035 StoreNonPointer(&raw_ptr()->is_nullable_, val ? kNullCid : kIllegalCid); | 3060 StoreNonPointer(&raw_ptr()->is_nullable_, val ? kNullCid : kIllegalCid); |
| 3036 } | 3061 } |
| 3037 static intptr_t is_nullable_offset() { | 3062 static intptr_t is_nullable_offset() { |
| 3038 return OFFSET_OF(RawField, is_nullable_); | 3063 return OFFSET_OF(RawField, is_nullable_); |
| 3039 } | 3064 } |
| 3040 | 3065 |
| 3041 // Record store of the given value into this field. May trigger | 3066 // Record store of the given value into this field. May trigger |
| 3042 // deoptimization of dependent optimized code. | 3067 // deoptimization of dependent optimized code. |
| 3043 void RecordStore(const Object& value) const; | 3068 void RecordStore(const Object& value) const; |
| (...skipping 5368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8412 | 8437 |
| 8413 | 8438 |
| 8414 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 8439 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 8415 intptr_t index) { | 8440 intptr_t index) { |
| 8416 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 8441 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 8417 } | 8442 } |
| 8418 | 8443 |
| 8419 } // namespace dart | 8444 } // namespace dart |
| 8420 | 8445 |
| 8421 #endif // VM_OBJECT_H_ | 8446 #endif // VM_OBJECT_H_ |
| OLD | NEW |