| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (create_memento) { | 129 if (create_memento) { |
| 130 __ jmp(count_incremented); | 130 __ jmp(count_incremented); |
| 131 } else { | 131 } else { |
| 132 __ jmp(allocated); | 132 __ jmp(allocated); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 137 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 138 bool is_api_function, | 138 bool is_api_function, |
| 139 bool use_new_target, |
| 139 bool create_memento) { | 140 bool create_memento) { |
| 140 // ----------- S t a t e ------------- | 141 // ----------- S t a t e ------------- |
| 141 // -- rax: number of arguments | 142 // -- rax: number of arguments |
| 142 // -- rdi: constructor function | 143 // -- rdi: constructor function |
| 143 // -- rbx: allocation site or undefined | 144 // -- rbx: allocation site or undefined |
| 144 // -- rdx: original constructor | 145 // -- rdx: original constructor |
| 145 // ----------------------------------- | 146 // ----------------------------------- |
| 146 | 147 |
| 147 // Should never create mementos for api functions. | 148 // Should never create mementos for api functions. |
| 148 DCHECK(!is_api_function || !create_memento); | 149 DCHECK(!is_api_function || !create_memento); |
| 149 | 150 |
| 150 // Enter a construct frame. | 151 // Enter a construct frame. |
| 151 { | 152 { |
| 152 FrameScope scope(masm, StackFrame::CONSTRUCT); | 153 FrameScope scope(masm, StackFrame::CONSTRUCT); |
| 153 | 154 |
| 154 if (create_memento) { | 155 if (create_memento) { |
| 155 __ AssertUndefinedOrAllocationSite(rbx); | 156 __ AssertUndefinedOrAllocationSite(rbx); |
| 156 __ Push(rbx); | 157 __ Push(rbx); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Store a smi-tagged arguments count on the stack. | 160 // Store a smi-tagged arguments count on the stack. |
| 160 __ Integer32ToSmi(rax, rax); | 161 __ Integer32ToSmi(rax, rax); |
| 161 __ Push(rax); | 162 __ Push(rax); |
| 162 | 163 |
| 163 // Push the function to invoke on the stack. | 164 // Push the function to invoke on the stack. |
| 164 __ Push(rdi); | 165 __ Push(rdi); |
| 165 | 166 |
| 167 if (use_new_target) { |
| 168 __ Push(rdx); |
| 169 } |
| 170 |
| 166 Label rt_call, normal_new, allocated, count_incremented; | 171 Label rt_call, normal_new, allocated, count_incremented; |
| 167 __ cmpp(rdx, rdi); | 172 __ cmpp(rdx, rdi); |
| 168 __ j(equal, &normal_new); | 173 __ j(equal, &normal_new); |
| 169 | 174 |
| 170 Generate_Runtime_NewObject(masm, create_memento, rdx, &count_incremented, | 175 Generate_Runtime_NewObject(masm, create_memento, rdx, &count_incremented, |
| 171 &allocated); | 176 &allocated); |
| 172 | 177 |
| 173 __ bind(&normal_new); | 178 __ bind(&normal_new); |
| 174 // Try to allocate the object without transitioning into C code. If any of | 179 // Try to allocate the object without transitioning into C code. If any of |
| 175 // the preconditions is not met, the code bails out to the runtime call. | 180 // the preconditions is not met, the code bails out to the runtime call. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // need to increment the memento create count. | 400 // need to increment the memento create count. |
| 396 __ SmiAddConstant( | 401 __ SmiAddConstant( |
| 397 FieldOperand(rcx, AllocationSite::kPretenureCreateCountOffset), | 402 FieldOperand(rcx, AllocationSite::kPretenureCreateCountOffset), |
| 398 Smi::FromInt(1)); | 403 Smi::FromInt(1)); |
| 399 __ bind(&count_incremented); | 404 __ bind(&count_incremented); |
| 400 } | 405 } |
| 401 | 406 |
| 402 // Retrieve the function from the stack. | 407 // Retrieve the function from the stack. |
| 403 __ Pop(rdi); | 408 __ Pop(rdi); |
| 404 | 409 |
| 410 if (use_new_target) { |
| 411 __ Pop(rdx); |
| 412 } |
| 413 |
| 405 // Retrieve smi-tagged arguments count from the stack. | 414 // Retrieve smi-tagged arguments count from the stack. |
| 406 __ movp(rax, Operand(rsp, 0)); | 415 __ movp(rax, Operand(rsp, 0)); |
| 407 __ SmiToInteger32(rax, rax); | 416 __ SmiToInteger32(rax, rax); |
| 408 | 417 |
| 409 // Push the allocated receiver to the stack. We need two copies | 418 // Push the allocated receiver to the stack. We need two copies |
| 410 // because we may have to return the original one and the calling | 419 // because we may have to return the original one and the calling |
| 411 // conventions dictate that the called function pops the receiver. | 420 // conventions dictate that the called function pops the receiver. |
| 412 __ Push(rbx); | 421 __ Push(rbx); |
| 422 |
| 423 if (use_new_target) { |
| 424 __ Push(rdx); |
| 425 } |
| 426 |
| 413 __ Push(rbx); | 427 __ Push(rbx); |
| 414 | 428 |
| 415 // Set up pointer to last argument. | 429 // Set up pointer to last argument. |
| 416 __ leap(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset)); | 430 __ leap(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset)); |
| 417 | 431 |
| 418 // Copy arguments and receiver to the expression stack. | 432 // Copy arguments and receiver to the expression stack. |
| 419 Label loop, entry; | 433 Label loop, entry; |
| 420 __ movp(rcx, rax); | 434 __ movp(rcx, rax); |
| 421 __ jmp(&entry); | 435 __ jmp(&entry); |
| 422 __ bind(&loop); | 436 __ bind(&loop); |
| 423 __ Push(Operand(rbx, rcx, times_pointer_size, 0)); | 437 __ Push(Operand(rbx, rcx, times_pointer_size, 0)); |
| 424 __ bind(&entry); | 438 __ bind(&entry); |
| 425 __ decp(rcx); | 439 __ decp(rcx); |
| 426 __ j(greater_equal, &loop); | 440 __ j(greater_equal, &loop); |
| 427 | 441 |
| 442 if (use_new_target) { |
| 443 __ incp(rax); // Pushed new.target |
| 444 } |
| 445 |
| 428 // Call the function. | 446 // Call the function. |
| 429 if (is_api_function) { | 447 if (is_api_function) { |
| 430 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 448 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 431 Handle<Code> code = | 449 Handle<Code> code = |
| 432 masm->isolate()->builtins()->HandleApiCallConstruct(); | 450 masm->isolate()->builtins()->HandleApiCallConstruct(); |
| 433 __ Call(code, RelocInfo::CODE_TARGET); | 451 __ Call(code, RelocInfo::CODE_TARGET); |
| 434 } else { | 452 } else { |
| 435 ParameterCount actual(rax); | 453 ParameterCount actual(rax); |
| 436 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); | 454 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); |
| 437 } | 455 } |
| 438 | 456 |
| 439 // Store offset of return address for deoptimizer. | 457 // Store offset of return address for deoptimizer. |
| 440 if (!is_api_function) { | 458 // TODO(adamk): Remove the "!use_new_target" before supporting optimization |
| 459 // of functions that reference new.target |
| 460 if (!is_api_function && !use_new_target) { |
| 441 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); | 461 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); |
| 442 } | 462 } |
| 443 | 463 |
| 444 // Restore context from the frame. | 464 // Restore context from the frame. |
| 445 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 465 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 446 | 466 |
| 447 // If the result is an object (in the ECMA sense), we should get rid | 467 // If the result is an object (in the ECMA sense), we should get rid |
| 448 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | 468 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
| 449 // on page 74. | 469 // on page 74. |
| 450 Label use_receiver, exit; | 470 Label use_receiver, exit; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 474 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 494 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
| 475 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 495 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
| 476 __ PushReturnAddressFrom(rcx); | 496 __ PushReturnAddressFrom(rcx); |
| 477 Counters* counters = masm->isolate()->counters(); | 497 Counters* counters = masm->isolate()->counters(); |
| 478 __ IncrementCounter(counters->constructed_objects(), 1); | 498 __ IncrementCounter(counters->constructed_objects(), 1); |
| 479 __ ret(0); | 499 __ ret(0); |
| 480 } | 500 } |
| 481 | 501 |
| 482 | 502 |
| 483 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 503 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
| 484 Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new); | 504 Generate_JSConstructStubHelper(masm, false, false, FLAG_pretenuring_call_new); |
| 485 } | 505 } |
| 486 | 506 |
| 487 | 507 |
| 488 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 508 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
| 489 Generate_JSConstructStubHelper(masm, true, false); | 509 Generate_JSConstructStubHelper(masm, true, false, false); |
| 490 } | 510 } |
| 491 | 511 |
| 492 | 512 |
| 513 void Builtins::Generate_JSConstructStubNewTarget(MacroAssembler* masm) { |
| 514 Generate_JSConstructStubHelper(masm, false, true, FLAG_pretenuring_call_new); |
| 515 } |
| 516 |
| 517 |
| 493 void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { | 518 void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { |
| 494 // ----------- S t a t e ------------- | 519 // ----------- S t a t e ------------- |
| 495 // -- rax: number of arguments | 520 // -- rax: number of arguments |
| 496 // -- rdi: constructor function | 521 // -- rdi: constructor function |
| 497 // -- rbx: allocation site or undefined | 522 // -- rbx: allocation site or undefined |
| 498 // -- rdx: original constructor | 523 // -- rdx: original constructor |
| 499 // ----------------------------------- | 524 // ----------------------------------- |
| 500 // TODO(dslomov): support pretenuring | 525 // TODO(dslomov): support pretenuring |
| 501 CHECK(!FLAG_pretenuring_call_new); | 526 CHECK(!FLAG_pretenuring_call_new); |
| 502 | 527 |
| (...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 __ ret(0); | 1801 __ ret(0); |
| 1777 } | 1802 } |
| 1778 | 1803 |
| 1779 | 1804 |
| 1780 #undef __ | 1805 #undef __ |
| 1781 | 1806 |
| 1782 } // namespace internal | 1807 } // namespace internal |
| 1783 } // namespace v8 | 1808 } // namespace v8 |
| 1784 | 1809 |
| 1785 #endif // V8_TARGET_ARCH_X64 | 1810 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |