| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 568 } |
| 569 | 569 |
| 570 | 570 |
| 571 // ---------------------------------------------------------------------------- | 571 // ---------------------------------------------------------------------------- |
| 572 // Recording of type feedback | 572 // Recording of type feedback |
| 573 | 573 |
| 574 // TODO(rossberg): all RecordTypeFeedback functions should disappear | 574 // TODO(rossberg): all RecordTypeFeedback functions should disappear |
| 575 // once we use the common type field in the AST consistently. | 575 // once we use the common type field in the AST consistently. |
| 576 | 576 |
| 577 | 577 |
| 578 void ForInStatement::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | |
| 579 for_in_type_ = static_cast<ForInType>(oracle->ForInType(this)); | |
| 580 } | |
| 581 | |
| 582 | |
| 583 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) { | 578 void Expression::RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle) { |
| 584 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); | 579 to_boolean_types_ = oracle->ToBooleanTypes(test_id()); |
| 585 } | 580 } |
| 586 | 581 |
| 587 | 582 |
| 588 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle, | |
| 589 Zone* zone) { | |
| 590 // Record type feedback from the oracle in the AST. | |
| 591 is_uninitialized_ = oracle->LoadIsUninitialized(this); | |
| 592 if (is_uninitialized_) return; | |
| 593 | |
| 594 is_pre_monomorphic_ = oracle->LoadIsPreMonomorphic(this); | |
| 595 is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); | |
| 596 ASSERT(!is_pre_monomorphic_ || !is_monomorphic_); | |
| 597 receiver_types_.Clear(); | |
| 598 if (key()->IsPropertyName()) { | |
| 599 FunctionPrototypeStub proto_stub(Code::LOAD_IC); | |
| 600 if (oracle->LoadIsStub(this, &proto_stub)) { | |
| 601 is_function_prototype_ = true; | |
| 602 } else { | |
| 603 Literal* lit_key = key()->AsLiteral(); | |
| 604 ASSERT(lit_key != NULL && lit_key->value()->IsString()); | |
| 605 Handle<String> name = Handle<String>::cast(lit_key->value()); | |
| 606 oracle->LoadReceiverTypes(this, name, &receiver_types_); | |
| 607 } | |
| 608 } else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) { | |
| 609 is_string_access_ = true; | |
| 610 } else if (is_monomorphic_) { | |
| 611 receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this), zone); | |
| 612 } else if (oracle->LoadIsPolymorphic(this)) { | |
| 613 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); | |
| 614 oracle->CollectKeyedReceiverTypes(PropertyFeedbackId(), &receiver_types_); | |
| 615 } | |
| 616 } | |
| 617 | |
| 618 | |
| 619 void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle, | |
| 620 Zone* zone) { | |
| 621 Property* prop = target()->AsProperty(); | |
| 622 ASSERT(prop != NULL); | |
| 623 TypeFeedbackId id = AssignmentFeedbackId(); | |
| 624 is_uninitialized_ = oracle->StoreIsUninitialized(id); | |
| 625 if (is_uninitialized_) return; | |
| 626 | |
| 627 is_pre_monomorphic_ = oracle->StoreIsPreMonomorphic(id); | |
| 628 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(id); | |
| 629 ASSERT(!is_pre_monomorphic_ || !is_monomorphic_); | |
| 630 receiver_types_.Clear(); | |
| 631 if (prop->key()->IsPropertyName()) { | |
| 632 Literal* lit_key = prop->key()->AsLiteral(); | |
| 633 ASSERT(lit_key != NULL && lit_key->value()->IsString()); | |
| 634 Handle<String> name = Handle<String>::cast(lit_key->value()); | |
| 635 oracle->StoreReceiverTypes(this, name, &receiver_types_); | |
| 636 } else if (is_monomorphic_) { | |
| 637 // Record receiver type for monomorphic keyed stores. | |
| 638 receiver_types_.Add(oracle->StoreMonomorphicReceiverType(id), zone); | |
| 639 store_mode_ = oracle->GetStoreMode(id); | |
| 640 } else if (oracle->StoreIsKeyedPolymorphic(id)) { | |
| 641 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); | |
| 642 oracle->CollectKeyedReceiverTypes(id, &receiver_types_); | |
| 643 store_mode_ = oracle->GetStoreMode(id); | |
| 644 } | |
| 645 } | |
| 646 | |
| 647 | |
| 648 void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle, | |
| 649 Zone* zone) { | |
| 650 TypeFeedbackId id = CountStoreFeedbackId(); | |
| 651 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(id); | |
| 652 receiver_types_.Clear(); | |
| 653 if (is_monomorphic_) { | |
| 654 // Record receiver type for monomorphic keyed stores. | |
| 655 receiver_types_.Add( | |
| 656 oracle->StoreMonomorphicReceiverType(id), zone); | |
| 657 } else if (oracle->StoreIsKeyedPolymorphic(id)) { | |
| 658 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); | |
| 659 oracle->CollectKeyedReceiverTypes(id, &receiver_types_); | |
| 660 } else { | |
| 661 oracle->CollectPolymorphicStoreReceiverTypes(id, &receiver_types_); | |
| 662 } | |
| 663 store_mode_ = oracle->GetStoreMode(id); | |
| 664 type_ = oracle->IncrementType(this); | |
| 665 } | |
| 666 | |
| 667 | |
| 668 void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | |
| 669 compare_type_ = oracle->ClauseType(CompareId()); | |
| 670 } | |
| 671 | |
| 672 | |
| 673 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { | 583 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { |
| 674 // If there is an interceptor, we can't compute the target for a direct call. | 584 // If there is an interceptor, we can't compute the target for a direct call. |
| 675 if (type->has_named_interceptor()) return false; | 585 if (type->has_named_interceptor()) return false; |
| 676 | 586 |
| 677 if (check_type_ == RECEIVER_MAP_CHECK) { | 587 if (check_type_ == RECEIVER_MAP_CHECK) { |
| 678 // For primitive checks the holder is set up to point to the corresponding | 588 // For primitive checks the holder is set up to point to the corresponding |
| 679 // prototype object, i.e. one step of the algorithm below has been already | 589 // prototype object, i.e. one step of the algorithm below has been already |
| 680 // performed. For non-primitive checks we clear it to allow computing | 590 // performed. For non-primitive checks we clear it to allow computing |
| 681 // targets for polymorphic calls. | 591 // targets for polymorphic calls. |
| 682 holder_ = Handle<JSObject>::null(); | 592 holder_ = Handle<JSObject>::null(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 function = native_context->boolean_function(); | 675 function = native_context->boolean_function(); |
| 766 break; | 676 break; |
| 767 } | 677 } |
| 768 ASSERT(function != NULL); | 678 ASSERT(function != NULL); |
| 769 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 679 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 770 } | 680 } |
| 771 | 681 |
| 772 | 682 |
| 773 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle, | 683 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 774 CallKind call_kind) { | 684 CallKind call_kind) { |
| 775 is_monomorphic_ = oracle->CallIsMonomorphic(this); | 685 is_monomorphic_ = oracle->CallIsMonomorphic(CallFeedbackId()); |
| 776 Property* property = expression()->AsProperty(); | 686 Property* property = expression()->AsProperty(); |
| 777 if (property == NULL) { | 687 if (property == NULL) { |
| 778 // Function call. Specialize for monomorphic calls. | 688 // Function call. Specialize for monomorphic calls. |
| 779 if (is_monomorphic_) target_ = oracle->GetCallTarget(this); | 689 if (is_monomorphic_) target_ = oracle->GetCallTarget(CallFeedbackId()); |
| 780 } else if (property->key()->IsPropertyName()) { | 690 } else if (property->key()->IsPropertyName()) { |
| 781 // Method call. Specialize for the receiver types seen at runtime. | 691 // Method call. Specialize for the receiver types seen at runtime. |
| 782 Literal* key = property->key()->AsLiteral(); | 692 Literal* key = property->key()->AsLiteral(); |
| 783 ASSERT(key != NULL && key->value()->IsString()); | 693 ASSERT(key != NULL && key->value()->IsString()); |
| 784 Handle<String> name = Handle<String>::cast(key->value()); | 694 Handle<String> name = Handle<String>::cast(key->value()); |
| 785 check_type_ = oracle->GetCallCheckType(this); | 695 check_type_ = oracle->GetCallCheckType(CallFeedbackId()); |
| 786 receiver_types_.Clear(); | 696 receiver_types_.Clear(); |
| 787 if (check_type_ == RECEIVER_MAP_CHECK) { | 697 if (check_type_ == RECEIVER_MAP_CHECK) { |
| 788 oracle->CallReceiverTypes(this, name, call_kind, &receiver_types_); | 698 oracle->CallReceiverTypes(CallFeedbackId(), |
| 699 name, arguments()->length(), call_kind, &receiver_types_); |
| 789 is_monomorphic_ = is_monomorphic_ && receiver_types_.length() > 0; | 700 is_monomorphic_ = is_monomorphic_ && receiver_types_.length() > 0; |
| 790 } else { | 701 } else { |
| 791 holder_ = GetPrototypeForPrimitiveCheck(check_type_, oracle->isolate()); | 702 holder_ = GetPrototypeForPrimitiveCheck(check_type_, oracle->isolate()); |
| 792 receiver_types_.Add(handle(holder_->map()), oracle->zone()); | 703 receiver_types_.Add(handle(holder_->map()), oracle->zone()); |
| 793 } | 704 } |
| 794 #ifdef ENABLE_SLOW_ASSERTS | 705 #ifdef ENABLE_SLOW_ASSERTS |
| 795 if (FLAG_enable_slow_asserts) { | 706 if (FLAG_enable_slow_asserts) { |
| 796 int length = receiver_types_.length(); | 707 int length = receiver_types_.length(); |
| 797 for (int i = 0; i < length; i++) { | 708 for (int i = 0; i < length; i++) { |
| 798 Handle<Map> map = receiver_types_.at(i); | 709 Handle<Map> map = receiver_types_.at(i); |
| 799 ASSERT(!map.is_null() && *map != NULL); | 710 ASSERT(!map.is_null() && *map != NULL); |
| 800 } | 711 } |
| 801 } | 712 } |
| 802 #endif | 713 #endif |
| 803 if (is_monomorphic_) { | 714 if (is_monomorphic_) { |
| 804 Handle<Map> map = receiver_types_.first(); | 715 Handle<Map> map = receiver_types_.first(); |
| 805 is_monomorphic_ = ComputeTarget(map, name); | 716 is_monomorphic_ = ComputeTarget(map, name); |
| 806 } | 717 } |
| 807 } else { | 718 } else { |
| 808 if (is_monomorphic_) { | 719 if (is_monomorphic_) { |
| 809 keyed_array_call_is_holey_ = oracle->KeyedArrayCallIsHoley(this); | 720 keyed_array_call_is_holey_ = |
| 721 oracle->KeyedArrayCallIsHoley(CallFeedbackId()); |
| 810 } | 722 } |
| 811 } | 723 } |
| 812 } | 724 } |
| 813 | 725 |
| 814 | 726 |
| 815 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 727 void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 816 allocation_info_cell_ = oracle->GetCallNewAllocationInfoCell(this); | 728 allocation_info_cell_ = |
| 817 is_monomorphic_ = oracle->CallNewIsMonomorphic(this); | 729 oracle->GetCallNewAllocationInfoCell(CallNewFeedbackId()); |
| 730 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackId()); |
| 818 if (is_monomorphic_) { | 731 if (is_monomorphic_) { |
| 819 target_ = oracle->GetCallNewTarget(this); | 732 target_ = oracle->GetCallNewTarget(CallNewFeedbackId()); |
| 820 Object* value = allocation_info_cell_->value(); | 733 Object* value = allocation_info_cell_->value(); |
| 821 ASSERT(!value->IsTheHole()); | 734 ASSERT(!value->IsTheHole()); |
| 822 if (value->IsAllocationSite()) { | 735 if (value->IsAllocationSite()) { |
| 823 AllocationSite* site = AllocationSite::cast(value); | 736 AllocationSite* site = AllocationSite::cast(value); |
| 824 elements_kind_ = site->GetElementsKind(); | 737 elements_kind_ = site->GetElementsKind(); |
| 825 } | 738 } |
| 826 } | 739 } |
| 827 } | 740 } |
| 828 | 741 |
| 829 | 742 |
| 830 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 743 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 831 receiver_type_ = oracle->ObjectLiteralStoreIsMonomorphic(this) | 744 TypeFeedbackId id = key()->LiteralFeedbackId(); |
| 832 ? oracle->GetObjectLiteralStoreMap(this) | 745 receiver_type_ = oracle->ObjectLiteralStoreIsMonomorphic(id) |
| 833 : Handle<Map>::null(); | 746 ? oracle->GetObjectLiteralStoreMap(id) : Handle<Map>::null(); |
| 834 } | 747 } |
| 835 | 748 |
| 836 | 749 |
| 837 // ---------------------------------------------------------------------------- | 750 // ---------------------------------------------------------------------------- |
| 838 // Implementation of AstVisitor | 751 // Implementation of AstVisitor |
| 839 | 752 |
| 840 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { | 753 void AstVisitor::VisitDeclarations(ZoneList<Declaration*>* declarations) { |
| 841 for (int i = 0; i < declarations->length(); i++) { | 754 for (int i = 0; i < declarations->length(); i++) { |
| 842 Visit(declarations->at(i)); | 755 Visit(declarations->at(i)); |
| 843 } | 756 } |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); | 1244 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); |
| 1332 str = arr; | 1245 str = arr; |
| 1333 } else { | 1246 } else { |
| 1334 str = DoubleToCString(value_->Number(), buffer); | 1247 str = DoubleToCString(value_->Number(), buffer); |
| 1335 } | 1248 } |
| 1336 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); | 1249 return isolate_->factory()->NewStringFromAscii(CStrVector(str)); |
| 1337 } | 1250 } |
| 1338 | 1251 |
| 1339 | 1252 |
| 1340 } } // namespace v8::internal | 1253 } } // namespace v8::internal |
| OLD | NEW |