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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 masm->isolate()); | 391 masm->isolate()); |
392 __ Set(rax, 6); | 392 __ Set(rax, 6); |
393 __ LoadAddress(rbx, ref); | 393 __ LoadAddress(rbx, ref); |
394 | 394 |
395 CEntryStub stub(1); | 395 CEntryStub stub(1); |
396 __ CallStub(&stub); | 396 __ CallStub(&stub); |
397 } | 397 } |
398 | 398 |
399 | 399 |
400 // Number of pointers to be reserved on stack for fast API call. | 400 // Number of pointers to be reserved on stack for fast API call. |
401 static const int kFastApiCallArguments = 4; | 401 static const int kFastApiCallArguments = FunctionCallbackArguments::kArgsLength; |
402 | 402 |
403 | 403 |
404 // Reserves space for the extra arguments to API function in the | 404 // Reserves space for the extra arguments to API function in the |
405 // caller's frame. | 405 // caller's frame. |
406 // | 406 // |
407 // These arguments are set by CheckPrototypes and GenerateFastApiCall. | 407 // These arguments are set by CheckPrototypes and GenerateFastApiCall. |
408 static void ReserveSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { | 408 static void ReserveSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { |
409 // ----------- S t a t e ------------- | 409 // ----------- S t a t e ------------- |
410 // -- rsp[0] : return address | 410 // -- rsp[0] : return address |
411 // -- rsp[8] : last argument in the internal frame of the caller | 411 // -- rsp[8] : last argument in the internal frame of the caller |
(...skipping 30 matching lines...) Expand all Loading... |
442 int argc) { | 442 int argc) { |
443 // ----------- S t a t e ------------- | 443 // ----------- S t a t e ------------- |
444 // -- rsp[0] : return address | 444 // -- rsp[0] : return address |
445 // -- rsp[8] : object passing the type check | 445 // -- rsp[8] : object passing the type check |
446 // (last fast api call extra argument, | 446 // (last fast api call extra argument, |
447 // set by CheckPrototypes) | 447 // set by CheckPrototypes) |
448 // -- rsp[16] : api function | 448 // -- rsp[16] : api function |
449 // (first fast api call extra argument) | 449 // (first fast api call extra argument) |
450 // -- rsp[24] : api call data | 450 // -- rsp[24] : api call data |
451 // -- rsp[32] : isolate | 451 // -- rsp[32] : isolate |
452 // -- rsp[40] : last argument | 452 // -- rsp[40] : ReturnValue |
| 453 // |
| 454 // -- rsp[48] : last argument |
453 // -- ... | 455 // -- ... |
454 // -- rsp[(argc + 4) * 8] : first argument | 456 // -- rsp[(argc + 5) * 8] : first argument |
455 // -- rsp[(argc + 5) * 8] : receiver | 457 // -- rsp[(argc + 6) * 8] : receiver |
456 // ----------------------------------- | 458 // ----------------------------------- |
457 // Get the function and setup the context. | 459 // Get the function and setup the context. |
458 Handle<JSFunction> function = optimization.constant_function(); | 460 Handle<JSFunction> function = optimization.constant_function(); |
459 __ LoadHeapObject(rdi, function); | 461 __ LoadHeapObject(rdi, function); |
460 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 462 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
461 | 463 |
462 // Pass the additional arguments. | 464 // Pass the additional arguments. |
463 __ movq(Operand(rsp, 2 * kPointerSize), rdi); | 465 __ movq(Operand(rsp, 2 * kPointerSize), rdi); |
464 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); | 466 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
465 Handle<Object> call_data(api_call_info->data(), masm->isolate()); | 467 Handle<Object> call_data(api_call_info->data(), masm->isolate()); |
466 if (masm->isolate()->heap()->InNewSpace(*call_data)) { | 468 if (masm->isolate()->heap()->InNewSpace(*call_data)) { |
467 __ Move(rcx, api_call_info); | 469 __ Move(rcx, api_call_info); |
468 __ movq(rbx, FieldOperand(rcx, CallHandlerInfo::kDataOffset)); | 470 __ movq(rbx, FieldOperand(rcx, CallHandlerInfo::kDataOffset)); |
469 __ movq(Operand(rsp, 3 * kPointerSize), rbx); | 471 __ movq(Operand(rsp, 3 * kPointerSize), rbx); |
470 } else { | 472 } else { |
471 __ Move(Operand(rsp, 3 * kPointerSize), call_data); | 473 __ Move(Operand(rsp, 3 * kPointerSize), call_data); |
472 } | 474 } |
473 __ movq(kScratchRegister, | 475 __ movq(kScratchRegister, |
474 ExternalReference::isolate_address(masm->isolate())); | 476 ExternalReference::isolate_address(masm->isolate())); |
475 __ movq(Operand(rsp, 4 * kPointerSize), kScratchRegister); | 477 __ movq(Operand(rsp, 4 * kPointerSize), kScratchRegister); |
| 478 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); |
| 479 __ movq(Operand(rsp, 5 * kPointerSize), kScratchRegister); |
476 | 480 |
477 // Prepare arguments. | 481 // Prepare arguments. |
478 __ lea(rbx, Operand(rsp, 4 * kPointerSize)); | 482 STATIC_ASSERT(kFastApiCallArguments == 5); |
| 483 __ lea(rbx, Operand(rsp, kFastApiCallArguments * kPointerSize)); |
479 | 484 |
480 #if defined(__MINGW64__) | 485 #if defined(__MINGW64__) |
481 Register arguments_arg = rcx; | 486 Register arguments_arg = rcx; |
482 #elif defined(_WIN64) | 487 #elif defined(_WIN64) |
483 // Win64 uses first register--rcx--for returned value. | 488 // Win64 uses first register--rcx--for returned value. |
484 Register arguments_arg = rdx; | 489 Register arguments_arg = rdx; |
485 #else | 490 #else |
486 Register arguments_arg = rdi; | 491 Register arguments_arg = rdi; |
487 #endif | 492 #endif |
488 | 493 |
489 // Allocate the v8::Arguments structure in the arguments' space since | 494 // Allocate the v8::Arguments structure in the arguments' space since |
490 // it's not controlled by GC. | 495 // it's not controlled by GC. |
491 const int kApiStackSpace = 4; | 496 const int kApiStackSpace = 4; |
492 | 497 |
493 __ PrepareCallApiFunction(kApiStackSpace); | 498 __ PrepareCallApiFunction(kApiStackSpace); |
494 | 499 |
495 __ movq(StackSpaceOperand(0), rbx); // v8::Arguments::implicit_args_. | 500 __ movq(StackSpaceOperand(0), rbx); // v8::Arguments::implicit_args_. |
496 __ addq(rbx, Immediate(argc * kPointerSize)); | 501 __ addq(rbx, Immediate(argc * kPointerSize)); |
497 __ movq(StackSpaceOperand(1), rbx); // v8::Arguments::values_. | 502 __ movq(StackSpaceOperand(1), rbx); // v8::Arguments::values_. |
498 __ Set(StackSpaceOperand(2), argc); // v8::Arguments::length_. | 503 __ Set(StackSpaceOperand(2), argc); // v8::Arguments::length_. |
499 // v8::Arguments::is_construct_call_. | 504 // v8::Arguments::is_construct_call_. |
500 __ Set(StackSpaceOperand(3), 0); | 505 __ Set(StackSpaceOperand(3), 0); |
501 | 506 |
502 // v8::InvocationCallback's argument. | 507 // v8::InvocationCallback's argument. |
503 __ lea(arguments_arg, StackSpaceOperand(0)); | 508 __ lea(arguments_arg, StackSpaceOperand(0)); |
504 | 509 |
505 // Function address is a foreign pointer outside V8's heap. | 510 // Function address is a foreign pointer outside V8's heap. |
506 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | 511 Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
507 __ CallApiFunctionAndReturn(function_address, | 512 __ CallApiFunctionAndReturn(function_address, |
508 argc + kFastApiCallArguments + 1); | 513 argc + kFastApiCallArguments + 1, |
| 514 FunctionCallbackArguments::kReturnValueOffset); |
509 } | 515 } |
510 | 516 |
511 | 517 |
512 class CallInterceptorCompiler BASE_EMBEDDED { | 518 class CallInterceptorCompiler BASE_EMBEDDED { |
513 public: | 519 public: |
514 CallInterceptorCompiler(StubCompiler* stub_compiler, | 520 CallInterceptorCompiler(StubCompiler* stub_compiler, |
515 const ParameterCount& arguments, | 521 const ParameterCount& arguments, |
516 Register name, | 522 Register name, |
517 Code::ExtraICState extra_ic_state) | 523 Code::ExtraICState extra_ic_state) |
518 : stub_compiler_(stub_compiler), | 524 : stub_compiler_(stub_compiler), |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 | 1287 |
1282 __ push(receiver()); // receiver | 1288 __ push(receiver()); // receiver |
1283 __ push(reg); // holder | 1289 __ push(reg); // holder |
1284 if (heap()->InNewSpace(callback->data())) { | 1290 if (heap()->InNewSpace(callback->data())) { |
1285 __ Move(scratch1(), callback); | 1291 __ Move(scratch1(), callback); |
1286 __ push(FieldOperand(scratch1(), | 1292 __ push(FieldOperand(scratch1(), |
1287 ExecutableAccessorInfo::kDataOffset)); // data | 1293 ExecutableAccessorInfo::kDataOffset)); // data |
1288 } else { | 1294 } else { |
1289 __ Push(Handle<Object>(callback->data(), isolate())); | 1295 __ Push(Handle<Object>(callback->data(), isolate())); |
1290 } | 1296 } |
1291 __ PushAddress(ExternalReference::isolate_address(isolate())); // isolate | 1297 __ PushAddress(ExternalReference::isolate_address(isolate())); |
| 1298 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); |
| 1299 __ push(kScratchRegister); // return value |
1292 __ push(name()); // name | 1300 __ push(name()); // name |
1293 // Save a pointer to where we pushed the arguments pointer. This will be | 1301 // Save a pointer to where we pushed the arguments pointer. This will be |
1294 // passed as the const ExecutableAccessorInfo& to the C++ callback. | 1302 // passed as the const ExecutableAccessorInfo& to the C++ callback. |
1295 | 1303 |
1296 #if defined(__MINGW64__) | 1304 #if defined(__MINGW64__) |
1297 Register accessor_info_arg = rdx; | 1305 Register accessor_info_arg = rdx; |
1298 Register name_arg = rcx; | 1306 Register name_arg = rcx; |
1299 #elif defined(_WIN64) | 1307 #elif defined(_WIN64) |
1300 // Win64 uses first register--rcx--for returned value. | 1308 // Win64 uses first register--rcx--for returned value. |
1301 Register accessor_info_arg = r8; | 1309 Register accessor_info_arg = r8; |
1302 Register name_arg = rdx; | 1310 Register name_arg = rdx; |
1303 #else | 1311 #else |
1304 Register accessor_info_arg = rsi; | 1312 Register accessor_info_arg = rsi; |
1305 Register name_arg = rdi; | 1313 Register name_arg = rdi; |
1306 #endif | 1314 #endif |
1307 | 1315 |
1308 ASSERT(!name_arg.is(scratch2())); | 1316 ASSERT(!name_arg.is(scratch2())); |
1309 __ movq(name_arg, rsp); | 1317 __ movq(name_arg, rsp); |
1310 __ push(scratch2()); // Restore return address. | 1318 __ push(scratch2()); // Restore return address. |
1311 | 1319 |
1312 // 4 elements array for v8::Arguments::values_ and handler for name. | 1320 // v8::Arguments::values_ and handler for name. |
1313 const int kStackSpace = 5; | 1321 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1; |
1314 | 1322 |
1315 // Allocate v8::AccessorInfo in non-GCed stack space. | 1323 // Allocate v8::AccessorInfo in non-GCed stack space. |
1316 const int kArgStackSpace = 1; | 1324 const int kArgStackSpace = 1; |
1317 | 1325 |
1318 __ PrepareCallApiFunction(kArgStackSpace); | 1326 __ PrepareCallApiFunction(kArgStackSpace); |
1319 __ lea(rax, Operand(name_arg, 4 * kPointerSize)); | 1327 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 5); |
| 1328 __ lea(rax, Operand(name_arg, 5 * kPointerSize)); |
1320 | 1329 |
1321 // v8::AccessorInfo::args_. | 1330 // v8::AccessorInfo::args_. |
1322 __ movq(StackSpaceOperand(0), rax); | 1331 __ movq(StackSpaceOperand(0), rax); |
1323 | 1332 |
1324 // The context register (rsi) has been saved in PrepareCallApiFunction and | 1333 // The context register (rsi) has been saved in PrepareCallApiFunction and |
1325 // could be used to pass arguments. | 1334 // could be used to pass arguments. |
1326 __ lea(accessor_info_arg, StackSpaceOperand(0)); | 1335 __ lea(accessor_info_arg, StackSpaceOperand(0)); |
1327 | 1336 |
1328 Address getter_address = v8::ToCData<Address>(callback->getter()); | 1337 Address getter_address = v8::ToCData<Address>(callback->getter()); |
1329 __ CallApiFunctionAndReturn(getter_address, kStackSpace); | 1338 __ CallApiFunctionAndReturn(getter_address, |
| 1339 kStackSpace, |
| 1340 PropertyCallbackArguments::kReturnValueOffset); |
1330 } | 1341 } |
1331 | 1342 |
1332 | 1343 |
1333 void BaseLoadStubCompiler::GenerateLoadConstant(Handle<JSFunction> value) { | 1344 void BaseLoadStubCompiler::GenerateLoadConstant(Handle<JSFunction> value) { |
1334 // Return the constant value. | 1345 // Return the constant value. |
1335 __ LoadHeapObject(rax, value); | 1346 __ LoadHeapObject(rax, value); |
1336 __ ret(0); | 1347 __ ret(0); |
1337 } | 1348 } |
1338 | 1349 |
1339 | 1350 |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2265 | 2276 |
2266 // Allocate space for v8::Arguments implicit values. Must be initialized | 2277 // Allocate space for v8::Arguments implicit values. Must be initialized |
2267 // before calling any runtime function. | 2278 // before calling any runtime function. |
2268 __ subq(rsp, Immediate(kFastApiCallArguments * kPointerSize)); | 2279 __ subq(rsp, Immediate(kFastApiCallArguments * kPointerSize)); |
2269 | 2280 |
2270 // Check that the maps haven't changed and find a Holder as a side effect. | 2281 // Check that the maps haven't changed and find a Holder as a side effect. |
2271 CheckPrototypes(Handle<JSObject>::cast(object), rdx, holder, rbx, rax, rdi, | 2282 CheckPrototypes(Handle<JSObject>::cast(object), rdx, holder, rbx, rax, rdi, |
2272 name, depth, &miss); | 2283 name, depth, &miss); |
2273 | 2284 |
2274 // Move the return address on top of the stack. | 2285 // Move the return address on top of the stack. |
2275 __ movq(rax, Operand(rsp, 4 * kPointerSize)); | 2286 __ movq(rax, Operand(rsp, kFastApiCallArguments * kPointerSize)); |
2276 __ movq(Operand(rsp, 0 * kPointerSize), rax); | 2287 __ movq(Operand(rsp, 0 * kPointerSize), rax); |
2277 | 2288 |
2278 GenerateFastApiCall(masm(), optimization, argc); | 2289 GenerateFastApiCall(masm(), optimization, argc); |
2279 | 2290 |
2280 __ bind(&miss); | 2291 __ bind(&miss); |
2281 __ addq(rsp, Immediate(kFastApiCallArguments * kPointerSize)); | 2292 __ addq(rsp, Immediate(kFastApiCallArguments * kPointerSize)); |
2282 | 2293 |
2283 __ bind(&miss_before_stack_reserved); | 2294 __ bind(&miss_before_stack_reserved); |
2284 GenerateMissBranch(); | 2295 GenerateMissBranch(); |
2285 | 2296 |
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3593 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow); | 3604 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow); |
3594 } | 3605 } |
3595 } | 3606 } |
3596 | 3607 |
3597 | 3608 |
3598 #undef __ | 3609 #undef __ |
3599 | 3610 |
3600 } } // namespace v8::internal | 3611 } } // namespace v8::internal |
3601 | 3612 |
3602 #endif // V8_TARGET_ARCH_X64 | 3613 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |