| 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 // -- rsp[kFastApiCallArguments * 8 + 8] : last argument in the internal | 429 // -- rsp[kFastApiCallArguments * 8 + 8] : last argument in the internal |
| 430 // frame. | 430 // frame. |
| 431 // ----------------------------------- | 431 // ----------------------------------- |
| 432 __ movq(scratch, StackOperandForReturnAddress(0)); | 432 __ movq(scratch, StackOperandForReturnAddress(0)); |
| 433 __ movq(StackOperandForReturnAddress(kFastApiCallArguments * kPointerSize), | 433 __ movq(StackOperandForReturnAddress(kFastApiCallArguments * kPointerSize), |
| 434 scratch); | 434 scratch); |
| 435 __ addq(rsp, Immediate(kPointerSize * kFastApiCallArguments)); | 435 __ addq(rsp, Immediate(kPointerSize * kFastApiCallArguments)); |
| 436 } | 436 } |
| 437 | 437 |
| 438 | 438 |
| 439 static void GenerateFastApiCallBody(MacroAssembler* masm, |
| 440 const CallOptimization& optimization, |
| 441 int argc, |
| 442 bool restore_context); |
| 443 |
| 444 |
| 439 // Generates call to API function. | 445 // Generates call to API function. |
| 440 static void GenerateFastApiCall(MacroAssembler* masm, | 446 static void GenerateFastApiCall(MacroAssembler* masm, |
| 441 const CallOptimization& optimization, | 447 const CallOptimization& optimization, |
| 442 int argc, | 448 int argc) { |
| 443 bool restore_context) { | |
| 444 // ----------- S t a t e ------------- | |
| 445 // -- rsp[0] : return address | |
| 446 // -- rsp[8] - rsp[56] : FunctionCallbackInfo, incl. | |
| 447 // : object passing the type check | |
| 448 // (set by CheckPrototypes) | |
| 449 // -- rsp[64] : last argument | |
| 450 // -- ... | |
| 451 // -- rsp[(argc + 7) * 8] : first argument | |
| 452 // -- rsp[(argc + 8) * 8] : receiver | |
| 453 // ----------------------------------- | |
| 454 typedef FunctionCallbackArguments FCA; | 449 typedef FunctionCallbackArguments FCA; |
| 455 StackArgumentsAccessor args(rsp, argc + kFastApiCallArguments); | 450 StackArgumentsAccessor args(rsp, argc + kFastApiCallArguments); |
| 456 | 451 |
| 457 // Save calling context. | 452 // Save calling context. |
| 458 int offset = argc + kFastApiCallArguments; | 453 int offset = argc + kFastApiCallArguments; |
| 459 __ movq(args.GetArgumentOperand(offset - FCA::kContextSaveIndex), rsi); | 454 __ movq(args.GetArgumentOperand(offset - FCA::kContextSaveIndex), rsi); |
| 460 | 455 |
| 461 // Get the function and setup the context. | 456 // Get the function and setup the context. |
| 462 Handle<JSFunction> function = optimization.constant_function(); | 457 Handle<JSFunction> function = optimization.constant_function(); |
| 463 __ Move(rdi, function); | 458 __ Move(rdi, function); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 478 __ movq(args.GetArgumentOperand(offset - FCA::kIsolateIndex), | 473 __ movq(args.GetArgumentOperand(offset - FCA::kIsolateIndex), |
| 479 kScratchRegister); | 474 kScratchRegister); |
| 480 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); | 475 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); |
| 481 __ movq(args.GetArgumentOperand(offset - FCA::kReturnValueDefaultValueIndex), | 476 __ movq(args.GetArgumentOperand(offset - FCA::kReturnValueDefaultValueIndex), |
| 482 kScratchRegister); | 477 kScratchRegister); |
| 483 __ movq(args.GetArgumentOperand(offset - FCA::kReturnValueOffset), | 478 __ movq(args.GetArgumentOperand(offset - FCA::kReturnValueOffset), |
| 484 kScratchRegister); | 479 kScratchRegister); |
| 485 | 480 |
| 486 // Prepare arguments. | 481 // Prepare arguments. |
| 487 STATIC_ASSERT(kFastApiCallArguments == 7); | 482 STATIC_ASSERT(kFastApiCallArguments == 7); |
| 488 __ lea(rbx, Operand(rsp, 1 * kPointerSize)); | 483 __ lea(rax, Operand(rsp, 1 * kPointerSize)); |
| 489 | 484 |
| 485 GenerateFastApiCallBody(masm, optimization, argc, false); |
| 486 } |
| 487 |
| 488 |
| 489 // Generate call to api function. |
| 490 // This function uses push() to generate smaller, faster code than |
| 491 // the version above. It is an optimization that should will be removed |
| 492 // when api call ICs are generated in hydrogen. |
| 493 static void GenerateFastApiCall(MacroAssembler* masm, |
| 494 const CallOptimization& optimization, |
| 495 Register receiver, |
| 496 Register scratch1, |
| 497 Register scratch2, |
| 498 Register scratch3, |
| 499 int argc, |
| 500 Register* values) { |
| 501 ASSERT(optimization.is_simple_api_call()); |
| 502 |
| 503 // Copy return value. |
| 504 __ pop(scratch1); |
| 505 |
| 506 // receiver |
| 507 __ push(receiver); |
| 508 |
| 509 // Write the arguments to stack frame. |
| 510 for (int i = 0; i < argc; i++) { |
| 511 Register arg = values[argc-1-i]; |
| 512 ASSERT(!receiver.is(arg)); |
| 513 ASSERT(!scratch1.is(arg)); |
| 514 ASSERT(!scratch2.is(arg)); |
| 515 ASSERT(!scratch3.is(arg)); |
| 516 __ push(arg); |
| 517 } |
| 518 |
| 519 typedef FunctionCallbackArguments FCA; |
| 520 |
| 521 STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 522 STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 523 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 524 STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 525 STATIC_ASSERT(FCA::kDataIndex == 4); |
| 526 STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 527 STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 528 STATIC_ASSERT(FCA::kArgsLength == 7); |
| 529 |
| 530 // context save |
| 531 __ push(rsi); |
| 532 |
| 533 // Get the function and setup the context. |
| 534 Handle<JSFunction> function = optimization.constant_function(); |
| 535 __ Move(scratch2, function); |
| 536 __ push(scratch2); |
| 537 |
| 538 Isolate* isolate = masm->isolate(); |
| 539 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 540 Handle<Object> call_data(api_call_info->data(), isolate); |
| 541 // Push data from ExecutableAccessorInfo. |
| 542 bool call_data_undefined = false; |
| 543 if (isolate->heap()->InNewSpace(*call_data)) { |
| 544 __ Move(scratch2, api_call_info); |
| 545 __ movq(scratch3, FieldOperand(scratch2, CallHandlerInfo::kDataOffset)); |
| 546 } else if (call_data->IsUndefined()) { |
| 547 call_data_undefined = true; |
| 548 __ LoadRoot(scratch3, Heap::kUndefinedValueRootIndex); |
| 549 } else { |
| 550 __ Move(scratch3, call_data); |
| 551 } |
| 552 // call data |
| 553 __ push(scratch3); |
| 554 if (!call_data_undefined) { |
| 555 __ LoadRoot(scratch3, Heap::kUndefinedValueRootIndex); |
| 556 } |
| 557 // return value |
| 558 __ push(scratch3); |
| 559 // return value default |
| 560 __ push(scratch3); |
| 561 // isolate |
| 562 __ Move(scratch3, |
| 563 ExternalReference::isolate_address(masm->isolate())); |
| 564 __ push(scratch3); |
| 565 // holder |
| 566 __ push(receiver); |
| 567 |
| 568 ASSERT(!scratch1.is(rax)); |
| 569 // store receiver address for GenerateFastApiCallBody |
| 570 __ movq(rax, rsp); |
| 571 |
| 572 // return address |
| 573 __ push(scratch1); |
| 574 |
| 575 GenerateFastApiCallBody(masm, optimization, argc, true); |
| 576 } |
| 577 |
| 578 |
| 579 static void GenerateFastApiCallBody(MacroAssembler* masm, |
| 580 const CallOptimization& optimization, |
| 581 int argc, |
| 582 bool restore_context) { |
| 583 // ----------- S t a t e ------------- |
| 584 // -- rsp[0] : return address |
| 585 // -- rsp[8] - rsp[56] : FunctionCallbackInfo, incl. |
| 586 // : object passing the type check |
| 587 // (set by CheckPrototypes) |
| 588 // -- rsp[64] : last argument |
| 589 // -- ... |
| 590 // -- rsp[(argc + 7) * 8] : first argument |
| 591 // -- rsp[(argc + 8) * 8] : receiver |
| 592 // |
| 593 // rax : receiver address |
| 594 // ----------------------------------- |
| 595 typedef FunctionCallbackArguments FCA; |
| 596 |
| 597 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 490 // Function address is a foreign pointer outside V8's heap. | 598 // Function address is a foreign pointer outside V8's heap. |
| 491 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | 599 Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
| 492 | 600 |
| 493 // Allocate the v8::Arguments structure in the arguments' space since | 601 // Allocate the v8::Arguments structure in the arguments' space since |
| 494 // it's not controlled by GC. | 602 // it's not controlled by GC. |
| 495 const int kApiStackSpace = 4; | 603 const int kApiStackSpace = 4; |
| 496 | 604 |
| 497 __ PrepareCallApiFunction(kApiStackSpace); | 605 __ PrepareCallApiFunction(kApiStackSpace); |
| 498 | 606 |
| 499 __ movq(StackSpaceOperand(0), rbx); // FunctionCallbackInfo::implicit_args_. | 607 __ movq(StackSpaceOperand(0), rax); // FunctionCallbackInfo::implicit_args_. |
| 500 __ addq(rbx, Immediate((argc + kFastApiCallArguments - 1) * kPointerSize)); | 608 __ addq(rax, Immediate((argc + kFastApiCallArguments - 1) * kPointerSize)); |
| 501 __ movq(StackSpaceOperand(1), rbx); // FunctionCallbackInfo::values_. | 609 __ movq(StackSpaceOperand(1), rax); // FunctionCallbackInfo::values_. |
| 502 __ Set(StackSpaceOperand(2), argc); // FunctionCallbackInfo::length_. | 610 __ Set(StackSpaceOperand(2), argc); // FunctionCallbackInfo::length_. |
| 503 // FunctionCallbackInfo::is_construct_call_. | 611 // FunctionCallbackInfo::is_construct_call_. |
| 504 __ Set(StackSpaceOperand(3), 0); | 612 __ Set(StackSpaceOperand(3), 0); |
| 505 | 613 |
| 506 #if defined(__MINGW64__) || defined(_WIN64) | 614 #if defined(__MINGW64__) || defined(_WIN64) |
| 507 Register arguments_arg = rcx; | 615 Register arguments_arg = rcx; |
| 508 Register callback_arg = rdx; | 616 Register callback_arg = rdx; |
| 509 #else | 617 #else |
| 510 Register arguments_arg = rdi; | 618 Register arguments_arg = rdi; |
| 511 Register callback_arg = rsi; | 619 Register callback_arg = rsi; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 525 __ CallApiFunctionAndReturn( | 633 __ CallApiFunctionAndReturn( |
| 526 function_address, | 634 function_address, |
| 527 thunk_address, | 635 thunk_address, |
| 528 callback_arg, | 636 callback_arg, |
| 529 argc + kFastApiCallArguments + 1, | 637 argc + kFastApiCallArguments + 1, |
| 530 return_value_operand, | 638 return_value_operand, |
| 531 restore_context ? &context_restore_operand : NULL); | 639 restore_context ? &context_restore_operand : NULL); |
| 532 } | 640 } |
| 533 | 641 |
| 534 | 642 |
| 535 // Generate call to api function. | |
| 536 static void GenerateFastApiCall(MacroAssembler* masm, | |
| 537 const CallOptimization& optimization, | |
| 538 Register receiver, | |
| 539 Register scratch, | |
| 540 int argc, | |
| 541 Register* values) { | |
| 542 ASSERT(optimization.is_simple_api_call()); | |
| 543 ASSERT(!receiver.is(scratch)); | |
| 544 | |
| 545 const int fast_api_call_argc = argc + kFastApiCallArguments; | |
| 546 StackArgumentsAccessor args(rsp, fast_api_call_argc); | |
| 547 // argc + 1 is the argument number before FastApiCall arguments, 1 ~ receiver | |
| 548 const int kHolderIndex = argc + 1 + | |
| 549 kFastApiCallArguments - 1 - FunctionCallbackArguments::kHolderIndex; | |
| 550 __ movq(scratch, StackOperandForReturnAddress(0)); | |
| 551 // Assign stack space for the call arguments and receiver. | |
| 552 __ subq(rsp, Immediate((fast_api_call_argc + 1) * kPointerSize)); | |
| 553 __ movq(StackOperandForReturnAddress(0), scratch); | |
| 554 // Write holder to stack frame. | |
| 555 __ movq(args.GetArgumentOperand(kHolderIndex), receiver); | |
| 556 __ movq(args.GetReceiverOperand(), receiver); | |
| 557 // Write the arguments to stack frame. | |
| 558 for (int i = 0; i < argc; i++) { | |
| 559 ASSERT(!receiver.is(values[i])); | |
| 560 ASSERT(!scratch.is(values[i])); | |
| 561 __ movq(args.GetArgumentOperand(i + 1), values[i]); | |
| 562 } | |
| 563 | |
| 564 GenerateFastApiCall(masm, optimization, argc, true); | |
| 565 } | |
| 566 | |
| 567 | |
| 568 class CallInterceptorCompiler BASE_EMBEDDED { | 643 class CallInterceptorCompiler BASE_EMBEDDED { |
| 569 public: | 644 public: |
| 570 CallInterceptorCompiler(StubCompiler* stub_compiler, | 645 CallInterceptorCompiler(StubCompiler* stub_compiler, |
| 571 const ParameterCount& arguments, | 646 const ParameterCount& arguments, |
| 572 Register name, | 647 Register name, |
| 573 Code::ExtraICState extra_ic_state) | 648 Code::ExtraICState extra_ic_state) |
| 574 : stub_compiler_(stub_compiler), | 649 : stub_compiler_(stub_compiler), |
| 575 arguments_(arguments), | 650 arguments_(arguments), |
| 576 name_(name), | 651 name_(name), |
| 577 extra_ic_state_(extra_ic_state) {} | 652 extra_ic_state_(extra_ic_state) {} |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 } else { | 743 } else { |
| 669 // CheckPrototypes has a side effect of fetching a 'holder' | 744 // CheckPrototypes has a side effect of fetching a 'holder' |
| 670 // for API (object which is instanceof for the signature). It's | 745 // for API (object which is instanceof for the signature). It's |
| 671 // safe to omit it here, as if present, it should be fetched | 746 // safe to omit it here, as if present, it should be fetched |
| 672 // by the previous CheckPrototypes. | 747 // by the previous CheckPrototypes. |
| 673 ASSERT(depth2 == kInvalidProtoDepth); | 748 ASSERT(depth2 == kInvalidProtoDepth); |
| 674 } | 749 } |
| 675 | 750 |
| 676 // Invoke function. | 751 // Invoke function. |
| 677 if (can_do_fast_api_call) { | 752 if (can_do_fast_api_call) { |
| 678 GenerateFastApiCall(masm, optimization, arguments_.immediate(), false); | 753 GenerateFastApiCall(masm, optimization, arguments_.immediate()); |
| 679 } else { | 754 } else { |
| 680 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_) | 755 CallKind call_kind = CallICBase::Contextual::decode(extra_ic_state_) |
| 681 ? CALL_AS_FUNCTION | 756 ? CALL_AS_FUNCTION |
| 682 : CALL_AS_METHOD; | 757 : CALL_AS_METHOD; |
| 683 Handle<JSFunction> fun = optimization.constant_function(); | 758 Handle<JSFunction> fun = optimization.constant_function(); |
| 684 ParameterCount expected(fun); | 759 ParameterCount expected(fun); |
| 685 __ InvokeFunction(fun, expected, arguments_, | 760 __ InvokeFunction(fun, expected, arguments_, |
| 686 JUMP_FUNCTION, NullCallWrapper(), call_kind); | 761 JUMP_FUNCTION, NullCallWrapper(), call_kind); |
| 687 } | 762 } |
| 688 | 763 |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 field.translate(holder), | 1362 field.translate(holder), |
| 1288 representation); | 1363 representation); |
| 1289 GenerateTailCall(masm(), stub.GetCode(isolate())); | 1364 GenerateTailCall(masm(), stub.GetCode(isolate())); |
| 1290 } | 1365 } |
| 1291 } | 1366 } |
| 1292 | 1367 |
| 1293 | 1368 |
| 1294 void LoadStubCompiler::GenerateLoadCallback( | 1369 void LoadStubCompiler::GenerateLoadCallback( |
| 1295 const CallOptimization& call_optimization) { | 1370 const CallOptimization& call_optimization) { |
| 1296 GenerateFastApiCall( | 1371 GenerateFastApiCall( |
| 1297 masm(), call_optimization, receiver(), scratch3(), 0, NULL); | 1372 masm(), call_optimization, receiver(), |
| 1373 scratch1(), scratch2(), name(), 0, NULL); |
| 1298 } | 1374 } |
| 1299 | 1375 |
| 1300 | 1376 |
| 1301 void LoadStubCompiler::GenerateLoadCallback( | 1377 void LoadStubCompiler::GenerateLoadCallback( |
| 1302 Register reg, | 1378 Register reg, |
| 1303 Handle<ExecutableAccessorInfo> callback) { | 1379 Handle<ExecutableAccessorInfo> callback) { |
| 1304 // Insert additional parameters into the stack frame above return address. | 1380 // Insert additional parameters into the stack frame above return address. |
| 1305 ASSERT(!scratch4().is(reg)); | 1381 ASSERT(!scratch4().is(reg)); |
| 1306 __ PopReturnAddressTo(scratch4()); | 1382 __ PopReturnAddressTo(scratch4()); |
| 1307 | 1383 |
| (...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 | 2570 |
| 2495 // Check that the maps haven't changed and find a Holder as a side effect. | 2571 // Check that the maps haven't changed and find a Holder as a side effect. |
| 2496 CheckPrototypes(Handle<JSObject>::cast(object), rdx, holder, rbx, rax, rdi, | 2572 CheckPrototypes(Handle<JSObject>::cast(object), rdx, holder, rbx, rax, rdi, |
| 2497 name, depth, &miss); | 2573 name, depth, &miss); |
| 2498 | 2574 |
| 2499 // Move the return address on top of the stack. | 2575 // Move the return address on top of the stack. |
| 2500 __ movq(rax, | 2576 __ movq(rax, |
| 2501 StackOperandForReturnAddress(kFastApiCallArguments * kPointerSize)); | 2577 StackOperandForReturnAddress(kFastApiCallArguments * kPointerSize)); |
| 2502 __ movq(StackOperandForReturnAddress(0), rax); | 2578 __ movq(StackOperandForReturnAddress(0), rax); |
| 2503 | 2579 |
| 2504 GenerateFastApiCall(masm(), optimization, argc, false); | 2580 GenerateFastApiCall(masm(), optimization, argc); |
| 2505 | 2581 |
| 2506 __ bind(&miss); | 2582 __ bind(&miss); |
| 2507 __ addq(rsp, Immediate(kFastApiCallArguments * kPointerSize)); | 2583 __ addq(rsp, Immediate(kFastApiCallArguments * kPointerSize)); |
| 2508 | 2584 |
| 2509 __ bind(&miss_before_stack_reserved); | 2585 __ bind(&miss_before_stack_reserved); |
| 2510 GenerateMissBranch(); | 2586 GenerateMissBranch(); |
| 2511 | 2587 |
| 2512 // Return the generated code. | 2588 // Return the generated code. |
| 2513 return GetCode(function); | 2589 return GetCode(function); |
| 2514 } | 2590 } |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2814 | 2890 |
| 2815 Handle<Code> StoreStubCompiler::CompileStoreCallback( | 2891 Handle<Code> StoreStubCompiler::CompileStoreCallback( |
| 2816 Handle<JSObject> object, | 2892 Handle<JSObject> object, |
| 2817 Handle<JSObject> holder, | 2893 Handle<JSObject> holder, |
| 2818 Handle<Name> name, | 2894 Handle<Name> name, |
| 2819 const CallOptimization& call_optimization) { | 2895 const CallOptimization& call_optimization) { |
| 2820 HandlerFrontend(object, receiver(), holder, name); | 2896 HandlerFrontend(object, receiver(), holder, name); |
| 2821 | 2897 |
| 2822 Register values[] = { value() }; | 2898 Register values[] = { value() }; |
| 2823 GenerateFastApiCall( | 2899 GenerateFastApiCall( |
| 2824 masm(), call_optimization, receiver(), scratch3(), 1, values); | 2900 masm(), call_optimization, receiver(), scratch1(), |
| 2901 scratch2(), this->name(), 1, values); |
| 2825 | 2902 |
| 2826 // Return the generated code. | 2903 // Return the generated code. |
| 2827 return GetCode(kind(), Code::CALLBACKS, name); | 2904 return GetCode(kind(), Code::CALLBACKS, name); |
| 2828 } | 2905 } |
| 2829 | 2906 |
| 2830 | 2907 |
| 2831 #undef __ | 2908 #undef __ |
| 2832 #define __ ACCESS_MASM(masm) | 2909 #define __ ACCESS_MASM(masm) |
| 2833 | 2910 |
| 2834 | 2911 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3157 // ----------------------------------- | 3234 // ----------------------------------- |
| 3158 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); | 3235 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); |
| 3159 } | 3236 } |
| 3160 | 3237 |
| 3161 | 3238 |
| 3162 #undef __ | 3239 #undef __ |
| 3163 | 3240 |
| 3164 } } // namespace v8::internal | 3241 } } // namespace v8::internal |
| 3165 | 3242 |
| 3166 #endif // V8_TARGET_ARCH_X64 | 3243 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |