Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/interpreter/interpreter-assembler.h" | 5 #include "src/interpreter/interpreter-assembler.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 | 462 |
| 463 Variable return_value(this, MachineRepresentation::kTagged); | 463 Variable return_value(this, MachineRepresentation::kTagged); |
| 464 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); | 464 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); |
| 465 | 465 |
| 466 // Slot id of 0 is used to indicate no typefeedback is available. Call using | 466 // Slot id of 0 is used to indicate no typefeedback is available. Call using |
| 467 // call builtin. | 467 // call builtin. |
| 468 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | 468 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); |
| 469 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | 469 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); |
| 470 GotoIf(is_feedback_unavailable, &call); | 470 GotoIf(is_feedback_unavailable, &call); |
| 471 | 471 |
| 472 // The checks. First, does rdi match the recorded monomorphic target? | 472 // The checks. First, does function match the recorded monomorphic target? |
| 473 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | 473 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); |
| 474 Node* feedback_value = LoadWeakCellValue(feedback_element); | 474 Node* feedback_value = LoadWeakCellValue(feedback_element); |
| 475 Node* is_monomorphic = WordEqual(function, feedback_value); | 475 Node* is_monomorphic = WordEqual(function, feedback_value); |
| 476 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); | 476 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); |
| 477 | 477 |
| 478 Bind(&handle_monomorphic); | 478 Bind(&handle_monomorphic); |
| 479 { | 479 { |
| 480 // The compare above could have been a SMI/SMI comparison. Guard against | 480 // The compare above could have been a SMI/SMI comparison. Guard against |
| 481 // this convincing us that we have a monomorphic JSFunction. | 481 // this convincing us that we have a monomorphic JSFunction. |
| 482 Node* is_smi = WordIsSmi(function); | 482 Node* is_smi = WordIsSmi(function); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 TailCallMode tail_call_mode) { | 596 TailCallMode tail_call_mode) { |
| 597 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | 597 Callable callable = CodeFactory::InterpreterPushArgsAndCall( |
| 598 isolate(), tail_call_mode, CallableType::kAny); | 598 isolate(), tail_call_mode, CallableType::kAny); |
| 599 Node* code_target = HeapConstant(callable.code()); | 599 Node* code_target = HeapConstant(callable.code()); |
| 600 return CallStub(callable.descriptor(), code_target, context, arg_count, | 600 return CallStub(callable.descriptor(), code_target, context, arg_count, |
| 601 first_arg, function); | 601 first_arg, function); |
| 602 } | 602 } |
| 603 | 603 |
| 604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, | 604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, |
| 605 Node* new_target, Node* first_arg, | 605 Node* new_target, Node* first_arg, |
| 606 Node* arg_count) { | 606 Node* arg_count, Node* slot_id, |
| 607 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); | 607 Node* type_feedback_vector) { |
| 608 Node* code_target = HeapConstant(callable.code()); | 608 Label call_construct(this), js_function(this), end(this); |
| 609 return CallStub(callable.descriptor(), code_target, context, arg_count, | 609 Variable return_value(this, MachineRepresentation::kTagged); |
| 610 new_target, constructor, first_arg); | 610 Variable allocation_feedback(this, MachineRepresentation::kTagged); |
| 611 allocation_feedback.Bind(UndefinedConstant()); | |
| 612 | |
| 613 // Slot id of 0 is used to indicate no typefeedback is available. | |
|
rmcilroy
2016/08/03 13:14:19
/s/typefeedback/type feedback/
mythria
2016/08/04 07:06:10
Done.
| |
| 614 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | |
| 615 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | |
| 616 GotoIf(is_feedback_unavailable, &call_construct); | |
| 617 | |
| 618 // Check that the constructor is not a smi. | |
| 619 Node* is_smi = WordIsSmi(constructor); | |
| 620 GotoIf(is_smi, &call_construct); | |
| 621 | |
| 622 // Check that constructor is a JSFunction. | |
| 623 Node* instance_type = LoadInstanceType(constructor); | |
| 624 Node* is_js_function = | |
| 625 WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); | |
| 626 BranchIf(is_js_function, &js_function, &call_construct); | |
| 627 | |
| 628 Bind(&js_function); | |
| 629 // Cache the called function in a feedback vector slot. Cache states | |
|
rmcilroy
2016/08/03 13:14:19
Remove extra space after fullstop
rmcilroy
2016/08/03 13:14:19
Add scope for binded label.
mythria
2016/08/04 07:06:11
Done.
mythria
2016/08/04 07:06:11
Done.
| |
| 630 // are uninitialized, monomorphic (indicated by a JSFunction), and | |
| 631 // megamorphic. | |
| 632 // TODO(mythria/v8:5210): Check if it is better to mark extra_checks as a | |
| 633 // deferred block so that call_construct_function will be scheduled just | |
| 634 // after increment_count and in the fast path we can reduce one branch in the | |
| 635 // fast path. | |
|
rmcilroy
2016/08/03 13:14:19
Could you check this again now that you've moved t
mythria
2016/08/04 07:06:10
It still has. so did not mark it deferred.
| |
| 636 Label increment_count(this), extra_checks(this), | |
| 637 call_construct_function(this); | |
| 638 | |
| 639 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | |
| 640 Node* feedback_value = LoadWeakCellValue(feedback_element); | |
| 641 Node* is_monomorphic = WordEqual(constructor, feedback_value); | |
| 642 BranchIf(is_monomorphic, &increment_count, &extra_checks); | |
| 643 | |
| 644 Bind(&extra_checks); | |
| 645 { | |
| 646 Label mark_megamorphic(this), initialize(this), check_allocation_site(this), | |
| 647 check_initialized(this), set_alloc_feedback_and_inc_count(this); | |
| 648 { | |
| 649 // Check if it is a megamorphic target | |
| 650 Comment("check if megamorphic"); | |
| 651 Node* is_megamorphic = WordEqual( | |
| 652 feedback_element, | |
| 653 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
| 654 GotoIf(is_megamorphic, &call_construct_function); | |
| 655 | |
| 656 Comment("check if weak cell"); | |
| 657 Node* is_weak_cell = WordEqual(LoadMap(feedback_element), | |
| 658 LoadRoot(Heap::kWeakCellMapRootIndex)); | |
| 659 GotoUnless(is_weak_cell, &check_allocation_site); | |
| 660 // If the weak cell is cleared, we have a new chance to become | |
| 661 // monomorphic. | |
| 662 Comment("check if weak cell is cleared"); | |
| 663 Node* is_smi = WordIsSmi(feedback_value); | |
| 664 BranchIf(is_smi, &initialize, &mark_megamorphic); | |
| 665 } | |
| 666 | |
| 667 Bind(&check_allocation_site); | |
| 668 { | |
| 669 Comment("check if it is an allocation site"); | |
| 670 Node* is_allocation_site = | |
| 671 WordEqual(LoadObjectField(feedback_element, 0), | |
| 672 LoadRoot(Heap::kAllocationSiteMapRootIndex)); | |
| 673 GotoUnless(is_allocation_site, &check_initialized); | |
| 674 | |
| 675 // Make sure the function is the Array() function | |
| 676 Node* context_slot = | |
| 677 LoadFixedArrayElement(LoadNativeContext(context), | |
| 678 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
| 679 Node* is_array_function = WordEqual(context_slot, constructor); | |
| 680 BranchIf(is_array_function, &set_alloc_feedback_and_inc_count, | |
| 681 &mark_megamorphic); | |
| 682 } | |
| 683 | |
| 684 Bind(&set_alloc_feedback_and_inc_count); | |
| 685 { | |
| 686 allocation_feedback.Bind(feedback_element); | |
| 687 Goto(&increment_count); | |
| 688 } | |
| 689 | |
| 690 Bind(&check_initialized); | |
| 691 { | |
| 692 // Check if it is uninitialized. | |
| 693 Comment("check if uninitialized"); | |
| 694 Node* is_uninitialized = WordEqual( | |
| 695 feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex)); | |
| 696 BranchIf(is_uninitialized, &initialize, &mark_megamorphic); | |
| 697 } | |
| 698 | |
| 699 Bind(&initialize); | |
| 700 { | |
| 701 Label initialize_count(this), create_weak_cell(this), | |
| 702 create_allocation_site(this); | |
| 703 Comment("initialize the feedback element"); | |
| 704 // Check that it is not the Array() function. | |
|
rmcilroy
2016/08/03 13:14:19
nit - Check if it is the Array() function.
mythria
2016/08/04 07:06:10
Done.
| |
| 705 Node* context_slot = | |
| 706 LoadFixedArrayElement(LoadNativeContext(context), | |
| 707 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
| 708 Node* is_array_function = WordEqual(context_slot, constructor); | |
| 709 BranchIf(is_array_function, &create_allocation_site, &create_weak_cell); | |
| 710 | |
| 711 Bind(&create_allocation_site); | |
| 712 { | |
| 713 // TODO(mythria): Inline the creation of allocation site. | |
| 714 CreateAllocationSiteStub create_stub(isolate()); | |
| 715 CallStub(create_stub.GetCallInterfaceDescriptor(), | |
| 716 HeapConstant(create_stub.GetCode()), context, | |
| 717 type_feedback_vector, SmiTag(slot_id)); | |
| 718 Node* feedback_element = | |
| 719 LoadFixedArrayElement(type_feedback_vector, slot_id); | |
| 720 allocation_feedback.Bind(feedback_element); | |
| 721 Goto(&initialize_count); | |
| 722 } | |
| 723 | |
| 724 Bind(&create_weak_cell); | |
| 725 { | |
| 726 CreateWeakCellInFeedbackVector(type_feedback_vector, SmiTag(slot_id), | |
| 727 constructor); | |
| 728 Goto(&initialize_count); | |
| 729 } | |
| 730 | |
| 731 Bind(&initialize_count); | |
| 732 { | |
| 733 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 734 // Count is Smi, so we don't need a write barrier. | |
| 735 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | |
| 736 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | |
| 737 Goto(&call_construct_function); | |
| 738 } | |
| 739 } | |
| 740 | |
| 741 Bind(&mark_megamorphic); | |
| 742 { | |
| 743 // MegamorphicSentinel is an immortal immovable object so no write-barrier | |
| 744 // is needed. | |
| 745 Comment("transition to megamorphic"); | |
| 746 DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); | |
| 747 StoreFixedArrayElement( | |
| 748 type_feedback_vector, slot_id, | |
| 749 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), | |
| 750 SKIP_WRITE_BARRIER); | |
| 751 Goto(&call_construct_function); | |
| 752 } | |
| 753 } | |
| 754 | |
| 755 Bind(&increment_count); | |
| 756 { | |
| 757 // Increment the call count. | |
| 758 Comment("increment call count"); | |
| 759 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 760 Node* call_count = | |
| 761 LoadFixedArrayElement(type_feedback_vector, call_count_slot); | |
| 762 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); | |
| 763 // Count is Smi, so we don't need a write barrier. | |
| 764 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, | |
| 765 SKIP_WRITE_BARRIER); | |
| 766 Goto(&call_construct_function); | |
| 767 } | |
| 768 | |
| 769 Bind(&call_construct_function); | |
| 770 { | |
| 771 Comment("call using callConstructFunction"); | |
| 772 Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 773 isolate(), CallableType::kJSFunction); | |
| 774 return_value.Bind(CallStub(callable_function.descriptor(), | |
| 775 HeapConstant(callable_function.code()), context, | |
| 776 arg_count, new_target, constructor, | |
| 777 allocation_feedback.value(), first_arg)); | |
| 778 Goto(&end); | |
| 779 } | |
| 780 | |
| 781 Bind(&call_construct); | |
| 782 { | |
| 783 Comment("call using callConstruct builtin"); | |
| 784 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 785 isolate(), CallableType::kAny); | |
| 786 Node* code_target = HeapConstant(callable.code()); | |
| 787 return_value.Bind(CallStub(callable.descriptor(), code_target, context, | |
| 788 arg_count, new_target, constructor, | |
| 789 UndefinedConstant(), first_arg)); | |
| 790 Goto(&end); | |
| 791 } | |
| 792 | |
| 793 Bind(&end); | |
| 794 return return_value.value(); | |
| 611 } | 795 } |
| 612 | 796 |
| 613 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, | 797 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, |
| 614 Node* first_arg, Node* arg_count, | 798 Node* first_arg, Node* arg_count, |
| 615 int result_size) { | 799 int result_size) { |
| 616 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); | 800 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); |
| 617 Node* code_target = HeapConstant(callable.code()); | 801 Node* code_target = HeapConstant(callable.code()); |
| 618 | 802 |
| 619 // Get the function entry from the function id. | 803 // Get the function entry from the function id. |
| 620 Node* function_table = ExternalConstant( | 804 Node* function_table = ExternalConstant( |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 992 Goto(&loop); | 1176 Goto(&loop); |
| 993 } | 1177 } |
| 994 Bind(&done_loop); | 1178 Bind(&done_loop); |
| 995 | 1179 |
| 996 return array; | 1180 return array; |
| 997 } | 1181 } |
| 998 | 1182 |
| 999 } // namespace interpreter | 1183 } // namespace interpreter |
| 1000 } // namespace internal | 1184 } // namespace internal |
| 1001 } // namespace v8 | 1185 } // namespace v8 |
| OLD | NEW |