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

Side by Side Diff: runtime/vm/class_finalizer.cc

Issue 11088079: Resolve interfaces before starting finalizing classes (issue 5586). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 #include "vm/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 isolate->set_long_jump_base(&jump); 50 isolate->set_long_jump_base(&jump);
51 if (setjmp(*jump.Set()) == 0) { 51 if (setjmp(*jump.Set()) == 0) {
52 GrowableObjectArray& class_array = GrowableObjectArray::Handle(); 52 GrowableObjectArray& class_array = GrowableObjectArray::Handle();
53 class_array = object_store->pending_classes(); 53 class_array = object_store->pending_classes();
54 ASSERT(!class_array.IsNull()); 54 ASSERT(!class_array.IsNull());
55 Class& cls = Class::Handle(); 55 Class& cls = Class::Handle();
56 // First resolve all superclasses. 56 // First resolve all superclasses.
57 for (intptr_t i = 0; i < class_array.Length(); i++) { 57 for (intptr_t i = 0; i < class_array.Length(); i++) {
58 cls ^= class_array.At(i); 58 cls ^= class_array.At(i);
59 if (FLAG_trace_class_finalization) { 59 if (FLAG_trace_class_finalization) {
60 OS::Print("Resolving super and default: %s\n", cls.ToCString()); 60 OS::Print("Resolving super and interfaces: %s\n", cls.ToCString());
61 } 61 }
62 ResolveSuperType(cls); 62 ResolveSuperType(cls);
63 if (cls.is_interface()) { 63 if (cls.is_interface()) {
64 ResolveFactoryClass(cls); 64 ResolveFactoryClass(cls);
65 } 65 }
66 GrowableArray<intptr_t> visited_interfaces;
67 ResolveInterfaces(cls, &visited_interfaces);
66 } 68 }
67 // Finalize all classes. 69 // Finalize all classes.
68 for (intptr_t i = 0; i < class_array.Length(); i++) { 70 for (intptr_t i = 0; i < class_array.Length(); i++) {
69 cls ^= class_array.At(i); 71 cls ^= class_array.At(i);
70 FinalizeClass(cls); 72 FinalizeClass(cls);
71 } 73 }
72 if (FLAG_print_classes) { 74 if (FLAG_print_classes) {
73 for (intptr_t i = 0; i < class_array.Length(); i++) { 75 for (intptr_t i = 0; i < class_array.Length(); i++) {
74 cls ^= class_array.At(i); 76 cls ^= class_array.At(i);
75 PrintClassInformation(cls); 77 PrintClassInformation(cls);
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 // Input: C<String, double> expressed as 616 // Input: C<String, double> expressed as
615 // cls = C, arguments = [null, null, String, double], 617 // cls = C, arguments = [null, null, String, double],
616 // i.e. cls_args = [String, double], offset = 2, length = 2. 618 // i.e. cls_args = [String, double], offset = 2, length = 2.
617 // Output: arguments = [int, double, String, double] 619 // Output: arguments = [int, double, String, double]
618 void ClassFinalizer::FinalizeTypeArguments( 620 void ClassFinalizer::FinalizeTypeArguments(
619 const Class& cls, 621 const Class& cls,
620 const AbstractTypeArguments& arguments, 622 const AbstractTypeArguments& arguments,
621 FinalizationKind finalization) { 623 FinalizationKind finalization) {
622 ASSERT(arguments.Length() >= cls.NumTypeArguments()); 624 ASSERT(arguments.Length() >= cls.NumTypeArguments());
623 if (!cls.is_finalized()) { 625 if (!cls.is_finalized()) {
624 GrowableArray<intptr_t> visited_interfaces;
625 ResolveInterfaces(cls, &visited_interfaces);
626 FinalizeTypeParameters(cls); 626 FinalizeTypeParameters(cls);
627 } 627 }
628 Type& super_type = Type::Handle(cls.super_type()); 628 Type& super_type = Type::Handle(cls.super_type());
629 if (!super_type.IsNull()) { 629 if (!super_type.IsNull()) {
630 const Class& super_class = Class::Handle(super_type.type_class()); 630 const Class& super_class = Class::Handle(super_type.type_class());
631 AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle(); 631 AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle();
632 if (super_type.IsBeingFinalized()) { 632 if (super_type.IsBeingFinalized()) {
633 // This type references itself via its type arguments. This is legal, but 633 // This type references itself via its type arguments. This is legal, but
634 // we must avoid endless recursion. We therefore map the innermost 634 // we must avoid endless recursion. We therefore map the innermost
635 // super type to Dynamic. 635 // super type to Dynamic.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 // Mark type as being finalized in order to detect illegal self reference. 723 // Mark type as being finalized in order to detect illegal self reference.
724 parameterized_type.set_is_being_finalized(); 724 parameterized_type.set_is_being_finalized();
725 725
726 // The type class does not need to be finalized in order to finalize the type, 726 // The type class does not need to be finalized in order to finalize the type,
727 // however, it must at least be resolved (this was done as part of resolving 727 // however, it must at least be resolved (this was done as part of resolving
728 // the type itself, a precondition to calling FinalizeType). 728 // the type itself, a precondition to calling FinalizeType).
729 // Also, the interfaces of the type class must be resolved and the type 729 // Also, the interfaces of the type class must be resolved and the type
730 // parameters of the type class must be finalized. 730 // parameters of the type class must be finalized.
731 Class& type_class = Class::Handle(parameterized_type.type_class()); 731 Class& type_class = Class::Handle(parameterized_type.type_class());
732 if (!type_class.is_finalized()) { 732 if (!type_class.is_finalized()) {
733 GrowableArray<intptr_t> visited_interfaces;
734 ResolveInterfaces(type_class, &visited_interfaces);
735 FinalizeTypeParameters(type_class); 733 FinalizeTypeParameters(type_class);
736 } 734 }
737 735
738 // Finalize the current type arguments of the type, which are still the 736 // Finalize the current type arguments of the type, which are still the
739 // parsed type arguments. 737 // parsed type arguments.
740 AbstractTypeArguments& arguments = 738 AbstractTypeArguments& arguments =
741 AbstractTypeArguments::Handle(parameterized_type.arguments()); 739 AbstractTypeArguments::Handle(parameterized_type.arguments());
742 if (!arguments.IsNull()) { 740 if (!arguments.IsNull()) {
743 intptr_t num_arguments = arguments.Length(); 741 intptr_t num_arguments = arguments.Length();
744 AbstractType& type_argument = AbstractType::Handle(); 742 AbstractType& type_argument = AbstractType::Handle();
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 if (FLAG_trace_class_finalization) { 1177 if (FLAG_trace_class_finalization) {
1180 OS::Print("Finalize %s\n", cls.ToCString()); 1178 OS::Print("Finalize %s\n", cls.ToCString());
1181 } 1179 }
1182 if (!IsSuperCycleFree(cls)) { 1180 if (!IsSuperCycleFree(cls)) {
1183 const String& name = String::Handle(cls.Name()); 1181 const String& name = String::Handle(cls.Name());
1184 const Script& script = Script::Handle(cls.script()); 1182 const Script& script = Script::Handle(cls.script());
1185 ReportError(script, cls.token_pos(), 1183 ReportError(script, cls.token_pos(),
1186 "class '%s' has a cycle in its superclass relationship", 1184 "class '%s' has a cycle in its superclass relationship",
1187 name.ToCString()); 1185 name.ToCString());
1188 } 1186 }
1189 GrowableArray<intptr_t> visited_interfaces;
1190 ResolveInterfaces(cls, &visited_interfaces);
1191 // Finalize super class. 1187 // Finalize super class.
1192 const Class& super_class = Class::Handle(cls.SuperClass()); 1188 const Class& super_class = Class::Handle(cls.SuperClass());
1193 if (!super_class.IsNull()) { 1189 if (!super_class.IsNull()) {
1194 FinalizeClass(super_class); 1190 FinalizeClass(super_class);
1195 } 1191 }
1196 // Finalize type parameters before finalizing the super type. 1192 // Finalize type parameters before finalizing the super type.
1197 FinalizeTypeParameters(cls); 1193 FinalizeTypeParameters(cls);
1198 // Finalize super type. 1194 // Finalize super type.
1199 Type& super_type = Type::Handle(cls.super_type()); 1195 Type& super_type = Type::Handle(cls.super_type());
1200 if (!super_type.IsNull()) { 1196 if (!super_type.IsNull()) {
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 void ClassFinalizer::ReportError(const char* format, ...) { 1585 void ClassFinalizer::ReportError(const char* format, ...) {
1590 va_list args; 1586 va_list args;
1591 va_start(args, format); 1587 va_start(args, format);
1592 const Error& error = Error::Handle( 1588 const Error& error = Error::Handle(
1593 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); 1589 Parser::FormatError(Script::Handle(), -1, "Error", format, args));
1594 va_end(args); 1590 va_end(args);
1595 ReportError(error); 1591 ReportError(error);
1596 } 1592 }
1597 1593
1598 } // namespace dart 1594 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698