Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Side by Side Diff: runtime/vm/object.h

Issue 1406943006: Pass type argument to Field construction, thus freezing that field, denoting it cannot be changed l… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: c Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2860 2860
2861 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } 2861 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); }
2862 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } 2862 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); }
2863 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } 2863 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); }
2864 bool is_reflectable() const { 2864 bool is_reflectable() const {
2865 return ReflectableBit::decode(raw_ptr()->kind_bits_); 2865 return ReflectableBit::decode(raw_ptr()->kind_bits_);
2866 } 2866 }
2867 bool is_double_initialized() const { 2867 bool is_double_initialized() const {
2868 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); 2868 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_);
2869 } 2869 }
2870 // Called in parser after allocating field, immutable property otherwise.
2871 // Marks fields that are initialized with a simple double constant.
2870 void set_is_double_initialized(bool value) const { 2872 void set_is_double_initialized(bool value) const {
2873 ASSERT(Thread::Current()->IsMutatorThread());
2871 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); 2874 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_));
2872 } 2875 }
2873 2876
2874 inline intptr_t Offset() const; 2877 inline intptr_t Offset() const;
2878 // Called during class finalization.
2875 inline void SetOffset(intptr_t offset_in_bytes) const; 2879 inline void SetOffset(intptr_t offset_in_bytes) const;
2876 2880
2877 inline RawInstance* StaticValue() const; 2881 inline RawInstance* StaticValue() const;
2878 inline void SetStaticValue(const Instance& value, 2882 inline void SetStaticValue(const Instance& value,
2879 bool save_initial_value = false) const; 2883 bool save_initial_value = false) const;
2880 2884
2881 RawClass* owner() const; 2885 RawClass* owner() const;
2882 RawClass* origin() const; // Either mixin class, or same as owner(). 2886 RawClass* origin() const; // Either mixin class, or same as owner().
2883 2887
2884 RawAbstractType* type() const { return raw_ptr()->type_; } 2888 RawAbstractType* type() const { return raw_ptr()->type_; }
2885 void set_type(const AbstractType& value) const; 2889 // Used by class finalizer, otherwise initialized in constructor.
2890 void SetFieldType(const AbstractType& value) const;
2886 2891
2887 static intptr_t InstanceSize() { 2892 static intptr_t InstanceSize() {
2888 return RoundedAllocationSize(sizeof(RawField)); 2893 return RoundedAllocationSize(sizeof(RawField));
2889 } 2894 }
2890 2895
2891 static RawField* New(const String& name, 2896 static RawField* New(const String& name,
2892 bool is_static, 2897 bool is_static,
2893 bool is_final, 2898 bool is_final,
2894 bool is_const, 2899 bool is_const,
2895 bool is_reflectable, 2900 bool is_reflectable,
2896 const Class& owner, 2901 const Class& owner,
2902 const AbstractType& type,
2897 intptr_t token_pos); 2903 intptr_t token_pos);
2898 2904
2899 // Allocate new field object, clone values from this field. The 2905 // Allocate new field object, clone values from this field. The
2900 // owner of the clone is new_owner. 2906 // owner of the clone is new_owner.
2901 RawField* Clone(const Class& new_owner) const; 2907 RawField* Clone(const Class& new_owner) const;
2902 2908
2903 static intptr_t instance_field_offset() { 2909 static intptr_t instance_field_offset() {
2904 return OFFSET_OF(RawField, value_.offset_); 2910 return OFFSET_OF(RawField, value_.offset_);
2905 } 2911 }
2906 static intptr_t static_value_offset() { 2912 static intptr_t static_value_offset() {
2907 return OFFSET_OF(RawField, value_.static_value_); 2913 return OFFSET_OF(RawField, value_.static_value_);
2908 } 2914 }
2909 2915
2910 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); } 2916 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); }
2911 2917
2912 intptr_t token_pos() const { return raw_ptr()->token_pos_; } 2918 intptr_t token_pos() const { return raw_ptr()->token_pos_; }
2913 2919
2914 bool has_initializer() const { 2920 bool has_initializer() const {
2915 return HasInitializerBit::decode(raw_ptr()->kind_bits_); 2921 return HasInitializerBit::decode(raw_ptr()->kind_bits_);
2916 } 2922 }
2923 // Called by parser after allocating field.
2917 void set_has_initializer(bool has_initializer) const { 2924 void set_has_initializer(bool has_initializer) const {
2925 ASSERT(Thread::Current()->IsMutatorThread());
2918 set_kind_bits(HasInitializerBit::update(has_initializer, 2926 set_kind_bits(HasInitializerBit::update(has_initializer,
2919 raw_ptr()->kind_bits_)); 2927 raw_ptr()->kind_bits_));
2920 } 2928 }
2921 2929
2922 // Return class id that any non-null value read from this field is guaranteed 2930 // Return class id that any non-null value read from this field is guaranteed
2923 // to have or kDynamicCid if such class id is not known. 2931 // to have or kDynamicCid if such class id is not known.
2924 // Stores to this field must update this information hence the name. 2932 // Stores to this field must update this information hence the name.
2925 intptr_t guarded_cid() const { return raw_ptr()->guarded_cid_; } 2933 intptr_t guarded_cid() const { return raw_ptr()->guarded_cid_; }
2926 2934
2927 void set_guarded_cid(intptr_t cid) const { 2935 void set_guarded_cid(intptr_t cid) const {
2936 ASSERT(Thread::Current()->IsMutatorThread());
2928 StoreNonPointer(&raw_ptr()->guarded_cid_, cid); 2937 StoreNonPointer(&raw_ptr()->guarded_cid_, cid);
2929 } 2938 }
2930 static intptr_t guarded_cid_offset() { 2939 static intptr_t guarded_cid_offset() {
2931 return OFFSET_OF(RawField, guarded_cid_); 2940 return OFFSET_OF(RawField, guarded_cid_);
2932 } 2941 }
2933 // Return the list length that any list stored in this field is guaranteed 2942 // Return the list length that any list stored in this field is guaranteed
2934 // to have. If length is kUnknownFixedLength the length has not 2943 // to have. If length is kUnknownFixedLength the length has not
2935 // been determined. If length is kNoFixedLength this field has multiple 2944 // been determined. If length is kNoFixedLength this field has multiple
2936 // list lengths associated with it and cannot be predicted. 2945 // list lengths associated with it and cannot be predicted.
2937 intptr_t guarded_list_length() const; 2946 intptr_t guarded_list_length() const;
(...skipping 15 matching lines...) Expand all
2953 2962
2954 const char* GuardedPropertiesAsCString() const; 2963 const char* GuardedPropertiesAsCString() const;
2955 2964
2956 intptr_t UnboxedFieldCid() const { 2965 intptr_t UnboxedFieldCid() const {
2957 return guarded_cid(); 2966 return guarded_cid();
2958 } 2967 }
2959 2968
2960 bool is_unboxing_candidate() const { 2969 bool is_unboxing_candidate() const {
2961 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_); 2970 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_);
2962 } 2971 }
2972 // Default 'true', set to false once optimizing compiler determines it should
2973 // be boxed
regis 2015/11/09 20:28:15 Missing period
srdjan 2015/11/09 21:09:40 Done.
2963 void set_is_unboxing_candidate(bool b) const { 2974 void set_is_unboxing_candidate(bool b) const {
2964 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_)); 2975 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_));
2965 } 2976 }
2966 2977
2967 static bool IsExternalizableCid(intptr_t cid) { 2978 static bool IsExternalizableCid(intptr_t cid) {
2968 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); 2979 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid);
2969 } 2980 }
2970 2981
2971 enum { 2982 enum {
2972 kUnknownLengthOffset = -1, 2983 kUnknownLengthOffset = -1,
2973 kUnknownFixedLength = -1, 2984 kUnknownFixedLength = -1,
2974 kNoFixedLength = -2, 2985 kNoFixedLength = -2,
2975 }; 2986 };
2976 // Returns false if any value read from this field is guaranteed to be 2987 // Returns false if any value read from this field is guaranteed to be
2977 // not null. 2988 // not null.
2978 // Internally we is_nullable_ field contains either kNullCid (nullable) or 2989 // Internally we is_nullable_ field contains either kNullCid (nullable) or
2979 // any other value (non-nullable) instead of boolean. This is done to simplify 2990 // any other value (non-nullable) instead of boolean. This is done to simplify
2980 // guarding sequence in the generated code. 2991 // guarding sequence in the generated code.
2981 bool is_nullable() const { 2992 bool is_nullable() const {
2982 return raw_ptr()->is_nullable_ == kNullCid; 2993 return raw_ptr()->is_nullable_ == kNullCid;
2983 } 2994 }
2984 void set_is_nullable(bool val) const { 2995 void set_is_nullable(bool val) const {
2996 ASSERT(Thread::Current()->IsMutatorThread());
2985 StoreNonPointer(&raw_ptr()->is_nullable_, val ? kNullCid : kIllegalCid); 2997 StoreNonPointer(&raw_ptr()->is_nullable_, val ? kNullCid : kIllegalCid);
2986 } 2998 }
2987 static intptr_t is_nullable_offset() { 2999 static intptr_t is_nullable_offset() {
2988 return OFFSET_OF(RawField, is_nullable_); 3000 return OFFSET_OF(RawField, is_nullable_);
2989 } 3001 }
2990 3002
2991 // Record store of the given value into this field. May trigger 3003 // Record store of the given value into this field. May trigger
2992 // deoptimization of dependent optimized code. 3004 // deoptimization of dependent optimized code.
2993 void RecordStore(const Object& value) const; 3005 void RecordStore(const Object& value) const;
2994 3006
(...skipping 5124 matching lines...) Expand 10 before | Expand all | Expand 10 after
8119 8131
8120 8132
8121 RawInstance* Field::StaticValue() const { 8133 RawInstance* Field::StaticValue() const {
8122 ASSERT(is_static()); // Valid only for static dart fields. 8134 ASSERT(is_static()); // Valid only for static dart fields.
8123 return raw_ptr()->value_.static_value_; 8135 return raw_ptr()->value_.static_value_;
8124 } 8136 }
8125 8137
8126 8138
8127 void Field::SetStaticValue(const Instance& value, 8139 void Field::SetStaticValue(const Instance& value,
8128 bool save_initial_value) const { 8140 bool save_initial_value) const {
8141 ASSERT(Thread::Current()->IsMutatorThread());
8129 ASSERT(is_static()); // Valid only for static dart fields. 8142 ASSERT(is_static()); // Valid only for static dart fields.
8130 StorePointer(&raw_ptr()->value_.static_value_, value.raw()); 8143 StorePointer(&raw_ptr()->value_.static_value_, value.raw());
8131 if (save_initial_value) { 8144 if (save_initial_value) {
8132 ASSERT(!HasPrecompiledInitializer()); 8145 ASSERT(!HasPrecompiledInitializer());
8133 StorePointer(&raw_ptr()->initializer_.saved_value_, value.raw()); 8146 StorePointer(&raw_ptr()->initializer_.saved_value_, value.raw());
8134 } 8147 }
8135 } 8148 }
8136 8149
8137 8150
8138 void Context::SetAt(intptr_t index, const Object& value) const { 8151 void Context::SetAt(intptr_t index, const Object& value) const {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
8223 8236
8224 8237
8225 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8238 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8226 intptr_t index) { 8239 intptr_t index) {
8227 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8240 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8228 } 8241 }
8229 8242
8230 } // namespace dart 8243 } // namespace dart
8231 8244
8232 #endif // VM_OBJECT_H_ 8245 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698