OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/code_generator.h" | 7 #include "vm/code_generator.h" |
8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (!super_type.IsMalformed() && super_type.HasResolvedTypeClass()) { | 86 if (!super_type.IsMalformed() && super_type.HasResolvedTypeClass()) { |
87 cls ^= super_type.type_class(); | 87 cls ^= super_type.type_class(); |
88 if (cls.is_finalized()) { | 88 if (cls.is_finalized()) { |
89 AddSuperType(super_type, finalized_super_classes); | 89 AddSuperType(super_type, finalized_super_classes); |
90 } | 90 } |
91 } | 91 } |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 | 95 |
| 96 static void CollectImmediateSuperInterfaces( |
| 97 const Class& cls, GrowableArray<intptr_t>* cids) { |
| 98 const Array& interfaces = Array::Handle(cls.interfaces()); |
| 99 Class& ifc = Class::Handle(); |
| 100 AbstractType& type = AbstractType::Handle(); |
| 101 for (intptr_t i = 0; i < interfaces.Length(); ++i) { |
| 102 type ^= interfaces.At(i); |
| 103 if (type.IsMalformed()) continue; |
| 104 if (!type.HasResolvedTypeClass()) continue; |
| 105 ifc ^= type.type_class(); |
| 106 for (intptr_t j = 0; j < cids->length(); ++j) { |
| 107 if ((*cids)[j] == ifc.id()) { |
| 108 // Already added. |
| 109 return; |
| 110 } |
| 111 } |
| 112 cids->Add(ifc.id()); |
| 113 } |
| 114 } |
| 115 |
| 116 |
96 // Processing ObjectStore::pending_classes_ occurs: | 117 // Processing ObjectStore::pending_classes_ occurs: |
97 // a) when bootstrap process completes (VerifyBootstrapClasses). | 118 // a) when bootstrap process completes (VerifyBootstrapClasses). |
98 // b) after the user classes are loaded (dart_api). | 119 // b) after the user classes are loaded (dart_api). |
99 bool ClassFinalizer::ProcessPendingClasses() { | 120 bool ClassFinalizer::ProcessPendingClasses() { |
100 Isolate* isolate = Isolate::Current(); | 121 Isolate* isolate = Isolate::Current(); |
101 ASSERT(isolate != NULL); | 122 ASSERT(isolate != NULL); |
102 HANDLESCOPE(isolate); | 123 HANDLESCOPE(isolate); |
103 ObjectStore* object_store = isolate->object_store(); | 124 ObjectStore* object_store = isolate->object_store(); |
104 const Error& error = Error::Handle(isolate, object_store->sticky_error()); | 125 const Error& error = Error::Handle(isolate, object_store->sticky_error()); |
105 if (!error.IsNull()) { | 126 if (!error.IsNull()) { |
(...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 } | 2301 } |
2281 if (FLAG_trace_class_finalization) { | 2302 if (FLAG_trace_class_finalization) { |
2282 OS::Print("Finalize %s\n", cls.ToCString()); | 2303 OS::Print("Finalize %s\n", cls.ToCString()); |
2283 } | 2304 } |
2284 if (cls.IsMixinApplication()) { | 2305 if (cls.IsMixinApplication()) { |
2285 // Copy instance methods and fields from the mixin class. | 2306 // Copy instance methods and fields from the mixin class. |
2286 // This has to happen before the check whether the methods of | 2307 // This has to happen before the check whether the methods of |
2287 // the class conflict with inherited methods. | 2308 // the class conflict with inherited methods. |
2288 ApplyMixinMembers(cls); | 2309 ApplyMixinMembers(cls); |
2289 } | 2310 } |
2290 GrowableArray<intptr_t> added_subclass_to_cids; | |
2291 CollectFinalizedSuperClasses(cls, &added_subclass_to_cids); | |
2292 // Ensure super class is finalized. | 2311 // Ensure super class is finalized. |
2293 const Class& super = Class::Handle(cls.SuperClass()); | 2312 const Class& super = Class::Handle(cls.SuperClass()); |
2294 if (!super.IsNull()) { | 2313 if (!super.IsNull()) { |
2295 FinalizeClass(super); | 2314 FinalizeClass(super); |
2296 } | 2315 } |
2297 // Mark as parsed and finalized. | 2316 // Mark as parsed and finalized. |
2298 cls.Finalize(); | 2317 cls.Finalize(); |
2299 // Mixin app alias classes may still lack their forwarding constructor. | 2318 // Mixin app alias classes may still lack their forwarding constructor. |
2300 if (cls.is_mixin_app_alias() && | 2319 if (cls.is_mixin_app_alias() && |
2301 (cls.functions() == Object::empty_array().raw())) { | 2320 (cls.functions() == Object::empty_array().raw())) { |
2302 const GrowableObjectArray& cloned_funcs = | 2321 const GrowableObjectArray& cloned_funcs = |
2303 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 2322 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
2304 CreateForwardingConstructors(cls, cloned_funcs); | 2323 CreateForwardingConstructors(cls, cloned_funcs); |
2305 const Array& functions = Array::Handle(Array::MakeArray(cloned_funcs)); | 2324 const Array& functions = Array::Handle(Array::MakeArray(cloned_funcs)); |
2306 cls.SetFunctions(functions); | 2325 cls.SetFunctions(functions); |
2307 } | 2326 } |
2308 // Every class should have at least a constructor, unless it is a top level | 2327 // Every class should have at least a constructor, unless it is a top level |
2309 // class or a signature class. | 2328 // class or a signature class. |
2310 ASSERT(cls.IsTopLevel() || | 2329 ASSERT(cls.IsTopLevel() || |
2311 cls.IsSignatureClass() || | 2330 cls.IsSignatureClass() || |
2312 (Array::Handle(cls.functions()).Length() > 0)); | 2331 (Array::Handle(cls.functions()).Length() > 0)); |
2313 // Resolve and finalize all member types. | 2332 // Resolve and finalize all member types. |
2314 ResolveAndFinalizeMemberTypes(cls); | 2333 ResolveAndFinalizeMemberTypes(cls); |
2315 // Run additional checks after all types are finalized. | 2334 // Run additional checks after all types are finalized. |
2316 if (cls.is_const()) { | 2335 if (cls.is_const()) { |
2317 CheckForLegalConstClass(cls); | 2336 CheckForLegalConstClass(cls); |
2318 } | 2337 } |
2319 if (FLAG_use_cha) { | 2338 if (FLAG_use_cha) { |
2320 RemoveCHAOptimizedCode(added_subclass_to_cids); | 2339 GrowableArray<intptr_t> cids; |
| 2340 CollectFinalizedSuperClasses(cls, &cids); |
| 2341 CollectImmediateSuperInterfaces(cls, &cids); |
| 2342 RemoveCHAOptimizedCode(cids); |
2321 } | 2343 } |
2322 } | 2344 } |
2323 | 2345 |
2324 | 2346 |
2325 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { | 2347 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { |
2326 Class& test1 = Class::Handle(cls.raw()); | 2348 Class& test1 = Class::Handle(cls.raw()); |
2327 Class& test2 = Class::Handle(cls.SuperClass()); | 2349 Class& test2 = Class::Handle(cls.SuperClass()); |
2328 // A finalized class has been checked for cycles. | 2350 // A finalized class has been checked for cycles. |
2329 // Using the hare and tortoise algorithm for locating cycles. | 2351 // Using the hare and tortoise algorithm for locating cycles. |
2330 while (!test1.is_type_finalized() && | 2352 while (!test1.is_type_finalized() && |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3056 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); | 3078 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
3057 field ^= fields_array.At(0); | 3079 field ^= fields_array.At(0); |
3058 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3080 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
3059 name ^= field.name(); | 3081 name ^= field.name(); |
3060 expected_name ^= String::New("_data"); | 3082 expected_name ^= String::New("_data"); |
3061 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3083 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
3062 #endif | 3084 #endif |
3063 } | 3085 } |
3064 | 3086 |
3065 } // namespace dart | 3087 } // namespace dart |
OLD | NEW |