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/become.h" | 10 #include "vm/become.h" |
(...skipping 3739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3750 StorePointer(&raw_ptr()->constants_, value.raw()); | 3750 StorePointer(&raw_ptr()->constants_, value.raw()); |
3751 } | 3751 } |
3752 | 3752 |
3753 | 3753 |
3754 RawType* Class::canonical_type() const { | 3754 RawType* Class::canonical_type() const { |
3755 return raw_ptr()->canonical_type_; | 3755 return raw_ptr()->canonical_type_; |
3756 } | 3756 } |
3757 | 3757 |
3758 | 3758 |
3759 void Class::set_canonical_type(const Type& value) const { | 3759 void Class::set_canonical_type(const Type& value) const { |
3760 ASSERT(!value.IsNull()); | 3760 ASSERT(!value.IsNull() && value.IsCanonical() && value.IsOld()); |
3761 StorePointer(&raw_ptr()->canonical_type_, value.raw()); | 3761 StorePointer(&raw_ptr()->canonical_type_, value.raw()); |
3762 } | 3762 } |
3763 | 3763 |
3764 | 3764 |
3765 RawType* Class::CanonicalType() const { | 3765 RawType* Class::CanonicalType() const { |
3766 return raw_ptr()->canonical_type_; | 3766 return raw_ptr()->canonical_type_; |
3767 } | 3767 } |
3768 | 3768 |
3769 | 3769 |
3770 void Class::SetCanonicalType(const Type& type) const { | 3770 void Class::SetCanonicalType(const Type& type) const { |
(...skipping 13744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17515 (isolate == Dart::vm_isolate())); | 17515 (isolate == Dart::vm_isolate())); |
17516 | 17516 |
17517 // Since dynamic is not a keyword, the parser builds a type that requires | 17517 // Since dynamic is not a keyword, the parser builds a type that requires |
17518 // canonicalization. | 17518 // canonicalization. |
17519 if ((type_class() == Object::dynamic_class()) && | 17519 if ((type_class() == Object::dynamic_class()) && |
17520 (isolate != Dart::vm_isolate())) { | 17520 (isolate != Dart::vm_isolate())) { |
17521 ASSERT(Object::dynamic_type().IsCanonical()); | 17521 ASSERT(Object::dynamic_type().IsCanonical()); |
17522 return Object::dynamic_type().raw(); | 17522 return Object::dynamic_type().raw(); |
17523 } | 17523 } |
17524 | 17524 |
17525 AbstractType& type = Type::Handle(zone); | |
17526 const Class& cls = Class::Handle(zone, type_class()); | 17525 const Class& cls = Class::Handle(zone, type_class()); |
17527 | 17526 |
17528 // Fast canonical lookup/registry for simple types. | 17527 // Fast canonical lookup/registry for simple types. |
17529 if (!cls.IsGeneric() && !cls.IsClosureClass() && !cls.IsTypedefClass()) { | 17528 if (!cls.IsGeneric() && !cls.IsClosureClass() && !cls.IsTypedefClass()) { |
17530 ASSERT(!IsFunctionType()); | 17529 ASSERT(!IsFunctionType()); |
17531 type = cls.CanonicalType(); | 17530 Type& type = Type::Handle(zone, cls.CanonicalType()); |
17532 if (type.IsNull()) { | 17531 if (type.IsNull()) { |
17533 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); | 17532 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); |
17534 // Canonicalize the type arguments of the supertype, if any. | 17533 // Canonicalize the type arguments of the supertype, if any. |
17535 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 17534 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
17536 type_args = type_args.Canonicalize(trail); | 17535 type_args = type_args.Canonicalize(trail); |
17537 if (IsCanonical()) { | 17536 if (IsCanonical()) { |
17538 // Canonicalizing type_args canonicalized this type. | 17537 // Canonicalizing type_args canonicalized this type. |
17539 ASSERT(IsRecursive()); | 17538 ASSERT(IsRecursive()); |
17540 return this->raw(); | 17539 return this->raw(); |
17541 } | 17540 } |
17542 set_arguments(type_args); | 17541 set_arguments(type_args); |
17543 type = cls.CanonicalType(); // May be set while canonicalizing type args. | 17542 type = cls.CanonicalType(); // May be set while canonicalizing type args. |
17544 if (type.IsNull()) { | 17543 if (type.IsNull()) { |
17545 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); | 17544 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); |
17546 // Recheck if type exists. | 17545 // Recheck if type exists. |
17547 type = cls.CanonicalType(); | 17546 type = cls.CanonicalType(); |
17548 if (type.IsNull()) { | 17547 if (type.IsNull()) { |
17549 ComputeHash(); | 17548 if (this->IsNew()) { |
17550 SetCanonical(); | 17549 type ^= Object::Clone(*this, Heap::kOld); |
17551 cls.set_canonical_type(*this); | 17550 } else { |
17552 return this->raw(); | 17551 type ^= this->raw(); |
| 17552 } |
| 17553 ASSERT(type.IsOld()); |
| 17554 type.ComputeHash(); |
| 17555 type.SetCanonical(); |
| 17556 cls.set_canonical_type(type); |
| 17557 return type.raw(); |
17553 } | 17558 } |
17554 } | 17559 } |
17555 } | 17560 } |
17556 ASSERT(this->Equals(type)); | 17561 ASSERT(this->Equals(type)); |
17557 ASSERT(type.IsCanonical()); | 17562 ASSERT(type.IsCanonical()); |
| 17563 ASSERT(type.IsOld()); |
17558 return type.raw(); | 17564 return type.raw(); |
17559 } | 17565 } |
17560 | 17566 |
| 17567 AbstractType& type = Type::Handle(zone); |
17561 ObjectStore* object_store = isolate->object_store(); | 17568 ObjectStore* object_store = isolate->object_store(); |
17562 { | 17569 { |
17563 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); | 17570 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); |
17564 CanonicalTypeSet table(zone, object_store->canonical_types()); | 17571 CanonicalTypeSet table(zone, object_store->canonical_types()); |
17565 type ^= table.GetOrNull(CanonicalTypeKey(*this)); | 17572 type ^= table.GetOrNull(CanonicalTypeKey(*this)); |
17566 ASSERT(object_store->canonical_types() == table.Release().raw()); | 17573 ASSERT(object_store->canonical_types() == table.Release().raw()); |
17567 } | 17574 } |
17568 if (type.IsNull()) { | 17575 if (type.IsNull()) { |
17569 // The type was not found in the table. It is not canonical yet. | 17576 // The type was not found in the table. It is not canonical yet. |
17570 | 17577 |
(...skipping 5805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23376 return UserTag::null(); | 23383 return UserTag::null(); |
23377 } | 23384 } |
23378 | 23385 |
23379 | 23386 |
23380 const char* UserTag::ToCString() const { | 23387 const char* UserTag::ToCString() const { |
23381 const String& tag_label = String::Handle(label()); | 23388 const String& tag_label = String::Handle(label()); |
23382 return tag_label.ToCString(); | 23389 return tag_label.ToCString(); |
23383 } | 23390 } |
23384 | 23391 |
23385 } // namespace dart | 23392 } // namespace dart |
OLD | NEW |