| 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/aot_optimizer.h" | 7 #include "vm/aot_optimizer.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/branch_optimizer.h" | 10 #include "vm/branch_optimizer.h" |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 509 |
| 510 while (pending_functions_.Length() > 0) { | 510 while (pending_functions_.Length() > 0) { |
| 511 function ^= pending_functions_.RemoveLast(); | 511 function ^= pending_functions_.RemoveLast(); |
| 512 ProcessFunction(function); | 512 ProcessFunction(function); |
| 513 } | 513 } |
| 514 | 514 |
| 515 CheckForNewDynamicFunctions(); | 515 CheckForNewDynamicFunctions(); |
| 516 if (!changed_) { | 516 if (!changed_) { |
| 517 TraceConstFunctions(); | 517 TraceConstFunctions(); |
| 518 } | 518 } |
| 519 CollectCallbackFields(); |
| 520 } |
| 521 } |
| 522 |
| 523 |
| 524 void Precompiler::CollectCallbackFields() { |
| 525 Library& lib = Library::Handle(Z); |
| 526 Class& cls = Class::Handle(Z); |
| 527 Class& subcls = Class::Handle(Z); |
| 528 Array& fields = Array::Handle(Z); |
| 529 Field& field = Field::Handle(Z); |
| 530 Function& function = Function::Handle(Z); |
| 531 Function& dispatcher = Function::Handle(Z); |
| 532 Array& args_desc = Array::Handle(Z); |
| 533 AbstractType& field_type = AbstractType::Handle(Z); |
| 534 String& field_name = String::Handle(Z); |
| 535 GrowableArray<intptr_t> cids; |
| 536 |
| 537 for (intptr_t i = 0; i < libraries_.Length(); i++) { |
| 538 lib ^= libraries_.At(i); |
| 539 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); |
| 540 while (it.HasNext()) { |
| 541 cls = it.GetNextClass(); |
| 542 |
| 543 if (!cls.is_allocated()) continue; |
| 544 |
| 545 fields = cls.fields(); |
| 546 for (intptr_t k = 0; k < fields.Length(); k++) { |
| 547 field ^= fields.At(k); |
| 548 if (field.is_static()) continue; |
| 549 field_type = field.type(); |
| 550 if (!field_type.IsFunctionType()) continue; |
| 551 field_name = field.name(); |
| 552 if (!IsSent(field_name)) continue; |
| 553 // Create arguments descriptor with fixed parameters from |
| 554 // signature of field_type. |
| 555 function = Type::Cast(field_type).signature(); |
| 556 if (function.HasOptionalParameters()) continue; |
| 557 if (FLAG_trace_precompiler) { |
| 558 THR_Print("Found callback field %s\n", field_name.ToCString()); |
| 559 } |
| 560 args_desc = |
| 561 ArgumentsDescriptor::New(function.num_fixed_parameters()); |
| 562 cids.Clear(); |
| 563 if (T->cha()->ConcreteSubclasses(cls, &cids)) { |
| 564 for (intptr_t j = 0; j < cids.length(); ++j) { |
| 565 subcls ^= I->class_table()->At(cids[j]); |
| 566 if (subcls.is_allocated()) { |
| 567 // Add dispatcher to cls. |
| 568 dispatcher = subcls.GetInvocationDispatcher( |
| 569 field_name, |
| 570 args_desc, |
| 571 RawFunction::kInvokeFieldDispatcher, |
| 572 /* create_if_absent = */ true); |
| 573 if (FLAG_trace_precompiler) { |
| 574 THR_Print("Added invoke-field-dispatcher for %s to %s\n", |
| 575 field_name.ToCString(), subcls.ToCString()); |
| 576 } |
| 577 AddFunction(dispatcher); |
| 578 } |
| 579 } |
| 580 } |
| 581 } |
| 582 } |
| 519 } | 583 } |
| 520 } | 584 } |
| 521 | 585 |
| 522 | 586 |
| 523 void Precompiler::ProcessFunction(const Function& function) { | 587 void Precompiler::ProcessFunction(const Function& function) { |
| 524 if (!function.HasCode()) { | 588 if (!function.HasCode()) { |
| 525 function_count_++; | 589 function_count_++; |
| 526 | 590 |
| 527 if (FLAG_trace_precompiler) { | 591 if (FLAG_trace_precompiler) { |
| 528 THR_Print("Precompiling %" Pd " %s (%s, %s)\n", | 592 THR_Print("Precompiling %" Pd " %s (%s, %s)\n", |
| (...skipping 2357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2886 CompilationPipeline::New(thread->zone(), function); | 2950 CompilationPipeline::New(thread->zone(), function); |
| 2887 | 2951 |
| 2888 ASSERT(FLAG_precompiled_mode); | 2952 ASSERT(FLAG_precompiled_mode); |
| 2889 const bool optimized = function.IsOptimizable(); // False for natives. | 2953 const bool optimized = function.IsOptimizable(); // False for natives. |
| 2890 return PrecompileFunctionHelper(pipeline, function, optimized); | 2954 return PrecompileFunctionHelper(pipeline, function, optimized); |
| 2891 } | 2955 } |
| 2892 | 2956 |
| 2893 #endif // DART_PRECOMPILER | 2957 #endif // DART_PRECOMPILER |
| 2894 | 2958 |
| 2895 } // namespace dart | 2959 } // namespace dart |
| OLD | NEW |