OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #if defined(V8_TARGET_ARCH_X64) | 30 #if defined(V8_TARGET_ARCH_X64) |
31 | 31 |
32 #include "codegen-inl.h" | 32 #include "codegen-inl.h" |
33 #include "macro-assembler.h" | 33 #include "deoptimizer.h" |
34 #include "full-codegen.h" | |
34 | 35 |
35 namespace v8 { | 36 namespace v8 { |
36 namespace internal { | 37 namespace internal { |
37 | 38 |
39 | |
38 #define __ ACCESS_MASM(masm) | 40 #define __ ACCESS_MASM(masm) |
39 | 41 |
40 | 42 |
41 void Builtins::Generate_Adaptor(MacroAssembler* masm, | 43 void Builtins::Generate_Adaptor(MacroAssembler* masm, |
42 CFunctionId id, | 44 CFunctionId id, |
43 BuiltinExtraArguments extra_args) { | 45 BuiltinExtraArguments extra_args) { |
44 // ----------- S t a t e ------------- | 46 // ----------- S t a t e ------------- |
45 // -- rax : number of arguments excluding receiver | 47 // -- rax : number of arguments excluding receiver |
46 // -- rdi : called function (only guaranteed when | 48 // -- rdi : called function (only guaranteed when |
47 // extra_args requires it) | 49 // extra_args requires it) |
(...skipping 16 matching lines...) Expand all Loading... | |
64 ASSERT(extra_args == NO_EXTRA_ARGUMENTS); | 66 ASSERT(extra_args == NO_EXTRA_ARGUMENTS); |
65 } | 67 } |
66 | 68 |
67 // JumpToExternalReference expects rax to contain the number of arguments | 69 // JumpToExternalReference expects rax to contain the number of arguments |
68 // including the receiver and the extra arguments. | 70 // including the receiver and the extra arguments. |
69 __ addq(rax, Immediate(num_extra_args + 1)); | 71 __ addq(rax, Immediate(num_extra_args + 1)); |
70 __ JumpToExternalReference(ExternalReference(id), 1); | 72 __ JumpToExternalReference(ExternalReference(id), 1); |
71 } | 73 } |
72 | 74 |
73 | 75 |
74 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { | 76 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { |
75 __ push(rbp); | 77 // ----------- S t a t e ------------- |
76 __ movq(rbp, rsp); | 78 // -- rax: number of arguments |
77 | 79 // -- rdi: constructor function |
78 // Store the arguments adaptor context sentinel. | 80 // ----------------------------------- |
79 __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); | 81 |
80 | 82 Label non_function_call; |
81 // Push the function on the stack. | 83 // Check that function is not a smi. |
84 __ JumpIfSmi(rdi, &non_function_call); | |
85 // Check that function is a JSFunction. | |
86 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | |
87 __ j(not_equal, &non_function_call); | |
88 | |
89 // Jump to the function-specific construct stub. | |
90 __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | |
91 __ movq(rbx, FieldOperand(rbx, SharedFunctionInfo::kConstructStubOffset)); | |
92 __ lea(rbx, FieldOperand(rbx, Code::kHeaderSize)); | |
93 __ jmp(rbx); | |
94 | |
95 // rdi: called object | |
96 // rax: number of arguments | |
97 __ bind(&non_function_call); | |
98 // Set expected number of arguments to zero (not changing rax). | |
99 __ movq(rbx, Immediate(0)); | |
100 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); | |
101 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)), | |
102 RelocInfo::CODE_TARGET); | |
103 } | |
104 | |
105 | |
106 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | |
107 bool is_api_function, | |
108 bool count_constructions) { | |
109 // Should never count constructions for api objects. | |
110 ASSERT(!is_api_function || !count_constructions); | |
111 | |
112 // Enter a construct frame. | |
113 __ EnterConstructFrame(); | |
114 | |
115 // Store a smi-tagged arguments count on the stack. | |
116 __ Integer32ToSmi(rax, rax); | |
117 __ push(rax); | |
118 | |
119 // Push the function to invoke on the stack. | |
82 __ push(rdi); | 120 __ push(rdi); |
83 | 121 |
84 // Preserve the number of arguments on the stack. Must preserve both | 122 // Try to allocate the object without transitioning into C code. If any of the |
85 // rax and rbx because these registers are used when copying the | 123 // preconditions is not met, the code bails out to the runtime call. |
86 // arguments and the receiver. | 124 Label rt_call, allocated; |
87 __ Integer32ToSmi(rcx, rax); | 125 if (FLAG_inline_new) { |
88 __ push(rcx); | 126 Label undo_allocation; |
89 } | 127 |
90 | 128 #ifdef ENABLE_DEBUGGER_SUPPORT |
91 | 129 ExternalReference debug_step_in_fp = |
92 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { | 130 ExternalReference::debug_step_in_fp_address(); |
93 // Retrieve the number of arguments from the stack. Number is a Smi. | 131 __ movq(kScratchRegister, debug_step_in_fp); |
94 __ movq(rbx, Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 132 __ cmpq(Operand(kScratchRegister, 0), Immediate(0)); |
95 | 133 __ j(not_equal, &rt_call); |
96 // Leave the frame. | 134 #endif |
97 __ movq(rsp, rbp); | 135 |
98 __ pop(rbp); | 136 // Verified that the constructor is a JSFunction. |
99 | 137 // Load the initial map and verify that it is in fact a map. |
100 // Remove caller arguments from the stack. | 138 // rdi: constructor |
139 __ movq(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); | |
140 // Will both indicate a NULL and a Smi | |
141 ASSERT(kSmiTag == 0); | |
142 __ JumpIfSmi(rax, &rt_call); | |
143 // rdi: constructor | |
144 // rax: initial map (if proven valid below) | |
145 __ CmpObjectType(rax, MAP_TYPE, rbx); | |
146 __ j(not_equal, &rt_call); | |
147 | |
148 // Check that the constructor is not constructing a JSFunction (see comments | |
149 // in Runtime_NewObject in runtime.cc). In which case the initial map's | |
150 // instance type would be JS_FUNCTION_TYPE. | |
151 // rdi: constructor | |
152 // rax: initial map | |
153 __ CmpInstanceType(rax, JS_FUNCTION_TYPE); | |
154 __ j(equal, &rt_call); | |
155 | |
156 if (count_constructions) { | |
157 Label allocate; | |
158 // Decrease generous allocation count. | |
159 __ movq(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | |
160 __ decb(FieldOperand(rcx, SharedFunctionInfo::kConstructionCountOffset)); | |
161 __ j(not_zero, &allocate); | |
162 | |
163 __ push(rax); | |
164 __ push(rdi); | |
165 | |
166 __ push(rdi); // constructor | |
167 // The call will replace the stub, so the countdown is only done once. | |
168 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); | |
169 | |
170 __ pop(rdi); | |
171 __ pop(rax); | |
172 | |
173 __ bind(&allocate); | |
174 } | |
175 | |
176 // Now allocate the JSObject on the heap. | |
177 __ movzxbq(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); | |
178 __ shl(rdi, Immediate(kPointerSizeLog2)); | |
179 // rdi: size of new object | |
180 __ AllocateInNewSpace(rdi, | |
181 rbx, | |
182 rdi, | |
183 no_reg, | |
184 &rt_call, | |
185 NO_ALLOCATION_FLAGS); | |
186 // Allocated the JSObject, now initialize the fields. | |
187 // rax: initial map | |
188 // rbx: JSObject (not HeapObject tagged - the actual address). | |
189 // rdi: start of next object | |
190 __ movq(Operand(rbx, JSObject::kMapOffset), rax); | |
191 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); | |
192 __ movq(Operand(rbx, JSObject::kPropertiesOffset), rcx); | |
193 __ movq(Operand(rbx, JSObject::kElementsOffset), rcx); | |
194 // Set extra fields in the newly allocated object. | |
195 // rax: initial map | |
196 // rbx: JSObject | |
197 // rdi: start of next object | |
198 { Label loop, entry; | |
199 // To allow for truncation. | |
200 if (count_constructions) { | |
201 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); | |
202 } else { | |
203 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | |
204 } | |
205 __ lea(rcx, Operand(rbx, JSObject::kHeaderSize)); | |
206 __ jmp(&entry); | |
207 __ bind(&loop); | |
208 __ movq(Operand(rcx, 0), rdx); | |
209 __ addq(rcx, Immediate(kPointerSize)); | |
210 __ bind(&entry); | |
211 __ cmpq(rcx, rdi); | |
212 __ j(less, &loop); | |
213 } | |
214 | |
215 // Add the object tag to make the JSObject real, so that we can continue and | |
216 // jump into the continuation code at any time from now on. Any failures | |
217 // need to undo the allocation, so that the heap is in a consistent state | |
218 // and verifiable. | |
219 // rax: initial map | |
220 // rbx: JSObject | |
221 // rdi: start of next object | |
222 __ or_(rbx, Immediate(kHeapObjectTag)); | |
223 | |
224 // Check if a non-empty properties array is needed. | |
225 // Allocate and initialize a FixedArray if it is. | |
226 // rax: initial map | |
227 // rbx: JSObject | |
228 // rdi: start of next object | |
229 // Calculate total properties described map. | |
230 __ movzxbq(rdx, FieldOperand(rax, Map::kUnusedPropertyFieldsOffset)); | |
231 __ movzxbq(rcx, FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); | |
232 __ addq(rdx, rcx); | |
233 // Calculate unused properties past the end of the in-object properties. | |
234 __ movzxbq(rcx, FieldOperand(rax, Map::kInObjectPropertiesOffset)); | |
235 __ subq(rdx, rcx); | |
236 // Done if no extra properties are to be allocated. | |
237 __ j(zero, &allocated); | |
238 __ Assert(positive, "Property allocation count failed."); | |
239 | |
240 // Scale the number of elements by pointer size and add the header for | |
241 // FixedArrays to the start of the next object calculation from above. | |
242 // rbx: JSObject | |
243 // rdi: start of next object (will be start of FixedArray) | |
244 // rdx: number of elements in properties array | |
245 __ AllocateInNewSpace(FixedArray::kHeaderSize, | |
246 times_pointer_size, | |
247 rdx, | |
248 rdi, | |
249 rax, | |
250 no_reg, | |
251 &undo_allocation, | |
252 RESULT_CONTAINS_TOP); | |
253 | |
254 // Initialize the FixedArray. | |
255 // rbx: JSObject | |
256 // rdi: FixedArray | |
257 // rdx: number of elements | |
258 // rax: start of next object | |
259 __ LoadRoot(rcx, Heap::kFixedArrayMapRootIndex); | |
260 __ movq(Operand(rdi, HeapObject::kMapOffset), rcx); // setup the map | |
261 __ Integer32ToSmi(rdx, rdx); | |
262 __ movq(Operand(rdi, FixedArray::kLengthOffset), rdx); // and length | |
263 | |
264 // Initialize the fields to undefined. | |
265 // rbx: JSObject | |
266 // rdi: FixedArray | |
267 // rax: start of next object | |
268 // rdx: number of elements | |
269 { Label loop, entry; | |
270 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | |
271 __ lea(rcx, Operand(rdi, FixedArray::kHeaderSize)); | |
272 __ jmp(&entry); | |
273 __ bind(&loop); | |
274 __ movq(Operand(rcx, 0), rdx); | |
275 __ addq(rcx, Immediate(kPointerSize)); | |
276 __ bind(&entry); | |
277 __ cmpq(rcx, rax); | |
278 __ j(below, &loop); | |
279 } | |
280 | |
281 // Store the initialized FixedArray into the properties field of | |
282 // the JSObject | |
283 // rbx: JSObject | |
284 // rdi: FixedArray | |
285 __ or_(rdi, Immediate(kHeapObjectTag)); // add the heap tag | |
286 __ movq(FieldOperand(rbx, JSObject::kPropertiesOffset), rdi); | |
287 | |
288 | |
289 // Continue with JSObject being successfully allocated | |
290 // rbx: JSObject | |
291 __ jmp(&allocated); | |
292 | |
293 // Undo the setting of the new top so that the heap is verifiable. For | |
294 // example, the map's unused properties potentially do not match the | |
295 // allocated objects unused properties. | |
296 // rbx: JSObject (previous new top) | |
297 __ bind(&undo_allocation); | |
298 __ UndoAllocationInNewSpace(rbx); | |
299 } | |
300 | |
301 // Allocate the new receiver object using the runtime call. | |
302 // rdi: function (constructor) | |
303 __ bind(&rt_call); | |
304 // Must restore rdi (constructor) before calling runtime. | |
305 __ movq(rdi, Operand(rsp, 0)); | |
306 __ push(rdi); | |
307 __ CallRuntime(Runtime::kNewObject, 1); | |
308 __ movq(rbx, rax); // store result in rbx | |
309 | |
310 // New object allocated. | |
311 // rbx: newly allocated object | |
312 __ bind(&allocated); | |
313 // Retrieve the function from the stack. | |
314 __ pop(rdi); | |
315 | |
316 // Retrieve smi-tagged arguments count from the stack. | |
317 __ movq(rax, Operand(rsp, 0)); | |
318 __ SmiToInteger32(rax, rax); | |
319 | |
320 // Push the allocated receiver to the stack. We need two copies | |
321 // because we may have to return the original one and the calling | |
322 // conventions dictate that the called function pops the receiver. | |
323 __ push(rbx); | |
324 __ push(rbx); | |
325 | |
326 // Setup pointer to last argument. | |
327 __ lea(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset)); | |
328 | |
329 // Copy arguments and receiver to the expression stack. | |
330 Label loop, entry; | |
331 __ movq(rcx, rax); | |
332 __ jmp(&entry); | |
333 __ bind(&loop); | |
334 __ push(Operand(rbx, rcx, times_pointer_size, 0)); | |
335 __ bind(&entry); | |
336 __ decq(rcx); | |
337 __ j(greater_equal, &loop); | |
338 | |
339 // Call the function. | |
340 if (is_api_function) { | |
341 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | |
342 Handle<Code> code = Handle<Code>( | |
343 Builtins::builtin(Builtins::HandleApiCallConstruct)); | |
344 ParameterCount expected(0); | |
345 __ InvokeCode(code, expected, expected, | |
346 RelocInfo::CODE_TARGET, CALL_FUNCTION); | |
347 } else { | |
348 ParameterCount actual(rax); | |
349 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | |
350 } | |
351 | |
352 // Restore context from the frame. | |
353 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | |
354 | |
355 // If the result is an object (in the ECMA sense), we should get rid | |
356 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | |
357 // on page 74. | |
358 Label use_receiver, exit; | |
359 // If the result is a smi, it is *not* an object in the ECMA sense. | |
360 __ JumpIfSmi(rax, &use_receiver); | |
361 | |
362 // If the type of the result (stored in its map) is less than | |
363 // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense. | |
364 __ CmpObjectType(rax, FIRST_JS_OBJECT_TYPE, rcx); | |
365 __ j(above_equal, &exit); | |
366 | |
367 // Throw away the result of the constructor invocation and use the | |
368 // on-stack receiver as the result. | |
369 __ bind(&use_receiver); | |
370 __ movq(rax, Operand(rsp, 0)); | |
371 | |
372 // Restore the arguments count and leave the construct frame. | |
373 __ bind(&exit); | |
374 __ movq(rbx, Operand(rsp, kPointerSize)); // get arguments count | |
375 __ LeaveConstructFrame(); | |
376 | |
377 // Remove caller arguments from the stack and return. | |
101 __ pop(rcx); | 378 __ pop(rcx); |
102 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 379 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
103 __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 380 __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
104 __ push(rcx); | 381 __ push(rcx); |
105 } | 382 __ IncrementCounter(&Counters::constructed_objects, 1); |
106 | 383 __ ret(0); |
107 | 384 } |
108 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { | 385 |
109 // ----------- S t a t e ------------- | 386 |
110 // -- rax : actual number of arguments | 387 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { |
111 // -- rbx : expected number of arguments | 388 Generate_JSConstructStubHelper(masm, false, true); |
112 // -- rdx : code entry to call | 389 } |
113 // ----------------------------------- | 390 |
114 | 391 |
115 Label invoke, dont_adapt_arguments; | 392 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
116 __ IncrementCounter(&Counters::arguments_adaptors, 1); | 393 Generate_JSConstructStubHelper(masm, false, false); |
117 | 394 } |
118 Label enough, too_few; | 395 |
119 __ cmpq(rax, rbx); | 396 |
120 __ j(less, &too_few); | 397 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
121 __ cmpq(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); | 398 Generate_JSConstructStubHelper(masm, true, false); |
122 __ j(equal, &dont_adapt_arguments); | 399 } |
123 | 400 |
124 { // Enough parameters: Actual >= expected. | 401 |
125 __ bind(&enough); | 402 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
126 EnterArgumentsAdaptorFrame(masm); | 403 bool is_construct) { |
127 | 404 // Expects five C++ function parameters. |
128 // Copy receiver and all expected arguments. | 405 // - Address entry (ignored) |
129 const int offset = StandardFrameConstants::kCallerSPOffset; | 406 // - JSFunction* function ( |
130 __ lea(rax, Operand(rbp, rax, times_pointer_size, offset)); | 407 // - Object* receiver |
131 __ movq(rcx, Immediate(-1)); // account for receiver | 408 // - int argc |
132 | 409 // - Object*** argv |
133 Label copy; | 410 // (see Handle::Invoke in execution.cc). |
134 __ bind(©); | 411 |
135 __ incq(rcx); | 412 // Platform specific argument handling. After this, the stack contains |
136 __ push(Operand(rax, 0)); | 413 // an internal frame and the pushed function and receiver, and |
137 __ subq(rax, Immediate(kPointerSize)); | 414 // register rax and rbx holds the argument count and argument array, |
138 __ cmpq(rcx, rbx); | 415 // while rdi holds the function pointer and rsi the context. |
139 __ j(less, ©); | 416 #ifdef _WIN64 |
140 __ jmp(&invoke); | 417 // MSVC parameters in: |
418 // rcx : entry (ignored) | |
419 // rdx : function | |
420 // r8 : receiver | |
421 // r9 : argc | |
422 // [rsp+0x20] : argv | |
423 | |
424 // Clear the context before we push it when entering the JS frame. | |
425 __ xor_(rsi, rsi); | |
426 __ EnterInternalFrame(); | |
427 | |
428 // Load the function context into rsi. | |
429 __ movq(rsi, FieldOperand(rdx, JSFunction::kContextOffset)); | |
430 | |
431 // Push the function and the receiver onto the stack. | |
432 __ push(rdx); | |
433 __ push(r8); | |
434 | |
435 // Load the number of arguments and setup pointer to the arguments. | |
436 __ movq(rax, r9); | |
437 // Load the previous frame pointer to access C argument on stack | |
438 __ movq(kScratchRegister, Operand(rbp, 0)); | |
439 __ movq(rbx, Operand(kScratchRegister, EntryFrameConstants::kArgvOffset)); | |
440 // Load the function pointer into rdi. | |
441 __ movq(rdi, rdx); | |
442 #else // _WIN64 | |
443 // GCC parameters in: | |
444 // rdi : entry (ignored) | |
445 // rsi : function | |
446 // rdx : receiver | |
447 // rcx : argc | |
448 // r8 : argv | |
449 | |
450 __ movq(rdi, rsi); | |
451 // rdi : function | |
452 | |
453 // Clear the context before we push it when entering the JS frame. | |
454 __ xor_(rsi, rsi); | |
455 // Enter an internal frame. | |
456 __ EnterInternalFrame(); | |
457 | |
458 // Push the function and receiver and setup the context. | |
459 __ push(rdi); | |
460 __ push(rdx); | |
461 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | |
462 | |
463 // Load the number of arguments and setup pointer to the arguments. | |
464 __ movq(rax, rcx); | |
465 __ movq(rbx, r8); | |
466 #endif // _WIN64 | |
467 | |
468 // Current stack contents: | |
469 // [rsp + 2 * kPointerSize ... ]: Internal frame | |
470 // [rsp + kPointerSize] : function | |
471 // [rsp] : receiver | |
472 // Current register contents: | |
473 // rax : argc | |
474 // rbx : argv | |
475 // rsi : context | |
476 // rdi : function | |
477 | |
478 // Copy arguments to the stack in a loop. | |
479 // Register rbx points to array of pointers to handle locations. | |
480 // Push the values of these handles. | |
481 Label loop, entry; | |
482 __ xor_(rcx, rcx); // Set loop variable to 0. | |
483 __ jmp(&entry); | |
484 __ bind(&loop); | |
485 __ movq(kScratchRegister, Operand(rbx, rcx, times_pointer_size, 0)); | |
486 __ push(Operand(kScratchRegister, 0)); // dereference handle | |
487 __ addq(rcx, Immediate(1)); | |
488 __ bind(&entry); | |
489 __ cmpq(rcx, rax); | |
490 __ j(not_equal, &loop); | |
491 | |
492 // Invoke the code. | |
493 if (is_construct) { | |
494 // Expects rdi to hold function pointer. | |
495 __ Call(Handle<Code>(Builtins::builtin(Builtins::JSConstructCall)), | |
496 RelocInfo::CODE_TARGET); | |
497 } else { | |
498 ParameterCount actual(rax); | |
499 // Function must be in rdi. | |
500 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | |
141 } | 501 } |
142 | 502 |
143 { // Too few parameters: Actual < expected. | 503 // Exit the JS frame. Notice that this also removes the empty |
144 __ bind(&too_few); | 504 // context and the function left on the stack by the code |
145 EnterArgumentsAdaptorFrame(masm); | 505 // invocation. |
146 | 506 __ LeaveInternalFrame(); |
147 // Copy receiver and all actual arguments. | 507 // TODO(X64): Is argument correct? Is there a receiver to remove? |
148 const int offset = StandardFrameConstants::kCallerSPOffset; | 508 __ ret(1 * kPointerSize); // remove receiver |
149 __ lea(rdi, Operand(rbp, rax, times_pointer_size, offset)); | 509 } |
150 __ movq(rcx, Immediate(-1)); // account for receiver | 510 |
151 | 511 |
152 Label copy; | 512 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { |
153 __ bind(©); | 513 Generate_JSEntryTrampolineHelper(masm, false); |
154 __ incq(rcx); | 514 } |
155 __ push(Operand(rdi, 0)); | 515 |
156 __ subq(rdi, Immediate(kPointerSize)); | 516 |
157 __ cmpq(rcx, rax); | 517 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { |
158 __ j(less, ©); | 518 Generate_JSEntryTrampolineHelper(masm, true); |
159 | 519 } |
160 // Fill remaining expected arguments with undefined values. | 520 |
161 Label fill; | 521 |
162 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); | 522 void Builtins::Generate_LazyCompile(MacroAssembler* masm) { |
163 __ bind(&fill); | 523 // Enter an internal frame. |
164 __ incq(rcx); | 524 __ EnterInternalFrame(); |
165 __ push(kScratchRegister); | 525 |
166 __ cmpq(rcx, rbx); | 526 // Push a copy of the function onto the stack. |
167 __ j(less, &fill); | 527 __ push(rdi); |
168 | 528 |
169 // Restore function pointer. | 529 __ push(rdi); // Function is also the parameter to the runtime call. |
170 __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 530 __ CallRuntime(Runtime::kLazyCompile, 1); |
171 } | 531 __ pop(rdi); |
172 | 532 |
173 // Call the entry point. | 533 // Tear down temporary frame. |
174 __ bind(&invoke); | 534 __ LeaveInternalFrame(); |
175 __ call(rdx); | 535 |
176 | 536 // Do a tail-call of the compiled function. |
177 // Leave frame and return. | 537 __ lea(rcx, FieldOperand(rax, Code::kHeaderSize)); |
178 LeaveArgumentsAdaptorFrame(masm); | 538 __ jmp(rcx); |
179 __ ret(0); | 539 } |
180 | 540 |
181 // ------------------------------------------- | 541 |
182 // Dont adapt arguments. | 542 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) { |
183 // ------------------------------------------- | 543 // Enter an internal frame. |
184 __ bind(&dont_adapt_arguments); | 544 __ EnterInternalFrame(); |
185 __ jmp(rdx); | 545 |
546 // Push a copy of the function onto the stack. | |
547 __ push(rdi); | |
548 | |
549 __ push(rdi); // Function is also the parameter to the runtime call. | |
550 __ CallRuntime(Runtime::kLazyRecompile, 1); | |
551 | |
552 // Restore function and tear down temporary frame. | |
553 __ pop(rdi); | |
554 __ LeaveInternalFrame(); | |
555 | |
556 // Do a tail-call of the compiled function. | |
557 __ lea(rcx, FieldOperand(rax, Code::kHeaderSize)); | |
558 __ jmp(rcx); | |
559 } | |
560 | |
561 | |
562 static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm, | |
563 Deoptimizer::BailoutType type) { | |
564 __ int3(); | |
565 } | |
566 | |
567 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { | |
568 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER); | |
569 } | |
570 | |
571 | |
572 void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) { | |
573 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER); | |
574 } | |
575 | |
576 | |
577 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) { | |
578 __ int3(); | |
186 } | 579 } |
187 | 580 |
188 | 581 |
189 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { | 582 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { |
190 // Stack Layout: | 583 // Stack Layout: |
191 // rsp[0]: Return address | 584 // rsp[0]: Return address |
192 // rsp[1]: Argument n | 585 // rsp[1]: Argument n |
193 // rsp[2]: Argument n-1 | 586 // rsp[2]: Argument n-1 |
194 // ... | 587 // ... |
195 // rsp[n]: Argument 1 | 588 // rsp[n]: Argument 1 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 | 834 |
442 // Invoke the function. | 835 // Invoke the function. |
443 ParameterCount actual(rax); | 836 ParameterCount actual(rax); |
444 __ SmiToInteger32(rax, rax); | 837 __ SmiToInteger32(rax, rax); |
445 __ movq(rdi, Operand(rbp, kFunctionOffset)); | 838 __ movq(rdi, Operand(rbp, kFunctionOffset)); |
446 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | 839 __ InvokeFunction(rdi, actual, CALL_FUNCTION); |
447 | 840 |
448 __ LeaveInternalFrame(); | 841 __ LeaveInternalFrame(); |
449 __ ret(3 * kPointerSize); // remove function, receiver, and arguments | 842 __ ret(3 * kPointerSize); // remove function, receiver, and arguments |
450 } | 843 } |
451 | 844 |
William Hesse
2010/12/13 11:25:03
This is the only change that is not just moving fu
| |
452 | 845 |
453 // Load the built-in Array function from the current context. | |
454 static void GenerateLoadArrayFunction(MacroAssembler* masm, Register result) { | |
455 // Load the global context. | |
456 __ movq(result, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX))); | |
457 __ movq(result, FieldOperand(result, GlobalObject::kGlobalContextOffset)); | |
458 // Load the Array function from the global context. | |
459 __ movq(result, | |
460 Operand(result, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); | |
461 } | |
462 | |
463 | |
464 // Number of empty elements to allocate for an empty array. | 846 // Number of empty elements to allocate for an empty array. |
465 static const int kPreallocatedArrayElements = 4; | 847 static const int kPreallocatedArrayElements = 4; |
466 | 848 |
467 | 849 |
468 // Allocate an empty JSArray. The allocated array is put into the result | 850 // Allocate an empty JSArray. The allocated array is put into the result |
469 // register. If the parameter initial_capacity is larger than zero an elements | 851 // register. If the parameter initial_capacity is larger than zero an elements |
470 // backing store is allocated with this size and filled with the hole values. | 852 // backing store is allocated with this size and filled with the hole values. |
471 // Otherwise the elements backing store is set to the empty FixedArray. | 853 // Otherwise the elements backing store is set to the empty FixedArray. |
472 static void AllocateEmptyJSArray(MacroAssembler* masm, | 854 static void AllocateEmptyJSArray(MacroAssembler* masm, |
473 Register array_function, | 855 Register array_function, |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 | 1188 |
807 void Builtins::Generate_ArrayCode(MacroAssembler* masm) { | 1189 void Builtins::Generate_ArrayCode(MacroAssembler* masm) { |
808 // ----------- S t a t e ------------- | 1190 // ----------- S t a t e ------------- |
809 // -- rax : argc | 1191 // -- rax : argc |
810 // -- rsp[0] : return address | 1192 // -- rsp[0] : return address |
811 // -- rsp[8] : last argument | 1193 // -- rsp[8] : last argument |
812 // ----------------------------------- | 1194 // ----------------------------------- |
813 Label generic_array_code; | 1195 Label generic_array_code; |
814 | 1196 |
815 // Get the Array function. | 1197 // Get the Array function. |
816 GenerateLoadArrayFunction(masm, rdi); | 1198 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rdi); |
William Hesse
2010/12/13 11:25:03
Here.
| |
817 | 1199 |
818 if (FLAG_debug_code) { | 1200 if (FLAG_debug_code) { |
819 // Initial map for the builtin Array function shoud be a map. | 1201 // Initial map for the builtin Array function shoud be a map. |
820 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); | 1202 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); |
821 // Will both indicate a NULL and a Smi. | 1203 // Will both indicate a NULL and a Smi. |
822 ASSERT(kSmiTag == 0); | 1204 ASSERT(kSmiTag == 0); |
823 Condition not_smi = NegateCondition(masm->CheckSmi(rbx)); | 1205 Condition not_smi = NegateCondition(masm->CheckSmi(rbx)); |
824 __ Check(not_smi, "Unexpected initial map for Array function"); | 1206 __ Check(not_smi, "Unexpected initial map for Array function"); |
825 __ CmpObjectType(rbx, MAP_TYPE, rcx); | 1207 __ CmpObjectType(rbx, MAP_TYPE, rcx); |
826 __ Check(equal, "Unexpected initial map for Array function"); | 1208 __ Check(equal, "Unexpected initial map for Array function"); |
(...skipping 16 matching lines...) Expand all Loading... | |
843 // -- rax : argc | 1225 // -- rax : argc |
844 // -- rdi : constructor | 1226 // -- rdi : constructor |
845 // -- rsp[0] : return address | 1227 // -- rsp[0] : return address |
846 // -- rsp[8] : last argument | 1228 // -- rsp[8] : last argument |
847 // ----------------------------------- | 1229 // ----------------------------------- |
848 Label generic_constructor; | 1230 Label generic_constructor; |
849 | 1231 |
850 if (FLAG_debug_code) { | 1232 if (FLAG_debug_code) { |
851 // The array construct code is only set for the builtin Array function which | 1233 // The array construct code is only set for the builtin Array function which |
852 // does always have a map. | 1234 // does always have a map. |
853 GenerateLoadArrayFunction(masm, rbx); | 1235 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rbx); |
William Hesse
2010/12/13 11:25:03
And here.
| |
854 __ cmpq(rdi, rbx); | 1236 __ cmpq(rdi, rbx); |
855 __ Check(equal, "Unexpected Array function"); | 1237 __ Check(equal, "Unexpected Array function"); |
856 // Initial map for the builtin Array function should be a map. | 1238 // Initial map for the builtin Array function should be a map. |
857 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); | 1239 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); |
858 // Will both indicate a NULL and a Smi. | 1240 // Will both indicate a NULL and a Smi. |
859 ASSERT(kSmiTag == 0); | 1241 ASSERT(kSmiTag == 0); |
860 Condition not_smi = NegateCondition(masm->CheckSmi(rbx)); | 1242 Condition not_smi = NegateCondition(masm->CheckSmi(rbx)); |
861 __ Check(not_smi, "Unexpected initial map for Array function"); | 1243 __ Check(not_smi, "Unexpected initial map for Array function"); |
862 __ CmpObjectType(rbx, MAP_TYPE, rcx); | 1244 __ CmpObjectType(rbx, MAP_TYPE, rcx); |
863 __ Check(equal, "Unexpected initial map for Array function"); | 1245 __ Check(equal, "Unexpected initial map for Array function"); |
(...skipping 11 matching lines...) Expand all Loading... | |
875 } | 1257 } |
876 | 1258 |
877 | 1259 |
878 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { | 1260 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { |
879 // TODO(849): implement custom construct stub. | 1261 // TODO(849): implement custom construct stub. |
880 // Generate a copy of the generic stub for now. | 1262 // Generate a copy of the generic stub for now. |
881 Generate_JSConstructStubGeneric(masm); | 1263 Generate_JSConstructStubGeneric(masm); |
882 } | 1264 } |
883 | 1265 |
884 | 1266 |
885 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { | 1267 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { |
886 // ----------- S t a t e ------------- | 1268 __ push(rbp); |
887 // -- rax: number of arguments | 1269 __ movq(rbp, rsp); |
888 // -- rdi: constructor function | |
889 // ----------------------------------- | |
890 | 1270 |
891 Label non_function_call; | 1271 // Store the arguments adaptor context sentinel. |
892 // Check that function is not a smi. | 1272 __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
893 __ JumpIfSmi(rdi, &non_function_call); | |
894 // Check that function is a JSFunction. | |
895 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | |
896 __ j(not_equal, &non_function_call); | |
897 | 1273 |
898 // Jump to the function-specific construct stub. | 1274 // Push the function on the stack. |
899 __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 1275 __ push(rdi); |
900 __ movq(rbx, FieldOperand(rbx, SharedFunctionInfo::kConstructStubOffset)); | |
901 __ lea(rbx, FieldOperand(rbx, Code::kHeaderSize)); | |
902 __ jmp(rbx); | |
903 | 1276 |
904 // rdi: called object | 1277 // Preserve the number of arguments on the stack. Must preserve both |
905 // rax: number of arguments | 1278 // rax and rbx because these registers are used when copying the |
906 __ bind(&non_function_call); | 1279 // arguments and the receiver. |
907 // Set expected number of arguments to zero (not changing rax). | 1280 __ Integer32ToSmi(rcx, rax); |
908 __ movq(rbx, Immediate(0)); | 1281 __ push(rcx); |
909 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); | |
910 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)), | |
911 RelocInfo::CODE_TARGET); | |
912 } | 1282 } |
913 | 1283 |
914 | 1284 |
915 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 1285 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { |
916 bool is_api_function, | 1286 // Retrieve the number of arguments from the stack. Number is a Smi. |
917 bool count_constructions) { | 1287 __ movq(rbx, Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
918 // Should never count constructions for api objects. | |
919 ASSERT(!is_api_function || !count_constructions); | |
920 | 1288 |
921 // Enter a construct frame. | 1289 // Leave the frame. |
922 __ EnterConstructFrame(); | 1290 __ movq(rsp, rbp); |
1291 __ pop(rbp); | |
923 | 1292 |
924 // Store a smi-tagged arguments count on the stack. | 1293 // Remove caller arguments from the stack. |
925 __ Integer32ToSmi(rax, rax); | |
926 __ push(rax); | |
927 | |
928 // Push the function to invoke on the stack. | |
929 __ push(rdi); | |
930 | |
931 // Try to allocate the object without transitioning into C code. If any of the | |
932 // preconditions is not met, the code bails out to the runtime call. | |
933 Label rt_call, allocated; | |
934 if (FLAG_inline_new) { | |
935 Label undo_allocation; | |
936 | |
937 #ifdef ENABLE_DEBUGGER_SUPPORT | |
938 ExternalReference debug_step_in_fp = | |
939 ExternalReference::debug_step_in_fp_address(); | |
940 __ movq(kScratchRegister, debug_step_in_fp); | |
941 __ cmpq(Operand(kScratchRegister, 0), Immediate(0)); | |
942 __ j(not_equal, &rt_call); | |
943 #endif | |
944 | |
945 // Verified that the constructor is a JSFunction. | |
946 // Load the initial map and verify that it is in fact a map. | |
947 // rdi: constructor | |
948 __ movq(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); | |
949 // Will both indicate a NULL and a Smi | |
950 ASSERT(kSmiTag == 0); | |
951 __ JumpIfSmi(rax, &rt_call); | |
952 // rdi: constructor | |
953 // rax: initial map (if proven valid below) | |
954 __ CmpObjectType(rax, MAP_TYPE, rbx); | |
955 __ j(not_equal, &rt_call); | |
956 | |
957 // Check that the constructor is not constructing a JSFunction (see comments | |
958 // in Runtime_NewObject in runtime.cc). In which case the initial map's | |
959 // instance type would be JS_FUNCTION_TYPE. | |
960 // rdi: constructor | |
961 // rax: initial map | |
962 __ CmpInstanceType(rax, JS_FUNCTION_TYPE); | |
963 __ j(equal, &rt_call); | |
964 | |
965 if (count_constructions) { | |
966 Label allocate; | |
967 // Decrease generous allocation count. | |
968 __ movq(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | |
969 __ decb(FieldOperand(rcx, SharedFunctionInfo::kConstructionCountOffset)); | |
970 __ j(not_zero, &allocate); | |
971 | |
972 __ push(rax); | |
973 __ push(rdi); | |
974 | |
975 __ push(rdi); // constructor | |
976 // The call will replace the stub, so the countdown is only done once. | |
977 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); | |
978 | |
979 __ pop(rdi); | |
980 __ pop(rax); | |
981 | |
982 __ bind(&allocate); | |
983 } | |
984 | |
985 // Now allocate the JSObject on the heap. | |
986 __ movzxbq(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); | |
987 __ shl(rdi, Immediate(kPointerSizeLog2)); | |
988 // rdi: size of new object | |
989 __ AllocateInNewSpace(rdi, | |
990 rbx, | |
991 rdi, | |
992 no_reg, | |
993 &rt_call, | |
994 NO_ALLOCATION_FLAGS); | |
995 // Allocated the JSObject, now initialize the fields. | |
996 // rax: initial map | |
997 // rbx: JSObject (not HeapObject tagged - the actual address). | |
998 // rdi: start of next object | |
999 __ movq(Operand(rbx, JSObject::kMapOffset), rax); | |
1000 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); | |
1001 __ movq(Operand(rbx, JSObject::kPropertiesOffset), rcx); | |
1002 __ movq(Operand(rbx, JSObject::kElementsOffset), rcx); | |
1003 // Set extra fields in the newly allocated object. | |
1004 // rax: initial map | |
1005 // rbx: JSObject | |
1006 // rdi: start of next object | |
1007 { Label loop, entry; | |
1008 // To allow for truncation. | |
1009 if (count_constructions) { | |
1010 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); | |
1011 } else { | |
1012 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | |
1013 } | |
1014 __ lea(rcx, Operand(rbx, JSObject::kHeaderSize)); | |
1015 __ jmp(&entry); | |
1016 __ bind(&loop); | |
1017 __ movq(Operand(rcx, 0), rdx); | |
1018 __ addq(rcx, Immediate(kPointerSize)); | |
1019 __ bind(&entry); | |
1020 __ cmpq(rcx, rdi); | |
1021 __ j(less, &loop); | |
1022 } | |
1023 | |
1024 // Add the object tag to make the JSObject real, so that we can continue and | |
1025 // jump into the continuation code at any time from now on. Any failures | |
1026 // need to undo the allocation, so that the heap is in a consistent state | |
1027 // and verifiable. | |
1028 // rax: initial map | |
1029 // rbx: JSObject | |
1030 // rdi: start of next object | |
1031 __ or_(rbx, Immediate(kHeapObjectTag)); | |
1032 | |
1033 // Check if a non-empty properties array is needed. | |
1034 // Allocate and initialize a FixedArray if it is. | |
1035 // rax: initial map | |
1036 // rbx: JSObject | |
1037 // rdi: start of next object | |
1038 // Calculate total properties described map. | |
1039 __ movzxbq(rdx, FieldOperand(rax, Map::kUnusedPropertyFieldsOffset)); | |
1040 __ movzxbq(rcx, FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); | |
1041 __ addq(rdx, rcx); | |
1042 // Calculate unused properties past the end of the in-object properties. | |
1043 __ movzxbq(rcx, FieldOperand(rax, Map::kInObjectPropertiesOffset)); | |
1044 __ subq(rdx, rcx); | |
1045 // Done if no extra properties are to be allocated. | |
1046 __ j(zero, &allocated); | |
1047 __ Assert(positive, "Property allocation count failed."); | |
1048 | |
1049 // Scale the number of elements by pointer size and add the header for | |
1050 // FixedArrays to the start of the next object calculation from above. | |
1051 // rbx: JSObject | |
1052 // rdi: start of next object (will be start of FixedArray) | |
1053 // rdx: number of elements in properties array | |
1054 __ AllocateInNewSpace(FixedArray::kHeaderSize, | |
1055 times_pointer_size, | |
1056 rdx, | |
1057 rdi, | |
1058 rax, | |
1059 no_reg, | |
1060 &undo_allocation, | |
1061 RESULT_CONTAINS_TOP); | |
1062 | |
1063 // Initialize the FixedArray. | |
1064 // rbx: JSObject | |
1065 // rdi: FixedArray | |
1066 // rdx: number of elements | |
1067 // rax: start of next object | |
1068 __ LoadRoot(rcx, Heap::kFixedArrayMapRootIndex); | |
1069 __ movq(Operand(rdi, HeapObject::kMapOffset), rcx); // setup the map | |
1070 __ Integer32ToSmi(rdx, rdx); | |
1071 __ movq(Operand(rdi, FixedArray::kLengthOffset), rdx); // and length | |
1072 | |
1073 // Initialize the fields to undefined. | |
1074 // rbx: JSObject | |
1075 // rdi: FixedArray | |
1076 // rax: start of next object | |
1077 // rdx: number of elements | |
1078 { Label loop, entry; | |
1079 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | |
1080 __ lea(rcx, Operand(rdi, FixedArray::kHeaderSize)); | |
1081 __ jmp(&entry); | |
1082 __ bind(&loop); | |
1083 __ movq(Operand(rcx, 0), rdx); | |
1084 __ addq(rcx, Immediate(kPointerSize)); | |
1085 __ bind(&entry); | |
1086 __ cmpq(rcx, rax); | |
1087 __ j(below, &loop); | |
1088 } | |
1089 | |
1090 // Store the initialized FixedArray into the properties field of | |
1091 // the JSObject | |
1092 // rbx: JSObject | |
1093 // rdi: FixedArray | |
1094 __ or_(rdi, Immediate(kHeapObjectTag)); // add the heap tag | |
1095 __ movq(FieldOperand(rbx, JSObject::kPropertiesOffset), rdi); | |
1096 | |
1097 | |
1098 // Continue with JSObject being successfully allocated | |
1099 // rbx: JSObject | |
1100 __ jmp(&allocated); | |
1101 | |
1102 // Undo the setting of the new top so that the heap is verifiable. For | |
1103 // example, the map's unused properties potentially do not match the | |
1104 // allocated objects unused properties. | |
1105 // rbx: JSObject (previous new top) | |
1106 __ bind(&undo_allocation); | |
1107 __ UndoAllocationInNewSpace(rbx); | |
1108 } | |
1109 | |
1110 // Allocate the new receiver object using the runtime call. | |
1111 // rdi: function (constructor) | |
1112 __ bind(&rt_call); | |
1113 // Must restore rdi (constructor) before calling runtime. | |
1114 __ movq(rdi, Operand(rsp, 0)); | |
1115 __ push(rdi); | |
1116 __ CallRuntime(Runtime::kNewObject, 1); | |
1117 __ movq(rbx, rax); // store result in rbx | |
1118 | |
1119 // New object allocated. | |
1120 // rbx: newly allocated object | |
1121 __ bind(&allocated); | |
1122 // Retrieve the function from the stack. | |
1123 __ pop(rdi); | |
1124 | |
1125 // Retrieve smi-tagged arguments count from the stack. | |
1126 __ movq(rax, Operand(rsp, 0)); | |
1127 __ SmiToInteger32(rax, rax); | |
1128 | |
1129 // Push the allocated receiver to the stack. We need two copies | |
1130 // because we may have to return the original one and the calling | |
1131 // conventions dictate that the called function pops the receiver. | |
1132 __ push(rbx); | |
1133 __ push(rbx); | |
1134 | |
1135 // Setup pointer to last argument. | |
1136 __ lea(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset)); | |
1137 | |
1138 // Copy arguments and receiver to the expression stack. | |
1139 Label loop, entry; | |
1140 __ movq(rcx, rax); | |
1141 __ jmp(&entry); | |
1142 __ bind(&loop); | |
1143 __ push(Operand(rbx, rcx, times_pointer_size, 0)); | |
1144 __ bind(&entry); | |
1145 __ decq(rcx); | |
1146 __ j(greater_equal, &loop); | |
1147 | |
1148 // Call the function. | |
1149 if (is_api_function) { | |
1150 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | |
1151 Handle<Code> code = Handle<Code>( | |
1152 Builtins::builtin(Builtins::HandleApiCallConstruct)); | |
1153 ParameterCount expected(0); | |
1154 __ InvokeCode(code, expected, expected, | |
1155 RelocInfo::CODE_TARGET, CALL_FUNCTION); | |
1156 } else { | |
1157 ParameterCount actual(rax); | |
1158 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | |
1159 } | |
1160 | |
1161 // Restore context from the frame. | |
1162 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | |
1163 | |
1164 // If the result is an object (in the ECMA sense), we should get rid | |
1165 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | |
1166 // on page 74. | |
1167 Label use_receiver, exit; | |
1168 // If the result is a smi, it is *not* an object in the ECMA sense. | |
1169 __ JumpIfSmi(rax, &use_receiver); | |
1170 | |
1171 // If the type of the result (stored in its map) is less than | |
1172 // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense. | |
1173 __ CmpObjectType(rax, FIRST_JS_OBJECT_TYPE, rcx); | |
1174 __ j(above_equal, &exit); | |
1175 | |
1176 // Throw away the result of the constructor invocation and use the | |
1177 // on-stack receiver as the result. | |
1178 __ bind(&use_receiver); | |
1179 __ movq(rax, Operand(rsp, 0)); | |
1180 | |
1181 // Restore the arguments count and leave the construct frame. | |
1182 __ bind(&exit); | |
1183 __ movq(rbx, Operand(rsp, kPointerSize)); // get arguments count | |
1184 __ LeaveConstructFrame(); | |
1185 | |
1186 // Remove caller arguments from the stack and return. | |
1187 __ pop(rcx); | 1294 __ pop(rcx); |
1188 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 1295 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
1189 __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 1296 __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
1190 __ push(rcx); | 1297 __ push(rcx); |
1191 __ IncrementCounter(&Counters::constructed_objects, 1); | |
1192 __ ret(0); | |
1193 } | 1298 } |
1194 | 1299 |
1195 | 1300 |
1196 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { | 1301 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { |
1197 Generate_JSConstructStubHelper(masm, false, true); | 1302 // ----------- S t a t e ------------- |
1198 } | 1303 // -- rax : actual number of arguments |
1304 // -- rbx : expected number of arguments | |
1305 // -- rdx : code entry to call | |
1306 // ----------------------------------- | |
1199 | 1307 |
1308 Label invoke, dont_adapt_arguments; | |
1309 __ IncrementCounter(&Counters::arguments_adaptors, 1); | |
1200 | 1310 |
1201 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 1311 Label enough, too_few; |
1202 Generate_JSConstructStubHelper(masm, false, false); | 1312 __ cmpq(rax, rbx); |
1203 } | 1313 __ j(less, &too_few); |
1314 __ cmpq(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); | |
1315 __ j(equal, &dont_adapt_arguments); | |
1204 | 1316 |
1317 { // Enough parameters: Actual >= expected. | |
1318 __ bind(&enough); | |
1319 EnterArgumentsAdaptorFrame(masm); | |
1205 | 1320 |
1206 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 1321 // Copy receiver and all expected arguments. |
1207 Generate_JSConstructStubHelper(masm, true, false); | 1322 const int offset = StandardFrameConstants::kCallerSPOffset; |
1208 } | 1323 __ lea(rax, Operand(rbp, rax, times_pointer_size, offset)); |
1324 __ movq(rcx, Immediate(-1)); // account for receiver | |
1209 | 1325 |
1210 | 1326 Label copy; |
1211 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 1327 __ bind(©); |
1212 bool is_construct) { | 1328 __ incq(rcx); |
1213 // Expects five C++ function parameters. | 1329 __ push(Operand(rax, 0)); |
1214 // - Address entry (ignored) | 1330 __ subq(rax, Immediate(kPointerSize)); |
1215 // - JSFunction* function ( | 1331 __ cmpq(rcx, rbx); |
1216 // - Object* receiver | 1332 __ j(less, ©); |
1217 // - int argc | 1333 __ jmp(&invoke); |
1218 // - Object*** argv | |
1219 // (see Handle::Invoke in execution.cc). | |
1220 | |
1221 // Platform specific argument handling. After this, the stack contains | |
1222 // an internal frame and the pushed function and receiver, and | |
1223 // register rax and rbx holds the argument count and argument array, | |
1224 // while rdi holds the function pointer and rsi the context. | |
1225 #ifdef _WIN64 | |
1226 // MSVC parameters in: | |
1227 // rcx : entry (ignored) | |
1228 // rdx : function | |
1229 // r8 : receiver | |
1230 // r9 : argc | |
1231 // [rsp+0x20] : argv | |
1232 | |
1233 // Clear the context before we push it when entering the JS frame. | |
1234 __ xor_(rsi, rsi); | |
1235 __ EnterInternalFrame(); | |
1236 | |
1237 // Load the function context into rsi. | |
1238 __ movq(rsi, FieldOperand(rdx, JSFunction::kContextOffset)); | |
1239 | |
1240 // Push the function and the receiver onto the stack. | |
1241 __ push(rdx); | |
1242 __ push(r8); | |
1243 | |
1244 // Load the number of arguments and setup pointer to the arguments. | |
1245 __ movq(rax, r9); | |
1246 // Load the previous frame pointer to access C argument on stack | |
1247 __ movq(kScratchRegister, Operand(rbp, 0)); | |
1248 __ movq(rbx, Operand(kScratchRegister, EntryFrameConstants::kArgvOffset)); | |
1249 // Load the function pointer into rdi. | |
1250 __ movq(rdi, rdx); | |
1251 #else // _WIN64 | |
1252 // GCC parameters in: | |
1253 // rdi : entry (ignored) | |
1254 // rsi : function | |
1255 // rdx : receiver | |
1256 // rcx : argc | |
1257 // r8 : argv | |
1258 | |
1259 __ movq(rdi, rsi); | |
1260 // rdi : function | |
1261 | |
1262 // Clear the context before we push it when entering the JS frame. | |
1263 __ xor_(rsi, rsi); | |
1264 // Enter an internal frame. | |
1265 __ EnterInternalFrame(); | |
1266 | |
1267 // Push the function and receiver and setup the context. | |
1268 __ push(rdi); | |
1269 __ push(rdx); | |
1270 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | |
1271 | |
1272 // Load the number of arguments and setup pointer to the arguments. | |
1273 __ movq(rax, rcx); | |
1274 __ movq(rbx, r8); | |
1275 #endif // _WIN64 | |
1276 | |
1277 // Current stack contents: | |
1278 // [rsp + 2 * kPointerSize ... ]: Internal frame | |
1279 // [rsp + kPointerSize] : function | |
1280 // [rsp] : receiver | |
1281 // Current register contents: | |
1282 // rax : argc | |
1283 // rbx : argv | |
1284 // rsi : context | |
1285 // rdi : function | |
1286 | |
1287 // Copy arguments to the stack in a loop. | |
1288 // Register rbx points to array of pointers to handle locations. | |
1289 // Push the values of these handles. | |
1290 Label loop, entry; | |
1291 __ xor_(rcx, rcx); // Set loop variable to 0. | |
1292 __ jmp(&entry); | |
1293 __ bind(&loop); | |
1294 __ movq(kScratchRegister, Operand(rbx, rcx, times_pointer_size, 0)); | |
1295 __ push(Operand(kScratchRegister, 0)); // dereference handle | |
1296 __ addq(rcx, Immediate(1)); | |
1297 __ bind(&entry); | |
1298 __ cmpq(rcx, rax); | |
1299 __ j(not_equal, &loop); | |
1300 | |
1301 // Invoke the code. | |
1302 if (is_construct) { | |
1303 // Expects rdi to hold function pointer. | |
1304 __ Call(Handle<Code>(Builtins::builtin(Builtins::JSConstructCall)), | |
1305 RelocInfo::CODE_TARGET); | |
1306 } else { | |
1307 ParameterCount actual(rax); | |
1308 // Function must be in rdi. | |
1309 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | |
1310 } | 1334 } |
1311 | 1335 |
1312 // Exit the JS frame. Notice that this also removes the empty | 1336 { // Too few parameters: Actual < expected. |
1313 // context and the function left on the stack by the code | 1337 __ bind(&too_few); |
1314 // invocation. | 1338 EnterArgumentsAdaptorFrame(masm); |
1315 __ LeaveInternalFrame(); | |
1316 // TODO(X64): Is argument correct? Is there a receiver to remove? | |
1317 __ ret(1 * kPointerSize); // remove receiver | |
1318 } | |
1319 | 1339 |
1340 // Copy receiver and all actual arguments. | |
1341 const int offset = StandardFrameConstants::kCallerSPOffset; | |
1342 __ lea(rdi, Operand(rbp, rax, times_pointer_size, offset)); | |
1343 __ movq(rcx, Immediate(-1)); // account for receiver | |
1320 | 1344 |
1321 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { | 1345 Label copy; |
1322 Generate_JSEntryTrampolineHelper(masm, false); | 1346 __ bind(©); |
1323 } | 1347 __ incq(rcx); |
1348 __ push(Operand(rdi, 0)); | |
1349 __ subq(rdi, Immediate(kPointerSize)); | |
1350 __ cmpq(rcx, rax); | |
1351 __ j(less, ©); | |
1324 | 1352 |
1353 // Fill remaining expected arguments with undefined values. | |
1354 Label fill; | |
1355 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); | |
1356 __ bind(&fill); | |
1357 __ incq(rcx); | |
1358 __ push(kScratchRegister); | |
1359 __ cmpq(rcx, rbx); | |
1360 __ j(less, &fill); | |
1325 | 1361 |
1326 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { | 1362 // Restore function pointer. |
1327 Generate_JSEntryTrampolineHelper(masm, true); | 1363 __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
1328 } | 1364 } |
1329 | 1365 |
1366 // Call the entry point. | |
1367 __ bind(&invoke); | |
1368 __ call(rdx); | |
1330 | 1369 |
1331 void Builtins::Generate_LazyCompile(MacroAssembler* masm) { | 1370 // Leave frame and return. |
1332 // Enter an internal frame. | 1371 LeaveArgumentsAdaptorFrame(masm); |
1333 __ EnterInternalFrame(); | 1372 __ ret(0); |
1334 | 1373 |
1335 // Push a copy of the function onto the stack. | 1374 // ------------------------------------------- |
1336 __ push(rdi); | 1375 // Dont adapt arguments. |
1337 | 1376 // ------------------------------------------- |
1338 __ push(rdi); // Function is also the parameter to the runtime call. | 1377 __ bind(&dont_adapt_arguments); |
1339 __ CallRuntime(Runtime::kLazyCompile, 1); | 1378 __ jmp(rdx); |
1340 __ pop(rdi); | |
1341 | |
1342 // Tear down temporary frame. | |
1343 __ LeaveInternalFrame(); | |
1344 | |
1345 // Do a tail-call of the compiled function. | |
1346 __ lea(rcx, FieldOperand(rax, Code::kHeaderSize)); | |
1347 __ jmp(rcx); | |
1348 } | |
1349 | |
1350 | |
1351 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) { | |
1352 // Enter an internal frame. | |
1353 __ EnterInternalFrame(); | |
1354 | |
1355 // Push a copy of the function onto the stack. | |
1356 __ push(rdi); | |
1357 | |
1358 __ push(rdi); // Function is also the parameter to the runtime call. | |
1359 __ CallRuntime(Runtime::kLazyRecompile, 1); | |
1360 | |
1361 // Restore function and tear down temporary frame. | |
1362 __ pop(rdi); | |
1363 __ LeaveInternalFrame(); | |
1364 | |
1365 // Do a tail-call of the compiled function. | |
1366 __ lea(rcx, FieldOperand(rax, Code::kHeaderSize)); | |
1367 __ jmp(rcx); | |
1368 } | |
1369 | |
1370 | |
1371 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { | |
1372 __ int3(); | |
1373 } | |
1374 | |
1375 | |
1376 void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) { | |
1377 __ int3(); | |
1378 } | |
1379 | |
1380 | |
1381 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) { | |
1382 __ int3(); | |
1383 } | 1379 } |
1384 | 1380 |
1385 | 1381 |
1386 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { | 1382 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { |
1387 __ int3(); | 1383 __ int3(); |
1388 } | 1384 } |
1389 | 1385 |
1390 | 1386 |
1387 #undef __ | |
1388 | |
1391 } } // namespace v8::internal | 1389 } } // namespace v8::internal |
1392 | 1390 |
1393 #endif // V8_TARGET_ARCH_X64 | 1391 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |