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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 if (info.IsSmi()) { | 552 if (info.IsSmi()) { |
554 compare_type_ = SMI_ONLY; | 553 compare_type_ = SMI_ONLY; |
555 } else if (info.IsNonPrimitive()) { | 554 } else if (info.IsNonPrimitive()) { |
556 compare_type_ = OBJECT_ONLY; | 555 compare_type_ = OBJECT_ONLY; |
557 } else { | 556 } else { |
558 ASSERT(compare_type_ == NONE); | 557 ASSERT(compare_type_ == NONE); |
559 } | 558 } |
560 } | 559 } |
561 | 560 |
562 | 561 |
563 static bool CallWithoutIC(Handle<JSFunction> target, int arity) { | 562 static bool CanCallWithoutIC(Handle<JSFunction> target, int arity) { |
564 SharedFunctionInfo* info = target->shared(); | 563 SharedFunctionInfo* info = target->shared(); |
565 if (target->NeedsArgumentsAdaption()) { | 564 // If the number of formal parameters of the target function does |
566 // If the number of formal parameters of the target function | 565 // not match the number of arguments we're passing, we don't want to |
567 // does not match the number of arguments we're passing, we | 566 // deal with it. Otherwise, we can call it directly. |
568 // don't want to deal with it. | 567 return !target->NeedsArgumentsAdaption() || |
569 return info->formal_parameter_count() == arity; | 568 info->formal_parameter_count() == arity; |
570 } else { | |
571 // If the target doesn't need arguments adaption, we can call | |
572 // it directly, but we avoid to do so if it has a custom call | |
573 // generator, because that is likely to generate better code. | |
574 return !info->HasBuiltinFunctionId() || | |
575 !CallStubCompiler::HasCustomCallGenerator(info->builtin_function_id()); | |
576 } | |
577 } | 569 } |
578 | 570 |
579 | 571 |
580 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { | 572 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { |
581 holder_ = Handle<JSObject>::null(); | 573 holder_ = Handle<JSObject>::null(); |
582 while (true) { | 574 while (true) { |
583 LookupResult lookup; | 575 LookupResult lookup; |
584 type->LookupInDescriptors(NULL, *name, &lookup); | 576 type->LookupInDescriptors(NULL, *name, &lookup); |
585 // If the function wasn't found directly in the map, we start | 577 // If the function wasn't found directly in the map, we start |
586 // looking upwards through the prototype chain. | 578 // looking upwards through the prototype chain. |
587 if (!lookup.IsFound() && type->prototype()->IsJSObject()) { | 579 if (!lookup.IsFound() && type->prototype()->IsJSObject()) { |
588 holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); | 580 holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); |
589 type = Handle<Map>(holder()->map()); | 581 type = Handle<Map>(holder()->map()); |
590 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) { | 582 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) { |
591 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); | 583 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); |
592 return CallWithoutIC(target_, arguments()->length()); | 584 return CanCallWithoutIC(target_, arguments()->length()); |
593 } else { | 585 } else { |
594 return false; | 586 return false; |
595 } | 587 } |
596 } | 588 } |
597 } | 589 } |
598 | 590 |
599 | 591 |
600 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, | 592 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, |
601 Handle<String> name) { | 593 Handle<String> name) { |
602 target_ = Handle<JSFunction>::null(); | 594 target_ = Handle<JSFunction>::null(); |
603 cell_ = Handle<JSGlobalPropertyCell>::null(); | 595 cell_ = Handle<JSGlobalPropertyCell>::null(); |
604 LookupResult lookup; | 596 LookupResult lookup; |
605 global->Lookup(*name, &lookup); | 597 global->Lookup(*name, &lookup); |
606 if (lookup.IsProperty() && lookup.type() == NORMAL) { | 598 if (lookup.IsProperty() && lookup.type() == NORMAL) { |
607 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); | 599 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); |
608 if (cell_->value()->IsJSFunction()) { | 600 if (cell_->value()->IsJSFunction()) { |
609 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); | 601 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); |
610 // If the function is in new space we assume it's more likely to | 602 // If the function is in new space we assume it's more likely to |
611 // change and thus prefer the general IC code. | 603 // change and thus prefer the general IC code. |
612 if (!Heap::InNewSpace(*candidate) | 604 if (!Heap::InNewSpace(*candidate) && |
613 && CallWithoutIC(candidate, arguments()->length())) { | 605 CanCallWithoutIC(candidate, arguments()->length())) { |
614 target_ = candidate; | 606 target_ = candidate; |
615 return true; | 607 return true; |
616 } | 608 } |
617 } | 609 } |
618 } | 610 } |
619 return false; | 611 return false; |
620 } | 612 } |
621 | 613 |
622 | 614 |
623 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 615 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 | 1040 |
1049 CaseClause::CaseClause(Expression* label, | 1041 CaseClause::CaseClause(Expression* label, |
1050 ZoneList<Statement*>* statements, | 1042 ZoneList<Statement*>* statements, |
1051 int pos) | 1043 int pos) |
1052 : label_(label), | 1044 : label_(label), |
1053 statements_(statements), | 1045 statements_(statements), |
1054 position_(pos), | 1046 position_(pos), |
1055 compare_type_(NONE) {} | 1047 compare_type_(NONE) {} |
1056 | 1048 |
1057 } } // namespace v8::internal | 1049 } } // namespace v8::internal |
OLD | NEW |