| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "ast.h" | 30 #include "ast.h" |
| 31 #include "jump-target-inl.h" | 31 #include "jump-target-inl.h" |
| 32 #include "parser.h" | 32 #include "parser.h" |
| 33 #include "scopes.h" | 33 #include "scopes.h" |
| 34 #include "string-stream.h" | 34 #include "string-stream.h" |
| 35 #include "stub-cache.h" | |
| 36 | 35 |
| 37 namespace v8 { | 36 namespace v8 { |
| 38 namespace internal { | 37 namespace internal { |
| 39 | 38 |
| 40 unsigned AstNode::current_id_ = 0; | 39 unsigned AstNode::current_id_ = 0; |
| 41 unsigned AstNode::count_ = 0; | 40 unsigned AstNode::count_ = 0; |
| 42 VariableProxySentinel VariableProxySentinel::this_proxy_(true); | 41 VariableProxySentinel VariableProxySentinel::this_proxy_(true); |
| 43 VariableProxySentinel VariableProxySentinel::identifier_proxy_(false); | 42 VariableProxySentinel VariableProxySentinel::identifier_proxy_(false); |
| 44 ValidLeftHandSideSentinel ValidLeftHandSideSentinel::instance_; | 43 ValidLeftHandSideSentinel ValidLeftHandSideSentinel::instance_; |
| 45 Property Property::this_property_(VariableProxySentinel::this_proxy(), NULL, 0); | 44 Property Property::this_property_(VariableProxySentinel::this_proxy(), NULL, 0); |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 if (info.IsSmi()) { | 558 if (info.IsSmi()) { |
| 560 compare_type_ = SMI_ONLY; | 559 compare_type_ = SMI_ONLY; |
| 561 } else if (info.IsNonPrimitive()) { | 560 } else if (info.IsNonPrimitive()) { |
| 562 compare_type_ = OBJECT_ONLY; | 561 compare_type_ = OBJECT_ONLY; |
| 563 } else { | 562 } else { |
| 564 ASSERT(compare_type_ == NONE); | 563 ASSERT(compare_type_ == NONE); |
| 565 } | 564 } |
| 566 } | 565 } |
| 567 | 566 |
| 568 | 567 |
| 569 static bool CallWithoutIC(Handle<JSFunction> target, int arity) { | 568 static bool CanCallWithoutIC(Handle<JSFunction> target, int arity) { |
| 570 SharedFunctionInfo* info = target->shared(); | 569 SharedFunctionInfo* info = target->shared(); |
| 571 if (target->NeedsArgumentsAdaption()) { | 570 // If the number of formal parameters of the target function does |
| 572 // If the number of formal parameters of the target function | 571 // not match the number of arguments we're passing, we don't want to |
| 573 // does not match the number of arguments we're passing, we | 572 // deal with it. Otherwise, we can call it directly. |
| 574 // don't want to deal with it. | 573 return !target->NeedsArgumentsAdaption() || |
| 575 return info->formal_parameter_count() == arity; | 574 info->formal_parameter_count() == arity; |
| 576 } else { | |
| 577 // If the target doesn't need arguments adaption, we can call | |
| 578 // it directly, but we avoid to do so if it has a custom call | |
| 579 // generator, because that is likely to generate better code. | |
| 580 return !info->HasBuiltinFunctionId() || | |
| 581 !CallStubCompiler::HasCustomCallGenerator(info->builtin_function_id()); | |
| 582 } | |
| 583 } | 575 } |
| 584 | 576 |
| 585 | 577 |
| 586 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { | 578 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { |
| 587 holder_ = Handle<JSObject>::null(); | 579 holder_ = Handle<JSObject>::null(); |
| 588 while (true) { | 580 while (true) { |
| 589 LookupResult lookup; | 581 LookupResult lookup; |
| 590 type->LookupInDescriptors(NULL, *name, &lookup); | 582 type->LookupInDescriptors(NULL, *name, &lookup); |
| 591 // If the function wasn't found directly in the map, we start | 583 // If the function wasn't found directly in the map, we start |
| 592 // looking upwards through the prototype chain. | 584 // looking upwards through the prototype chain. |
| 593 if (!lookup.IsFound() && type->prototype()->IsJSObject()) { | 585 if (!lookup.IsFound() && type->prototype()->IsJSObject()) { |
| 594 holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); | 586 holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); |
| 595 type = Handle<Map>(holder()->map()); | 587 type = Handle<Map>(holder()->map()); |
| 596 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) { | 588 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) { |
| 597 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); | 589 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); |
| 598 return CallWithoutIC(target_, arguments()->length()); | 590 return CanCallWithoutIC(target_, arguments()->length()); |
| 599 } else { | 591 } else { |
| 600 return false; | 592 return false; |
| 601 } | 593 } |
| 602 } | 594 } |
| 603 } | 595 } |
| 604 | 596 |
| 605 | 597 |
| 606 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, | 598 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, |
| 607 Handle<String> name) { | 599 Handle<String> name) { |
| 608 target_ = Handle<JSFunction>::null(); | 600 target_ = Handle<JSFunction>::null(); |
| 609 cell_ = Handle<JSGlobalPropertyCell>::null(); | 601 cell_ = Handle<JSGlobalPropertyCell>::null(); |
| 610 LookupResult lookup; | 602 LookupResult lookup; |
| 611 global->Lookup(*name, &lookup); | 603 global->Lookup(*name, &lookup); |
| 612 if (lookup.IsProperty() && lookup.type() == NORMAL) { | 604 if (lookup.IsProperty() && lookup.type() == NORMAL) { |
| 613 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); | 605 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); |
| 614 if (cell_->value()->IsJSFunction()) { | 606 if (cell_->value()->IsJSFunction()) { |
| 615 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); | 607 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); |
| 616 // If the function is in new space we assume it's more likely to | 608 // If the function is in new space we assume it's more likely to |
| 617 // change and thus prefer the general IC code. | 609 // change and thus prefer the general IC code. |
| 618 if (!Heap::InNewSpace(*candidate) | 610 if (!Heap::InNewSpace(*candidate) && |
| 619 && CallWithoutIC(candidate, arguments()->length())) { | 611 CanCallWithoutIC(candidate, arguments()->length())) { |
| 620 target_ = candidate; | 612 target_ = candidate; |
| 621 return true; | 613 return true; |
| 622 } | 614 } |
| 623 } | 615 } |
| 624 } | 616 } |
| 625 return false; | 617 return false; |
| 626 } | 618 } |
| 627 | 619 |
| 628 | 620 |
| 629 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 621 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 | 1046 |
| 1055 CaseClause::CaseClause(Expression* label, | 1047 CaseClause::CaseClause(Expression* label, |
| 1056 ZoneList<Statement*>* statements, | 1048 ZoneList<Statement*>* statements, |
| 1057 int pos) | 1049 int pos) |
| 1058 : label_(label), | 1050 : label_(label), |
| 1059 statements_(statements), | 1051 statements_(statements), |
| 1060 position_(pos), | 1052 position_(pos), |
| 1061 compare_type_(NONE) {} | 1053 compare_type_(NONE) {} |
| 1062 | 1054 |
| 1063 } } // namespace v8::internal | 1055 } } // namespace v8::internal |
| OLD | NEW |