| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 // -- esp[kFastApiCallArguments * 4] : first fast api call extra argument. | 444 // -- esp[kFastApiCallArguments * 4] : first fast api call extra argument. |
| 445 // -- esp[kFastApiCallArguments * 4 + 4] : last argument in the internal | 445 // -- esp[kFastApiCallArguments * 4 + 4] : last argument in the internal |
| 446 // frame. | 446 // frame. |
| 447 // ----------------------------------- | 447 // ----------------------------------- |
| 448 __ pop(scratch); | 448 __ pop(scratch); |
| 449 __ add(esp, Immediate(kPointerSize * kFastApiCallArguments)); | 449 __ add(esp, Immediate(kPointerSize * kFastApiCallArguments)); |
| 450 __ push(scratch); | 450 __ push(scratch); |
| 451 } | 451 } |
| 452 | 452 |
| 453 | 453 |
| 454 static void GenerateFastApiCallBody(MacroAssembler* masm, |
| 455 const CallOptimization& optimization, |
| 456 int argc, |
| 457 bool restore_context); |
| 458 |
| 459 |
| 454 // Generates call to API function. | 460 // Generates call to API function. |
| 455 static void GenerateFastApiCall(MacroAssembler* masm, | 461 static void GenerateFastApiCall(MacroAssembler* masm, |
| 456 const CallOptimization& optimization, | 462 const CallOptimization& optimization, |
| 457 int argc, | 463 int argc) { |
| 458 bool restore_context) { | |
| 459 // ----------- S t a t e ------------- | |
| 460 // -- esp[0] : return address | |
| 461 // -- esp[4] - esp[28] : FunctionCallbackInfo, incl. | |
| 462 // : object passing the type check | |
| 463 // (set by CheckPrototypes) | |
| 464 // -- esp[32] : last argument | |
| 465 // -- ... | |
| 466 // -- esp[(argc + 7) * 4] : first argument | |
| 467 // -- esp[(argc + 8) * 4] : receiver | |
| 468 // ----------------------------------- | |
| 469 | |
| 470 typedef FunctionCallbackArguments FCA; | 464 typedef FunctionCallbackArguments FCA; |
| 471 // Save calling context. | 465 // Save calling context. |
| 472 __ mov(Operand(esp, (1 + FCA::kContextSaveIndex) * kPointerSize), esi); | 466 __ mov(Operand(esp, (1 + FCA::kContextSaveIndex) * kPointerSize), esi); |
| 473 | 467 |
| 474 // Get the function and setup the context. | 468 // Get the function and setup the context. |
| 475 Handle<JSFunction> function = optimization.constant_function(); | 469 Handle<JSFunction> function = optimization.constant_function(); |
| 476 __ LoadHeapObject(edi, function); | 470 __ LoadHeapObject(edi, function); |
| 477 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); | 471 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 478 | 472 |
| 479 // Construct the FunctionCallbackInfo. | 473 // Construct the FunctionCallbackInfo. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 492 Immediate(reinterpret_cast<int>(masm->isolate()))); | 486 Immediate(reinterpret_cast<int>(masm->isolate()))); |
| 493 __ mov(Operand(esp, (1 + FCA::kReturnValueOffset) * kPointerSize), | 487 __ mov(Operand(esp, (1 + FCA::kReturnValueOffset) * kPointerSize), |
| 494 masm->isolate()->factory()->undefined_value()); | 488 masm->isolate()->factory()->undefined_value()); |
| 495 __ mov(Operand(esp, (1 + FCA::kReturnValueDefaultValueIndex) * kPointerSize), | 489 __ mov(Operand(esp, (1 + FCA::kReturnValueDefaultValueIndex) * kPointerSize), |
| 496 masm->isolate()->factory()->undefined_value()); | 490 masm->isolate()->factory()->undefined_value()); |
| 497 | 491 |
| 498 // Prepare arguments. | 492 // Prepare arguments. |
| 499 STATIC_ASSERT(kFastApiCallArguments == 7); | 493 STATIC_ASSERT(kFastApiCallArguments == 7); |
| 500 __ lea(eax, Operand(esp, 1 * kPointerSize)); | 494 __ lea(eax, Operand(esp, 1 * kPointerSize)); |
| 501 | 495 |
| 496 GenerateFastApiCallBody(masm, optimization, argc, false); |
| 497 } |
| 498 |
| 499 |
| 500 // Generate call to api function. |
| 501 // This function uses push() to generate smaller, faster code than |
| 502 // the version above. It is an optimization that should will be removed |
| 503 // when api call ICs are generated in hydrogen. |
| 504 static void GenerateFastApiCall(MacroAssembler* masm, |
| 505 const CallOptimization& optimization, |
| 506 Register receiver, |
| 507 Register scratch1, |
| 508 Register scratch2, |
| 509 Register scratch3, |
| 510 int argc, |
| 511 Register* values) { |
| 512 ASSERT(optimization.is_simple_api_call()); |
| 513 |
| 514 // Copy return value. |
| 515 __ pop(scratch1); |
| 516 |
| 517 // receiver |
| 518 __ push(receiver); |
| 519 |
| 520 // Write the arguments to stack frame. |
| 521 for (int i = 0; i < argc; i++) { |
| 522 Register arg = values[argc-1-i]; |
| 523 ASSERT(!receiver.is(arg)); |
| 524 ASSERT(!scratch1.is(arg)); |
| 525 ASSERT(!scratch2.is(arg)); |
| 526 ASSERT(!scratch3.is(arg)); |
| 527 __ push(arg); |
| 528 } |
| 529 |
| 530 typedef FunctionCallbackArguments FCA; |
| 531 |
| 532 STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 533 STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 534 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 535 STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 536 STATIC_ASSERT(FCA::kDataIndex == 4); |
| 537 STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 538 STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 539 STATIC_ASSERT(FCA::kArgsLength == 7); |
| 540 |
| 541 // context save |
| 542 __ push(esi); |
| 543 |
| 544 // Get the function and setup the context. |
| 545 Handle<JSFunction> function = optimization.constant_function(); |
| 546 __ LoadHeapObject(scratch2, function); |
| 547 __ mov(esi, FieldOperand(scratch2, JSFunction::kContextOffset)); |
| 548 // callee |
| 549 __ push(scratch2); |
| 550 |
| 551 Isolate* isolate = masm->isolate(); |
| 552 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 553 Handle<Object> call_data(api_call_info->data(), isolate); |
| 554 // Push data from ExecutableAccessorInfo. |
| 555 if (isolate->heap()->InNewSpace(*call_data)) { |
| 556 __ mov(scratch2, api_call_info); |
| 557 __ mov(scratch3, FieldOperand(scratch2, CallHandlerInfo::kDataOffset)); |
| 558 __ push(scratch3); |
| 559 } else { |
| 560 __ push(Immediate(call_data)); |
| 561 } |
| 562 // return value |
| 563 __ push(Immediate(isolate->factory()->undefined_value())); |
| 564 // return value default |
| 565 __ push(Immediate(isolate->factory()->undefined_value())); |
| 566 // isolate |
| 567 __ push(Immediate(reinterpret_cast<int>(isolate))); |
| 568 // holder |
| 569 __ push(receiver); |
| 570 |
| 571 // store receiver address for GenerateFastApiCallBody |
| 572 ASSERT(!scratch1.is(eax)); |
| 573 __ mov(eax, esp); |
| 574 |
| 575 // return address |
| 576 __ push(scratch1); |
| 577 |
| 578 GenerateFastApiCallBody(masm, optimization, argc, true); |
| 579 } |
| 580 |
| 581 |
| 582 static void GenerateFastApiCallBody(MacroAssembler* masm, |
| 583 const CallOptimization& optimization, |
| 584 int argc, |
| 585 bool restore_context) { |
| 586 // ----------- S t a t e ------------- |
| 587 // -- esp[0] : return address |
| 588 // -- esp[4] - esp[28] : FunctionCallbackInfo, incl. |
| 589 // : object passing the type check |
| 590 // (set by CheckPrototypes) |
| 591 // -- esp[32] : last argument |
| 592 // -- ... |
| 593 // -- esp[(argc + 7) * 4] : first argument |
| 594 // -- esp[(argc + 8) * 4] : receiver |
| 595 // |
| 596 // -- eax : receiver address |
| 597 // ----------------------------------- |
| 598 typedef FunctionCallbackArguments FCA; |
| 599 |
| 502 // API function gets reference to the v8::Arguments. If CPU profiler | 600 // API function gets reference to the v8::Arguments. If CPU profiler |
| 503 // is enabled wrapper function will be called and we need to pass | 601 // is enabled wrapper function will be called and we need to pass |
| 504 // address of the callback as additional parameter, always allocate | 602 // address of the callback as additional parameter, always allocate |
| 505 // space for it. | 603 // space for it. |
| 506 const int kApiArgc = 1 + 1; | 604 const int kApiArgc = 1 + 1; |
| 507 | 605 |
| 508 // Allocate the v8::Arguments structure in the arguments' space since | 606 // Allocate the v8::Arguments structure in the arguments' space since |
| 509 // it's not controlled by GC. | 607 // it's not controlled by GC. |
| 510 const int kApiStackSpace = 4; | 608 const int kApiStackSpace = 4; |
| 511 | 609 |
| 610 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 611 |
| 512 // Function address is a foreign pointer outside V8's heap. | 612 // Function address is a foreign pointer outside V8's heap. |
| 513 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | 613 Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
| 514 __ PrepareCallApiFunction(kApiArgc + kApiStackSpace); | 614 __ PrepareCallApiFunction(kApiArgc + kApiStackSpace); |
| 515 | 615 |
| 516 // FunctionCallbackInfo::implicit_args_. | 616 // FunctionCallbackInfo::implicit_args_. |
| 517 __ mov(ApiParameterOperand(2), eax); | 617 __ mov(ApiParameterOperand(2), eax); |
| 518 __ add(eax, Immediate((argc + kFastApiCallArguments - 1) * kPointerSize)); | 618 __ add(eax, Immediate((argc + kFastApiCallArguments - 1) * kPointerSize)); |
| 519 // FunctionCallbackInfo::values_. | 619 // FunctionCallbackInfo::values_. |
| 520 __ mov(ApiParameterOperand(3), eax); | 620 __ mov(ApiParameterOperand(3), eax); |
| 521 // FunctionCallbackInfo::length_. | 621 // FunctionCallbackInfo::length_. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 536 __ CallApiFunctionAndReturn(function_address, | 636 __ CallApiFunctionAndReturn(function_address, |
| 537 thunk_address, | 637 thunk_address, |
| 538 ApiParameterOperand(1), | 638 ApiParameterOperand(1), |
| 539 argc + kFastApiCallArguments + 1, | 639 argc + kFastApiCallArguments + 1, |
| 540 return_value_operand, | 640 return_value_operand, |
| 541 restore_context ? | 641 restore_context ? |
| 542 &context_restore_operand : NULL); | 642 &context_restore_operand : NULL); |
| 543 } | 643 } |
| 544 | 644 |
| 545 | 645 |
| 546 // Generate call to api function. | |
| 547 static void GenerateFastApiCall(MacroAssembler* masm, | |
| 548 const CallOptimization& optimization, | |
| 549 Register receiver, | |
| 550 Register scratch, | |
| 551 int argc, | |
| 552 Register* values) { | |
| 553 ASSERT(optimization.is_simple_api_call()); | |
| 554 ASSERT(!receiver.is(scratch)); | |
| 555 | |
| 556 const int stack_space = kFastApiCallArguments + argc + 1; | |
| 557 const int kHolderIndex = FunctionCallbackArguments::kHolderIndex + 1; | |
| 558 // Copy return value. | |
| 559 __ mov(scratch, Operand(esp, 0)); | |
| 560 // Assign stack space for the call arguments. | |
| 561 __ sub(esp, Immediate(stack_space * kPointerSize)); | |
| 562 // Move the return address on top of the stack. | |
| 563 __ mov(Operand(esp, 0), scratch); | |
| 564 // Write holder to stack frame. | |
| 565 __ mov(Operand(esp, kHolderIndex * kPointerSize), receiver); | |
| 566 // Write receiver to stack frame. | |
| 567 int index = stack_space; | |
| 568 __ mov(Operand(esp, index-- * kPointerSize), receiver); | |
| 569 // Write the arguments to stack frame. | |
| 570 for (int i = 0; i < argc; i++) { | |
| 571 ASSERT(!receiver.is(values[i])); | |
| 572 ASSERT(!scratch.is(values[i])); | |
| 573 __ mov(Operand(esp, index-- * kPointerSize), values[i]); | |
| 574 } | |
| 575 | |
| 576 GenerateFastApiCall(masm, optimization, argc, true); | |
| 577 } | |
| 578 | |
| 579 | |
| 580 class CallInterceptorCompiler BASE_EMBEDDED { | 646 class CallInterceptorCompiler BASE_EMBEDDED { |
| 581 public: | 647 public: |
| 582 CallInterceptorCompiler(StubCompiler* stub_compiler, | 648 CallInterceptorCompiler(StubCompiler* stub_compiler, |
| 583 const ParameterCount& arguments, | 649 const ParameterCount& arguments, |
| 584 Register name, | 650 Register name, |
| 585 Code::ExtraICState extra_state) | 651 Code::ExtraICState extra_state) |
| 586 : stub_compiler_(stub_compiler), | 652 : stub_compiler_(stub_compiler), |
| 587 arguments_(arguments), | 653 arguments_(arguments), |
| 588 name_(name), | 654 name_(name), |
| 589 extra_state_(extra_state) {} | 655 extra_state_(extra_state) {} |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 } else { | 746 } else { |
| 681 // CheckPrototypes has a side effect of fetching a 'holder' | 747 // CheckPrototypes has a side effect of fetching a 'holder' |
| 682 // for API (object which is instanceof for the signature). It's | 748 // for API (object which is instanceof for the signature). It's |
| 683 // safe to omit it here, as if present, it should be fetched | 749 // safe to omit it here, as if present, it should be fetched |
| 684 // by the previous CheckPrototypes. | 750 // by the previous CheckPrototypes. |
| 685 ASSERT(depth2 == kInvalidProtoDepth); | 751 ASSERT(depth2 == kInvalidProtoDepth); |
| 686 } | 752 } |
| 687 | 753 |
| 688 // Invoke function. | 754 // Invoke function. |
| 689 if (can_do_fast_api_call) { | 755 if (can_do_fast_api_call) { |
| 690 GenerateFastApiCall(masm, optimization, arguments_.immediate(), false); | 756 GenerateFastApiCall(masm, optimization, arguments_.immediate()); |
| 691 } else { | 757 } else { |
| 692 CallKind call_kind = CallICBase::Contextual::decode(extra_state_) | 758 CallKind call_kind = CallICBase::Contextual::decode(extra_state_) |
| 693 ? CALL_AS_FUNCTION | 759 ? CALL_AS_FUNCTION |
| 694 : CALL_AS_METHOD; | 760 : CALL_AS_METHOD; |
| 695 Handle<JSFunction> function = optimization.constant_function(); | 761 Handle<JSFunction> function = optimization.constant_function(); |
| 696 ParameterCount expected(function); | 762 ParameterCount expected(function); |
| 697 __ InvokeFunction(function, expected, arguments_, | 763 __ InvokeFunction(function, expected, arguments_, |
| 698 JUMP_FUNCTION, NullCallWrapper(), call_kind); | 764 JUMP_FUNCTION, NullCallWrapper(), call_kind); |
| 699 } | 765 } |
| 700 | 766 |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 field.translate(holder), | 1429 field.translate(holder), |
| 1364 representation); | 1430 representation); |
| 1365 GenerateTailCall(masm(), stub.GetCode(isolate())); | 1431 GenerateTailCall(masm(), stub.GetCode(isolate())); |
| 1366 } | 1432 } |
| 1367 } | 1433 } |
| 1368 | 1434 |
| 1369 | 1435 |
| 1370 void LoadStubCompiler::GenerateLoadCallback( | 1436 void LoadStubCompiler::GenerateLoadCallback( |
| 1371 const CallOptimization& call_optimization) { | 1437 const CallOptimization& call_optimization) { |
| 1372 GenerateFastApiCall( | 1438 GenerateFastApiCall( |
| 1373 masm(), call_optimization, receiver(), scratch3(), 0, NULL); | 1439 masm(), call_optimization, receiver(), scratch1(), |
| 1440 scratch2(), name(), 0, NULL); |
| 1374 } | 1441 } |
| 1375 | 1442 |
| 1376 | 1443 |
| 1377 void LoadStubCompiler::GenerateLoadCallback( | 1444 void LoadStubCompiler::GenerateLoadCallback( |
| 1378 Register reg, | 1445 Register reg, |
| 1379 Handle<ExecutableAccessorInfo> callback) { | 1446 Handle<ExecutableAccessorInfo> callback) { |
| 1380 // Insert additional parameters into the stack frame above return address. | 1447 // Insert additional parameters into the stack frame above return address. |
| 1381 ASSERT(!scratch3().is(reg)); | 1448 ASSERT(!scratch3().is(reg)); |
| 1382 __ pop(scratch3()); // Get return address to place it below. | 1449 __ pop(scratch3()); // Get return address to place it below. |
| 1383 | 1450 |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 // Check that the maps haven't changed and find a Holder as a side effect. | 2663 // Check that the maps haven't changed and find a Holder as a side effect. |
| 2597 CheckPrototypes(Handle<JSObject>::cast(object), edx, holder, ebx, eax, edi, | 2664 CheckPrototypes(Handle<JSObject>::cast(object), edx, holder, ebx, eax, edi, |
| 2598 name, depth, &miss); | 2665 name, depth, &miss); |
| 2599 | 2666 |
| 2600 // Move the return address on top of the stack. | 2667 // Move the return address on top of the stack. |
| 2601 __ mov(eax, Operand(esp, kFastApiCallArguments * kPointerSize)); | 2668 __ mov(eax, Operand(esp, kFastApiCallArguments * kPointerSize)); |
| 2602 __ mov(Operand(esp, 0 * kPointerSize), eax); | 2669 __ mov(Operand(esp, 0 * kPointerSize), eax); |
| 2603 | 2670 |
| 2604 // esp[2 * kPointerSize] is uninitialized, esp[3 * kPointerSize] contains | 2671 // esp[2 * kPointerSize] is uninitialized, esp[3 * kPointerSize] contains |
| 2605 // duplicate of return address and will be overwritten. | 2672 // duplicate of return address and will be overwritten. |
| 2606 GenerateFastApiCall(masm(), optimization, argc, false); | 2673 GenerateFastApiCall(masm(), optimization, argc); |
| 2607 | 2674 |
| 2608 __ bind(&miss); | 2675 __ bind(&miss); |
| 2609 __ add(esp, Immediate(kFastApiCallArguments * kPointerSize)); | 2676 __ add(esp, Immediate(kFastApiCallArguments * kPointerSize)); |
| 2610 | 2677 |
| 2611 __ bind(&miss_before_stack_reserved); | 2678 __ bind(&miss_before_stack_reserved); |
| 2612 GenerateMissBranch(); | 2679 GenerateMissBranch(); |
| 2613 | 2680 |
| 2614 // Return the generated code. | 2681 // Return the generated code. |
| 2615 return GetCode(function); | 2682 return GetCode(function); |
| 2616 } | 2683 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 | 2980 |
| 2914 Handle<Code> StoreStubCompiler::CompileStoreCallback( | 2981 Handle<Code> StoreStubCompiler::CompileStoreCallback( |
| 2915 Handle<JSObject> object, | 2982 Handle<JSObject> object, |
| 2916 Handle<JSObject> holder, | 2983 Handle<JSObject> holder, |
| 2917 Handle<Name> name, | 2984 Handle<Name> name, |
| 2918 const CallOptimization& call_optimization) { | 2985 const CallOptimization& call_optimization) { |
| 2919 HandlerFrontend(object, receiver(), holder, name); | 2986 HandlerFrontend(object, receiver(), holder, name); |
| 2920 | 2987 |
| 2921 Register values[] = { value() }; | 2988 Register values[] = { value() }; |
| 2922 GenerateFastApiCall( | 2989 GenerateFastApiCall( |
| 2923 masm(), call_optimization, receiver(), scratch1(), 1, values); | 2990 masm(), call_optimization, receiver(), scratch1(), |
| 2991 scratch2(), this->name(), 1, values); |
| 2924 | 2992 |
| 2925 // Return the generated code. | 2993 // Return the generated code. |
| 2926 return GetCode(kind(), Code::CALLBACKS, name); | 2994 return GetCode(kind(), Code::CALLBACKS, name); |
| 2927 } | 2995 } |
| 2928 | 2996 |
| 2929 | 2997 |
| 2930 #undef __ | 2998 #undef __ |
| 2931 #define __ ACCESS_MASM(masm) | 2999 #define __ ACCESS_MASM(masm) |
| 2932 | 3000 |
| 2933 | 3001 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3246 // ----------------------------------- | 3314 // ----------------------------------- |
| 3247 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); | 3315 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); |
| 3248 } | 3316 } |
| 3249 | 3317 |
| 3250 | 3318 |
| 3251 #undef __ | 3319 #undef __ |
| 3252 | 3320 |
| 3253 } } // namespace v8::internal | 3321 } } // namespace v8::internal |
| 3254 | 3322 |
| 3255 #endif // V8_TARGET_ARCH_IA32 | 3323 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |