OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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/precompiler.h" | 5 #include "vm/precompiler.h" |
6 | 6 |
7 #include "vm/code_patcher.h" | 7 #include "vm/code_patcher.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/log.h" | 10 #include "vm/log.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 kCapabilityCid, | 179 kCapabilityCid, |
180 ReceivePort::kClassId, | 180 ReceivePort::kClassId, |
181 SendPort::kClassId, | 181 SendPort::kClassId, |
182 | 182 |
183 kIllegalCid | 183 kIllegalCid |
184 }; | 184 }; |
185 | 185 |
186 Class& cls = Class::Handle(Z); | 186 Class& cls = Class::Handle(Z); |
187 for (intptr_t i = 0; kExternallyAllocatedCids[i] != kIllegalCid; i++) { | 187 for (intptr_t i = 0; kExternallyAllocatedCids[i] != kIllegalCid; i++) { |
188 cls = isolate()->class_table()->At(kExternallyAllocatedCids[i]); | 188 cls = isolate()->class_table()->At(kExternallyAllocatedCids[i]); |
189 AddClass(cls); | 189 AddInstantiatedClass(cls); |
190 } | 190 } |
191 | 191 |
192 Dart_QualifiedFunctionName vm_entry_points[] = { | 192 Dart_QualifiedFunctionName vm_entry_points[] = { |
193 { "dart:async", "::", "_setScheduleImmediateClosure" }, | 193 { "dart:async", "::", "_setScheduleImmediateClosure" }, |
194 { "dart:core", "::", "_completeDeferredLoads"}, | 194 { "dart:core", "::", "_completeDeferredLoads"}, |
195 { "dart:core", "AbstractClassInstantiationError", | 195 { "dart:core", "AbstractClassInstantiationError", |
196 "AbstractClassInstantiationError._create" }, | 196 "AbstractClassInstantiationError._create" }, |
197 { "dart:core", "ArgumentError", "ArgumentError." }, | 197 { "dart:core", "ArgumentError", "ArgumentError." }, |
198 { "dart:core", "AssertionError", "AssertionError." }, | 198 { "dart:core", "AssertionError", "AssertionError." }, |
199 { "dart:core", "CyclicInitializationError", | 199 { "dart:core", "CyclicInitializationError", |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if (FLAG_trace_precompiler) { | 275 if (FLAG_trace_precompiler) { |
276 THR_Print("WARNING: Missing %s %s %s\n", | 276 THR_Print("WARNING: Missing %s %s %s\n", |
277 entry_points[i].library_uri, | 277 entry_points[i].library_uri, |
278 entry_points[i].class_name, | 278 entry_points[i].class_name, |
279 entry_points[i].function_name); | 279 entry_points[i].function_name); |
280 } | 280 } |
281 continue; | 281 continue; |
282 } | 282 } |
283 | 283 |
284 AddFunction(func); | 284 AddFunction(func); |
| 285 if (func.IsGenerativeConstructor()) { |
| 286 // Allocation stubs are referenced from the call site of the constructor, |
| 287 // not in the constructor itself. So compiling the constructor isn't |
| 288 // enough for us to discover the class is instantiated if the class isn't |
| 289 // otherwise instantiated from Dart code and only instantiated from C++. |
| 290 AddInstantiatedClass(cls); |
| 291 } |
285 } | 292 } |
286 } | 293 } |
287 | 294 |
288 | 295 |
289 void Precompiler::Iterate() { | 296 void Precompiler::Iterate() { |
290 Function& function = Function::Handle(Z); | 297 Function& function = Function::Handle(Z); |
291 | 298 |
292 while (changed_) { | 299 while (changed_) { |
293 changed_ = false; | 300 changed_ = false; |
294 | 301 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 instance ^= entry.raw(); | 395 instance ^= entry.raw(); |
389 AddConstObject(instance); | 396 AddConstObject(instance); |
390 } else if (entry.IsFunction()) { | 397 } else if (entry.IsFunction()) { |
391 // Local closure function. | 398 // Local closure function. |
392 target ^= entry.raw(); | 399 target ^= entry.raw(); |
393 AddFunction(target); | 400 AddFunction(target); |
394 } else if (entry.IsCode()) { | 401 } else if (entry.IsCode()) { |
395 target_code ^= entry.raw(); | 402 target_code ^= entry.raw(); |
396 if (target_code.IsAllocationStubCode()) { | 403 if (target_code.IsAllocationStubCode()) { |
397 cls ^= target_code.owner(); | 404 cls ^= target_code.owner(); |
398 AddClass(cls); | 405 AddInstantiatedClass(cls); |
399 } | 406 } |
400 } | 407 } |
401 } | 408 } |
402 } | 409 } |
403 } | 410 } |
404 | 411 |
405 | 412 |
406 void Precompiler::AddConstObject(const Instance& instance) { | 413 void Precompiler::AddConstObject(const Instance& instance) { |
407 const Class& cls = Class::Handle(Z, instance.clazz()); | 414 const Class& cls = Class::Handle(Z, instance.clazz()); |
408 AddClass(cls); | 415 AddInstantiatedClass(cls); |
409 | 416 |
410 if (instance.IsClosure()) { | 417 if (instance.IsClosure()) { |
411 // An implicit static closure. | 418 // An implicit static closure. |
412 const Function& func = Function::Handle(Z, Closure::function(instance)); | 419 const Function& func = Function::Handle(Z, Closure::function(instance)); |
413 ASSERT(func.is_static()); | 420 ASSERT(func.is_static()); |
414 AddFunction(func); | 421 AddFunction(func); |
415 return; | 422 return; |
416 } | 423 } |
417 | 424 |
418 // Can't ask immediate objects if they're canoncial. | 425 // Can't ask immediate objects if they're canoncial. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 | 530 |
524 if (FLAG_trace_precompiler) { | 531 if (FLAG_trace_precompiler) { |
525 THR_Print("Enqueueing selector %" Pd " %s\n", | 532 THR_Print("Enqueueing selector %" Pd " %s\n", |
526 selector_count_, | 533 selector_count_, |
527 selector.ToCString()); | 534 selector.ToCString()); |
528 } | 535 } |
529 } | 536 } |
530 } | 537 } |
531 | 538 |
532 | 539 |
533 void Precompiler::AddClass(const Class& cls) { | 540 void Precompiler::AddInstantiatedClass(const Class& cls) { |
534 if (cls.is_allocated()) return; | 541 if (cls.is_allocated()) return; |
535 | 542 |
536 class_count_++; | 543 class_count_++; |
537 cls.set_is_allocated(); | 544 cls.set_is_allocated(); |
538 changed_ = true; | 545 changed_ = true; |
539 | 546 |
540 if (FLAG_trace_precompiler) { | 547 if (FLAG_trace_precompiler) { |
541 THR_Print("Allocation %" Pd " %s\n", class_count_, cls.ToCString()); | 548 THR_Print("Allocation %" Pd " %s\n", class_count_, cls.ToCString()); |
542 } | 549 } |
543 | 550 |
544 const Class& superclass = Class::Handle(cls.SuperClass()); | 551 const Class& superclass = Class::Handle(cls.SuperClass()); |
545 if (!superclass.IsNull()) { | 552 if (!superclass.IsNull()) { |
546 AddClass(superclass); | 553 AddInstantiatedClass(superclass); |
547 } | 554 } |
548 } | 555 } |
549 | 556 |
550 | 557 |
551 void Precompiler::CheckForNewDynamicFunctions() { | 558 void Precompiler::CheckForNewDynamicFunctions() { |
552 Library& lib = Library::Handle(Z); | 559 Library& lib = Library::Handle(Z); |
553 Class& cls = Class::Handle(Z); | 560 Class& cls = Class::Handle(Z); |
554 Array& functions = Array::Handle(Z); | 561 Array& functions = Array::Handle(Z); |
555 Function& function = Function::Handle(Z); | 562 Function& function = Function::Handle(Z); |
556 Function& function2 = Function::Handle(Z); | 563 Function& function2 = Function::Handle(Z); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 continue; // class 'dynamic' is in the read-only VM isolate. | 873 continue; // class 'dynamic' is in the read-only VM isolate. |
867 } | 874 } |
868 cls.EnsureIsFinalized(T); | 875 cls.EnsureIsFinalized(T); |
869 } | 876 } |
870 } | 877 } |
871 I->set_all_classes_finalized(true); | 878 I->set_all_classes_finalized(true); |
872 } | 879 } |
873 | 880 |
874 | 881 |
875 } // namespace dart | 882 } // namespace dart |
OLD | NEW |