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

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

Issue 1373213003: Avoid eagerly enqueueing converted forms of selectors or eagerly creating their converted symbols. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | runtime/vm/symbols.h » ('j') | 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) 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/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/log.h" 9 #include "vm/log.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 pending_functions_(GrowableObjectArray::Handle(Z, 57 pending_functions_(GrowableObjectArray::Handle(Z,
58 GrowableObjectArray::New())), 58 GrowableObjectArray::New())),
59 collected_closures_(GrowableObjectArray::Handle(Z, I->collected_closures())), 59 collected_closures_(GrowableObjectArray::Handle(Z, I->collected_closures())),
60 sent_selectors_(Z), 60 sent_selectors_(Z),
61 error_(Error::Handle(Z)) { 61 error_(Error::Handle(Z)) {
62 } 62 }
63 63
64 64
65 void Precompiler::DoCompileAll( 65 void Precompiler::DoCompileAll(
66 Dart_QualifiedFunctionName embedder_entry_points[]) { 66 Dart_QualifiedFunctionName embedder_entry_points[]) {
67 LogBlock lb;
68
69 // Drop all existing code so we can use the presence of code as an indicator 67 // Drop all existing code so we can use the presence of code as an indicator
70 // that we have already looked for the function's callees. 68 // that we have already looked for the function's callees.
71 ClearAllCode(); 69 ClearAllCode();
72 70
73 // Start with the allocations and invocations that happen from C++. 71 // Start with the allocations and invocations that happen from C++.
74 AddRoots(embedder_entry_points); 72 AddRoots(embedder_entry_points);
75 73
76 // TODO(rmacnak): Eagerly add field-invocation functions to all signature 74 // TODO(rmacnak): Eagerly add field-invocation functions to all signature
77 // classes so closure calls don't go through the runtime. 75 // classes so closure calls don't go through the runtime.
78 76
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 462
465 void Precompiler::AddFunction(const Function& function) { 463 void Precompiler::AddFunction(const Function& function) {
466 if (function.HasCode()) return; 464 if (function.HasCode()) return;
467 465
468 pending_functions_.Add(function); 466 pending_functions_.Add(function);
469 changed_ = true; 467 changed_ = true;
470 } 468 }
471 469
472 470
473 bool Precompiler::IsSent(const String& selector) { 471 bool Precompiler::IsSent(const String& selector) {
472 if (selector.IsNull()) {
473 return false;
474 }
474 return sent_selectors_.Includes(selector); 475 return sent_selectors_.Includes(selector);
475 } 476 }
476 477
477 478
478 void Precompiler::AddSelector(const String& selector) { 479 void Precompiler::AddSelector(const String& selector) {
479 if (!IsSent(selector)) { 480 if (!IsSent(selector)) {
hausner 2015/09/29 19:43:21 You enter this if for a null selector. Is that on
rmacnak 2015/09/29 20:40:06 AddSelector should never be called with null, sele
480 sent_selectors_.Add(selector); 481 sent_selectors_.Add(selector);
481 selector_count_++; 482 selector_count_++;
482 changed_ = true; 483 changed_ = true;
483 484
484 if (FLAG_trace_precompiler) { 485 if (FLAG_trace_precompiler) {
485 THR_Print("Enqueueing selector %" Pd " %s\n", 486 THR_Print("Enqueueing selector %" Pd " %s\n",
486 selector_count_, 487 selector_count_,
487 selector.ToCString()); 488 selector.ToCString());
488 } 489 }
489
490 if (!Field::IsGetterName(selector) &&
491 !Field::IsSetterName(selector)) {
492 // Regular method may be call-through-getter.
493 const String& getter = String::Handle(Field::GetterSymbol(selector));
494 AddSelector(getter);
495 }
496 } 490 }
497 } 491 }
498 492
499 493
500 void Precompiler::AddClass(const Class& cls) { 494 void Precompiler::AddClass(const Class& cls) {
501 if (cls.is_allocated()) return; 495 if (cls.is_allocated()) return;
502 496
503 class_count_++; 497 class_count_++;
504 cls.set_is_allocated(); 498 cls.set_is_allocated();
505 changed_ = true; 499 changed_ = true;
506 500
507 if (FLAG_trace_precompiler) { 501 if (FLAG_trace_precompiler) {
508 THR_Print("Allocation %" Pd " %s\n", class_count_, cls.ToCString()); 502 THR_Print("Allocation %" Pd " %s\n", class_count_, cls.ToCString());
509 } 503 }
510 504
511 const Class& superclass = Class::Handle(cls.SuperClass()); 505 const Class& superclass = Class::Handle(cls.SuperClass());
512 if (!superclass.IsNull()) { 506 if (!superclass.IsNull()) {
513 AddClass(superclass); 507 AddClass(superclass);
514 } 508 }
515 } 509 }
516 510
517 511
518 void Precompiler::CheckForNewDynamicFunctions() { 512 void Precompiler::CheckForNewDynamicFunctions() {
519 Library& lib = Library::Handle(Z); 513 Library& lib = Library::Handle(Z);
520 Class& cls = Class::Handle(Z); 514 Class& cls = Class::Handle(Z);
521 Array& functions = Array::Handle(Z); 515 Array& functions = Array::Handle(Z);
522 Function& function = Function::Handle(Z); 516 Function& function = Function::Handle(Z);
517 Function& function2 = Function::Handle(Z);
523 String& selector = String::Handle(Z); 518 String& selector = String::Handle(Z);
519 String& selector2 = String::Handle(Z);
524 520
525 for (intptr_t i = 0; i < libraries_.Length(); i++) { 521 for (intptr_t i = 0; i < libraries_.Length(); i++) {
526 lib ^= libraries_.At(i); 522 lib ^= libraries_.At(i);
527 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); 523 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
528 while (it.HasNext()) { 524 while (it.HasNext()) {
529 cls = it.GetNextClass(); 525 cls = it.GetNextClass();
530 526
531 if (!cls.is_allocated()) { 527 if (!cls.is_allocated()) {
532 bool has_compiled_constructor = false; 528 bool has_compiled_constructor = false;
533 if (cls.allocation_stub() != Code::null()) { 529 if (cls.allocation_stub() != Code::null()) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 570
575 // Don't bail out early if there is already code because we may discover 571 // Don't bail out early if there is already code because we may discover
576 // the corresponding getter selector is sent in some later iteration. 572 // the corresponding getter selector is sent in some later iteration.
577 // if (function.HasCode()) continue; 573 // if (function.HasCode()) continue;
578 574
579 selector = function.name(); 575 selector = function.name();
580 if (IsSent(selector)) { 576 if (IsSent(selector)) {
581 AddFunction(function); 577 AddFunction(function);
582 } 578 }
583 579
584 if (function.kind() == RawFunction::kRegularFunction && 580 // Handle the implicit call type conversions.
585 !Field::IsGetterName(selector) && 581 if (Field::IsGetterName(selector)) {
586 !Field::IsSetterName(selector)) { 582 selector2 = Field::NameFromGetter(selector);
587 selector = Field::GetterSymbol(selector); 583 selector2 = Symbols::Lookup(selector2);
hausner 2015/09/29 19:43:21 Is this symbol guaranteed to exist?
rmacnak 2015/09/29 20:40:06 In this case, yes. There cannot be a getter functi
588 if (IsSent(selector)) { 584 if (IsSent(selector2)) {
589 function = function.ImplicitClosureFunction(); 585 // Call-through-getter.
586 // Function is get:foo and somewhere foo is called.
590 AddFunction(function); 587 AddFunction(function);
591 } 588 }
589 selector2 = Field::NameFromGetter(selector);
hausner 2015/09/29 19:43:21 This has been computed above. Why do it again?
rmacnak 2015/09/29 20:40:06 Hoisted out.
590 selector2 = Symbols::LookupFromConcat(Symbols::ClosurizePrefix(),
591 selector2);
592 if (IsSent(selector2)) {
593 // Hash-closurization.
594 // Function is get:foo and somewhere get:#foo is called.
595 AddFunction(function);
596
597 function2 = function.ImplicitClosureFunction();
598 AddFunction(function2);
599 }
600 } else if (Field::IsSetterName(selector)) {
601 selector2 = Symbols::LookupFromConcat(Symbols::ClosurizePrefix(),
602 selector);
603 if (IsSent(selector2)) {
604 // Hash-closurization.
605 // Function is set:foo and somewhere get:#set:foo is called.
606 AddFunction(function);
607
608 function2 = function.ImplicitClosureFunction();
609 AddFunction(function2);
610 }
611 } else if (function.kind() == RawFunction::kRegularFunction) {
612 selector2 = Field::LookupGetterSymbol(selector);
613 if (IsSent(selector2)) {
614 // Closurization.
615 // Function is foo and somewhere get:foo is called.
616 function2 = function.ImplicitClosureFunction();
617 AddFunction(function2);
618 }
619 selector2 = Symbols::LookupFromConcat(Symbols::ClosurizePrefix(),
620 selector);
621 if (IsSent(selector2)) {
622 // Hash-closurization.
623 // Function is foo and somewhere get:#foo is called.
624 function2 = function.ImplicitClosureFunction();
625 AddFunction(function2);
626 }
592 } 627 }
593 } 628 }
594 } 629 }
595 } 630 }
596 } 631 }
597 632
598 633
599 void Precompiler::DropUncompiledFunctions() { 634 void Precompiler::DropUncompiledFunctions() {
600 Library& lib = Library::Handle(Z); 635 Library& lib = Library::Handle(Z);
601 Class& cls = Class::Handle(Z); 636 Class& cls = Class::Handle(Z);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 for (intptr_t j = 0; j < closures.Length(); j++) { 675 for (intptr_t j = 0; j < closures.Length(); j++) {
641 function ^= closures.At(j); 676 function ^= closures.At(j);
642 ASSERT(function.HasCode()); 677 ASSERT(function.HasCode());
643 } 678 }
644 } 679 }
645 } 680 }
646 } 681 }
647 } 682 }
648 683
649 } // namespace dart 684 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698