Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/x64/builtins-x64.cc

Issue 6580038: [Isolates] Merge from bleeding_edge, revisions 5934-6100. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/version.cc ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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>(Isolate::Current()->builtins()->builtin(
102 ArgumentsAdaptorTrampoline)), 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>(Isolate::Current()->builtins()->builtin(
343 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(&copy); 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, &copy); 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>(Isolate::Current()->builtins()->builtin(
496 Builtins::JSConstructCall)), 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(&copy); 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, &copy); 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 ParameterCount actual(rax); 837 ParameterCount actual(rax);
445 __ SmiToInteger32(rax, rax); 838 __ SmiToInteger32(rax, rax);
446 __ movq(rdi, Operand(rbp, kFunctionOffset)); 839 __ movq(rdi, Operand(rbp, kFunctionOffset));
447 __ InvokeFunction(rdi, actual, CALL_FUNCTION); 840 __ InvokeFunction(rdi, actual, CALL_FUNCTION);
448 841
449 __ LeaveInternalFrame(); 842 __ LeaveInternalFrame();
450 __ ret(3 * kPointerSize); // remove function, receiver, and arguments 843 __ ret(3 * kPointerSize); // remove function, receiver, and arguments
451 } 844 }
452 845
453 846
454 // Load the built-in Array function from the current context.
455 static void GenerateLoadArrayFunction(MacroAssembler* masm, Register result) {
456 // Load the global context.
457 __ movq(result, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX)));
458 __ movq(result, FieldOperand(result, GlobalObject::kGlobalContextOffset));
459 // Load the Array function from the global context.
460 __ movq(result,
461 Operand(result, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX)));
462 }
463
464
465 // Number of empty elements to allocate for an empty array. 847 // Number of empty elements to allocate for an empty array.
466 static const int kPreallocatedArrayElements = 4; 848 static const int kPreallocatedArrayElements = 4;
467 849
468 850
469 // Allocate an empty JSArray. The allocated array is put into the result 851 // Allocate an empty JSArray. The allocated array is put into the result
470 // register. If the parameter initial_capacity is larger than zero an elements 852 // register. If the parameter initial_capacity is larger than zero an elements
471 // backing store is allocated with this size and filled with the hole values. 853 // backing store is allocated with this size and filled with the hole values.
472 // Otherwise the elements backing store is set to the empty FixedArray. 854 // Otherwise the elements backing store is set to the empty FixedArray.
473 static void AllocateEmptyJSArray(MacroAssembler* masm, 855 static void AllocateEmptyJSArray(MacroAssembler* masm,
474 Register array_function, 856 Register array_function,
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 1189
808 void Builtins::Generate_ArrayCode(MacroAssembler* masm) { 1190 void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
809 // ----------- S t a t e ------------- 1191 // ----------- S t a t e -------------
810 // -- rax : argc 1192 // -- rax : argc
811 // -- rsp[0] : return address 1193 // -- rsp[0] : return address
812 // -- rsp[8] : last argument 1194 // -- rsp[8] : last argument
813 // ----------------------------------- 1195 // -----------------------------------
814 Label generic_array_code; 1196 Label generic_array_code;
815 1197
816 // Get the Array function. 1198 // Get the Array function.
817 GenerateLoadArrayFunction(masm, rdi); 1199 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rdi);
818 1200
819 if (FLAG_debug_code) { 1201 if (FLAG_debug_code) {
820 // Initial map for the builtin Array function shoud be a map. 1202 // Initial map for the builtin Array function shoud be a map.
821 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); 1203 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
822 // Will both indicate a NULL and a Smi. 1204 // Will both indicate a NULL and a Smi.
823 ASSERT(kSmiTag == 0); 1205 ASSERT(kSmiTag == 0);
824 Condition not_smi = NegateCondition(masm->CheckSmi(rbx)); 1206 Condition not_smi = NegateCondition(masm->CheckSmi(rbx));
825 __ Check(not_smi, "Unexpected initial map for Array function"); 1207 __ Check(not_smi, "Unexpected initial map for Array function");
826 __ CmpObjectType(rbx, MAP_TYPE, rcx); 1208 __ CmpObjectType(rbx, MAP_TYPE, rcx);
827 __ Check(equal, "Unexpected initial map for Array function"); 1209 __ Check(equal, "Unexpected initial map for Array function");
(...skipping 17 matching lines...) Expand all
845 // -- rax : argc 1227 // -- rax : argc
846 // -- rdi : constructor 1228 // -- rdi : constructor
847 // -- rsp[0] : return address 1229 // -- rsp[0] : return address
848 // -- rsp[8] : last argument 1230 // -- rsp[8] : last argument
849 // ----------------------------------- 1231 // -----------------------------------
850 Label generic_constructor; 1232 Label generic_constructor;
851 1233
852 if (FLAG_debug_code) { 1234 if (FLAG_debug_code) {
853 // The array construct code is only set for the builtin Array function which 1235 // The array construct code is only set for the builtin Array function which
854 // does always have a map. 1236 // does always have a map.
855 GenerateLoadArrayFunction(masm, rbx); 1237 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rbx);
856 __ cmpq(rdi, rbx); 1238 __ cmpq(rdi, rbx);
857 __ Check(equal, "Unexpected Array function"); 1239 __ Check(equal, "Unexpected Array function");
858 // Initial map for the builtin Array function should be a map. 1240 // Initial map for the builtin Array function should be a map.
859 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); 1241 __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
860 // Will both indicate a NULL and a Smi. 1242 // Will both indicate a NULL and a Smi.
861 ASSERT(kSmiTag == 0); 1243 ASSERT(kSmiTag == 0);
862 Condition not_smi = NegateCondition(masm->CheckSmi(rbx)); 1244 Condition not_smi = NegateCondition(masm->CheckSmi(rbx));
863 __ Check(not_smi, "Unexpected initial map for Array function"); 1245 __ Check(not_smi, "Unexpected initial map for Array function");
864 __ CmpObjectType(rbx, MAP_TYPE, rcx); 1246 __ CmpObjectType(rbx, MAP_TYPE, rcx);
865 __ Check(equal, "Unexpected initial map for Array function"); 1247 __ Check(equal, "Unexpected initial map for Array function");
(...skipping 12 matching lines...) Expand all
878 } 1260 }
879 1261
880 1262
881 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { 1263 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
882 // TODO(849): implement custom construct stub. 1264 // TODO(849): implement custom construct stub.
883 // Generate a copy of the generic stub for now. 1265 // Generate a copy of the generic stub for now.
884 Generate_JSConstructStubGeneric(masm); 1266 Generate_JSConstructStubGeneric(masm);
885 } 1267 }
886 1268
887 1269
888 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { 1270 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
889 // ----------- S t a t e ------------- 1271 __ push(rbp);
890 // -- rax: number of arguments 1272 __ movq(rbp, rsp);
891 // -- rdi: constructor function
892 // -----------------------------------
893 1273
894 Label non_function_call; 1274 // Store the arguments adaptor context sentinel.
895 // Check that function is not a smi. 1275 __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
896 __ JumpIfSmi(rdi, &non_function_call);
897 // Check that function is a JSFunction.
898 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
899 __ j(not_equal, &non_function_call);
900 1276
901 // Jump to the function-specific construct stub. 1277 // Push the function on the stack.
902 __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); 1278 __ push(rdi);
903 __ movq(rbx, FieldOperand(rbx, SharedFunctionInfo::kConstructStubOffset));
904 __ lea(rbx, FieldOperand(rbx, Code::kHeaderSize));
905 __ jmp(rbx);
906 1279
907 // rdi: called object 1280 // Preserve the number of arguments on the stack. Must preserve both
908 // rax: number of arguments 1281 // rax and rbx because these registers are used when copying the
909 __ bind(&non_function_call); 1282 // arguments and the receiver.
910 // Set expected number of arguments to zero (not changing rax). 1283 __ Integer32ToSmi(rcx, rax);
911 __ movq(rbx, Immediate(0)); 1284 __ push(rcx);
912 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
913 __ Jump(Handle<Code>(Isolate::Current()->builtins()->builtin(
914 ArgumentsAdaptorTrampoline)), RelocInfo::CODE_TARGET);
915 } 1285 }
916 1286
917 1287
918 static void Generate_JSConstructStubHelper(MacroAssembler* masm, 1288 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
919 bool is_api_function, 1289 // Retrieve the number of arguments from the stack. Number is a Smi.
920 bool count_constructions) { 1290 __ movq(rbx, Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset));
921 // Should never count constructions for api objects.
922 ASSERT(!is_api_function || !count_constructions);
923 1291
924 // Enter a construct frame. 1292 // Leave the frame.
925 __ EnterConstructFrame(); 1293 __ movq(rsp, rbp);
1294 __ pop(rbp);
926 1295
927 // Store a smi-tagged arguments count on the stack. 1296 // Remove caller arguments from the stack.
928 __ Integer32ToSmi(rax, rax);
929 __ push(rax);
930
931 // Push the function to invoke on the stack.
932 __ push(rdi);
933
934 // Try to allocate the object without transitioning into C code. If any of the
935 // preconditions is not met, the code bails out to the runtime call.
936 Label rt_call, allocated;
937 if (FLAG_inline_new) {
938 Label undo_allocation;
939
940 #ifdef ENABLE_DEBUGGER_SUPPORT
941 ExternalReference debug_step_in_fp =
942 ExternalReference::debug_step_in_fp_address();
943 __ movq(kScratchRegister, debug_step_in_fp);
944 __ cmpq(Operand(kScratchRegister, 0), Immediate(0));
945 __ j(not_equal, &rt_call);
946 #endif
947
948 // Verified that the constructor is a JSFunction.
949 // Load the initial map and verify that it is in fact a map.
950 // rdi: constructor
951 __ movq(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
952 // Will both indicate a NULL and a Smi
953 ASSERT(kSmiTag == 0);
954 __ JumpIfSmi(rax, &rt_call);
955 // rdi: constructor
956 // rax: initial map (if proven valid below)
957 __ CmpObjectType(rax, MAP_TYPE, rbx);
958 __ j(not_equal, &rt_call);
959
960 // Check that the constructor is not constructing a JSFunction (see comments
961 // in Runtime_NewObject in runtime.cc). In which case the initial map's
962 // instance type would be JS_FUNCTION_TYPE.
963 // rdi: constructor
964 // rax: initial map
965 __ CmpInstanceType(rax, JS_FUNCTION_TYPE);
966 __ j(equal, &rt_call);
967
968 if (count_constructions) {
969 Label allocate;
970 // Decrease generous allocation count.
971 __ movq(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
972 __ decb(FieldOperand(rcx, SharedFunctionInfo::kConstructionCountOffset));
973 __ j(not_zero, &allocate);
974
975 __ push(rax);
976 __ push(rdi);
977
978 __ push(rdi); // constructor
979 // The call will replace the stub, so the countdown is only done once.
980 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
981
982 __ pop(rdi);
983 __ pop(rax);
984
985 __ bind(&allocate);
986 }
987
988 // Now allocate the JSObject on the heap.
989 __ movzxbq(rdi, FieldOperand(rax, Map::kInstanceSizeOffset));
990 __ shl(rdi, Immediate(kPointerSizeLog2));
991 // rdi: size of new object
992 __ AllocateInNewSpace(rdi,
993 rbx,
994 rdi,
995 no_reg,
996 &rt_call,
997 NO_ALLOCATION_FLAGS);
998 // Allocated the JSObject, now initialize the fields.
999 // rax: initial map
1000 // rbx: JSObject (not HeapObject tagged - the actual address).
1001 // rdi: start of next object
1002 __ movq(Operand(rbx, JSObject::kMapOffset), rax);
1003 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex);
1004 __ movq(Operand(rbx, JSObject::kPropertiesOffset), rcx);
1005 __ movq(Operand(rbx, JSObject::kElementsOffset), rcx);
1006 // Set extra fields in the newly allocated object.
1007 // rax: initial map
1008 // rbx: JSObject
1009 // rdi: start of next object
1010 { Label loop, entry;
1011 // To allow for truncation.
1012 if (count_constructions) {
1013 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex);
1014 } else {
1015 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
1016 }
1017 __ lea(rcx, Operand(rbx, JSObject::kHeaderSize));
1018 __ jmp(&entry);
1019 __ bind(&loop);
1020 __ movq(Operand(rcx, 0), rdx);
1021 __ addq(rcx, Immediate(kPointerSize));
1022 __ bind(&entry);
1023 __ cmpq(rcx, rdi);
1024 __ j(less, &loop);
1025 }
1026
1027 // Add the object tag to make the JSObject real, so that we can continue and
1028 // jump into the continuation code at any time from now on. Any failures
1029 // need to undo the allocation, so that the heap is in a consistent state
1030 // and verifiable.
1031 // rax: initial map
1032 // rbx: JSObject
1033 // rdi: start of next object
1034 __ or_(rbx, Immediate(kHeapObjectTag));
1035
1036 // Check if a non-empty properties array is needed.
1037 // Allocate and initialize a FixedArray if it is.
1038 // rax: initial map
1039 // rbx: JSObject
1040 // rdi: start of next object
1041 // Calculate total properties described map.
1042 __ movzxbq(rdx, FieldOperand(rax, Map::kUnusedPropertyFieldsOffset));
1043 __ movzxbq(rcx, FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset));
1044 __ addq(rdx, rcx);
1045 // Calculate unused properties past the end of the in-object properties.
1046 __ movzxbq(rcx, FieldOperand(rax, Map::kInObjectPropertiesOffset));
1047 __ subq(rdx, rcx);
1048 // Done if no extra properties are to be allocated.
1049 __ j(zero, &allocated);
1050 __ Assert(positive, "Property allocation count failed.");
1051
1052 // Scale the number of elements by pointer size and add the header for
1053 // FixedArrays to the start of the next object calculation from above.
1054 // rbx: JSObject
1055 // rdi: start of next object (will be start of FixedArray)
1056 // rdx: number of elements in properties array
1057 __ AllocateInNewSpace(FixedArray::kHeaderSize,
1058 times_pointer_size,
1059 rdx,
1060 rdi,
1061 rax,
1062 no_reg,
1063 &undo_allocation,
1064 RESULT_CONTAINS_TOP);
1065
1066 // Initialize the FixedArray.
1067 // rbx: JSObject
1068 // rdi: FixedArray
1069 // rdx: number of elements
1070 // rax: start of next object
1071 __ LoadRoot(rcx, Heap::kFixedArrayMapRootIndex);
1072 __ movq(Operand(rdi, HeapObject::kMapOffset), rcx); // setup the map
1073 __ Integer32ToSmi(rdx, rdx);
1074 __ movq(Operand(rdi, FixedArray::kLengthOffset), rdx); // and length
1075
1076 // Initialize the fields to undefined.
1077 // rbx: JSObject
1078 // rdi: FixedArray
1079 // rax: start of next object
1080 // rdx: number of elements
1081 { Label loop, entry;
1082 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
1083 __ lea(rcx, Operand(rdi, FixedArray::kHeaderSize));
1084 __ jmp(&entry);
1085 __ bind(&loop);
1086 __ movq(Operand(rcx, 0), rdx);
1087 __ addq(rcx, Immediate(kPointerSize));
1088 __ bind(&entry);
1089 __ cmpq(rcx, rax);
1090 __ j(below, &loop);
1091 }
1092
1093 // Store the initialized FixedArray into the properties field of
1094 // the JSObject
1095 // rbx: JSObject
1096 // rdi: FixedArray
1097 __ or_(rdi, Immediate(kHeapObjectTag)); // add the heap tag
1098 __ movq(FieldOperand(rbx, JSObject::kPropertiesOffset), rdi);
1099
1100
1101 // Continue with JSObject being successfully allocated
1102 // rbx: JSObject
1103 __ jmp(&allocated);
1104
1105 // Undo the setting of the new top so that the heap is verifiable. For
1106 // example, the map's unused properties potentially do not match the
1107 // allocated objects unused properties.
1108 // rbx: JSObject (previous new top)
1109 __ bind(&undo_allocation);
1110 __ UndoAllocationInNewSpace(rbx);
1111 }
1112
1113 // Allocate the new receiver object using the runtime call.
1114 // rdi: function (constructor)
1115 __ bind(&rt_call);
1116 // Must restore rdi (constructor) before calling runtime.
1117 __ movq(rdi, Operand(rsp, 0));
1118 __ push(rdi);
1119 __ CallRuntime(Runtime::kNewObject, 1);
1120 __ movq(rbx, rax); // store result in rbx
1121
1122 // New object allocated.
1123 // rbx: newly allocated object
1124 __ bind(&allocated);
1125 // Retrieve the function from the stack.
1126 __ pop(rdi);
1127
1128 // Retrieve smi-tagged arguments count from the stack.
1129 __ movq(rax, Operand(rsp, 0));
1130 __ SmiToInteger32(rax, rax);
1131
1132 // Push the allocated receiver to the stack. We need two copies
1133 // because we may have to return the original one and the calling
1134 // conventions dictate that the called function pops the receiver.
1135 __ push(rbx);
1136 __ push(rbx);
1137
1138 // Setup pointer to last argument.
1139 __ lea(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset));
1140
1141 // Copy arguments and receiver to the expression stack.
1142 Label loop, entry;
1143 __ movq(rcx, rax);
1144 __ jmp(&entry);
1145 __ bind(&loop);
1146 __ push(Operand(rbx, rcx, times_pointer_size, 0));
1147 __ bind(&entry);
1148 __ decq(rcx);
1149 __ j(greater_equal, &loop);
1150
1151 // Call the function.
1152 if (is_api_function) {
1153 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
1154 Handle<Code> code = Handle<Code>(
1155 Isolate::Current()->builtins()->builtin(
1156 Builtins::HandleApiCallConstruct));
1157 ParameterCount expected(0);
1158 __ InvokeCode(code, expected, expected,
1159 RelocInfo::CODE_TARGET, CALL_FUNCTION);
1160 } else {
1161 ParameterCount actual(rax);
1162 __ InvokeFunction(rdi, actual, CALL_FUNCTION);
1163 }
1164
1165 // Restore context from the frame.
1166 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
1167
1168 // If the result is an object (in the ECMA sense), we should get rid
1169 // of the receiver and use the result; see ECMA-262 section 13.2.2-7
1170 // on page 74.
1171 Label use_receiver, exit;
1172 // If the result is a smi, it is *not* an object in the ECMA sense.
1173 __ JumpIfSmi(rax, &use_receiver);
1174
1175 // If the type of the result (stored in its map) is less than
1176 // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense.
1177 __ CmpObjectType(rax, FIRST_JS_OBJECT_TYPE, rcx);
1178 __ j(above_equal, &exit);
1179
1180 // Throw away the result of the constructor invocation and use the
1181 // on-stack receiver as the result.
1182 __ bind(&use_receiver);
1183 __ movq(rax, Operand(rsp, 0));
1184
1185 // Restore the arguments count and leave the construct frame.
1186 __ bind(&exit);
1187 __ movq(rbx, Operand(rsp, kPointerSize)); // get arguments count
1188 __ LeaveConstructFrame();
1189
1190 // Remove caller arguments from the stack and return.
1191 __ pop(rcx); 1297 __ pop(rcx);
1192 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); 1298 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2);
1193 __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); 1299 __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize));
1194 __ push(rcx); 1300 __ push(rcx);
1195 __ IncrementCounter(COUNTERS->constructed_objects(), 1);
1196 __ ret(0);
1197 } 1301 }
1198 1302
1199 1303
1200 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { 1304 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
1201 Generate_JSConstructStubHelper(masm, false, true); 1305 // ----------- S t a t e -------------
1202 } 1306 // -- rax : actual number of arguments
1307 // -- rbx : expected number of arguments
1308 // -- rdx : code entry to call
1309 // -----------------------------------
1203 1310
1311 Label invoke, dont_adapt_arguments;
1312 __ IncrementCounter(COUNTERS->arguments_adaptors(), 1);
1204 1313
1205 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { 1314 Label enough, too_few;
1206 Generate_JSConstructStubHelper(masm, false, false); 1315 __ cmpq(rax, rbx);
1207 } 1316 __ j(less, &too_few);
1317 __ cmpq(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
1318 __ j(equal, &dont_adapt_arguments);
1208 1319
1320 { // Enough parameters: Actual >= expected.
1321 __ bind(&enough);
1322 EnterArgumentsAdaptorFrame(masm);
1209 1323
1210 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { 1324 // Copy receiver and all expected arguments.
1211 Generate_JSConstructStubHelper(masm, true, false); 1325 const int offset = StandardFrameConstants::kCallerSPOffset;
1212 } 1326 __ lea(rax, Operand(rbp, rax, times_pointer_size, offset));
1327 __ movq(rcx, Immediate(-1)); // account for receiver
1213 1328
1214 1329 Label copy;
1215 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, 1330 __ bind(&copy);
1216 bool is_construct) { 1331 __ incq(rcx);
1217 // Expects five C++ function parameters. 1332 __ push(Operand(rax, 0));
1218 // - Address entry (ignored) 1333 __ subq(rax, Immediate(kPointerSize));
1219 // - JSFunction* function ( 1334 __ cmpq(rcx, rbx);
1220 // - Object* receiver 1335 __ j(less, &copy);
1221 // - int argc 1336 __ jmp(&invoke);
1222 // - Object*** argv
1223 // (see Handle::Invoke in execution.cc).
1224
1225 // Platform specific argument handling. After this, the stack contains
1226 // an internal frame and the pushed function and receiver, and
1227 // register rax and rbx holds the argument count and argument array,
1228 // while rdi holds the function pointer and rsi the context.
1229 #ifdef _WIN64
1230 // MSVC parameters in:
1231 // rcx : entry (ignored)
1232 // rdx : function
1233 // r8 : receiver
1234 // r9 : argc
1235 // [rsp+0x20] : argv
1236
1237 // Clear the context before we push it when entering the JS frame.
1238 __ xor_(rsi, rsi);
1239 __ EnterInternalFrame();
1240
1241 // Load the function context into rsi.
1242 __ movq(rsi, FieldOperand(rdx, JSFunction::kContextOffset));
1243
1244 // Push the function and the receiver onto the stack.
1245 __ push(rdx);
1246 __ push(r8);
1247
1248 // Load the number of arguments and setup pointer to the arguments.
1249 __ movq(rax, r9);
1250 // Load the previous frame pointer to access C argument on stack
1251 __ movq(kScratchRegister, Operand(rbp, 0));
1252 __ movq(rbx, Operand(kScratchRegister, EntryFrameConstants::kArgvOffset));
1253 // Load the function pointer into rdi.
1254 __ movq(rdi, rdx);
1255 #else // _WIN64
1256 // GCC parameters in:
1257 // rdi : entry (ignored)
1258 // rsi : function
1259 // rdx : receiver
1260 // rcx : argc
1261 // r8 : argv
1262
1263 __ movq(rdi, rsi);
1264 // rdi : function
1265
1266 // Clear the context before we push it when entering the JS frame.
1267 __ xor_(rsi, rsi);
1268 // Enter an internal frame.
1269 __ EnterInternalFrame();
1270
1271 // Push the function and receiver and setup the context.
1272 __ push(rdi);
1273 __ push(rdx);
1274 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
1275
1276 // Load the number of arguments and setup pointer to the arguments.
1277 __ movq(rax, rcx);
1278 __ movq(rbx, r8);
1279 #endif // _WIN64
1280
1281 // Current stack contents:
1282 // [rsp + 2 * kPointerSize ... ]: Internal frame
1283 // [rsp + kPointerSize] : function
1284 // [rsp] : receiver
1285 // Current register contents:
1286 // rax : argc
1287 // rbx : argv
1288 // rsi : context
1289 // rdi : function
1290
1291 // Copy arguments to the stack in a loop.
1292 // Register rbx points to array of pointers to handle locations.
1293 // Push the values of these handles.
1294 Label loop, entry;
1295 __ xor_(rcx, rcx); // Set loop variable to 0.
1296 __ jmp(&entry);
1297 __ bind(&loop);
1298 __ movq(kScratchRegister, Operand(rbx, rcx, times_pointer_size, 0));
1299 __ push(Operand(kScratchRegister, 0)); // dereference handle
1300 __ addq(rcx, Immediate(1));
1301 __ bind(&entry);
1302 __ cmpq(rcx, rax);
1303 __ j(not_equal, &loop);
1304
1305 // Invoke the code.
1306 if (is_construct) {
1307 // Expects rdi to hold function pointer.
1308 __ Call(Handle<Code>(Isolate::Current()->builtins()->builtin(
1309 Builtins::JSConstructCall)), RelocInfo::CODE_TARGET);
1310 } else {
1311 ParameterCount actual(rax);
1312 // Function must be in rdi.
1313 __ InvokeFunction(rdi, actual, CALL_FUNCTION);
1314 } 1337 }
1315 1338
1316 // Exit the JS frame. Notice that this also removes the empty 1339 { // Too few parameters: Actual < expected.
1317 // context and the function left on the stack by the code 1340 __ bind(&too_few);
1318 // invocation. 1341 EnterArgumentsAdaptorFrame(masm);
1319 __ LeaveInternalFrame();
1320 // TODO(X64): Is argument correct? Is there a receiver to remove?
1321 __ ret(1 * kPointerSize); // remove receiver
1322 }
1323 1342
1343 // Copy receiver and all actual arguments.
1344 const int offset = StandardFrameConstants::kCallerSPOffset;
1345 __ lea(rdi, Operand(rbp, rax, times_pointer_size, offset));
1346 __ movq(rcx, Immediate(-1)); // account for receiver
1324 1347
1325 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { 1348 Label copy;
1326 Generate_JSEntryTrampolineHelper(masm, false); 1349 __ bind(&copy);
1327 } 1350 __ incq(rcx);
1351 __ push(Operand(rdi, 0));
1352 __ subq(rdi, Immediate(kPointerSize));
1353 __ cmpq(rcx, rax);
1354 __ j(less, &copy);
1328 1355
1356 // Fill remaining expected arguments with undefined values.
1357 Label fill;
1358 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex);
1359 __ bind(&fill);
1360 __ incq(rcx);
1361 __ push(kScratchRegister);
1362 __ cmpq(rcx, rbx);
1363 __ j(less, &fill);
1329 1364
1330 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { 1365 // Restore function pointer.
1331 Generate_JSEntryTrampolineHelper(masm, true); 1366 __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1332 } 1367 }
1333 1368
1369 // Call the entry point.
1370 __ bind(&invoke);
1371 __ call(rdx);
1334 1372
1335 void Builtins::Generate_LazyCompile(MacroAssembler* masm) { 1373 // Leave frame and return.
1336 // Enter an internal frame. 1374 LeaveArgumentsAdaptorFrame(masm);
1337 __ EnterInternalFrame(); 1375 __ ret(0);
1338 1376
1339 // Push a copy of the function onto the stack. 1377 // -------------------------------------------
1340 __ push(rdi); 1378 // Dont adapt arguments.
1341 1379 // -------------------------------------------
1342 __ push(rdi); // Function is also the parameter to the runtime call. 1380 __ bind(&dont_adapt_arguments);
1343 __ CallRuntime(Runtime::kLazyCompile, 1); 1381 __ jmp(rdx);
1344 __ pop(rdi);
1345
1346 // Tear down temporary frame.
1347 __ LeaveInternalFrame();
1348
1349 // Do a tail-call of the compiled function.
1350 __ lea(rcx, FieldOperand(rax, Code::kHeaderSize));
1351 __ jmp(rcx);
1352 }
1353
1354
1355 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) {
1356 // Enter an internal frame.
1357 __ EnterInternalFrame();
1358
1359 // Push a copy of the function onto the stack.
1360 __ push(rdi);
1361
1362 __ push(rdi); // Function is also the parameter to the runtime call.
1363 __ CallRuntime(Runtime::kLazyRecompile, 1);
1364
1365 // Restore function and tear down temporary frame.
1366 __ pop(rdi);
1367 __ LeaveInternalFrame();
1368
1369 // Do a tail-call of the compiled function.
1370 __ lea(rcx, FieldOperand(rax, Code::kHeaderSize));
1371 __ jmp(rcx);
1372 }
1373
1374
1375 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) {
1376 __ int3();
1377 }
1378
1379
1380 void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
1381 __ int3();
1382 }
1383
1384
1385 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) {
1386 __ int3();
1387 } 1382 }
1388 1383
1389 1384
1390 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { 1385 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1391 __ int3(); 1386 __ int3();
1392 } 1387 }
1393 1388
1394 1389
1390 #undef __
1391
1395 } } // namespace v8::internal 1392 } } // namespace v8::internal
1396 1393
1397 #endif // V8_TARGET_ARCH_X64 1394 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/version.cc ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698