| 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 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 } | 2207 } |
| 2208 // Return the list length that any list stored in this field is guaranteed | 2208 // Return the list length that any list stored in this field is guaranteed |
| 2209 // to have. If length is kUnknownFixedLength the length has not | 2209 // to have. If length is kUnknownFixedLength the length has not |
| 2210 // been determined. If length is kNoFixedLength this field has multiple | 2210 // been determined. If length is kNoFixedLength this field has multiple |
| 2211 // list lengths associated with it and cannot be predicted. | 2211 // list lengths associated with it and cannot be predicted. |
| 2212 intptr_t guarded_list_length() const; | 2212 intptr_t guarded_list_length() const; |
| 2213 void set_guarded_list_length(intptr_t list_length) const; | 2213 void set_guarded_list_length(intptr_t list_length) const; |
| 2214 static intptr_t guarded_list_length_offset() { | 2214 static intptr_t guarded_list_length_offset() { |
| 2215 return OFFSET_OF(RawField, guarded_list_length_); | 2215 return OFFSET_OF(RawField, guarded_list_length_); |
| 2216 } | 2216 } |
| 2217 intptr_t guarded_list_length_in_object_offset() const; |
| 2218 void set_guarded_list_length_in_object_offset(intptr_t offset) const; |
| 2219 static intptr_t guarded_list_length_in_object_offset_offset() { |
| 2220 return OFFSET_OF(RawField, guarded_list_length_in_object_offset_); |
| 2221 } |
| 2222 |
| 2217 bool needs_length_check() const { | 2223 bool needs_length_check() const { |
| 2218 const bool r = guarded_list_length() >= Field::kUnknownFixedLength; | 2224 const bool r = guarded_list_length() >= Field::kUnknownFixedLength; |
| 2219 ASSERT(!r || is_final()); | 2225 ASSERT(!r || is_final()); |
| 2220 return r; | 2226 return r; |
| 2221 } | 2227 } |
| 2222 | 2228 |
| 2229 const char* GuardedPropertiesAsCString() const; |
| 2230 |
| 2223 intptr_t UnboxedFieldCid() const { | 2231 intptr_t UnboxedFieldCid() const { |
| 2224 ASSERT(IsUnboxedField()); | 2232 ASSERT(IsUnboxedField()); |
| 2225 return guarded_cid(); | 2233 return guarded_cid(); |
| 2226 } | 2234 } |
| 2227 | 2235 |
| 2228 bool IsUnboxedField() const; | 2236 bool IsUnboxedField() const; |
| 2229 | 2237 |
| 2230 bool IsPotentialUnboxedField() const; | 2238 bool IsPotentialUnboxedField() const; |
| 2231 | 2239 |
| 2232 bool is_unboxing_candidate() const { | 2240 bool is_unboxing_candidate() const { |
| 2233 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_); | 2241 return UnboxingCandidateBit::decode(raw_ptr()->kind_bits_); |
| 2234 } | 2242 } |
| 2235 void set_is_unboxing_candidate(bool b) const { | 2243 void set_is_unboxing_candidate(bool b) const { |
| 2236 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_)); | 2244 set_kind_bits(UnboxingCandidateBit::update(b, raw_ptr()->kind_bits_)); |
| 2237 } | 2245 } |
| 2238 | 2246 |
| 2239 static bool IsExternalizableCid(intptr_t cid) { | 2247 static bool IsExternalizableCid(intptr_t cid) { |
| 2240 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); | 2248 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); |
| 2241 } | 2249 } |
| 2242 | 2250 |
| 2243 enum { | 2251 enum { |
| 2252 kUnknownLengthOffset = -1, |
| 2244 kUnknownFixedLength = -1, | 2253 kUnknownFixedLength = -1, |
| 2245 kNoFixedLength = -2, | 2254 kNoFixedLength = -2, |
| 2246 }; | 2255 }; |
| 2247 // Returns false if any value read from this field is guaranteed to be | 2256 // Returns false if any value read from this field is guaranteed to be |
| 2248 // not null. | 2257 // not null. |
| 2249 // Internally we is_nullable_ field contains either kNullCid (nullable) or | 2258 // Internally we is_nullable_ field contains either kNullCid (nullable) or |
| 2250 // any other value (non-nullable) instead of boolean. This is done to simplify | 2259 // any other value (non-nullable) instead of boolean. This is done to simplify |
| 2251 // guarding sequence in the generated code. | 2260 // guarding sequence in the generated code. |
| 2252 bool is_nullable() const { | 2261 bool is_nullable() const { |
| 2253 return raw_ptr()->is_nullable_ == kNullCid; | 2262 return raw_ptr()->is_nullable_ == kNullCid; |
| 2254 } | 2263 } |
| 2255 void set_is_nullable(bool val) const { | 2264 void set_is_nullable(bool val) const { |
| 2256 raw_ptr()->is_nullable_ = val ? kNullCid : kIllegalCid; | 2265 raw_ptr()->is_nullable_ = val ? kNullCid : kIllegalCid; |
| 2257 } | 2266 } |
| 2258 static intptr_t is_nullable_offset() { | 2267 static intptr_t is_nullable_offset() { |
| 2259 return OFFSET_OF(RawField, is_nullable_); | 2268 return OFFSET_OF(RawField, is_nullable_); |
| 2260 } | 2269 } |
| 2261 | 2270 |
| 2262 // Update guarded cid and guarded length for this field. May trigger | 2271 // Record store of the given value into this field. May trigger |
| 2263 // deoptimization of dependent optimized code. | 2272 // deoptimization of dependent optimized code. |
| 2264 bool UpdateGuardedCidAndLength(const Object& value) const; | 2273 void RecordStore(const Object& value) const; |
| 2265 | 2274 |
| 2266 // Return the list of optimized code objects that were optimized under | 2275 // Return the list of optimized code objects that were optimized under |
| 2267 // assumptions about guarded class id and nullability of this field. | 2276 // assumptions about guarded class id and nullability of this field. |
| 2268 // These code objects must be deoptimized when field's properties change. | 2277 // These code objects must be deoptimized when field's properties change. |
| 2269 // Code objects are held weakly via an indirection through WeakProperty. | 2278 // Code objects are held weakly via an indirection through WeakProperty. |
| 2270 RawArray* dependent_code() const; | 2279 RawArray* dependent_code() const; |
| 2271 void set_dependent_code(const Array& array) const; | 2280 void set_dependent_code(const Array& array) const; |
| 2272 | 2281 |
| 2273 // Add the given code object to the list of dependent ones. | 2282 // Add the given code object to the list of dependent ones. |
| 2274 void RegisterDependentCode(const Code& code) const; | 2283 void RegisterDependentCode(const Code& code) const; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2299 kUnboxingCandidateBit | 2308 kUnboxingCandidateBit |
| 2300 }; | 2309 }; |
| 2301 class ConstBit : public BitField<bool, kConstBit, 1> {}; | 2310 class ConstBit : public BitField<bool, kConstBit, 1> {}; |
| 2302 class StaticBit : public BitField<bool, kStaticBit, 1> {}; | 2311 class StaticBit : public BitField<bool, kStaticBit, 1> {}; |
| 2303 class FinalBit : public BitField<bool, kFinalBit, 1> {}; | 2312 class FinalBit : public BitField<bool, kFinalBit, 1> {}; |
| 2304 class HasInitializerBit : public BitField<bool, kHasInitializerBit, 1> {}; | 2313 class HasInitializerBit : public BitField<bool, kHasInitializerBit, 1> {}; |
| 2305 class UnboxingCandidateBit : public BitField<bool, | 2314 class UnboxingCandidateBit : public BitField<bool, |
| 2306 kUnboxingCandidateBit, 1> { | 2315 kUnboxingCandidateBit, 1> { |
| 2307 }; | 2316 }; |
| 2308 | 2317 |
| 2309 // Update guarded class id and nullability of the field to reflect assignment | 2318 // Update guarded cid and guarded length for this field. Returns true, if |
| 2310 // of the value with the given class id to this field. Returns true, if | |
| 2311 // deoptimization of dependent code is required. | 2319 // deoptimization of dependent code is required. |
| 2312 bool UpdateCid(intptr_t cid) const; | 2320 bool UpdateGuardedCidAndLength(const Object& value) const; |
| 2313 | |
| 2314 // Update guarded class length of the field to reflect assignment of the | |
| 2315 // value with the given length. Returns true if deoptimization of dependent | |
| 2316 // code is required. | |
| 2317 bool UpdateLength(intptr_t length) const; | |
| 2318 | 2321 |
| 2319 void set_name(const String& value) const; | 2322 void set_name(const String& value) const; |
| 2320 void set_is_static(bool is_static) const { | 2323 void set_is_static(bool is_static) const { |
| 2321 set_kind_bits(StaticBit::update(is_static, raw_ptr()->kind_bits_)); | 2324 set_kind_bits(StaticBit::update(is_static, raw_ptr()->kind_bits_)); |
| 2322 } | 2325 } |
| 2323 void set_is_final(bool is_final) const { | 2326 void set_is_final(bool is_final) const { |
| 2324 set_kind_bits(FinalBit::update(is_final, raw_ptr()->kind_bits_)); | 2327 set_kind_bits(FinalBit::update(is_final, raw_ptr()->kind_bits_)); |
| 2325 } | 2328 } |
| 2326 void set_is_const(bool value) const { | 2329 void set_is_const(bool value) const { |
| 2327 set_kind_bits(ConstBit::update(value, raw_ptr()->kind_bits_)); | 2330 set_kind_bits(ConstBit::update(value, raw_ptr()->kind_bits_)); |
| (...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4152 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const; | 4155 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const; |
| 4153 | 4156 |
| 4154 // Returns true if all fields are OK for canonicalization. | 4157 // Returns true if all fields are OK for canonicalization. |
| 4155 virtual bool CheckAndCanonicalizeFields(const char** error_str) const; | 4158 virtual bool CheckAndCanonicalizeFields(const char** error_str) const; |
| 4156 | 4159 |
| 4157 RawObject* GetField(const Field& field) const { | 4160 RawObject* GetField(const Field& field) const { |
| 4158 return *FieldAddr(field); | 4161 return *FieldAddr(field); |
| 4159 } | 4162 } |
| 4160 | 4163 |
| 4161 void SetField(const Field& field, const Object& value) const { | 4164 void SetField(const Field& field, const Object& value) const { |
| 4162 field.UpdateGuardedCidAndLength(value); | 4165 field.RecordStore(value); |
| 4163 StorePointer(FieldAddr(field), value.raw()); | 4166 StorePointer(FieldAddr(field), value.raw()); |
| 4164 } | 4167 } |
| 4165 | 4168 |
| 4166 RawType* GetType() const; | 4169 RawType* GetType() const; |
| 4167 | 4170 |
| 4168 virtual RawTypeArguments* GetTypeArguments() const; | 4171 virtual RawTypeArguments* GetTypeArguments() const; |
| 4169 virtual void SetTypeArguments(const TypeArguments& value) const; | 4172 virtual void SetTypeArguments(const TypeArguments& value) const; |
| 4170 | 4173 |
| 4171 // Check if the type of this instance is a subtype of the given type. | 4174 // Check if the type of this instance is a subtype of the given type. |
| 4172 bool IsInstanceOf(const AbstractType& type, | 4175 bool IsInstanceOf(const AbstractType& type, |
| (...skipping 2897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7070 | 7073 |
| 7071 | 7074 |
| 7072 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7075 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
| 7073 intptr_t index) { | 7076 intptr_t index) { |
| 7074 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7077 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
| 7075 } | 7078 } |
| 7076 | 7079 |
| 7077 } // namespace dart | 7080 } // namespace dart |
| 7078 | 7081 |
| 7079 #endif // VM_OBJECT_H_ | 7082 #endif // VM_OBJECT_H_ |
| OLD | NEW |