| 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 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 DEFINE_FLAG(bool, trace_cha, false, "Trace CHA operations"); | 61 DEFINE_FLAG(bool, trace_cha, false, "Trace CHA operations"); |
| 62 DEFINE_FLAG(bool, use_field_guards, true, "Guard field cids."); | 62 DEFINE_FLAG(bool, use_field_guards, true, "Guard field cids."); |
| 63 DEFINE_FLAG(bool, use_lib_cache, true, "Use library name cache"); | 63 DEFINE_FLAG(bool, use_lib_cache, true, "Use library name cache"); |
| 64 DEFINE_FLAG(bool, trace_field_guards, false, "Trace changes in field's cids."); | 64 DEFINE_FLAG(bool, trace_field_guards, false, "Trace changes in field's cids."); |
| 65 DEFINE_FLAG(bool, ignore_patch_signature_mismatch, false, | 65 DEFINE_FLAG(bool, ignore_patch_signature_mismatch, false, |
| 66 "Ignore patch file member signature mismatch."); | 66 "Ignore patch file member signature mismatch."); |
| 67 | 67 |
| 68 DECLARE_FLAG(charp, coverage_dir); | 68 DECLARE_FLAG(charp, coverage_dir); |
| 69 DECLARE_FLAG(bool, load_deferred_eagerly); | 69 DECLARE_FLAG(bool, load_deferred_eagerly); |
| 70 DECLARE_FLAG(bool, show_invisible_frames); | 70 DECLARE_FLAG(bool, show_invisible_frames); |
| 71 DECLARE_FLAG(bool, trace_compiler); | |
| 72 DECLARE_FLAG(bool, trace_deoptimization); | 71 DECLARE_FLAG(bool, trace_deoptimization); |
| 73 DECLARE_FLAG(bool, trace_deoptimization_verbose); | 72 DECLARE_FLAG(bool, trace_deoptimization_verbose); |
| 74 DECLARE_FLAG(bool, write_protect_code); | 73 DECLARE_FLAG(bool, write_protect_code); |
| 75 | 74 |
| 76 | 75 |
| 77 static const char* const kGetterPrefix = "get:"; | 76 static const char* const kGetterPrefix = "get:"; |
| 78 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); | 77 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); |
| 79 static const char* const kSetterPrefix = "set:"; | 78 static const char* const kSetterPrefix = "set:"; |
| 80 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); | 79 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); |
| 81 | 80 |
| (...skipping 2258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2340 void Class::set_type_parameters(const TypeArguments& value) const { | 2339 void Class::set_type_parameters(const TypeArguments& value) const { |
| 2341 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | 2340 StorePointer(&raw_ptr()->type_parameters_, value.raw()); |
| 2342 } | 2341 } |
| 2343 | 2342 |
| 2344 | 2343 |
| 2345 intptr_t Class::NumTypeParameters(Thread* thread) const { | 2344 intptr_t Class::NumTypeParameters(Thread* thread) const { |
| 2346 if (IsMixinApplication() && !is_mixin_type_applied()) { | 2345 if (IsMixinApplication() && !is_mixin_type_applied()) { |
| 2347 ClassFinalizer::ApplyMixinType(*this); | 2346 ClassFinalizer::ApplyMixinType(*this); |
| 2348 } | 2347 } |
| 2349 if (type_parameters() == TypeArguments::null()) { | 2348 if (type_parameters() == TypeArguments::null()) { |
| 2349 const intptr_t cid = id(); |
| 2350 if ((cid == kArrayCid) || |
| 2351 (cid == kImmutableArrayCid) || |
| 2352 (cid == kGrowableObjectArrayCid)) { |
| 2353 return 1; // List's type parameter may not have been parsed yet. |
| 2354 } |
| 2350 return 0; | 2355 return 0; |
| 2351 } | 2356 } |
| 2352 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 2357 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
| 2353 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 2358 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
| 2354 type_params = type_parameters(); | 2359 type_params = type_parameters(); |
| 2355 return type_params.Length(); | 2360 return type_params.Length(); |
| 2356 } | 2361 } |
| 2357 | 2362 |
| 2358 | 2363 |
| 2359 intptr_t Class::NumOwnTypeArguments() const { | 2364 intptr_t Class::NumOwnTypeArguments() const { |
| (...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3623 } | 3628 } |
| 3624 | 3629 |
| 3625 | 3630 |
| 3626 void Class::set_canonical_types(const Object& value) const { | 3631 void Class::set_canonical_types(const Object& value) const { |
| 3627 ASSERT(!value.IsNull()); | 3632 ASSERT(!value.IsNull()); |
| 3628 StorePointer(&raw_ptr()->canonical_types_, value.raw()); | 3633 StorePointer(&raw_ptr()->canonical_types_, value.raw()); |
| 3629 } | 3634 } |
| 3630 | 3635 |
| 3631 | 3636 |
| 3632 RawType* Class::CanonicalType() const { | 3637 RawType* Class::CanonicalType() const { |
| 3633 if (NumTypeArguments() == 0) { | 3638 if (!IsGeneric()) { |
| 3634 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_); | 3639 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_); |
| 3635 } | 3640 } |
| 3636 Array& types = Array::Handle(); | 3641 Array& types = Array::Handle(); |
| 3637 types ^= canonical_types(); | 3642 types ^= canonical_types(); |
| 3638 if (!types.IsNull() && (types.Length() > 0)) { | 3643 if (!types.IsNull() && (types.Length() > 0)) { |
| 3639 return reinterpret_cast<RawType*>(types.At(0)); | 3644 return reinterpret_cast<RawType*>(types.At(0)); |
| 3640 } | 3645 } |
| 3641 return reinterpret_cast<RawType*>(Object::null()); | 3646 return reinterpret_cast<RawType*>(Object::null()); |
| 3642 } | 3647 } |
| 3643 | 3648 |
| 3644 | 3649 |
| 3645 void Class::SetCanonicalType(const Type& type) const { | 3650 void Class::SetCanonicalType(const Type& type) const { |
| 3646 ASSERT(type.IsCanonical()); | 3651 ASSERT(type.IsCanonical()); |
| 3647 if (NumTypeArguments() == 0) { | 3652 if (!IsGeneric()) { |
| 3648 ASSERT((canonical_types() == Object::null()) || | 3653 ASSERT((canonical_types() == Object::null()) || |
| 3649 (canonical_types() == type.raw())); // Set during own finalization. | 3654 (canonical_types() == type.raw())); // Set during own finalization. |
| 3650 set_canonical_types(type); | 3655 set_canonical_types(type); |
| 3651 } else { | 3656 } else { |
| 3652 Array& types = Array::Handle(); | 3657 Array& types = Array::Handle(); |
| 3653 types ^= canonical_types(); | 3658 types ^= canonical_types(); |
| 3654 ASSERT(!types.IsNull() && (types.Length() > 1)); | 3659 ASSERT(!types.IsNull() && (types.Length() > 1)); |
| 3655 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); | 3660 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); |
| 3656 types.SetAt(0, type); | 3661 types.SetAt(0, type); |
| 3657 } | 3662 } |
| (...skipping 11288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14946 return result.raw(); | 14951 return result.raw(); |
| 14947 } | 14952 } |
| 14948 | 14953 |
| 14949 | 14954 |
| 14950 RawType* Instance::GetType() const { | 14955 RawType* Instance::GetType() const { |
| 14951 if (IsNull()) { | 14956 if (IsNull()) { |
| 14952 return Type::NullType(); | 14957 return Type::NullType(); |
| 14953 } | 14958 } |
| 14954 const Class& cls = Class::Handle(clazz()); | 14959 const Class& cls = Class::Handle(clazz()); |
| 14955 Type& type = Type::Handle(); | 14960 Type& type = Type::Handle(); |
| 14956 if (cls.NumTypeArguments() == 0) { | 14961 if (!cls.IsGeneric()) { |
| 14957 type = cls.CanonicalType(); | 14962 type = cls.CanonicalType(); |
| 14958 } | 14963 } |
| 14959 if (type.IsNull()) { | 14964 if (type.IsNull()) { |
| 14960 TypeArguments& type_arguments = TypeArguments::Handle(); | 14965 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 14961 if (cls.NumTypeArguments() > 0) { | 14966 if (cls.NumTypeArguments() > 0) { |
| 14962 type_arguments = GetTypeArguments(); | 14967 type_arguments = GetTypeArguments(); |
| 14963 } | 14968 } |
| 14964 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); | 14969 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); |
| 14965 type.SetIsFinalized(); | 14970 type.SetIsFinalized(); |
| 14966 type ^= type.Canonicalize(); | 14971 type ^= type.Canonicalize(); |
| (...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16207 } | 16212 } |
| 16208 Thread* thread = Thread::Current(); | 16213 Thread* thread = Thread::Current(); |
| 16209 Zone* zone = thread->zone(); | 16214 Zone* zone = thread->zone(); |
| 16210 Isolate* isolate = thread->isolate(); | 16215 Isolate* isolate = thread->isolate(); |
| 16211 Type& type = Type::Handle(zone); | 16216 Type& type = Type::Handle(zone); |
| 16212 const Class& cls = Class::Handle(zone, type_class()); | 16217 const Class& cls = Class::Handle(zone, type_class()); |
| 16213 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { | 16218 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { |
| 16214 return Object::dynamic_type().raw(); | 16219 return Object::dynamic_type().raw(); |
| 16215 } | 16220 } |
| 16216 // Fast canonical lookup/registry for simple types. | 16221 // Fast canonical lookup/registry for simple types. |
| 16217 if (cls.NumTypeArguments() == 0) { | 16222 if (!cls.IsGeneric()) { |
| 16218 type = cls.CanonicalType(); | 16223 type = cls.CanonicalType(); |
| 16219 if (type.IsNull()) { | 16224 if (type.IsNull()) { |
| 16220 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); | 16225 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); |
| 16221 cls.set_canonical_types(*this); | 16226 // Canonicalize the type arguments of the supertype, if any. |
| 16222 SetCanonical(); | 16227 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
| 16223 return this->raw(); | 16228 type_args = type_args.Canonicalize(trail); |
| 16229 set_arguments(type_args); |
| 16230 type = cls.CanonicalType(); // May be set while canonicalizing type args. |
| 16231 if (type.IsNull()) { |
| 16232 cls.set_canonical_types(*this); |
| 16233 SetCanonical(); |
| 16234 return this->raw(); |
| 16235 } |
| 16224 } | 16236 } |
| 16225 ASSERT(this->Equals(type)); | 16237 ASSERT(this->Equals(type)); |
| 16226 ASSERT(type.IsCanonical()); | 16238 ASSERT(type.IsCanonical()); |
| 16227 return type.raw(); | 16239 return type.raw(); |
| 16228 } | 16240 } |
| 16229 | 16241 |
| 16230 Array& canonical_types = Array::Handle(zone); | 16242 Array& canonical_types = Array::Handle(zone); |
| 16231 canonical_types ^= cls.canonical_types(); | 16243 canonical_types ^= cls.canonical_types(); |
| 16232 if (canonical_types.IsNull()) { | 16244 if (canonical_types.IsNull()) { |
| 16233 canonical_types = empty_array().raw(); | 16245 canonical_types = empty_array().raw(); |
| (...skipping 5790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22024 return tag_label.ToCString(); | 22036 return tag_label.ToCString(); |
| 22025 } | 22037 } |
| 22026 | 22038 |
| 22027 | 22039 |
| 22028 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 22040 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 22029 Instance::PrintJSONImpl(stream, ref); | 22041 Instance::PrintJSONImpl(stream, ref); |
| 22030 } | 22042 } |
| 22031 | 22043 |
| 22032 | 22044 |
| 22033 } // namespace dart | 22045 } // namespace dart |
| OLD | NEW |