OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
8 | 8 |
9 #include "codegen.h" | 9 #include "codegen.h" |
10 #include "deoptimizer.h" | 10 #include "deoptimizer.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 CallRuntimePassFunction(masm, Runtime::kHiddenTryInstallOptimizedCode); | 94 CallRuntimePassFunction(masm, Runtime::kHiddenTryInstallOptimizedCode); |
95 GenerateTailCallToReturnedCode(masm); | 95 GenerateTailCallToReturnedCode(masm); |
96 | 96 |
97 __ bind(&ok); | 97 __ bind(&ok); |
98 GenerateTailCallToSharedCode(masm); | 98 GenerateTailCallToSharedCode(masm); |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 102 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
103 bool is_api_function, | 103 bool is_api_function, |
104 bool count_constructions, | |
105 bool create_memento) { | 104 bool create_memento) { |
106 // ----------- S t a t e ------------- | 105 // ----------- S t a t e ------------- |
107 // -- rax: number of arguments | 106 // -- rax: number of arguments |
108 // -- rdi: constructor function | 107 // -- rdi: constructor function |
109 // -- rbx: allocation site or undefined | 108 // -- rbx: allocation site or undefined |
110 // ----------------------------------- | 109 // ----------------------------------- |
111 | 110 |
112 // Should never count constructions for api objects. | |
113 ASSERT(!is_api_function || !count_constructions);\ | |
114 | |
115 // Should never create mementos for api functions. | 111 // Should never create mementos for api functions. |
116 ASSERT(!is_api_function || !create_memento); | 112 ASSERT(!is_api_function || !create_memento); |
117 | 113 |
118 // Should never create mementos before slack tracking is finished. | |
119 ASSERT(!count_constructions || !create_memento); | |
120 | |
121 // Enter a construct frame. | 114 // Enter a construct frame. |
122 { | 115 { |
123 FrameScope scope(masm, StackFrame::CONSTRUCT); | 116 FrameScope scope(masm, StackFrame::CONSTRUCT); |
124 | 117 |
125 if (create_memento) { | 118 if (create_memento) { |
126 __ AssertUndefinedOrAllocationSite(rbx); | 119 __ AssertUndefinedOrAllocationSite(rbx); |
127 __ Push(rbx); | 120 __ Push(rbx); |
128 } | 121 } |
129 | 122 |
130 // Store a smi-tagged arguments count on the stack. | 123 // Store a smi-tagged arguments count on the stack. |
(...skipping 28 matching lines...) Expand all Loading... |
159 __ j(not_equal, &rt_call); | 152 __ j(not_equal, &rt_call); |
160 | 153 |
161 // Check that the constructor is not constructing a JSFunction (see | 154 // Check that the constructor is not constructing a JSFunction (see |
162 // comments in Runtime_NewObject in runtime.cc). In which case the | 155 // comments in Runtime_NewObject in runtime.cc). In which case the |
163 // initial map's instance type would be JS_FUNCTION_TYPE. | 156 // initial map's instance type would be JS_FUNCTION_TYPE. |
164 // rdi: constructor | 157 // rdi: constructor |
165 // rax: initial map | 158 // rax: initial map |
166 __ CmpInstanceType(rax, JS_FUNCTION_TYPE); | 159 __ CmpInstanceType(rax, JS_FUNCTION_TYPE); |
167 __ j(equal, &rt_call); | 160 __ j(equal, &rt_call); |
168 | 161 |
169 if (count_constructions) { | 162 if (!is_api_function) { |
170 Label allocate; | 163 Label allocate; |
| 164 // The code below relies on these assumptions. |
| 165 STATIC_ASSERT(JSFunction::kNoSlackTracking == 0); |
| 166 STATIC_ASSERT(Map::ConstructionCount::kShift + |
| 167 Map::ConstructionCount::kSize == 32); |
| 168 // Check if slack tracking is enabled. |
| 169 __ movl(rsi, FieldOperand(rax, Map::kBitField3Offset)); |
| 170 __ shrl(rsi, Immediate(Map::ConstructionCount::kShift)); |
| 171 __ j(zero, &allocate); // JSFunction::kNoSlackTracking |
171 // Decrease generous allocation count. | 172 // Decrease generous allocation count. |
172 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 173 __ subl(FieldOperand(rax, Map::kBitField3Offset), |
173 __ decb(FieldOperand(rcx, | 174 Immediate(1 << Map::ConstructionCount::kShift)); |
174 SharedFunctionInfo::kConstructionCountOffset)); | 175 |
175 __ j(not_zero, &allocate); | 176 __ cmpl(rsi, Immediate(JSFunction::kFinishSlackTracking)); |
| 177 __ j(not_equal, &allocate); |
176 | 178 |
177 __ Push(rax); | 179 __ Push(rax); |
178 __ Push(rdi); | 180 __ Push(rdi); |
179 | 181 |
180 __ Push(rdi); // constructor | 182 __ Push(rdi); // constructor |
181 // The call will replace the stub, so the countdown is only done once. | |
182 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); | 183 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); |
183 | 184 |
184 __ Pop(rdi); | 185 __ Pop(rdi); |
185 __ Pop(rax); | 186 __ Pop(rax); |
| 187 __ xorl(rsi, rsi); // JSFunction::kNoSlackTracking |
186 | 188 |
187 __ bind(&allocate); | 189 __ bind(&allocate); |
188 } | 190 } |
189 | 191 |
190 // Now allocate the JSObject on the heap. | 192 // Now allocate the JSObject on the heap. |
191 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); | 193 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); |
192 __ shlp(rdi, Immediate(kPointerSizeLog2)); | 194 __ shlp(rdi, Immediate(kPointerSizeLog2)); |
193 if (create_memento) { | 195 if (create_memento) { |
194 __ addp(rdi, Immediate(AllocationMemento::kSize)); | 196 __ addp(rdi, Immediate(AllocationMemento::kSize)); |
195 } | 197 } |
(...skipping 10 matching lines...) Expand all Loading... |
206 // rbx: JSObject (not HeapObject tagged - the actual address). | 208 // rbx: JSObject (not HeapObject tagged - the actual address). |
207 // rdi: start of next object (including memento if create_memento) | 209 // rdi: start of next object (including memento if create_memento) |
208 __ movp(Operand(rbx, JSObject::kMapOffset), rax); | 210 __ movp(Operand(rbx, JSObject::kMapOffset), rax); |
209 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); | 211 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); |
210 __ movp(Operand(rbx, JSObject::kPropertiesOffset), rcx); | 212 __ movp(Operand(rbx, JSObject::kPropertiesOffset), rcx); |
211 __ movp(Operand(rbx, JSObject::kElementsOffset), rcx); | 213 __ movp(Operand(rbx, JSObject::kElementsOffset), rcx); |
212 // Set extra fields in the newly allocated object. | 214 // Set extra fields in the newly allocated object. |
213 // rax: initial map | 215 // rax: initial map |
214 // rbx: JSObject | 216 // rbx: JSObject |
215 // rdi: start of next object (including memento if create_memento) | 217 // rdi: start of next object (including memento if create_memento) |
| 218 // rsi: slack tracking counter (non-API function case) |
216 __ leap(rcx, Operand(rbx, JSObject::kHeaderSize)); | 219 __ leap(rcx, Operand(rbx, JSObject::kHeaderSize)); |
217 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 220 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
218 if (count_constructions) { | 221 if (!is_api_function) { |
| 222 Label no_inobject_slack_tracking; |
| 223 |
| 224 // Check if slack tracking is enabled. |
| 225 __ cmpl(rsi, Immediate(JSFunction::kNoSlackTracking)); |
| 226 __ j(equal, &no_inobject_slack_tracking); |
| 227 |
| 228 // Allocate object with a slack. |
219 __ movzxbp(rsi, | 229 __ movzxbp(rsi, |
220 FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); | 230 FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); |
221 __ leap(rsi, | 231 __ leap(rsi, |
222 Operand(rbx, rsi, times_pointer_size, JSObject::kHeaderSize)); | 232 Operand(rbx, rsi, times_pointer_size, JSObject::kHeaderSize)); |
223 // rsi: offset of first field after pre-allocated fields | 233 // rsi: offset of first field after pre-allocated fields |
224 if (FLAG_debug_code) { | 234 if (FLAG_debug_code) { |
225 __ cmpp(rsi, rdi); | 235 __ cmpp(rsi, rdi); |
226 __ Assert(less_equal, | 236 __ Assert(less_equal, |
227 kUnexpectedNumberOfPreAllocatedPropertyFields); | 237 kUnexpectedNumberOfPreAllocatedPropertyFields); |
228 } | 238 } |
229 __ InitializeFieldsWithFiller(rcx, rsi, rdx); | 239 __ InitializeFieldsWithFiller(rcx, rsi, rdx); |
230 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); | 240 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); |
231 __ InitializeFieldsWithFiller(rcx, rdi, rdx); | 241 // Fill the remaining fields with one pointer filler map. |
232 } else if (create_memento) { | 242 |
| 243 __ bind(&no_inobject_slack_tracking); |
| 244 } |
| 245 if (create_memento) { |
233 __ leap(rsi, Operand(rdi, -AllocationMemento::kSize)); | 246 __ leap(rsi, Operand(rdi, -AllocationMemento::kSize)); |
234 __ InitializeFieldsWithFiller(rcx, rsi, rdx); | 247 __ InitializeFieldsWithFiller(rcx, rsi, rdx); |
235 | 248 |
236 // Fill in memento fields if necessary. | 249 // Fill in memento fields if necessary. |
237 // rsi: points to the allocated but uninitialized memento. | 250 // rsi: points to the allocated but uninitialized memento. |
238 Handle<Map> allocation_memento_map = factory->allocation_memento_map(); | |
239 __ Move(Operand(rsi, AllocationMemento::kMapOffset), | 251 __ Move(Operand(rsi, AllocationMemento::kMapOffset), |
240 allocation_memento_map); | 252 factory->allocation_memento_map()); |
241 // Get the cell or undefined. | 253 // Get the cell or undefined. |
242 __ movp(rdx, Operand(rsp, kPointerSize*2)); | 254 __ movp(rdx, Operand(rsp, kPointerSize*2)); |
243 __ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), | 255 __ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), rdx); |
244 rdx); | |
245 } else { | 256 } else { |
246 __ InitializeFieldsWithFiller(rcx, rdi, rdx); | 257 __ InitializeFieldsWithFiller(rcx, rdi, rdx); |
247 } | 258 } |
248 | 259 |
249 // Add the object tag to make the JSObject real, so that we can continue | 260 // Add the object tag to make the JSObject real, so that we can continue |
250 // and jump into the continuation code at any time from now on. Any | 261 // and jump into the continuation code at any time from now on. Any |
251 // failures need to undo the allocation, so that the heap is in a | 262 // failures need to undo the allocation, so that the heap is in a |
252 // consistent state and verifiable. | 263 // consistent state and verifiable. |
253 // rax: initial map | 264 // rax: initial map |
254 // rbx: JSObject | 265 // rbx: JSObject |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 420 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
410 Handle<Code> code = | 421 Handle<Code> code = |
411 masm->isolate()->builtins()->HandleApiCallConstruct(); | 422 masm->isolate()->builtins()->HandleApiCallConstruct(); |
412 __ Call(code, RelocInfo::CODE_TARGET); | 423 __ Call(code, RelocInfo::CODE_TARGET); |
413 } else { | 424 } else { |
414 ParameterCount actual(rax); | 425 ParameterCount actual(rax); |
415 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); | 426 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); |
416 } | 427 } |
417 | 428 |
418 // Store offset of return address for deoptimizer. | 429 // Store offset of return address for deoptimizer. |
419 if (!is_api_function && !count_constructions) { | 430 if (!is_api_function) { |
420 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); | 431 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); |
421 } | 432 } |
422 | 433 |
423 // Restore context from the frame. | 434 // Restore context from the frame. |
424 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 435 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
425 | 436 |
426 // If the result is an object (in the ECMA sense), we should get rid | 437 // If the result is an object (in the ECMA sense), we should get rid |
427 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | 438 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
428 // on page 74. | 439 // on page 74. |
429 Label use_receiver, exit; | 440 Label use_receiver, exit; |
(...skipping 22 matching lines...) Expand all Loading... |
452 __ PopReturnAddressTo(rcx); | 463 __ PopReturnAddressTo(rcx); |
453 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 464 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
454 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 465 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
455 __ PushReturnAddressFrom(rcx); | 466 __ PushReturnAddressFrom(rcx); |
456 Counters* counters = masm->isolate()->counters(); | 467 Counters* counters = masm->isolate()->counters(); |
457 __ IncrementCounter(counters->constructed_objects(), 1); | 468 __ IncrementCounter(counters->constructed_objects(), 1); |
458 __ ret(0); | 469 __ ret(0); |
459 } | 470 } |
460 | 471 |
461 | 472 |
462 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { | |
463 Generate_JSConstructStubHelper(masm, false, true, false); | |
464 } | |
465 | |
466 | |
467 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 473 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
468 Generate_JSConstructStubHelper(masm, false, false, FLAG_pretenuring_call_new); | 474 Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new); |
469 } | 475 } |
470 | 476 |
471 | 477 |
472 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 478 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
473 Generate_JSConstructStubHelper(masm, true, false, false); | 479 Generate_JSConstructStubHelper(masm, true, false); |
474 } | 480 } |
475 | 481 |
476 | 482 |
477 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 483 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
478 bool is_construct) { | 484 bool is_construct) { |
479 ProfileEntryHookStub::MaybeCallEntryHook(masm); | 485 ProfileEntryHookStub::MaybeCallEntryHook(masm); |
480 | 486 |
481 // Expects five C++ function parameters. | 487 // Expects five C++ function parameters. |
482 // - Address entry (ignored) | 488 // - Address entry (ignored) |
483 // - JSFunction* function ( | 489 // - JSFunction* function ( |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 __ bind(&ok); | 1512 __ bind(&ok); |
1507 __ ret(0); | 1513 __ ret(0); |
1508 } | 1514 } |
1509 | 1515 |
1510 | 1516 |
1511 #undef __ | 1517 #undef __ |
1512 | 1518 |
1513 } } // namespace v8::internal | 1519 } } // namespace v8::internal |
1514 | 1520 |
1515 #endif // V8_TARGET_ARCH_X64 | 1521 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |