 Chromium Code Reviews
 Chromium Code Reviews Issue 2153433002:
  [Interpreter] Collect type feedback for 'new' in the bytecode handler  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 2153433002:
  [Interpreter] Collect type feedback for 'new' in the bytecode handler  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| 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 115 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 | 
| 611 // Slot id of 0 is used to indicate no typefeedback is available. | |
| 612 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | |
| 613 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | |
| 614 GotoIf(is_feedback_unavailable, &call_construct); | |
| 615 | |
| 616 // Check that the constructor is not a smi. | |
| 617 Node* is_smi = WordIsSmi(constructor); | |
| 618 GotoIf(is_smi, &call_construct); | |
| 619 | |
| 620 // Check that constructor is a JSFunction. | |
| 621 Node* instance_type = LoadInstanceType(constructor); | |
| 622 Node* is_js_function = | |
| 623 WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); | |
| 624 BranchIf(is_js_function, &js_function, &call_construct); | |
| 625 | |
| 626 Bind(&js_function); | |
| 627 // Cache the called function in a feedback vector slot. Cache states | |
| 628 // are uninitialized, monomorphic (indicated by a JSFunction), and | |
| 629 // megamorphic. | |
| 630 Label increment_count(this), extra_checks(this), | |
| 631 call_construct_function(this); | |
| 632 | |
| 633 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | |
| 634 Node* feedback_value = LoadWeakCellValue(feedback_element); | |
| 635 Node* is_monomorphic = WordEqual(constructor, feedback_value); | |
| 636 BranchIf(is_monomorphic, &increment_count, &extra_checks); | |
| 637 | |
| 638 Bind(&increment_count); | |
| 639 { | |
| 640 // Increment the call count. | |
| 641 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 642 Node* call_count = | |
| 643 LoadFixedArrayElement(type_feedback_vector, call_count_slot); | |
| 644 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); | |
| 645 // Count is Smi, so we don't need a write barrier. | |
| 646 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, | |
| 647 SKIP_WRITE_BARRIER); | |
| 648 Goto(&call_construct_function); | |
| 649 } | |
| 650 | |
| 651 Bind(&extra_checks); | |
| 652 { | |
| 653 Label mark_megamorphic(this), initialize(this), | |
| 654 check_weak_cell_cleared(this); | |
| 655 // Check if it is a megamorphic target | |
| 656 Node* is_megamorphic = WordEqual( | |
| 657 feedback_element, | |
| 658 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
| 659 GotoIf(is_megamorphic, &call_construct_function); | |
| 660 | |
| 661 // Check if it is uninitialized. | |
| 662 Node* is_uninitialized = WordEqual( | |
| 663 feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex)); | |
| 664 BranchIf(is_uninitialized, &initialize, &check_weak_cell_cleared); | |
| 665 | |
| 666 Bind(&check_weak_cell_cleared); | |
| 667 { | |
| 668 Node* is_weak_cell = WordEqual(LoadMap(feedback_element), | |
| 669 LoadRoot(Heap::kWeakCellMapRootIndex)); | |
| 670 GotoUnless(is_weak_cell, &mark_megamorphic); | |
| 671 | |
| 672 // If the weak cell is cleared, we have a new chance to become | |
| 673 // monomorphic. | |
| 674 Node* is_smi = WordIsSmi(feedback_value); | |
| 675 BranchIf(is_smi, &initialize, &mark_megamorphic); | |
| 676 } | |
| 677 | |
| 678 Bind(&initialize); | |
| 679 { | |
| 680 // Check that it is not the Array() function. | |
| 681 Node* context_slot = | |
| 682 LoadFixedArrayElement(LoadNativeContext(context), | |
| 683 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
| 684 Node* is_array_function = WordEqual(context_slot, constructor); | |
| 685 GotoIf(is_array_function, &mark_megamorphic); | |
| 686 | |
| 687 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 688 // Count is Smi, so we don't need a write barrier. | |
| 689 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | |
| 690 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | |
| 691 | |
| 692 CreateWeakCellStub weak_cell_stub(isolate()); | |
| 
Benedikt Meurer
2016/07/17 19:37:13
Can you place a TODO here, that we want to inline
 
mythria
2016/07/18 09:22:40
Thanks Benedikt. I can look at it after I have don
 | |
| 693 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), | |
| 694 HeapConstant(weak_cell_stub.GetCode()), context, | |
| 695 type_feedback_vector, SmiTag(slot_id), constructor); | |
| 696 Goto(&call_construct_function); | |
| 697 } | |
| 698 | |
| 699 Bind(&mark_megamorphic); | |
| 700 { | |
| 701 // MegamorphicSentinel is an immortal immovable object so no write-barrier | |
| 702 // is needed. | |
| 703 DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); | |
| 704 StoreFixedArrayElement( | |
| 705 type_feedback_vector, slot_id, | |
| 706 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), | |
| 707 SKIP_WRITE_BARRIER); | |
| 708 Goto(&call_construct_function); | |
| 709 } | |
| 710 } | |
| 711 | |
| 712 Bind(&call_construct_function); | |
| 713 { | |
| 714 // TODO(mythria): Get allocation site feedback if available. Currently | |
| 715 // we do not collect allocation site feedback. | |
| 716 Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 717 isolate(), CallableType::kJSFunction); | |
| 718 return_value.Bind(CallStub(callable_function.descriptor(), | |
| 719 HeapConstant(callable_function.code()), context, | |
| 720 arg_count, new_target, constructor, first_arg)); | |
| 721 Goto(&end); | |
| 722 } | |
| 723 | |
| 724 Bind(&call_construct); | |
| 725 { | |
| 726 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct( | |
| 727 isolate(), CallableType::kAny); | |
| 728 Node* code_target = HeapConstant(callable.code()); | |
| 729 return_value.Bind(CallStub(callable.descriptor(), code_target, context, | |
| 730 arg_count, new_target, constructor, first_arg)); | |
| 731 Goto(&end); | |
| 732 } | |
| 733 | |
| 734 Bind(&end); | |
| 735 return return_value.value(); | |
| 611 } | 736 } | 
| 612 | 737 | 
| 613 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, | 738 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, | 
| 614 Node* first_arg, Node* arg_count, | 739 Node* first_arg, Node* arg_count, | 
| 615 int result_size) { | 740 int result_size) { | 
| 616 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); | 741 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); | 
| 617 Node* code_target = HeapConstant(callable.code()); | 742 Node* code_target = HeapConstant(callable.code()); | 
| 618 | 743 | 
| 619 // Get the function entry from the function id. | 744 // Get the function entry from the function id. | 
| 620 Node* function_table = ExternalConstant( | 745 Node* function_table = ExternalConstant( | 
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 Goto(&loop); | 1057 Goto(&loop); | 
| 933 } | 1058 } | 
| 934 Bind(&done_loop); | 1059 Bind(&done_loop); | 
| 935 | 1060 | 
| 936 return array; | 1061 return array; | 
| 937 } | 1062 } | 
| 938 | 1063 | 
| 939 } // namespace interpreter | 1064 } // namespace interpreter | 
| 940 } // namespace internal | 1065 } // namespace internal | 
| 941 } // namespace v8 | 1066 } // namespace v8 | 
| OLD | NEW |