| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // need to increment the memento create count. | 408 // need to increment the memento create count. |
| 404 __ SmiAddConstant( | 409 __ SmiAddConstant( |
| 405 FieldOperand(rcx, AllocationSite::kPretenureCreateCountOffset), | 410 FieldOperand(rcx, AllocationSite::kPretenureCreateCountOffset), |
| 406 Smi::FromInt(1)); | 411 Smi::FromInt(1)); |
| 407 __ bind(&count_incremented); | 412 __ bind(&count_incremented); |
| 408 } | 413 } |
| 409 | 414 |
| 410 // Retrieve the function from the stack. | 415 // Retrieve the function from the stack. |
| 411 __ Pop(rdi); | 416 __ Pop(rdi); |
| 412 | 417 |
| 418 if (use_new_target) { |
| 419 __ Pop(rdx); |
| 420 } |
| 421 |
| 413 // Retrieve smi-tagged arguments count from the stack. | 422 // Retrieve smi-tagged arguments count from the stack. |
| 414 __ movp(rax, Operand(rsp, 0)); | 423 __ movp(rax, Operand(rsp, 0)); |
| 415 __ SmiToInteger32(rax, rax); | 424 __ SmiToInteger32(rax, rax); |
| 416 | 425 |
| 417 // Push the allocated receiver to the stack. We need two copies | 426 // Push the allocated receiver to the stack. We need two copies |
| 418 // because we may have to return the original one and the calling | 427 // because we may have to return the original one and the calling |
| 419 // conventions dictate that the called function pops the receiver. | 428 // conventions dictate that the called function pops the receiver. |
| 420 __ Push(rbx); | 429 __ Push(rbx); |
| 430 |
| 431 if (use_new_target) { |
| 432 __ Push(rdx); |
| 433 } |
| 434 |
| 421 __ Push(rbx); | 435 __ Push(rbx); |
| 422 | 436 |
| 423 // Set up pointer to last argument. | 437 // Set up pointer to last argument. |
| 424 __ leap(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset)); | 438 __ leap(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset)); |
| 425 | 439 |
| 426 // Copy arguments and receiver to the expression stack. | 440 // Copy arguments and receiver to the expression stack. |
| 427 Label loop, entry; | 441 Label loop, entry; |
| 428 __ movp(rcx, rax); | 442 __ movp(rcx, rax); |
| 429 __ jmp(&entry); | 443 __ jmp(&entry); |
| 430 __ bind(&loop); | 444 __ bind(&loop); |
| 431 __ Push(Operand(rbx, rcx, times_pointer_size, 0)); | 445 __ Push(Operand(rbx, rcx, times_pointer_size, 0)); |
| 432 __ bind(&entry); | 446 __ bind(&entry); |
| 433 __ decp(rcx); | 447 __ decp(rcx); |
| 434 __ j(greater_equal, &loop); | 448 __ j(greater_equal, &loop); |
| 435 | 449 |
| 450 if (use_new_target) { |
| 451 __ incp(rax); // Pushed new.target |
| 452 } |
| 453 |
| 436 // Call the function. | 454 // Call the function. |
| 437 if (is_api_function) { | 455 if (is_api_function) { |
| 438 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 456 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 439 Handle<Code> code = | 457 Handle<Code> code = |
| 440 masm->isolate()->builtins()->HandleApiCallConstruct(); | 458 masm->isolate()->builtins()->HandleApiCallConstruct(); |
| 441 __ Call(code, RelocInfo::CODE_TARGET); | 459 __ Call(code, RelocInfo::CODE_TARGET); |
| 442 } else { | 460 } else { |
| 443 ParameterCount actual(rax); | 461 ParameterCount actual(rax); |
| 444 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); | 462 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); |
| 445 } | 463 } |
| 446 | 464 |
| 447 // Store offset of return address for deoptimizer. | 465 // Store offset of return address for deoptimizer. |
| 448 if (!is_api_function) { | 466 // TODO(adamk): Remove the "!use_new_target" before supporting optimization |
| 467 // of functions that reference new.target |
| 468 if (!is_api_function && !use_new_target) { |
| 449 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); | 469 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); |
| 450 } | 470 } |
| 451 | 471 |
| 452 // Restore context from the frame. | 472 // Restore context from the frame. |
| 453 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 473 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 454 | 474 |
| 455 // If the result is an object (in the ECMA sense), we should get rid | 475 // If the result is an object (in the ECMA sense), we should get rid |
| 456 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | 476 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
| 457 // on page 74. | 477 // on page 74. |
| 458 Label use_receiver, exit; | 478 Label use_receiver, exit; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 482 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 502 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
| 483 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 503 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
| 484 __ PushReturnAddressFrom(rcx); | 504 __ PushReturnAddressFrom(rcx); |
| 485 Counters* counters = masm->isolate()->counters(); | 505 Counters* counters = masm->isolate()->counters(); |
| 486 __ IncrementCounter(counters->constructed_objects(), 1); | 506 __ IncrementCounter(counters->constructed_objects(), 1); |
| 487 __ ret(0); | 507 __ ret(0); |
| 488 } | 508 } |
| 489 | 509 |
| 490 | 510 |
| 491 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 511 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
| 492 Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new); | 512 Generate_JSConstructStubHelper(masm, false, false, FLAG_pretenuring_call_new); |
| 493 } | 513 } |
| 494 | 514 |
| 495 | 515 |
| 496 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 516 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
| 497 Generate_JSConstructStubHelper(masm, true, false); | 517 Generate_JSConstructStubHelper(masm, true, false, false); |
| 498 } | 518 } |
| 499 | 519 |
| 500 | 520 |
| 521 void Builtins::Generate_JSConstructStubNewTarget(MacroAssembler* masm) { |
| 522 Generate_JSConstructStubHelper(masm, false, true, FLAG_pretenuring_call_new); |
| 523 } |
| 524 |
| 525 |
| 501 void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { | 526 void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { |
| 502 // ----------- S t a t e ------------- | 527 // ----------- S t a t e ------------- |
| 503 // -- rax: number of arguments | 528 // -- rax: number of arguments |
| 504 // -- rdi: constructor function | 529 // -- rdi: constructor function |
| 505 // -- rbx: allocation site or undefined | 530 // -- rbx: allocation site or undefined |
| 506 // -- rdx: original constructor | 531 // -- rdx: original constructor |
| 507 // ----------------------------------- | 532 // ----------------------------------- |
| 508 // TODO(dslomov): support pretenuring | 533 // TODO(dslomov): support pretenuring |
| 509 CHECK(!FLAG_pretenuring_call_new); | 534 CHECK(!FLAG_pretenuring_call_new); |
| 510 | 535 |
| (...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 __ ret(0); | 1809 __ ret(0); |
| 1785 } | 1810 } |
| 1786 | 1811 |
| 1787 | 1812 |
| 1788 #undef __ | 1813 #undef __ |
| 1789 | 1814 |
| 1790 } // namespace internal | 1815 } // namespace internal |
| 1791 } // namespace v8 | 1816 } // namespace v8 |
| 1792 | 1817 |
| 1793 #endif // V8_TARGET_ARCH_X64 | 1818 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |