| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ASSERT(extra_args == NO_EXTRA_ARGUMENTS); | 66 ASSERT(extra_args == NO_EXTRA_ARGUMENTS); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // JumpToExternalReference expects rax to contain the number of arguments | 69 // JumpToExternalReference expects rax to contain the number of arguments |
| 70 // including the receiver and the extra arguments. | 70 // including the receiver and the extra arguments. |
| 71 __ addq(rax, Immediate(num_extra_args + 1)); | 71 __ addq(rax, Immediate(num_extra_args + 1)); |
| 72 __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1); | 72 __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1); |
| 73 } | 73 } |
| 74 | 74 |
| 75 | 75 |
| 76 static void CallRuntimePassFunction(MacroAssembler* masm, | 76 static void CallRuntimePassFunction( |
| 77 Runtime::FunctionId function_id) { | 77 MacroAssembler* masm, Runtime::FunctionId function_id) { |
| 78 FrameScope scope(masm, StackFrame::INTERNAL); | 78 FrameScope scope(masm, StackFrame::INTERNAL); |
| 79 // Push a copy of the function onto the stack. | 79 // Push a copy of the function onto the stack. |
| 80 __ push(rdi); | 80 __ push(rdi); |
| 81 // Push call kind information. | 81 // Push call kind information. |
| 82 __ push(rcx); | 82 __ push(rcx); |
| 83 // Function is also the parameter to the runtime call. | 83 // Function is also the parameter to the runtime call. |
| 84 __ push(rdi); | 84 __ push(rdi); |
| 85 | 85 |
| 86 __ CallRuntime(function_id, 1); | 86 __ CallRuntime(function_id, 1); |
| 87 // Restore call kind information. | 87 // Restore call kind information. |
| 88 __ pop(rcx); | 88 __ pop(rcx); |
| 89 // Restore receiver. | 89 // Restore receiver. |
| 90 __ pop(rdi); | 90 __ pop(rdi); |
| 91 } | 91 } |
| 92 | 92 |
| 93 | 93 |
| 94 static void GenerateTailCallToSharedCode(MacroAssembler* masm) { | 94 static void GenerateTailCallToSharedCode(MacroAssembler* masm) { |
| 95 __ movq(kScratchRegister, | 95 __ movq(kScratchRegister, |
| 96 FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 96 FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 97 __ movq(kScratchRegister, | 97 __ movq(kScratchRegister, |
| 98 FieldOperand(kScratchRegister, SharedFunctionInfo::kCodeOffset)); | 98 FieldOperand(kScratchRegister, SharedFunctionInfo::kCodeOffset)); |
| 99 __ lea(kScratchRegister, FieldOperand(kScratchRegister, Code::kHeaderSize)); | 99 __ lea(kScratchRegister, FieldOperand(kScratchRegister, Code::kHeaderSize)); |
| 100 __ jmp(kScratchRegister); | 100 __ jmp(kScratchRegister); |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 void Builtins::Generate_InRecompileQueue(MacroAssembler* masm) { | 104 static void GenerateTailCallToReturnedCode(MacroAssembler* masm) { |
| 105 __ lea(rax, FieldOperand(rax, Code::kHeaderSize)); |
| 106 __ jmp(rax); |
| 107 } |
| 108 |
| 109 |
| 110 void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { |
| 105 // Checking whether the queued function is ready for install is optional, | 111 // Checking whether the queued function is ready for install is optional, |
| 106 // since we come across interrupts and stack checks elsewhere. However, | 112 // since we come across interrupts and stack checks elsewhere. However, |
| 107 // not checking may delay installing ready functions, and always checking | 113 // not checking may delay installing ready functions, and always checking |
| 108 // would be quite expensive. A good compromise is to first check against | 114 // would be quite expensive. A good compromise is to first check against |
| 109 // stack limit as a cue for an interrupt signal. | 115 // stack limit as a cue for an interrupt signal. |
| 110 Label ok; | 116 Label ok; |
| 111 __ CompareRoot(rsp, Heap::kStackLimitRootIndex); | 117 __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
| 112 __ j(above_equal, &ok); | 118 __ j(above_equal, &ok); |
| 113 | 119 |
| 114 CallRuntimePassFunction(masm, Runtime::kTryInstallRecompiledCode); | 120 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); |
| 115 // Tail call to returned code. | 121 GenerateTailCallToReturnedCode(masm); |
| 116 __ lea(rax, FieldOperand(rax, Code::kHeaderSize)); | |
| 117 __ jmp(rax); | |
| 118 | 122 |
| 119 __ bind(&ok); | 123 __ bind(&ok); |
| 120 GenerateTailCallToSharedCode(masm); | 124 GenerateTailCallToSharedCode(masm); |
| 121 } | 125 } |
| 122 | 126 |
| 123 | 127 |
| 124 void Builtins::Generate_ConcurrentRecompile(MacroAssembler* masm) { | |
| 125 CallRuntimePassFunction(masm, Runtime::kConcurrentRecompile); | |
| 126 GenerateTailCallToSharedCode(masm); | |
| 127 } | |
| 128 | |
| 129 | |
| 130 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 128 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 131 bool is_api_function, | 129 bool is_api_function, |
| 132 bool count_constructions) { | 130 bool count_constructions) { |
| 133 // ----------- S t a t e ------------- | 131 // ----------- S t a t e ------------- |
| 134 // -- rax: number of arguments | 132 // -- rax: number of arguments |
| 135 // -- rdi: constructor function | 133 // -- rdi: constructor function |
| 136 // ----------------------------------- | 134 // ----------------------------------- |
| 137 | 135 |
| 138 // Should never count constructions for api objects. | 136 // Should never count constructions for api objects. |
| 139 ASSERT(!is_api_function || !count_constructions); | 137 ASSERT(!is_api_function || !count_constructions); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { | 564 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { |
| 567 Generate_JSEntryTrampolineHelper(masm, false); | 565 Generate_JSEntryTrampolineHelper(masm, false); |
| 568 } | 566 } |
| 569 | 567 |
| 570 | 568 |
| 571 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { | 569 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { |
| 572 Generate_JSEntryTrampolineHelper(masm, true); | 570 Generate_JSEntryTrampolineHelper(masm, true); |
| 573 } | 571 } |
| 574 | 572 |
| 575 | 573 |
| 576 void Builtins::Generate_LazyCompile(MacroAssembler* masm) { | 574 void Builtins::Generate_CompileUnoptimized(MacroAssembler* masm) { |
| 577 CallRuntimePassFunction(masm, Runtime::kLazyCompile); | 575 CallRuntimePassFunction(masm, Runtime::kCompileUnoptimized); |
| 578 // Do a tail-call of the compiled function. | 576 GenerateTailCallToReturnedCode(masm); |
| 579 __ lea(rax, FieldOperand(rax, Code::kHeaderSize)); | |
| 580 __ jmp(rax); | |
| 581 } | 577 } |
| 582 | 578 |
| 583 | 579 |
| 584 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) { | 580 static void CallCompileOptimized(MacroAssembler* masm, |
| 585 CallRuntimePassFunction(masm, Runtime::kLazyRecompile); | 581 bool concurrent) { |
| 586 // Do a tail-call of the compiled function. | 582 FrameScope scope(masm, StackFrame::INTERNAL); |
| 587 __ lea(rax, FieldOperand(rax, Code::kHeaderSize)); | 583 // Push a copy of the function onto the stack. |
| 588 __ jmp(rax); | 584 __ push(rdi); |
| 585 // Push call kind information. |
| 586 __ push(rcx); |
| 587 // Function is also the parameter to the runtime call. |
| 588 __ push(rdi); |
| 589 // Whether to compile in a background thread. |
| 590 __ Push(masm->isolate()->factory()->ToBoolean(concurrent)); |
| 591 |
| 592 __ CallRuntime(Runtime::kCompileOptimized, 2); |
| 593 // Restore call kind information. |
| 594 __ pop(rcx); |
| 595 // Restore receiver. |
| 596 __ pop(rdi); |
| 589 } | 597 } |
| 590 | 598 |
| 591 | 599 |
| 600 void Builtins::Generate_CompileOptimized(MacroAssembler* masm) { |
| 601 CallCompileOptimized(masm, false); |
| 602 GenerateTailCallToReturnedCode(masm); |
| 603 } |
| 604 |
| 605 |
| 606 void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { |
| 607 CallCompileOptimized(masm, true); |
| 608 GenerateTailCallToReturnedCode(masm); |
| 609 } |
| 610 |
| 611 |
| 592 static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) { | 612 static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) { |
| 593 // For now, we are relying on the fact that make_code_young doesn't do any | 613 // For now, we are relying on the fact that make_code_young doesn't do any |
| 594 // garbage collection which allows us to save/restore the registers without | 614 // garbage collection which allows us to save/restore the registers without |
| 595 // worrying about which of them contain pointers. We also don't build an | 615 // worrying about which of them contain pointers. We also don't build an |
| 596 // internal frame to make the code faster, since we shouldn't have to do stack | 616 // internal frame to make the code faster, since we shouldn't have to do stack |
| 597 // crawls in MakeCodeYoung. This seems a bit fragile. | 617 // crawls in MakeCodeYoung. This seems a bit fragile. |
| 598 | 618 |
| 599 // Re-execute the code that was patched back to the young age when | 619 // Re-execute the code that was patched back to the young age when |
| 600 // the stub returns. | 620 // the stub returns. |
| 601 __ subq(Operand(rsp, 0), Immediate(5)); | 621 __ subq(Operand(rsp, 0), Immediate(5)); |
| 602 __ Pushad(); | 622 __ Pushad(); |
| 603 __ Move(arg_reg_2, ExternalReference::isolate_address(masm->isolate())); | 623 __ Move(arg_reg_2, ExternalReference::isolate_address(masm->isolate())); |
| 604 __ movq(arg_reg_1, Operand(rsp, kNumSafepointRegisters * kPointerSize)); | 624 __ movq(arg_reg_1, Operand(rsp, kNumSafepointRegisters * kPointerSize)); |
| 605 { // NOLINT | 625 { // NOLINT |
| 606 FrameScope scope(masm, StackFrame::MANUAL); | 626 FrameScope scope(masm, StackFrame::MANUAL); |
| 607 __ PrepareCallCFunction(1); | 627 __ PrepareCallCFunction(2); |
| 608 __ CallCFunction( | 628 __ CallCFunction( |
| 609 ExternalReference::get_make_code_young_function(masm->isolate()), 1); | 629 ExternalReference::get_make_code_young_function(masm->isolate()), 2); |
| 610 } | 630 } |
| 611 __ Popad(); | 631 __ Popad(); |
| 612 __ ret(0); | 632 __ ret(0); |
| 613 } | 633 } |
| 614 | 634 |
| 615 | 635 |
| 616 #define DEFINE_CODE_AGE_BUILTIN_GENERATOR(C) \ | 636 #define DEFINE_CODE_AGE_BUILTIN_GENERATOR(C) \ |
| 617 void Builtins::Generate_Make##C##CodeYoungAgainEvenMarking( \ | 637 void Builtins::Generate_Make##C##CodeYoungAgainEvenMarking( \ |
| 618 MacroAssembler* masm) { \ | 638 MacroAssembler* masm) { \ |
| 619 GenerateMakeCodeYoungAgainCommon(masm); \ | 639 GenerateMakeCodeYoungAgainCommon(masm); \ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 630 // For now, as in GenerateMakeCodeYoungAgainCommon, we are relying on the fact | 650 // For now, as in GenerateMakeCodeYoungAgainCommon, we are relying on the fact |
| 631 // that make_code_young doesn't do any garbage collection which allows us to | 651 // that make_code_young doesn't do any garbage collection which allows us to |
| 632 // save/restore the registers without worrying about which of them contain | 652 // save/restore the registers without worrying about which of them contain |
| 633 // pointers. | 653 // pointers. |
| 634 __ Pushad(); | 654 __ Pushad(); |
| 635 __ Move(arg_reg_2, ExternalReference::isolate_address(masm->isolate())); | 655 __ Move(arg_reg_2, ExternalReference::isolate_address(masm->isolate())); |
| 636 __ movq(arg_reg_1, Operand(rsp, kNumSafepointRegisters * kPointerSize)); | 656 __ movq(arg_reg_1, Operand(rsp, kNumSafepointRegisters * kPointerSize)); |
| 637 __ subq(arg_reg_1, Immediate(Assembler::kShortCallInstructionLength)); | 657 __ subq(arg_reg_1, Immediate(Assembler::kShortCallInstructionLength)); |
| 638 { // NOLINT | 658 { // NOLINT |
| 639 FrameScope scope(masm, StackFrame::MANUAL); | 659 FrameScope scope(masm, StackFrame::MANUAL); |
| 640 __ PrepareCallCFunction(1); | 660 __ PrepareCallCFunction(2); |
| 641 __ CallCFunction( | 661 __ CallCFunction( |
| 642 ExternalReference::get_mark_code_as_executed_function(masm->isolate()), | 662 ExternalReference::get_mark_code_as_executed_function(masm->isolate()), |
| 643 1); | 663 2); |
| 644 } | 664 } |
| 645 __ Popad(); | 665 __ Popad(); |
| 646 | 666 |
| 647 // Perform prologue operations usually performed by the young code stub. | 667 // Perform prologue operations usually performed by the young code stub. |
| 648 __ PopReturnAddressTo(kScratchRegister); | 668 __ PopReturnAddressTo(kScratchRegister); |
| 649 __ push(rbp); // Caller's frame pointer. | 669 __ push(rbp); // Caller's frame pointer. |
| 650 __ movq(rbp, rsp); | 670 __ movq(rbp, rsp); |
| 651 __ push(rsi); // Callee's context. | 671 __ push(rsi); // Callee's context. |
| 652 __ push(rdi); // Callee's JS Function. | 672 __ push(rdi); // Callee's JS Function. |
| 653 __ PushReturnAddressFrom(kScratchRegister); | 673 __ PushReturnAddressFrom(kScratchRegister); |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 __ bind(&dont_adapt_arguments); | 1406 __ bind(&dont_adapt_arguments); |
| 1387 __ jmp(rdx); | 1407 __ jmp(rdx); |
| 1388 } | 1408 } |
| 1389 | 1409 |
| 1390 | 1410 |
| 1391 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { | 1411 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { |
| 1392 // Lookup the function in the JavaScript frame. | 1412 // Lookup the function in the JavaScript frame. |
| 1393 __ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 1413 __ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1394 { | 1414 { |
| 1395 FrameScope scope(masm, StackFrame::INTERNAL); | 1415 FrameScope scope(masm, StackFrame::INTERNAL); |
| 1396 // Lookup and calculate pc offset. | 1416 // Pass function as argument. |
| 1397 __ movq(rdx, Operand(rbp, StandardFrameConstants::kCallerPCOffset)); | |
| 1398 __ movq(rbx, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); | |
| 1399 __ subq(rdx, Immediate(Code::kHeaderSize - kHeapObjectTag)); | |
| 1400 __ subq(rdx, FieldOperand(rbx, SharedFunctionInfo::kCodeOffset)); | |
| 1401 __ Integer32ToSmi(rdx, rdx); | |
| 1402 | |
| 1403 // Pass both function and pc offset as arguments. | |
| 1404 __ push(rax); | 1417 __ push(rax); |
| 1405 __ push(rdx); | 1418 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); |
| 1406 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 2); | |
| 1407 } | 1419 } |
| 1408 | 1420 |
| 1409 Label skip; | 1421 Label skip; |
| 1410 // If the code object is null, just return to the unoptimized code. | 1422 // If the code object is null, just return to the unoptimized code. |
| 1411 __ cmpq(rax, Immediate(0)); | 1423 __ cmpq(rax, Immediate(0)); |
| 1412 __ j(not_equal, &skip, Label::kNear); | 1424 __ j(not_equal, &skip, Label::kNear); |
| 1413 __ ret(0); | 1425 __ ret(0); |
| 1414 | 1426 |
| 1415 __ bind(&skip); | 1427 __ bind(&skip); |
| 1416 | 1428 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1447 __ bind(&ok); | 1459 __ bind(&ok); |
| 1448 __ ret(0); | 1460 __ ret(0); |
| 1449 } | 1461 } |
| 1450 | 1462 |
| 1451 | 1463 |
| 1452 #undef __ | 1464 #undef __ |
| 1453 | 1465 |
| 1454 } } // namespace v8::internal | 1466 } } // namespace v8::internal |
| 1455 | 1467 |
| 1456 #endif // V8_TARGET_ARCH_X64 | 1468 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |