Chromium Code Reviews| Index: src/interpreter/interpreter-assembler.cc |
| diff --git a/src/interpreter/interpreter-assembler.cc b/src/interpreter/interpreter-assembler.cc |
| index 8f5d941e5a2e6632fd93c8a0965fc5999375e629..bc74747de546808463ad5fe3f0ee4721dde4a1bb 100644 |
| --- a/src/interpreter/interpreter-assembler.cc |
| +++ b/src/interpreter/interpreter-assembler.cc |
| @@ -467,7 +467,7 @@ Node* InterpreterAssembler::CallJSWithFeedback(Node* function, Node* context, |
| Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); |
| GotoIf(is_feedback_unavailable, &call); |
| - // The checks. First, does rdi match the recorded monomorphic target? |
| + // The checks. First, does function match the recorded monomorphic target? |
| Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); |
| Node* feedback_value = LoadWeakCellValue(feedback_element); |
| Node* is_monomorphic = WordEqual(function, feedback_value); |
| @@ -546,6 +546,7 @@ Node* InterpreterAssembler::CallJSWithFeedback(Node* function, Node* context, |
| StoreFixedArrayElement(type_feedback_vector, call_count_slot, |
| SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); |
| + // TODO(mythria): Inline the weak cell creation/registration. |
| CreateWeakCellStub weak_cell_stub(isolate()); |
| CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), |
| HeapConstant(weak_cell_stub.GetCode()), context, |
| @@ -603,11 +604,137 @@ Node* InterpreterAssembler::CallJS(Node* function, Node* context, |
| Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, |
| Node* new_target, Node* first_arg, |
| - Node* arg_count) { |
| - Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); |
| - Node* code_target = HeapConstant(callable.code()); |
| - return CallStub(callable.descriptor(), code_target, context, arg_count, |
| - new_target, constructor, first_arg); |
| + Node* arg_count, Node* slot_id, |
| + Node* type_feedback_vector) { |
| + Label call_construct(this), js_function(this), end(this); |
| + Variable return_value(this, MachineRepresentation::kTagged); |
| + |
| + // Slot id of 0 is used to indicate no typefeedback is available. |
| + STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); |
| + Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); |
| + GotoIf(is_feedback_unavailable, &call_construct); |
| + |
| + // Check that the constructor is not a smi. |
| + Node* is_smi = WordIsSmi(constructor); |
| + GotoIf(is_smi, &call_construct); |
| + |
| + // Check that constructor is a JSFunction. |
| + Node* instance_type = LoadInstanceType(constructor); |
| + Node* is_js_function = |
| + WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); |
| + BranchIf(is_js_function, &js_function, &call_construct); |
| + |
| + Bind(&js_function); |
| + // Cache the called function in a feedback vector slot. Cache states |
| + // are uninitialized, monomorphic (indicated by a JSFunction), and |
| + // megamorphic. |
| + 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
|
| + call_construct_function(this); |
| + |
| + Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); |
| + Node* feedback_value = LoadWeakCellValue(feedback_element); |
| + Node* is_monomorphic = WordEqual(constructor, feedback_value); |
| + BranchIf(is_monomorphic, &increment_count, &extra_checks); |
| + |
| + Bind(&increment_count); |
| + { |
| + // Increment the call count. |
| + Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); |
| + Node* call_count = |
| + LoadFixedArrayElement(type_feedback_vector, call_count_slot); |
| + Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); |
| + // Count is Smi, so we don't need a write barrier. |
| + StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, |
| + SKIP_WRITE_BARRIER); |
| + Goto(&call_construct_function); |
| + } |
| + |
| + Bind(&extra_checks); |
| + { |
| + Label mark_megamorphic(this), initialize(this), |
| + 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
|
| + // Check if it is a megamorphic target |
| + Node* is_megamorphic = WordEqual( |
| + feedback_element, |
| + HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); |
| + GotoIf(is_megamorphic, &call_construct_function); |
| + |
| + // Check if it is uninitialized. |
| + Node* is_uninitialized = WordEqual( |
| + feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex)); |
| + BranchIf(is_uninitialized, &initialize, &check_weak_cell_cleared); |
| + |
| + Bind(&check_weak_cell_cleared); |
| + { |
| + Node* is_weak_cell = WordEqual(LoadMap(feedback_element), |
| + LoadRoot(Heap::kWeakCellMapRootIndex)); |
| + GotoUnless(is_weak_cell, &mark_megamorphic); |
| + |
| + // If the weak cell is cleared, we have a new chance to become |
| + // monomorphic. |
| + Node* is_smi = WordIsSmi(feedback_value); |
| + BranchIf(is_smi, &initialize, &mark_megamorphic); |
| + } |
| + |
| + Bind(&initialize); |
| + { |
| + // Check that it is not the Array() function. |
| + Node* context_slot = |
| + LoadFixedArrayElement(LoadNativeContext(context), |
| + Int32Constant(Context::ARRAY_FUNCTION_INDEX)); |
| + Node* is_array_function = WordEqual(context_slot, constructor); |
| + GotoIf(is_array_function, &mark_megamorphic); |
| + |
| + Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); |
| + // Count is Smi, so we don't need a write barrier. |
| + StoreFixedArrayElement(type_feedback_vector, call_count_slot, |
| + SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); |
| + |
| + // TODO(mythria): Inline the weak cell creation/registration. |
| + CreateWeakCellStub weak_cell_stub(isolate()); |
| + CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), |
| + HeapConstant(weak_cell_stub.GetCode()), context, |
| + type_feedback_vector, SmiTag(slot_id), constructor); |
| + Goto(&call_construct_function); |
| + } |
| + |
| + Bind(&mark_megamorphic); |
| + { |
| + // MegamorphicSentinel is an immortal immovable object so no write-barrier |
| + // is needed. |
| + DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); |
| + StoreFixedArrayElement( |
| + type_feedback_vector, slot_id, |
| + HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), |
| + SKIP_WRITE_BARRIER); |
| + Goto(&call_construct_function); |
| + } |
| + } |
| + |
| + Bind(&call_construct_function); |
| + { |
| + // TODO(mythria): Get allocation site feedback if available. Currently |
| + // we do not collect allocation site feedback. |
| + Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct( |
| + isolate(), CallableType::kJSFunction); |
| + return_value.Bind(CallStub(callable_function.descriptor(), |
| + HeapConstant(callable_function.code()), context, |
| + arg_count, new_target, constructor, first_arg)); |
| + Goto(&end); |
| + } |
| + |
| + Bind(&call_construct); |
| + { |
| + Callable callable = CodeFactory::InterpreterPushArgsAndConstruct( |
| + isolate(), CallableType::kAny); |
| + Node* code_target = HeapConstant(callable.code()); |
| + return_value.Bind(CallStub(callable.descriptor(), code_target, context, |
| + arg_count, new_target, constructor, first_arg)); |
| + Goto(&end); |
| + } |
| + |
| + Bind(&end); |
| + return return_value.value(); |
| } |
| Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, |