Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: src/interpreter/interpreter-assembler.cc

Issue 2153433002: [Interpreter] Collect type feedback for 'new' in the bytecode handler (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/interpreter/interpreter-assembler.h ('k') | test/cctest/cctest.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 // TODO(mythria/v8:5210): Check if it is better to mark extra_checks as a
632 // deferred block so that call_construct_function will be scheduled just
633 // after increment_count and in the fast path we can reduce one branch in the
634 // fast path.
635 Label increment_count(this), extra_checks(this),
636 call_construct_function(this);
637
638 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id);
639 Node* feedback_value = LoadWeakCellValue(feedback_element);
640 Node* is_monomorphic = WordEqual(constructor, feedback_value);
641 BranchIf(is_monomorphic, &increment_count, &extra_checks);
642
643 Bind(&increment_count);
644 {
645 // Increment the call count.
646 Comment("increment call count");
647 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1));
648 Node* call_count =
649 LoadFixedArrayElement(type_feedback_vector, call_count_slot);
650 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1)));
651 // Count is Smi, so we don't need a write barrier.
652 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count,
653 SKIP_WRITE_BARRIER);
654 Goto(&call_construct_function);
655 }
656
657 Bind(&extra_checks);
658 {
659 Label mark_megamorphic(this), initialize(this),
660 check_weak_cell_cleared(this);
661 // Check if it is a megamorphic target
662 Comment("check if megamorphic");
663 Node* is_megamorphic = WordEqual(
664 feedback_element,
665 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())));
666 GotoIf(is_megamorphic, &call_construct_function);
667
668 // Check if it is uninitialized.
669 Comment("check if uninitialized");
670 Node* is_uninitialized = WordEqual(
671 feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex));
672 BranchIf(is_uninitialized, &initialize, &check_weak_cell_cleared);
673
674 Bind(&check_weak_cell_cleared);
675 {
676 Comment("check if weak cell");
677 Node* is_weak_cell = WordEqual(LoadMap(feedback_element),
678 LoadRoot(Heap::kWeakCellMapRootIndex));
679 GotoUnless(is_weak_cell, &mark_megamorphic);
680
681 // If the weak cell is cleared, we have a new chance to become
682 // monomorphic.
683 Comment("check if weak cell is not cleared");
684 Node* is_smi = WordIsSmi(feedback_value);
685 BranchIf(is_smi, &initialize, &mark_megamorphic);
686 }
687
688 Bind(&initialize);
689 {
690 // Check that it is not the Array() function.
691 Comment("check it is not Array()");
692 Node* context_slot =
693 LoadFixedArrayElement(LoadNativeContext(context),
694 Int32Constant(Context::ARRAY_FUNCTION_INDEX));
695 Node* is_array_function = WordEqual(context_slot, constructor);
696 GotoIf(is_array_function, &mark_megamorphic);
697
698 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1));
699 // Count is Smi, so we don't need a write barrier.
700 StoreFixedArrayElement(type_feedback_vector, call_count_slot,
701 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER);
702
703 // TODO(mythria): Inline the weak cell creation/registration.
704 CreateWeakCellStub weak_cell_stub(isolate());
705 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(),
706 HeapConstant(weak_cell_stub.GetCode()), context,
707 type_feedback_vector, SmiTag(slot_id), constructor);
708 Goto(&call_construct_function);
709 }
710
711 Bind(&mark_megamorphic);
712 {
713 // MegamorphicSentinel is an immortal immovable object so no write-barrier
714 // is needed.
715 Comment("transition to megamorphic");
716 DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex));
717 StoreFixedArrayElement(
718 type_feedback_vector, slot_id,
719 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())),
720 SKIP_WRITE_BARRIER);
721 Goto(&call_construct_function);
722 }
723 }
724
725 Bind(&call_construct_function);
726 {
727 // TODO(mythria): Get allocation site feedback if available. Currently
728 // we do not collect allocation site feedback.
729 Comment("call using callConstructFunction");
730 Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct(
731 isolate(), CallableType::kJSFunction);
732 return_value.Bind(CallStub(callable_function.descriptor(),
733 HeapConstant(callable_function.code()), context,
734 arg_count, new_target, constructor, first_arg));
735 Goto(&end);
736 }
737
738 Bind(&call_construct);
739 {
740 Comment("call using callConstruct builtin");
741 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(
742 isolate(), CallableType::kAny);
743 Node* code_target = HeapConstant(callable.code());
744 return_value.Bind(CallStub(callable.descriptor(), code_target, context,
745 arg_count, new_target, constructor, first_arg));
746 Goto(&end);
747 }
748
749 Bind(&end);
750 return return_value.value();
611 } 751 }
612 752
613 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, 753 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context,
614 Node* first_arg, Node* arg_count, 754 Node* first_arg, Node* arg_count,
615 int result_size) { 755 int result_size) {
616 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); 756 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size);
617 Node* code_target = HeapConstant(callable.code()); 757 Node* code_target = HeapConstant(callable.code());
618 758
619 // Get the function entry from the function id. 759 // Get the function entry from the function id.
620 Node* function_table = ExternalConstant( 760 Node* function_table = ExternalConstant(
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 Goto(&loop); 1072 Goto(&loop);
933 } 1073 }
934 Bind(&done_loop); 1074 Bind(&done_loop);
935 1075
936 return array; 1076 return array;
937 } 1077 }
938 1078
939 } // namespace interpreter 1079 } // namespace interpreter
940 } // namespace internal 1080 } // namespace internal
941 } // namespace v8 1081 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter-assembler.h ('k') | test/cctest/cctest.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698