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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 | 460 |
| 461 Variable return_value(this, MachineRepresentation::kTagged); | 461 Variable return_value(this, MachineRepresentation::kTagged); |
| 462 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); | 462 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); |
| 463 | 463 |
| 464 // Slot id of 0 is used to indicate no typefeedback is available. Call using | 464 // Slot id of 0 is used to indicate no typefeedback is available. Call using |
| 465 // call builtin. | 465 // call builtin. |
| 466 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | 466 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); |
| 467 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | 467 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); |
| 468 GotoIf(is_feedback_unavailable, &call); | 468 GotoIf(is_feedback_unavailable, &call); |
| 469 | 469 |
| 470 // The checks. First, does rdi match the recorded monomorphic target? | 470 // The checks. First, does function match the recorded monomorphic target? |
| 471 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | 471 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); |
| 472 Node* feedback_value = LoadWeakCellValue(feedback_element); | 472 Node* feedback_value = LoadWeakCellValue(feedback_element); |
| 473 Node* is_monomorphic = WordEqual(function, feedback_value); | 473 Node* is_monomorphic = WordEqual(function, feedback_value); |
| 474 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); | 474 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); |
| 475 | 475 |
| 476 Bind(&handle_monomorphic); | 476 Bind(&handle_monomorphic); |
| 477 { | 477 { |
| 478 // The compare above could have been a SMI/SMI comparison. Guard against | 478 // The compare above could have been a SMI/SMI comparison. Guard against |
| 479 // this convincing us that we have a monomorphic JSFunction. | 479 // this convincing us that we have a monomorphic JSFunction. |
| 480 Node* is_smi = WordIsSmi(function); | 480 Node* is_smi = WordIsSmi(function); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 Node* InterpreterAssembler::CallJS(Node* function, Node* context, | 594 Node* InterpreterAssembler::CallJS(Node* function, Node* context, |
| 595 Node* first_arg, Node* arg_count, | 595 Node* first_arg, Node* arg_count, |
| 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 void InterpreterAssembler::UpdateTypeFeedback(Node* slot_id, | |
|
rmcilroy
2016/07/15 10:44:06
Could we just do this inline? Or at least make the
mythria
2016/07/15 13:53:41
I inlined it into the callConstruct. Done.
| |
| 605 Node* type_feedback_vector, | |
| 606 Node* constructor, | |
| 607 Node* context) { | |
| 608 Label increment_count(this), extra_checks(this), done(this); | |
| 609 | |
| 610 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | |
| 611 Node* feedback_value = LoadWeakCellValue(feedback_element); | |
| 612 Node* is_monomorphic = WordEqual(constructor, feedback_value); | |
| 613 BranchIf(is_monomorphic, &increment_count, &extra_checks); | |
| 614 | |
| 615 Bind(&increment_count); | |
| 616 { | |
| 617 // Increment the call count. | |
| 618 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 619 Node* call_count = | |
| 620 LoadFixedArrayElement(type_feedback_vector, call_count_slot); | |
| 621 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); | |
| 622 // Count is Smi, so we don't need a write barrier. | |
| 623 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, | |
| 624 SKIP_WRITE_BARRIER); | |
| 625 Goto(&done); | |
| 626 } | |
| 627 | |
| 628 Bind(&extra_checks); | |
| 629 { | |
| 630 Label mark_megamorphic(this), initialize(this), | |
| 631 check_weak_cell_cleared(this); | |
| 632 // Check if it is a megamorphic target | |
| 633 Node* is_megamorphic = WordEqual( | |
| 634 feedback_element, | |
| 635 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
| 636 GotoIf(is_megamorphic, &done); | |
| 637 | |
| 638 // Check if it is uninitialized. | |
| 639 Node* is_uninitialized = WordEqual( | |
| 640 feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex)); | |
| 641 BranchIf(is_uninitialized, &initialize, &check_weak_cell_cleared); | |
| 642 | |
| 643 Bind(&check_weak_cell_cleared); | |
| 644 { | |
| 645 Node* is_weak_cell = WordEqual(LoadMap(feedback_element), | |
| 646 LoadRoot(Heap::kWeakCellMapRootIndex)); | |
| 647 GotoUnless(is_weak_cell, &mark_megamorphic); | |
| 648 | |
| 649 // If the weak cell is cleared, we have a new chance to become | |
| 650 // monomorphic. | |
| 651 Node* is_smi = WordIsSmi(feedback_value); | |
| 652 BranchIf(is_smi, &initialize, &mark_megamorphic); | |
|
mythria
2016/07/14 15:00:56
This is a bit different from Call type feedback. W
| |
| 653 } | |
| 654 | |
| 655 Bind(&initialize); | |
| 656 { | |
| 657 // Check that it is not the Array() function. | |
| 658 Node* context_slot = | |
| 659 LoadFixedArrayElement(LoadNativeContext(context), | |
| 660 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
| 661 Node* is_array_function = WordEqual(context_slot, constructor); | |
| 662 GotoIf(is_array_function, &mark_megamorphic); | |
| 663 | |
| 664 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 665 // Count is Smi, so we don't need a write barrier. | |
| 666 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | |
| 667 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | |
| 668 | |
| 669 CreateWeakCellStub weak_cell_stub(isolate()); | |
| 670 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), | |
| 671 HeapConstant(weak_cell_stub.GetCode()), context, | |
| 672 type_feedback_vector, SmiTag(slot_id), constructor); | |
| 673 Goto(&done); | |
| 674 } | |
| 675 | |
| 676 Bind(&mark_megamorphic); | |
| 677 { | |
| 678 // MegamorphicSentinel is an immortal immovable object so no write-barrier | |
| 679 // is needed. | |
| 680 DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); | |
| 681 StoreFixedArrayElement( | |
| 682 type_feedback_vector, slot_id, | |
| 683 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), | |
| 684 SKIP_WRITE_BARRIER); | |
| 685 Goto(&done); | |
| 686 } | |
| 687 } | |
| 688 | |
| 689 Bind(&done); | |
| 690 } | |
| 691 | |
| 604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, | 692 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, |
| 605 Node* new_target, Node* first_arg, | 693 Node* new_target, Node* first_arg, |
| 606 Node* arg_count) { | 694 Node* arg_count, Node* slot_id, |
| 607 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); | 695 Node* type_feedback_vector) { |
| 696 Label call_constrcut(this), js_function(this), end(this); | |
| 697 Variable return_value(this, MachineRepresentation::kTagged); | |
| 698 | |
| 699 // Slot id of 0 is used to indicate no typefeedback is available. | |
| 700 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | |
| 701 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | |
| 702 GotoIf(is_feedback_unavailable, &call_constrcut); | |
| 703 | |
| 704 // Check that the constructor is not a smi. | |
| 705 Node* is_smi = WordIsSmi(constructor); | |
| 706 GotoIf(is_smi, &call_constrcut); | |
| 707 | |
| 708 // Check that constructor is a JSFunction. | |
| 709 Node* instance_type = LoadInstanceType(constructor); | |
| 710 Node* is_js_function = | |
| 711 WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); | |
| 712 BranchIf(is_js_function, &js_function, &call_constrcut); | |
|
mythria
2016/07/14 15:00:56
If constructor is not a JSFunction, we do not upda
rmcilroy
2016/07/15 10:44:06
call_constrcut - fix typo
mythria
2016/07/15 13:53:41
Thanks. Done.
| |
| 713 | |
| 714 Bind(&js_function); | |
| 715 // Cache the called function in a feedback vector slot. Cache states | |
| 716 // are uninitialized, monomorphic (indicated by a JSFunction), and | |
| 717 // megamorphic. | |
| 718 UpdateTypeFeedback(slot_id, type_feedback_vector, constructor, context); | |
| 719 | |
| 720 // TODO(mythria): Get allocation site feedback if available. Currently | |
| 721 // we do not collect allocation site feedback. | |
| 722 Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 723 isolate(), CallableType::kJSFunction); | |
| 724 return_value.Bind(CallStub(callable_function.descriptor(), | |
| 725 HeapConstant(callable_function.code()), context, | |
| 726 arg_count, new_target, constructor, first_arg)); | |
| 727 Goto(&end); | |
| 728 | |
| 729 Bind(&call_constrcut); | |
| 730 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 731 isolate(), CallableType::kAny); | |
| 608 Node* code_target = HeapConstant(callable.code()); | 732 Node* code_target = HeapConstant(callable.code()); |
| 609 return CallStub(callable.descriptor(), code_target, context, arg_count, | 733 return_value.Bind(CallStub(callable.descriptor(), code_target, context, |
| 610 new_target, constructor, first_arg); | 734 arg_count, new_target, constructor, first_arg)); |
| 735 Goto(&end); | |
| 736 | |
| 737 Bind(&end); | |
| 738 return return_value.value(); | |
| 611 } | 739 } |
| 612 | 740 |
| 613 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, | 741 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, |
| 614 Node* first_arg, Node* arg_count, | 742 Node* first_arg, Node* arg_count, |
| 615 int result_size) { | 743 int result_size) { |
| 616 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); | 744 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); |
| 617 Node* code_target = HeapConstant(callable.code()); | 745 Node* code_target = HeapConstant(callable.code()); |
| 618 | 746 |
| 619 // Get the function entry from the function id. | 747 // Get the function entry from the function id. |
| 620 Node* function_table = ExternalConstant( | 748 Node* function_table = ExternalConstant( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 Goto(&loop); | 1060 Goto(&loop); |
| 933 } | 1061 } |
| 934 Bind(&done_loop); | 1062 Bind(&done_loop); |
| 935 | 1063 |
| 936 return array; | 1064 return array; |
| 937 } | 1065 } |
| 938 | 1066 |
| 939 } // namespace interpreter | 1067 } // namespace interpreter |
| 940 } // namespace internal | 1068 } // namespace internal |
| 941 } // namespace v8 | 1069 } // namespace v8 |
| OLD | NEW |