| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 __ bind(&entry); | 336 __ bind(&entry); |
| 337 __ decq(rcx); | 337 __ decq(rcx); |
| 338 __ j(greater_equal, &loop); | 338 __ j(greater_equal, &loop); |
| 339 | 339 |
| 340 // Call the function. | 340 // Call the function. |
| 341 if (is_api_function) { | 341 if (is_api_function) { |
| 342 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 342 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 343 Handle<Code> code = | 343 Handle<Code> code = |
| 344 masm->isolate()->builtins()->HandleApiCallConstruct(); | 344 masm->isolate()->builtins()->HandleApiCallConstruct(); |
| 345 ParameterCount expected(0); | 345 ParameterCount expected(0); |
| 346 __ InvokeCode(code, expected, expected, | 346 __ InvokeCode(code, expected, expected, RelocInfo::CODE_TARGET, |
| 347 RelocInfo::CODE_TARGET, CALL_FUNCTION); | 347 CALL_FUNCTION, NullCallWrapper(), CALL_AS_METHOD); |
| 348 } else { | 348 } else { |
| 349 ParameterCount actual(rax); | 349 ParameterCount actual(rax); |
| 350 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | 350 __ InvokeFunction(rdi, actual, CALL_FUNCTION, |
| 351 NullCallWrapper(), CALL_AS_METHOD); |
| 351 } | 352 } |
| 352 | 353 |
| 353 // Restore context from the frame. | 354 // Restore context from the frame. |
| 354 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 355 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 355 | 356 |
| 356 // If the result is an object (in the ECMA sense), we should get rid | 357 // If the result is an object (in the ECMA sense), we should get rid |
| 357 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | 358 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
| 358 // on page 74. | 359 // on page 74. |
| 359 Label use_receiver, exit; | 360 Label use_receiver, exit; |
| 360 // If the result is a smi, it is *not* an object in the ECMA sense. | 361 // If the result is a smi, it is *not* an object in the ECMA sense. |
| 361 __ JumpIfSmi(rax, &use_receiver); | 362 __ JumpIfSmi(rax, &use_receiver); |
| 362 | 363 |
| 363 // If the type of the result (stored in its map) is less than | 364 // If the type of the result (stored in its map) is less than |
| 364 // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense. | 365 // FIRST_SPEC_OBJECT_TYPE, it is not an object in the ECMA sense. |
| 365 __ CmpObjectType(rax, FIRST_JS_OBJECT_TYPE, rcx); | 366 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 367 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
| 366 __ j(above_equal, &exit); | 368 __ j(above_equal, &exit); |
| 367 | 369 |
| 368 // Throw away the result of the constructor invocation and use the | 370 // Throw away the result of the constructor invocation and use the |
| 369 // on-stack receiver as the result. | 371 // on-stack receiver as the result. |
| 370 __ bind(&use_receiver); | 372 __ bind(&use_receiver); |
| 371 __ movq(rax, Operand(rsp, 0)); | 373 __ movq(rax, Operand(rsp, 0)); |
| 372 | 374 |
| 373 // Restore the arguments count and leave the construct frame. | 375 // Restore the arguments count and leave the construct frame. |
| 374 __ bind(&exit); | 376 __ bind(&exit); |
| 375 __ movq(rbx, Operand(rsp, kPointerSize)); // get arguments count | 377 __ movq(rbx, Operand(rsp, kPointerSize)); // get arguments count |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 __ j(not_equal, &loop); | 494 __ j(not_equal, &loop); |
| 493 | 495 |
| 494 // Invoke the code. | 496 // Invoke the code. |
| 495 if (is_construct) { | 497 if (is_construct) { |
| 496 // Expects rdi to hold function pointer. | 498 // Expects rdi to hold function pointer. |
| 497 __ Call(masm->isolate()->builtins()->JSConstructCall(), | 499 __ Call(masm->isolate()->builtins()->JSConstructCall(), |
| 498 RelocInfo::CODE_TARGET); | 500 RelocInfo::CODE_TARGET); |
| 499 } else { | 501 } else { |
| 500 ParameterCount actual(rax); | 502 ParameterCount actual(rax); |
| 501 // Function must be in rdi. | 503 // Function must be in rdi. |
| 502 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | 504 __ InvokeFunction(rdi, actual, CALL_FUNCTION, |
| 505 NullCallWrapper(), CALL_AS_METHOD); |
| 503 } | 506 } |
| 504 | 507 |
| 505 // Exit the JS frame. Notice that this also removes the empty | 508 // Exit the JS frame. Notice that this also removes the empty |
| 506 // context and the function left on the stack by the code | 509 // context and the function left on the stack by the code |
| 507 // invocation. | 510 // invocation. |
| 508 __ LeaveInternalFrame(); | 511 __ LeaveInternalFrame(); |
| 509 // TODO(X64): Is argument correct? Is there a receiver to remove? | 512 // TODO(X64): Is argument correct? Is there a receiver to remove? |
| 510 __ ret(1 * kPointerSize); // remove receiver | 513 __ ret(1 * kPointerSize); // remove receiver |
| 511 } | 514 } |
| 512 | 515 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 669 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 667 | 670 |
| 668 // Do not transform the receiver for strict mode functions. | 671 // Do not transform the receiver for strict mode functions. |
| 669 __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 672 __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 670 __ testb(FieldOperand(rbx, SharedFunctionInfo::kStrictModeByteOffset), | 673 __ testb(FieldOperand(rbx, SharedFunctionInfo::kStrictModeByteOffset), |
| 671 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); | 674 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); |
| 672 __ j(not_equal, &shift_arguments); | 675 __ j(not_equal, &shift_arguments); |
| 673 | 676 |
| 674 // Do not transform the receiver for natives. | 677 // Do not transform the receiver for natives. |
| 675 // SharedFunctionInfo is already loaded into rbx. | 678 // SharedFunctionInfo is already loaded into rbx. |
| 676 __ testb(FieldOperand(rbx, SharedFunctionInfo::kES5NativeByteOffset), | 679 __ testb(FieldOperand(rbx, SharedFunctionInfo::kNativeByteOffset), |
| 677 Immediate(1 << SharedFunctionInfo::kES5NativeBitWithinByte)); | 680 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); |
| 678 __ j(not_zero, &shift_arguments); | 681 __ j(not_zero, &shift_arguments); |
| 679 | 682 |
| 680 // Compute the receiver in non-strict mode. | 683 // Compute the receiver in non-strict mode. |
| 681 __ movq(rbx, Operand(rsp, rax, times_pointer_size, 0)); | 684 __ movq(rbx, Operand(rsp, rax, times_pointer_size, 0)); |
| 682 __ JumpIfSmi(rbx, &convert_to_object, Label::kNear); | 685 __ JumpIfSmi(rbx, &convert_to_object, Label::kNear); |
| 683 | 686 |
| 684 __ CompareRoot(rbx, Heap::kNullValueRootIndex); | 687 __ CompareRoot(rbx, Heap::kNullValueRootIndex); |
| 685 __ j(equal, &use_global_receiver); | 688 __ j(equal, &use_global_receiver); |
| 686 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); | 689 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
| 687 __ j(equal, &use_global_receiver); | 690 __ j(equal, &use_global_receiver); |
| 688 | 691 |
| 689 STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE); | 692 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 690 STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); | 693 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); |
| 691 __ CmpObjectType(rbx, FIRST_JS_OBJECT_TYPE, rcx); | |
| 692 __ j(above_equal, &shift_arguments); | 694 __ j(above_equal, &shift_arguments); |
| 693 | 695 |
| 694 __ bind(&convert_to_object); | 696 __ bind(&convert_to_object); |
| 695 __ EnterInternalFrame(); // In order to preserve argument count. | 697 __ EnterInternalFrame(); // In order to preserve argument count. |
| 696 __ Integer32ToSmi(rax, rax); | 698 __ Integer32ToSmi(rax, rax); |
| 697 __ push(rax); | 699 __ push(rax); |
| 698 | 700 |
| 699 __ push(rbx); | 701 __ push(rbx); |
| 700 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | 702 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 701 __ movq(rbx, rax); | 703 __ movq(rbx, rax); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 FieldOperand(rdx, | 769 FieldOperand(rdx, |
| 768 SharedFunctionInfo::kFormalParameterCountOffset)); | 770 SharedFunctionInfo::kFormalParameterCountOffset)); |
| 769 __ movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); | 771 __ movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
| 770 __ SetCallKind(rcx, CALL_AS_METHOD); | 772 __ SetCallKind(rcx, CALL_AS_METHOD); |
| 771 __ cmpq(rax, rbx); | 773 __ cmpq(rax, rbx); |
| 772 __ j(not_equal, | 774 __ j(not_equal, |
| 773 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), | 775 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 774 RelocInfo::CODE_TARGET); | 776 RelocInfo::CODE_TARGET); |
| 775 | 777 |
| 776 ParameterCount expected(0); | 778 ParameterCount expected(0); |
| 777 __ InvokeCode(rdx, expected, expected, JUMP_FUNCTION); | 779 __ InvokeCode(rdx, expected, expected, JUMP_FUNCTION, |
| 780 NullCallWrapper(), CALL_AS_METHOD); |
| 778 } | 781 } |
| 779 | 782 |
| 780 | 783 |
| 781 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { | 784 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { |
| 782 // Stack at entry: | 785 // Stack at entry: |
| 783 // rsp: return address | 786 // rsp: return address |
| 784 // rsp+8: arguments | 787 // rsp+8: arguments |
| 785 // rsp+16: receiver ("this") | 788 // rsp+16: receiver ("this") |
| 786 // rsp+24: function | 789 // rsp+24: function |
| 787 __ EnterInternalFrame(); | 790 __ EnterInternalFrame(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 Label call_to_object, use_global_receiver, push_receiver; | 840 Label call_to_object, use_global_receiver, push_receiver; |
| 838 __ movq(rbx, Operand(rbp, kReceiverOffset)); | 841 __ movq(rbx, Operand(rbp, kReceiverOffset)); |
| 839 | 842 |
| 840 // Do not transform the receiver for strict mode functions. | 843 // Do not transform the receiver for strict mode functions. |
| 841 __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 844 __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 842 __ testb(FieldOperand(rdx, SharedFunctionInfo::kStrictModeByteOffset), | 845 __ testb(FieldOperand(rdx, SharedFunctionInfo::kStrictModeByteOffset), |
| 843 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); | 846 Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte)); |
| 844 __ j(not_equal, &push_receiver); | 847 __ j(not_equal, &push_receiver); |
| 845 | 848 |
| 846 // Do not transform the receiver for natives. | 849 // Do not transform the receiver for natives. |
| 847 __ testb(FieldOperand(rdx, SharedFunctionInfo::kES5NativeByteOffset), | 850 __ testb(FieldOperand(rdx, SharedFunctionInfo::kNativeByteOffset), |
| 848 Immediate(1 << SharedFunctionInfo::kES5NativeBitWithinByte)); | 851 Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte)); |
| 849 __ j(not_zero, &push_receiver); | 852 __ j(not_equal, &push_receiver); |
| 850 | 853 |
| 851 // Compute the receiver in non-strict mode. | 854 // Compute the receiver in non-strict mode. |
| 852 __ JumpIfSmi(rbx, &call_to_object, Label::kNear); | 855 __ JumpIfSmi(rbx, &call_to_object, Label::kNear); |
| 853 __ CompareRoot(rbx, Heap::kNullValueRootIndex); | 856 __ CompareRoot(rbx, Heap::kNullValueRootIndex); |
| 854 __ j(equal, &use_global_receiver); | 857 __ j(equal, &use_global_receiver); |
| 855 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); | 858 __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
| 856 __ j(equal, &use_global_receiver); | 859 __ j(equal, &use_global_receiver); |
| 857 | 860 |
| 858 // If given receiver is already a JavaScript object then there's no | 861 // If given receiver is already a JavaScript object then there's no |
| 859 // reason for converting it. | 862 // reason for converting it. |
| 860 STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE); | 863 STATIC_ASSERT(LAST_SPEC_OBJECT_TYPE == LAST_TYPE); |
| 861 STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); | 864 __ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, rcx); |
| 862 __ CmpObjectType(rbx, FIRST_JS_OBJECT_TYPE, rcx); | |
| 863 __ j(above_equal, &push_receiver); | 865 __ j(above_equal, &push_receiver); |
| 864 | 866 |
| 865 // Convert the receiver to an object. | 867 // Convert the receiver to an object. |
| 866 __ bind(&call_to_object); | 868 __ bind(&call_to_object); |
| 867 __ push(rbx); | 869 __ push(rbx); |
| 868 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | 870 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 869 __ movq(rbx, rax); | 871 __ movq(rbx, rax); |
| 870 __ jmp(&push_receiver, Label::kNear); | 872 __ jmp(&push_receiver, Label::kNear); |
| 871 | 873 |
| 872 // Use the current global receiver object as the receiver. | 874 // Use the current global receiver object as the receiver. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 __ movq(Operand(rbp, kIndexOffset), rax); | 909 __ movq(Operand(rbp, kIndexOffset), rax); |
| 908 | 910 |
| 909 __ bind(&entry); | 911 __ bind(&entry); |
| 910 __ cmpq(rax, Operand(rbp, kLimitOffset)); | 912 __ cmpq(rax, Operand(rbp, kLimitOffset)); |
| 911 __ j(not_equal, &loop); | 913 __ j(not_equal, &loop); |
| 912 | 914 |
| 913 // Invoke the function. | 915 // Invoke the function. |
| 914 ParameterCount actual(rax); | 916 ParameterCount actual(rax); |
| 915 __ SmiToInteger32(rax, rax); | 917 __ SmiToInteger32(rax, rax); |
| 916 __ movq(rdi, Operand(rbp, kFunctionOffset)); | 918 __ movq(rdi, Operand(rbp, kFunctionOffset)); |
| 917 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | 919 __ InvokeFunction(rdi, actual, CALL_FUNCTION, |
| 920 NullCallWrapper(), CALL_AS_METHOD); |
| 918 | 921 |
| 919 __ LeaveInternalFrame(); | 922 __ LeaveInternalFrame(); |
| 920 __ ret(3 * kPointerSize); // remove function, receiver, and arguments | 923 __ ret(3 * kPointerSize); // remove function, receiver, and arguments |
| 921 } | 924 } |
| 922 | 925 |
| 923 | 926 |
| 924 // Number of empty elements to allocate for an empty array. | 927 // Number of empty elements to allocate for an empty array. |
| 925 static const int kPreallocatedArrayElements = 4; | 928 static const int kPreallocatedArrayElements = 4; |
| 926 | 929 |
| 927 | 930 |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); | 1514 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); |
| 1512 generator.Generate(); | 1515 generator.Generate(); |
| 1513 } | 1516 } |
| 1514 | 1517 |
| 1515 | 1518 |
| 1516 #undef __ | 1519 #undef __ |
| 1517 | 1520 |
| 1518 } } // namespace v8::internal | 1521 } } // namespace v8::internal |
| 1519 | 1522 |
| 1520 #endif // V8_TARGET_ARCH_X64 | 1523 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |