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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 Node* is_same_native_context = | 539 Node* is_same_native_context = |
| 540 WordEqual(native_context, LoadNativeContext(context)); | 540 WordEqual(native_context, LoadNativeContext(context)); |
| 541 GotoUnless(is_same_native_context, &mark_megamorphic); | 541 GotoUnless(is_same_native_context, &mark_megamorphic); |
| 542 | 542 |
| 543 // Initialize it to a monomorphic target. | 543 // Initialize it to a monomorphic target. |
| 544 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | 544 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); |
| 545 // Count is Smi, so we don't need a write barrier. | 545 // Count is Smi, so we don't need a write barrier. |
| 546 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | 546 StoreFixedArrayElement(type_feedback_vector, call_count_slot, |
| 547 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | 547 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); |
| 548 | 548 |
| 549 // TODO(mythria): Inline the weak cell creation/registration. | |
| 549 CreateWeakCellStub weak_cell_stub(isolate()); | 550 CreateWeakCellStub weak_cell_stub(isolate()); |
| 550 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), | 551 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), |
| 551 HeapConstant(weak_cell_stub.GetCode()), context, | 552 HeapConstant(weak_cell_stub.GetCode()), context, |
| 552 type_feedback_vector, SmiTag(slot_id), function); | 553 type_feedback_vector, SmiTag(slot_id), function); |
| 553 | 554 |
| 554 // Call using call function builtin. | 555 // Call using call function builtin. |
| 555 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | 556 Callable callable = CodeFactory::InterpreterPushArgsAndCall( |
| 556 isolate(), tail_call_mode, CallableType::kJSFunction); | 557 isolate(), tail_call_mode, CallableType::kJSFunction); |
| 557 Node* code_target = HeapConstant(callable.code()); | 558 Node* code_target = HeapConstant(callable.code()); |
| 558 Node* ret_value = CallStub(callable.descriptor(), code_target, context, | 559 Node* ret_value = CallStub(callable.descriptor(), code_target, context, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 TailCallMode tail_call_mode) { | 597 TailCallMode tail_call_mode) { |
| 597 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | 598 Callable callable = CodeFactory::InterpreterPushArgsAndCall( |
| 598 isolate(), tail_call_mode, CallableType::kAny); | 599 isolate(), tail_call_mode, CallableType::kAny); |
| 599 Node* code_target = HeapConstant(callable.code()); | 600 Node* code_target = HeapConstant(callable.code()); |
| 600 return CallStub(callable.descriptor(), code_target, context, arg_count, | 601 return CallStub(callable.descriptor(), code_target, context, arg_count, |
| 601 first_arg, function); | 602 first_arg, function); |
| 602 } | 603 } |
| 603 | 604 |
| 604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, | 605 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, |
| 605 Node* new_target, Node* first_arg, | 606 Node* new_target, Node* first_arg, |
| 606 Node* arg_count) { | 607 Node* arg_count, Node* slot_id, |
| 607 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); | 608 Node* type_feedback_vector) { |
| 608 Node* code_target = HeapConstant(callable.code()); | 609 Label call_construct(this), js_function(this), end(this); |
| 609 return CallStub(callable.descriptor(), code_target, context, arg_count, | 610 Variable return_value(this, MachineRepresentation::kTagged); |
| 610 new_target, constructor, first_arg); | 611 |
| 612 // Slot id of 0 is used to indicate no typefeedback is available. | |
| 613 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | |
| 614 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | |
| 615 GotoIf(is_feedback_unavailable, &call_construct); | |
| 616 | |
| 617 // Check that the constructor is not a smi. | |
| 618 Node* is_smi = WordIsSmi(constructor); | |
| 619 GotoIf(is_smi, &call_construct); | |
| 620 | |
| 621 // Check that constructor is a JSFunction. | |
| 622 Node* instance_type = LoadInstanceType(constructor); | |
| 623 Node* is_js_function = | |
| 624 WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); | |
| 625 BranchIf(is_js_function, &js_function, &call_construct); | |
| 626 | |
| 627 Bind(&js_function); | |
| 628 // Cache the called function in a feedback vector slot. Cache states | |
| 629 // are uninitialized, monomorphic (indicated by a JSFunction), and | |
| 630 // megamorphic. | |
| 631 Label increment_count(this), extra_checks(this), | |
|
rmcilroy
2016/07/18 10:13:01
Should extra_checks be kDeferred ?
mythria
2016/07/19 09:50:59
As discussed offline, making any of the blocks kDe
| |
| 632 call_construct_function(this); | |
| 633 | |
| 634 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | |
| 635 Node* feedback_value = LoadWeakCellValue(feedback_element); | |
| 636 Node* is_monomorphic = WordEqual(constructor, feedback_value); | |
| 637 BranchIf(is_monomorphic, &increment_count, &extra_checks); | |
| 638 | |
| 639 Bind(&increment_count); | |
| 640 { | |
| 641 // Increment the call count. | |
| 642 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 643 Node* call_count = | |
| 644 LoadFixedArrayElement(type_feedback_vector, call_count_slot); | |
| 645 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); | |
| 646 // Count is Smi, so we don't need a write barrier. | |
| 647 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, | |
| 648 SKIP_WRITE_BARRIER); | |
| 649 Goto(&call_construct_function); | |
| 650 } | |
| 651 | |
| 652 Bind(&extra_checks); | |
| 653 { | |
| 654 Label mark_megamorphic(this), initialize(this), | |
| 655 check_weak_cell_cleared(this); | |
|
rmcilroy
2016/07/18 10:13:01
Should any of these be kDeferred?
mythria
2016/07/19 09:50:59
I think Deferred label for extra_checks would be s
| |
| 656 // Check if it is a megamorphic target | |
| 657 Node* is_megamorphic = WordEqual( | |
| 658 feedback_element, | |
| 659 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
| 660 GotoIf(is_megamorphic, &call_construct_function); | |
| 661 | |
| 662 // Check if it is uninitialized. | |
| 663 Node* is_uninitialized = WordEqual( | |
| 664 feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex)); | |
| 665 BranchIf(is_uninitialized, &initialize, &check_weak_cell_cleared); | |
| 666 | |
| 667 Bind(&check_weak_cell_cleared); | |
| 668 { | |
| 669 Node* is_weak_cell = WordEqual(LoadMap(feedback_element), | |
| 670 LoadRoot(Heap::kWeakCellMapRootIndex)); | |
| 671 GotoUnless(is_weak_cell, &mark_megamorphic); | |
| 672 | |
| 673 // If the weak cell is cleared, we have a new chance to become | |
| 674 // monomorphic. | |
| 675 Node* is_smi = WordIsSmi(feedback_value); | |
| 676 BranchIf(is_smi, &initialize, &mark_megamorphic); | |
| 677 } | |
| 678 | |
| 679 Bind(&initialize); | |
| 680 { | |
| 681 // Check that it is not the Array() function. | |
| 682 Node* context_slot = | |
| 683 LoadFixedArrayElement(LoadNativeContext(context), | |
| 684 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
| 685 Node* is_array_function = WordEqual(context_slot, constructor); | |
| 686 GotoIf(is_array_function, &mark_megamorphic); | |
| 687 | |
| 688 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 689 // Count is Smi, so we don't need a write barrier. | |
| 690 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | |
| 691 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | |
| 692 | |
| 693 // TODO(mythria): Inline the weak cell creation/registration. | |
| 694 CreateWeakCellStub weak_cell_stub(isolate()); | |
| 695 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), | |
| 696 HeapConstant(weak_cell_stub.GetCode()), context, | |
| 697 type_feedback_vector, SmiTag(slot_id), constructor); | |
| 698 Goto(&call_construct_function); | |
| 699 } | |
| 700 | |
| 701 Bind(&mark_megamorphic); | |
| 702 { | |
| 703 // MegamorphicSentinel is an immortal immovable object so no write-barrier | |
| 704 // is needed. | |
| 705 DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); | |
| 706 StoreFixedArrayElement( | |
| 707 type_feedback_vector, slot_id, | |
| 708 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), | |
| 709 SKIP_WRITE_BARRIER); | |
| 710 Goto(&call_construct_function); | |
| 711 } | |
| 712 } | |
| 713 | |
| 714 Bind(&call_construct_function); | |
| 715 { | |
| 716 // TODO(mythria): Get allocation site feedback if available. Currently | |
| 717 // we do not collect allocation site feedback. | |
| 718 Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 719 isolate(), CallableType::kJSFunction); | |
| 720 return_value.Bind(CallStub(callable_function.descriptor(), | |
| 721 HeapConstant(callable_function.code()), context, | |
| 722 arg_count, new_target, constructor, first_arg)); | |
| 723 Goto(&end); | |
| 724 } | |
| 725 | |
| 726 Bind(&call_construct); | |
| 727 { | |
| 728 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 729 isolate(), CallableType::kAny); | |
| 730 Node* code_target = HeapConstant(callable.code()); | |
| 731 return_value.Bind(CallStub(callable.descriptor(), code_target, context, | |
| 732 arg_count, new_target, constructor, first_arg)); | |
| 733 Goto(&end); | |
| 734 } | |
| 735 | |
| 736 Bind(&end); | |
| 737 return return_value.value(); | |
| 611 } | 738 } |
| 612 | 739 |
| 613 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, | 740 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, |
| 614 Node* first_arg, Node* arg_count, | 741 Node* first_arg, Node* arg_count, |
| 615 int result_size) { | 742 int result_size) { |
| 616 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); | 743 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); |
| 617 Node* code_target = HeapConstant(callable.code()); | 744 Node* code_target = HeapConstant(callable.code()); |
| 618 | 745 |
| 619 // Get the function entry from the function id. | 746 // Get the function entry from the function id. |
| 620 Node* function_table = ExternalConstant( | 747 Node* function_table = ExternalConstant( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 Goto(&loop); | 1059 Goto(&loop); |
| 933 } | 1060 } |
| 934 Bind(&done_loop); | 1061 Bind(&done_loop); |
| 935 | 1062 |
| 936 return array; | 1063 return array; |
| 937 } | 1064 } |
| 938 | 1065 |
| 939 } // namespace interpreter | 1066 } // namespace interpreter |
| 940 } // namespace internal | 1067 } // namespace internal |
| 941 } // namespace v8 | 1068 } // namespace v8 |
| OLD | NEW |