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) { |
| 163 // rsi: slack tracking counter |
170 Label allocate; | 164 Label allocate; |
| 165 // The code below relies on these assumptions. |
| 166 STATIC_ASSERT(JSFunction::kNoSlackTracking == 0); |
| 167 STATIC_ASSERT(Map::ConstructionCount::kShift + |
| 168 Map::ConstructionCount::kSize == 32); |
| 169 // Check if slack tracking is enabled. |
| 170 __ movl(rsi, FieldOperand(rax, Map::kBitField3Offset)); |
| 171 __ shrl(rsi, Immediate(Map::ConstructionCount::kShift)); |
| 172 __ j(zero, &allocate); // JSFunction::kNoSlackTracking |
171 // Decrease generous allocation count. | 173 // Decrease generous allocation count. |
172 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 174 __ subl(FieldOperand(rax, Map::kBitField3Offset), |
173 __ decb(FieldOperand(rcx, | 175 Immediate(1 << Map::ConstructionCount::kShift)); |
174 SharedFunctionInfo::kConstructionCountOffset)); | 176 |
175 __ j(not_zero, &allocate); | 177 __ cmpl(rsi, Immediate(JSFunction::kFinishSlackTracking)); |
| 178 __ j(not_equal, &allocate); |
176 | 179 |
177 __ Push(rax); | 180 __ Push(rax); |
178 __ Push(rdi); | 181 __ Push(rdi); |
179 | 182 |
180 __ Push(rdi); // constructor | 183 __ Push(rdi); // constructor |
181 // The call will replace the stub, so the countdown is only done once. | |
182 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); | 184 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); |
183 | 185 |
184 __ Pop(rdi); | 186 __ Pop(rdi); |
185 __ Pop(rax); | 187 __ Pop(rax); |
| 188 __ xorl(rsi, rsi); // JSFunction::kNoSlackTracking |
186 | 189 |
187 __ bind(&allocate); | 190 __ bind(&allocate); |
188 } | 191 } |
189 | 192 |
190 // Now allocate the JSObject on the heap. | 193 // Now allocate the JSObject on the heap. |
191 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); | 194 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); |
192 __ shlp(rdi, Immediate(kPointerSizeLog2)); | 195 __ shlp(rdi, Immediate(kPointerSizeLog2)); |
193 if (create_memento) { | 196 if (create_memento) { |
194 __ addp(rdi, Immediate(AllocationMemento::kSize)); | 197 __ addp(rdi, Immediate(AllocationMemento::kSize)); |
195 } | 198 } |
(...skipping 10 matching lines...) Expand all Loading... |
206 // rbx: JSObject (not HeapObject tagged - the actual address). | 209 // rbx: JSObject (not HeapObject tagged - the actual address). |
207 // rdi: start of next object (including memento if create_memento) | 210 // rdi: start of next object (including memento if create_memento) |
208 __ movp(Operand(rbx, JSObject::kMapOffset), rax); | 211 __ movp(Operand(rbx, JSObject::kMapOffset), rax); |
209 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); | 212 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); |
210 __ movp(Operand(rbx, JSObject::kPropertiesOffset), rcx); | 213 __ movp(Operand(rbx, JSObject::kPropertiesOffset), rcx); |
211 __ movp(Operand(rbx, JSObject::kElementsOffset), rcx); | 214 __ movp(Operand(rbx, JSObject::kElementsOffset), rcx); |
212 // Set extra fields in the newly allocated object. | 215 // Set extra fields in the newly allocated object. |
213 // rax: initial map | 216 // rax: initial map |
214 // rbx: JSObject | 217 // rbx: JSObject |
215 // rdi: start of next object (including memento if create_memento) | 218 // rdi: start of next object (including memento if create_memento) |
| 219 // rsi: slack tracking counter (non-API function case) |
216 __ leap(rcx, Operand(rbx, JSObject::kHeaderSize)); | 220 __ leap(rcx, Operand(rbx, JSObject::kHeaderSize)); |
217 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 221 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
218 if (count_constructions) { | 222 if (is_api_function) { |
| 223 __ InitializeFieldsWithFiller(rcx, rdi, rdx); |
| 224 } else { |
| 225 Label no_inobject_slack_tracking, done_field_initialization; |
| 226 |
| 227 // Check if slack tracking is enabled. |
| 228 __ cmpl(rsi, |
| 229 Immediate(static_cast<int32_t>(JSFunction::kNoSlackTracking))); |
| 230 __ j(equal, &no_inobject_slack_tracking); |
| 231 |
| 232 // Allocate object with a slack. |
219 __ movzxbp(rsi, | 233 __ movzxbp(rsi, |
220 FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); | 234 FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); |
221 __ leap(rsi, | 235 __ leap(rsi, |
222 Operand(rbx, rsi, times_pointer_size, JSObject::kHeaderSize)); | 236 Operand(rbx, rsi, times_pointer_size, JSObject::kHeaderSize)); |
223 // rsi: offset of first field after pre-allocated fields | 237 // rsi: offset of first field after pre-allocated fields |
224 if (FLAG_debug_code) { | 238 if (FLAG_debug_code) { |
225 __ cmpp(rsi, rdi); | 239 __ cmpp(rsi, rdi); |
226 __ Assert(less_equal, | 240 __ Assert(less_equal, |
227 kUnexpectedNumberOfPreAllocatedPropertyFields); | 241 kUnexpectedNumberOfPreAllocatedPropertyFields); |
228 } | 242 } |
229 __ InitializeFieldsWithFiller(rcx, rsi, rdx); | 243 __ InitializeFieldsWithFiller(rcx, rsi, rdx); |
230 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); | 244 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); |
231 __ InitializeFieldsWithFiller(rcx, rdi, rdx); | 245 __ InitializeFieldsWithFiller(rcx, rdi, rdx); |
232 } else if (create_memento) { | 246 __ jmp(&done_field_initialization); |
233 __ leap(rsi, Operand(rdi, -AllocationMemento::kSize)); | |
234 __ InitializeFieldsWithFiller(rcx, rsi, rdx); | |
235 | 247 |
236 // Fill in memento fields if necessary. | 248 __ bind(&no_inobject_slack_tracking); |
237 // rsi: points to the allocated but uninitialized memento. | 249 if (create_memento) { |
238 Handle<Map> allocation_memento_map = factory->allocation_memento_map(); | 250 __ leap(rsi, Operand(rdi, -AllocationMemento::kSize)); |
239 __ Move(Operand(rsi, AllocationMemento::kMapOffset), | 251 __ InitializeFieldsWithFiller(rcx, rsi, rdx); |
240 allocation_memento_map); | 252 |
241 // Get the cell or undefined. | 253 // Fill in memento fields if necessary. |
242 __ movp(rdx, Operand(rsp, kPointerSize*2)); | 254 // rsi: points to the allocated but uninitialized memento. |
243 __ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), | 255 __ Move(Operand(rsi, AllocationMemento::kMapOffset), |
244 rdx); | 256 factory->allocation_memento_map()); |
245 } else { | 257 // Get the cell or undefined. |
246 __ InitializeFieldsWithFiller(rcx, rdi, rdx); | 258 __ movp(rdx, Operand(rsp, kPointerSize*2)); |
| 259 __ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), rdx); |
| 260 } else { |
| 261 __ InitializeFieldsWithFiller(rcx, rdi, rdx); |
| 262 } |
| 263 __ bind(&done_field_initialization); |
247 } | 264 } |
248 | 265 |
249 // Add the object tag to make the JSObject real, so that we can continue | 266 // 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 | 267 // 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 | 268 // failures need to undo the allocation, so that the heap is in a |
252 // consistent state and verifiable. | 269 // consistent state and verifiable. |
253 // rax: initial map | 270 // rax: initial map |
254 // rbx: JSObject | 271 // rbx: JSObject |
255 // rdi: start of next object | 272 // rdi: start of next object |
256 __ orp(rbx, Immediate(kHeapObjectTag)); | 273 __ orp(rbx, Immediate(kHeapObjectTag)); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 426 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
410 Handle<Code> code = | 427 Handle<Code> code = |
411 masm->isolate()->builtins()->HandleApiCallConstruct(); | 428 masm->isolate()->builtins()->HandleApiCallConstruct(); |
412 __ Call(code, RelocInfo::CODE_TARGET); | 429 __ Call(code, RelocInfo::CODE_TARGET); |
413 } else { | 430 } else { |
414 ParameterCount actual(rax); | 431 ParameterCount actual(rax); |
415 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); | 432 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); |
416 } | 433 } |
417 | 434 |
418 // Store offset of return address for deoptimizer. | 435 // Store offset of return address for deoptimizer. |
419 if (!is_api_function && !count_constructions) { | 436 if (!is_api_function) { |
420 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); | 437 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); |
421 } | 438 } |
422 | 439 |
423 // Restore context from the frame. | 440 // Restore context from the frame. |
424 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 441 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
425 | 442 |
426 // If the result is an object (in the ECMA sense), we should get rid | 443 // 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 | 444 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
428 // on page 74. | 445 // on page 74. |
429 Label use_receiver, exit; | 446 Label use_receiver, exit; |
(...skipping 22 matching lines...) Expand all Loading... |
452 __ PopReturnAddressTo(rcx); | 469 __ PopReturnAddressTo(rcx); |
453 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 470 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
454 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 471 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
455 __ PushReturnAddressFrom(rcx); | 472 __ PushReturnAddressFrom(rcx); |
456 Counters* counters = masm->isolate()->counters(); | 473 Counters* counters = masm->isolate()->counters(); |
457 __ IncrementCounter(counters->constructed_objects(), 1); | 474 __ IncrementCounter(counters->constructed_objects(), 1); |
458 __ ret(0); | 475 __ ret(0); |
459 } | 476 } |
460 | 477 |
461 | 478 |
462 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { | |
463 Generate_JSConstructStubHelper(masm, false, true, false); | |
464 } | |
465 | |
466 | |
467 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 479 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
468 Generate_JSConstructStubHelper(masm, false, false, FLAG_pretenuring_call_new); | 480 Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new); |
469 } | 481 } |
470 | 482 |
471 | 483 |
472 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 484 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
473 Generate_JSConstructStubHelper(masm, true, false, false); | 485 Generate_JSConstructStubHelper(masm, true, false); |
474 } | 486 } |
475 | 487 |
476 | 488 |
477 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 489 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
478 bool is_construct) { | 490 bool is_construct) { |
479 ProfileEntryHookStub::MaybeCallEntryHook(masm); | 491 ProfileEntryHookStub::MaybeCallEntryHook(masm); |
480 | 492 |
481 // Expects five C++ function parameters. | 493 // Expects five C++ function parameters. |
482 // - Address entry (ignored) | 494 // - Address entry (ignored) |
483 // - JSFunction* function ( | 495 // - JSFunction* function ( |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 __ bind(&ok); | 1518 __ bind(&ok); |
1507 __ ret(0); | 1519 __ ret(0); |
1508 } | 1520 } |
1509 | 1521 |
1510 | 1522 |
1511 #undef __ | 1523 #undef __ |
1512 | 1524 |
1513 } } // namespace v8::internal | 1525 } } // namespace v8::internal |
1514 | 1526 |
1515 #endif // V8_TARGET_ARCH_X64 | 1527 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |