OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 } else if (info.IsNonSymbol()) { | 717 } else if (info.IsNonSymbol()) { |
718 compare_type_ = STRING_ONLY; | 718 compare_type_ = STRING_ONLY; |
719 } else if (info.IsNonPrimitive()) { | 719 } else if (info.IsNonPrimitive()) { |
720 compare_type_ = OBJECT_ONLY; | 720 compare_type_ = OBJECT_ONLY; |
721 } else { | 721 } else { |
722 ASSERT(compare_type_ == NONE); | 722 ASSERT(compare_type_ == NONE); |
723 } | 723 } |
724 } | 724 } |
725 | 725 |
726 | 726 |
727 static bool CanCallWithoutIC(Handle<JSFunction> target, int arity) { | |
728 SharedFunctionInfo* info = target->shared(); | |
729 // If the number of formal parameters of the target function does | |
730 // not match the number of arguments we're passing, we don't want to | |
731 // deal with it. Otherwise, we can call it directly. | |
732 return !target->NeedsArgumentsAdaption() || | |
733 info->formal_parameter_count() == arity; | |
734 } | |
735 | |
736 | |
737 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { | 727 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { |
738 if (check_type_ == RECEIVER_MAP_CHECK) { | 728 if (check_type_ == RECEIVER_MAP_CHECK) { |
739 // For primitive checks the holder is set up to point to the | 729 // For primitive checks the holder is set up to point to the |
740 // corresponding prototype object, i.e. one step of the algorithm | 730 // corresponding prototype object, i.e. one step of the algorithm |
741 // below has been already performed. | 731 // below has been already performed. |
742 // For non-primitive checks we clear it to allow computing targets | 732 // For non-primitive checks we clear it to allow computing targets |
743 // for polymorphic calls. | 733 // for polymorphic calls. |
744 holder_ = Handle<JSObject>::null(); | 734 holder_ = Handle<JSObject>::null(); |
745 } | 735 } |
746 while (true) { | 736 while (true) { |
747 LookupResult lookup(type->GetIsolate()); | 737 LookupResult lookup(type->GetIsolate()); |
748 type->LookupInDescriptors(NULL, *name, &lookup); | 738 type->LookupInDescriptors(NULL, *name, &lookup); |
749 // If the function wasn't found directly in the map, we start | 739 // If the function wasn't found directly in the map, we start |
750 // looking upwards through the prototype chain. | 740 // looking upwards through the prototype chain. |
751 if ((!lookup.IsFound() || IsTransitionType(lookup.type())) | 741 if ((!lookup.IsFound() || IsTransitionType(lookup.type())) |
752 && type->prototype()->IsJSObject()) { | 742 && type->prototype()->IsJSObject()) { |
753 holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); | 743 holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); |
754 type = Handle<Map>(holder()->map()); | 744 type = Handle<Map>(holder()->map()); |
755 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) { | 745 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) { |
756 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); | 746 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); |
757 return CanCallWithoutIC(target_, arguments()->length()); | 747 return true; |
758 } else { | 748 } else { |
759 return false; | 749 return false; |
760 } | 750 } |
761 } | 751 } |
762 } | 752 } |
763 | 753 |
764 | 754 |
765 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, | 755 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, |
766 LookupResult* lookup) { | 756 LookupResult* lookup) { |
767 target_ = Handle<JSFunction>::null(); | 757 target_ = Handle<JSFunction>::null(); |
768 cell_ = Handle<JSGlobalPropertyCell>::null(); | 758 cell_ = Handle<JSGlobalPropertyCell>::null(); |
769 ASSERT(lookup->IsProperty() && | 759 ASSERT(lookup->IsProperty() && |
770 lookup->type() == NORMAL && | 760 lookup->type() == NORMAL && |
771 lookup->holder() == *global); | 761 lookup->holder() == *global); |
772 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(lookup)); | 762 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(lookup)); |
773 if (cell_->value()->IsJSFunction()) { | 763 if (cell_->value()->IsJSFunction()) { |
774 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); | 764 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); |
775 // If the function is in new space we assume it's more likely to | 765 // If the function is in new space we assume it's more likely to |
776 // change and thus prefer the general IC code. | 766 // change and thus prefer the general IC code. |
777 if (!HEAP->InNewSpace(*candidate) && | 767 if (!HEAP->InNewSpace(*candidate)) { |
778 CanCallWithoutIC(candidate, arguments()->length())) { | |
779 target_ = candidate; | 768 target_ = candidate; |
780 return true; | 769 return true; |
781 } | 770 } |
782 } | 771 } |
783 return false; | 772 return false; |
784 } | 773 } |
785 | 774 |
786 | 775 |
787 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle, | 776 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
788 CallKind call_kind) { | 777 CallKind call_kind) { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 int pos) | 1200 int pos) |
1212 : label_(label), | 1201 : label_(label), |
1213 statements_(statements), | 1202 statements_(statements), |
1214 position_(pos), | 1203 position_(pos), |
1215 compare_type_(NONE), | 1204 compare_type_(NONE), |
1216 compare_id_(AstNode::GetNextId(isolate)), | 1205 compare_id_(AstNode::GetNextId(isolate)), |
1217 entry_id_(AstNode::GetNextId(isolate)) { | 1206 entry_id_(AstNode::GetNextId(isolate)) { |
1218 } | 1207 } |
1219 | 1208 |
1220 } } // namespace v8::internal | 1209 } } // namespace v8::internal |
OLD | NEW |