| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 __ pop(rbx); // Discard copy of return address. | 291 __ pop(rbx); // Discard copy of return address. |
| 292 __ decq(rax); // One fewer argument (first argument is new receiver). | 292 __ decq(rax); // One fewer argument (first argument is new receiver). |
| 293 } | 293 } |
| 294 | 294 |
| 295 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin. | 295 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin. |
| 296 { Label function; | 296 { Label function; |
| 297 __ testq(rdi, rdi); | 297 __ testq(rdi, rdi); |
| 298 __ j(not_zero, &function); | 298 __ j(not_zero, &function); |
| 299 __ xor_(rbx, rbx); | 299 __ xor_(rbx, rbx); |
| 300 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION); | 300 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION); |
| 301 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)), | 301 __ Jump(Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 302 RelocInfo::CODE_TARGET); | 302 ArgumentsAdaptorTrampoline)), RelocInfo::CODE_TARGET); |
| 303 __ bind(&function); | 303 __ bind(&function); |
| 304 } | 304 } |
| 305 | 305 |
| 306 // 5b. Get the code to call from the function and check that the number of | 306 // 5b. Get the code to call from the function and check that the number of |
| 307 // expected arguments matches what we're providing. If so, jump | 307 // expected arguments matches what we're providing. If so, jump |
| 308 // (tail-call) to the code in register edx without checking arguments. | 308 // (tail-call) to the code in register edx without checking arguments. |
| 309 __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 309 __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 310 __ movsxlq(rbx, | 310 __ movsxlq(rbx, |
| 311 FieldOperand(rdx, | 311 FieldOperand(rdx, |
| 312 SharedFunctionInfo::kFormalParameterCountOffset)); | 312 SharedFunctionInfo::kFormalParameterCountOffset)); |
| 313 __ movq(rdx, FieldOperand(rdx, SharedFunctionInfo::kCodeOffset)); | 313 __ movq(rdx, FieldOperand(rdx, SharedFunctionInfo::kCodeOffset)); |
| 314 __ lea(rdx, FieldOperand(rdx, Code::kHeaderSize)); | 314 __ lea(rdx, FieldOperand(rdx, Code::kHeaderSize)); |
| 315 __ cmpq(rax, rbx); | 315 __ cmpq(rax, rbx); |
| 316 __ j(not_equal, | 316 __ j(not_equal, |
| 317 Handle<Code>(builtin(ArgumentsAdaptorTrampoline)), | 317 Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 318 RelocInfo::CODE_TARGET); | 318 ArgumentsAdaptorTrampoline)), RelocInfo::CODE_TARGET); |
| 319 | 319 |
| 320 ParameterCount expected(0); | 320 ParameterCount expected(0); |
| 321 __ InvokeCode(rdx, expected, expected, JUMP_FUNCTION); | 321 __ InvokeCode(rdx, expected, expected, JUMP_FUNCTION); |
| 322 } | 322 } |
| 323 | 323 |
| 324 | 324 |
| 325 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { | 325 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { |
| 326 // Stack at entry: | 326 // Stack at entry: |
| 327 // rsp: return address | 327 // rsp: return address |
| 328 // rsp+8: arguments | 328 // rsp+8: arguments |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 __ push(rbx); | 414 __ push(rbx); |
| 415 | 415 |
| 416 // Copy all arguments from the array to the stack. | 416 // Copy all arguments from the array to the stack. |
| 417 Label entry, loop; | 417 Label entry, loop; |
| 418 __ movq(rax, Operand(rbp, kIndexOffset)); | 418 __ movq(rax, Operand(rbp, kIndexOffset)); |
| 419 __ jmp(&entry); | 419 __ jmp(&entry); |
| 420 __ bind(&loop); | 420 __ bind(&loop); |
| 421 __ movq(rdx, Operand(rbp, kArgumentsOffset)); // load arguments | 421 __ movq(rdx, Operand(rbp, kArgumentsOffset)); // load arguments |
| 422 | 422 |
| 423 // Use inline caching to speed up access to arguments. | 423 // Use inline caching to speed up access to arguments. |
| 424 Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); | 424 Handle<Code> ic(Isolate::Current()->builtins()->builtin( |
| 425 Builtins::KeyedLoadIC_Initialize)); |
| 425 __ Call(ic, RelocInfo::CODE_TARGET); | 426 __ Call(ic, RelocInfo::CODE_TARGET); |
| 426 // It is important that we do not have a test instruction after the | 427 // It is important that we do not have a test instruction after the |
| 427 // call. A test instruction after the call is used to indicate that | 428 // call. A test instruction after the call is used to indicate that |
| 428 // we have generated an inline version of the keyed load. In this | 429 // we have generated an inline version of the keyed load. In this |
| 429 // case, we know that we are not generating a test instruction next. | 430 // case, we know that we are not generating a test instruction next. |
| 430 | 431 |
| 431 // Push the nth argument. | 432 // Push the nth argument. |
| 432 __ push(rax); | 433 __ push(rax); |
| 433 | 434 |
| 434 // Update the index on the stack and in register rax. | 435 // Update the index on the stack and in register rax. |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 __ CmpObjectType(rbx, MAP_TYPE, rcx); | 827 __ CmpObjectType(rbx, MAP_TYPE, rcx); |
| 827 __ Check(equal, "Unexpected initial map for Array function"); | 828 __ Check(equal, "Unexpected initial map for Array function"); |
| 828 } | 829 } |
| 829 | 830 |
| 830 // Run the native code for the Array function called as a normal function. | 831 // Run the native code for the Array function called as a normal function. |
| 831 ArrayNativeCode(masm, &generic_array_code); | 832 ArrayNativeCode(masm, &generic_array_code); |
| 832 | 833 |
| 833 // Jump to the generic array code in case the specialized code cannot handle | 834 // Jump to the generic array code in case the specialized code cannot handle |
| 834 // the construction. | 835 // the construction. |
| 835 __ bind(&generic_array_code); | 836 __ bind(&generic_array_code); |
| 836 Code* code = Builtins::builtin(Builtins::ArrayCodeGeneric); | 837 Code* code = Isolate::Current()->builtins()->builtin( |
| 838 Builtins::ArrayCodeGeneric); |
| 837 Handle<Code> array_code(code); | 839 Handle<Code> array_code(code); |
| 838 __ Jump(array_code, RelocInfo::CODE_TARGET); | 840 __ Jump(array_code, RelocInfo::CODE_TARGET); |
| 839 } | 841 } |
| 840 | 842 |
| 841 | 843 |
| 842 void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) { | 844 void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) { |
| 843 // ----------- S t a t e ------------- | 845 // ----------- S t a t e ------------- |
| 844 // -- rax : argc | 846 // -- rax : argc |
| 845 // -- rdi : constructor | 847 // -- rdi : constructor |
| 846 // -- rsp[0] : return address | 848 // -- rsp[0] : return address |
| (...skipping 16 matching lines...) Expand all Loading... |
| 863 __ CmpObjectType(rbx, MAP_TYPE, rcx); | 865 __ CmpObjectType(rbx, MAP_TYPE, rcx); |
| 864 __ Check(equal, "Unexpected initial map for Array function"); | 866 __ Check(equal, "Unexpected initial map for Array function"); |
| 865 } | 867 } |
| 866 | 868 |
| 867 // Run the native code for the Array function called as constructor. | 869 // Run the native code for the Array function called as constructor. |
| 868 ArrayNativeCode(masm, &generic_constructor); | 870 ArrayNativeCode(masm, &generic_constructor); |
| 869 | 871 |
| 870 // Jump to the generic construct code in case the specialized code cannot | 872 // Jump to the generic construct code in case the specialized code cannot |
| 871 // handle the construction. | 873 // handle the construction. |
| 872 __ bind(&generic_constructor); | 874 __ bind(&generic_constructor); |
| 873 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); | 875 Code* code = Isolate::Current()->builtins()->builtin( |
| 876 Builtins::JSConstructStubGeneric); |
| 874 Handle<Code> generic_construct_stub(code); | 877 Handle<Code> generic_construct_stub(code); |
| 875 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); | 878 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 876 } | 879 } |
| 877 | 880 |
| 878 | 881 |
| 879 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { | 882 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { |
| 880 // ----------- S t a t e ------------- | 883 // ----------- S t a t e ------------- |
| 881 // -- rax: number of arguments | 884 // -- rax: number of arguments |
| 882 // -- rdi: constructor function | 885 // -- rdi: constructor function |
| 883 // ----------------------------------- | 886 // ----------------------------------- |
| (...skipping 14 matching lines...) Expand all Loading... |
| 898 // edi: called object | 901 // edi: called object |
| 899 // eax: number of arguments | 902 // eax: number of arguments |
| 900 __ bind(&non_function_call); | 903 __ bind(&non_function_call); |
| 901 // CALL_NON_FUNCTION expects the non-function constructor as receiver | 904 // CALL_NON_FUNCTION expects the non-function constructor as receiver |
| 902 // (instead of the original receiver from the call site). The receiver is | 905 // (instead of the original receiver from the call site). The receiver is |
| 903 // stack element argc+1. | 906 // stack element argc+1. |
| 904 __ movq(Operand(rsp, rax, times_pointer_size, kPointerSize), rdi); | 907 __ movq(Operand(rsp, rax, times_pointer_size, kPointerSize), rdi); |
| 905 // Set expected number of arguments to zero (not changing rax). | 908 // Set expected number of arguments to zero (not changing rax). |
| 906 __ movq(rbx, Immediate(0)); | 909 __ movq(rbx, Immediate(0)); |
| 907 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); | 910 __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 908 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)), | 911 __ Jump(Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 909 RelocInfo::CODE_TARGET); | 912 ArgumentsAdaptorTrampoline)), RelocInfo::CODE_TARGET); |
| 910 } | 913 } |
| 911 | 914 |
| 912 | 915 |
| 913 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 916 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 914 bool is_api_function) { | 917 bool is_api_function) { |
| 915 // Enter a construct frame. | 918 // Enter a construct frame. |
| 916 __ EnterConstructFrame(); | 919 __ EnterConstructFrame(); |
| 917 | 920 |
| 918 // Store a smi-tagged arguments count on the stack. | 921 // Store a smi-tagged arguments count on the stack. |
| 919 __ Integer32ToSmi(rax, rax); | 922 __ Integer32ToSmi(rax, rax); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 __ bind(&loop); | 1114 __ bind(&loop); |
| 1112 __ push(Operand(rbx, rcx, times_pointer_size, 0)); | 1115 __ push(Operand(rbx, rcx, times_pointer_size, 0)); |
| 1113 __ bind(&entry); | 1116 __ bind(&entry); |
| 1114 __ decq(rcx); | 1117 __ decq(rcx); |
| 1115 __ j(greater_equal, &loop); | 1118 __ j(greater_equal, &loop); |
| 1116 | 1119 |
| 1117 // Call the function. | 1120 // Call the function. |
| 1118 if (is_api_function) { | 1121 if (is_api_function) { |
| 1119 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 1122 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 1120 Handle<Code> code = Handle<Code>( | 1123 Handle<Code> code = Handle<Code>( |
| 1121 Builtins::builtin(Builtins::HandleApiCallConstruct)); | 1124 Isolate::Current()->builtins()->builtin( |
| 1125 Builtins::HandleApiCallConstruct)); |
| 1122 ParameterCount expected(0); | 1126 ParameterCount expected(0); |
| 1123 __ InvokeCode(code, expected, expected, | 1127 __ InvokeCode(code, expected, expected, |
| 1124 RelocInfo::CODE_TARGET, CALL_FUNCTION); | 1128 RelocInfo::CODE_TARGET, CALL_FUNCTION); |
| 1125 } else { | 1129 } else { |
| 1126 ParameterCount actual(rax); | 1130 ParameterCount actual(rax); |
| 1127 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | 1131 __ InvokeFunction(rdi, actual, CALL_FUNCTION); |
| 1128 } | 1132 } |
| 1129 | 1133 |
| 1130 // Restore context from the frame. | 1134 // Restore context from the frame. |
| 1131 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 1135 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 __ movq(kScratchRegister, Operand(rbx, rcx, times_pointer_size, 0)); | 1266 __ movq(kScratchRegister, Operand(rbx, rcx, times_pointer_size, 0)); |
| 1263 __ push(Operand(kScratchRegister, 0)); // dereference handle | 1267 __ push(Operand(kScratchRegister, 0)); // dereference handle |
| 1264 __ addq(rcx, Immediate(1)); | 1268 __ addq(rcx, Immediate(1)); |
| 1265 __ bind(&entry); | 1269 __ bind(&entry); |
| 1266 __ cmpq(rcx, rax); | 1270 __ cmpq(rcx, rax); |
| 1267 __ j(not_equal, &loop); | 1271 __ j(not_equal, &loop); |
| 1268 | 1272 |
| 1269 // Invoke the code. | 1273 // Invoke the code. |
| 1270 if (is_construct) { | 1274 if (is_construct) { |
| 1271 // Expects rdi to hold function pointer. | 1275 // Expects rdi to hold function pointer. |
| 1272 __ Call(Handle<Code>(Builtins::builtin(Builtins::JSConstructCall)), | 1276 __ Call(Handle<Code>(Isolate::Current()->builtins()->builtin( |
| 1273 RelocInfo::CODE_TARGET); | 1277 Builtins::JSConstructCall)), RelocInfo::CODE_TARGET); |
| 1274 } else { | 1278 } else { |
| 1275 ParameterCount actual(rax); | 1279 ParameterCount actual(rax); |
| 1276 // Function must be in rdi. | 1280 // Function must be in rdi. |
| 1277 __ InvokeFunction(rdi, actual, CALL_FUNCTION); | 1281 __ InvokeFunction(rdi, actual, CALL_FUNCTION); |
| 1278 } | 1282 } |
| 1279 | 1283 |
| 1280 // Exit the JS frame. Notice that this also removes the empty | 1284 // Exit the JS frame. Notice that this also removes the empty |
| 1281 // context and the function left on the stack by the code | 1285 // context and the function left on the stack by the code |
| 1282 // invocation. | 1286 // invocation. |
| 1283 __ LeaveInternalFrame(); | 1287 __ LeaveInternalFrame(); |
| 1284 // TODO(X64): Is argument correct? Is there a receiver to remove? | 1288 // TODO(X64): Is argument correct? Is there a receiver to remove? |
| 1285 __ ret(1 * kPointerSize); // remove receiver | 1289 __ ret(1 * kPointerSize); // remove receiver |
| 1286 } | 1290 } |
| 1287 | 1291 |
| 1288 | 1292 |
| 1289 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { | 1293 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { |
| 1290 Generate_JSEntryTrampolineHelper(masm, false); | 1294 Generate_JSEntryTrampolineHelper(masm, false); |
| 1291 } | 1295 } |
| 1292 | 1296 |
| 1293 | 1297 |
| 1294 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { | 1298 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { |
| 1295 Generate_JSEntryTrampolineHelper(masm, true); | 1299 Generate_JSEntryTrampolineHelper(masm, true); |
| 1296 } | 1300 } |
| 1297 | 1301 |
| 1298 } } // namespace v8::internal | 1302 } } // namespace v8::internal |
| 1299 | 1303 |
| 1300 #endif // V8_TARGET_ARCH_X64 | 1304 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |