Index: src/x64/code-stubs-x64.cc |
diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc |
index ec42c8967fac84b5faefe5d565585fb5927094e2..b8721badd9470bdc9610b9c6769b01986b209bbd 100644 |
--- a/src/x64/code-stubs-x64.cc |
+++ b/src/x64/code-stubs-x64.cc |
@@ -75,6 +75,10 @@ void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
static void InitializeArrayConstructorDescriptor(Isolate* isolate, |
CodeStubInterfaceDescriptor* descriptor) { |
+ // register state |
+ // rdi -- constructor function |
+ // rbx -- type info cell with elements kind |
+ // rax -- number of arguments to the constructor function |
static Register registers[] = { rdi, rbx }; |
descriptor->register_param_count_ = 2; |
// stack param count needs (constructor pointer, and single argument) |
@@ -3884,12 +3888,52 @@ void InterruptStub::Generate(MacroAssembler* masm) { |
} |
+static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) { |
+ // Cache the called function in a global property cell. Cache states |
+ // are uninitialized, monomorphic (indicated by a JSFunction), and |
+ // megamorphic. |
+ // rbx : cache cell for call target |
+ // rdi : the function to call |
+ ASSERT(!FLAG_optimize_constructed_arrays); |
+ Isolate* isolate = masm->isolate(); |
+ Label initialize, done; |
+ |
+ // Load the cache state into rcx. |
+ __ movq(rcx, FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset)); |
+ |
+ // A monomorphic cache hit or an already megamorphic state: invoke the |
+ // function without changing the state. |
+ __ cmpq(rcx, rdi); |
+ __ j(equal, &done, Label::kNear); |
+ __ Cmp(rcx, TypeFeedbackCells::MegamorphicSentinel(isolate)); |
+ __ j(equal, &done, Label::kNear); |
+ |
+ // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
+ // megamorphic. |
+ __ Cmp(rcx, TypeFeedbackCells::UninitializedSentinel(isolate)); |
+ __ j(equal, &initialize, Label::kNear); |
+ // MegamorphicSentinel is an immortal immovable object (undefined) so no |
+ // write-barrier is needed. |
+ __ Move(FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset), |
+ TypeFeedbackCells::MegamorphicSentinel(isolate)); |
+ __ jmp(&done, Label::kNear); |
+ |
+ // An uninitialized cache is patched with the function. |
+ __ bind(&initialize); |
+ __ movq(FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset), rdi); |
+ // No need for a write barrier here - cells are rescanned. |
+ |
+ __ bind(&done); |
+} |
+ |
+ |
static void GenerateRecordCallTarget(MacroAssembler* masm) { |
// Cache the called function in a global property cell. Cache states |
// are uninitialized, monomorphic (indicated by a JSFunction), and |
// megamorphic. |
// rbx : cache cell for call target |
// rdi : the function to call |
+ ASSERT(FLAG_optimize_constructed_arrays); |
Isolate* isolate = masm->isolate(); |
Label initialize, done, miss, megamorphic, not_array_function; |
@@ -3899,37 +3943,30 @@ static void GenerateRecordCallTarget(MacroAssembler* masm) { |
// A monomorphic cache hit or an already megamorphic state: invoke the |
// function without changing the state. |
__ cmpq(rcx, rdi); |
- __ j(equal, &done, Label::kFar); |
+ __ j(equal, &done); |
__ Cmp(rcx, TypeFeedbackCells::MegamorphicSentinel(isolate)); |
- __ j(equal, &done, Label::kFar); |
+ __ j(equal, &done); |
// Special handling of the Array() function, which caches not only the |
// monomorphic Array function but the initial ElementsKind with special |
// sentinels |
Handle<Object> terminal_kind_sentinel = |
- TypeFeedbackCells::MonomorphicArraySentinel(LAST_FAST_ELEMENTS_KIND); |
+ TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
+ LAST_FAST_ELEMENTS_KIND); |
__ Cmp(rcx, terminal_kind_sentinel); |
- __ j(not_equal, &miss, Label::kFar); |
- // Load the global or builtins object from the current context |
- __ movq(rcx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
- __ movq(rcx, FieldOperand(rcx, GlobalObject::kGlobalContextOffset)); |
- __ movq(rcx, |
- Operand(rcx, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
+ __ j(not_equal, &miss); |
// Make sure the function is the Array() function |
+ __ LoadArrayFunction(rcx); |
__ cmpq(rdi, rcx); |
- Label megamorphic_pre; |
- __ j(not_equal, &megamorphic_pre, Label::kFar); |
+ __ j(not_equal, &megamorphic); |
__ jmp(&done); |
- __ bind(&megamorphic_pre); |
- __ jmp(&megamorphic, Label::kFar); |
- |
__ bind(&miss); |
// A monomorphic miss (i.e, here the cache is not uninitialized) goes |
// megamorphic. |
__ Cmp(rcx, TypeFeedbackCells::UninitializedSentinel(isolate)); |
- __ j(equal, &initialize, Label::kFar); |
+ __ j(equal, &initialize); |
// MegamorphicSentinel is an immortal immovable object (undefined) so no |
// write-barrier is needed. |
__ bind(&megamorphic); |
@@ -3940,11 +3977,8 @@ static void GenerateRecordCallTarget(MacroAssembler* masm) { |
// An uninitialized cache is patched with the function or sentinel to |
// indicate the ElementsKind if function is the Array constructor. |
__ bind(&initialize); |
- __ movq(rcx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
- __ movq(rcx, FieldOperand(rcx, GlobalObject::kGlobalContextOffset)); |
- __ movq(rcx, |
- Operand(rcx, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
// Make sure the function is the Array() function |
+ __ LoadArrayFunction(rcx); |
__ cmpq(rdi, rcx); |
__ j(not_equal, ¬_array_function); |
@@ -3952,7 +3986,7 @@ static void GenerateRecordCallTarget(MacroAssembler* masm) { |
// the constructor's type info cell that will track the initial ElementsKind |
// that should be used for the array when its constructed. |
Handle<Object> initial_kind_sentinel = |
- TypeFeedbackCells::MonomorphicArraySentinel( |
+ TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
GetInitialFastElementsKind()); |
__ Move(FieldOperand(rbx, JSGlobalPropertyCell::kValueOffset), |
initial_kind_sentinel); |
@@ -3997,7 +4031,11 @@ void CallFunctionStub::Generate(MacroAssembler* masm) { |
__ j(not_equal, &slow); |
if (RecordCallTarget()) { |
- GenerateRecordCallTarget(masm); |
+ if (FLAG_optimize_constructed_arrays) { |
+ GenerateRecordCallTarget(masm); |
+ } else { |
+ GenerateRecordCallTargetNoArray(masm); |
+ } |
} |
// Fast-case: Just invoke the function. |
@@ -4072,14 +4110,20 @@ void CallConstructStub::Generate(MacroAssembler* masm) { |
__ j(not_equal, &slow); |
if (RecordCallTarget()) { |
- GenerateRecordCallTarget(masm); |
+ if (FLAG_optimize_constructed_arrays) { |
+ GenerateRecordCallTarget(masm); |
+ } else { |
+ GenerateRecordCallTargetNoArray(masm); |
+ } |
} |
// Jump to the function-specific construct stub. |
- __ movq(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
- __ movq(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); |
- __ lea(rcx, FieldOperand(rcx, Code::kHeaderSize)); |
- __ jmp(rcx); |
+ Register jmp_reg = FLAG_optimize_constructed_arrays ? rcx : rbx; |
+ __ movq(jmp_reg, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
+ __ movq(jmp_reg, FieldOperand(jmp_reg, |
+ SharedFunctionInfo::kConstructStubOffset)); |
+ __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
+ __ jmp(jmp_reg); |
// rdi: called object |
// rax: number of arguments |