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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 440 } |
441 | 441 |
442 | 442 |
443 // Generates call to API function. | 443 // Generates call to API function. |
444 static void GenerateFastApiCall(MacroAssembler* masm, | 444 static void GenerateFastApiCall(MacroAssembler* masm, |
445 const CallOptimization& optimization, | 445 const CallOptimization& optimization, |
446 int argc, | 446 int argc, |
447 bool restore_context) { | 447 bool restore_context) { |
448 // ----------- S t a t e ------------- | 448 // ----------- S t a t e ------------- |
449 // -- rsp[0] : return address | 449 // -- rsp[0] : return address |
450 // -- rsp[8] - rsp[56] : FunctionCallbackInfo, incl. | 450 // -- rsp[8] - rsp[58] : FunctionCallbackInfo, incl. |
451 // : object passing the type check | 451 // : object passing the type check |
452 // (set by CheckPrototypes) | 452 // (set by CheckPrototypes) |
453 // -- rsp[64] : last argument | 453 // -- rsp[64] : last argument |
454 // -- ... | 454 // -- ... |
455 // -- rsp[(argc + 7) * 8] : first argument | 455 // -- rsp[(argc + 7) * 8] : first argument |
456 // -- rsp[(argc + 8) * 8] : receiver | 456 // -- rsp[(argc + 8) * 8] : receiver |
457 // ----------------------------------- | 457 // ----------------------------------- |
458 typedef FunctionCallbackArguments FCA; | 458 typedef FunctionCallbackArguments FCA; |
459 StackArgumentsAccessor args(rsp, argc + kFastApiCallArguments); | 459 StackArgumentsAccessor args(rsp, argc + kFastApiCallArguments); |
460 | 460 |
461 // Save calling context. | 461 // Save calling context. |
462 int offset = argc + kFastApiCallArguments; | 462 __ movq(args.GetArgumentOperand(argc + 1 - FCA::kContextSaveIndex), rsi); |
463 __ movq(args.GetArgumentOperand(offset - FCA::kContextSaveIndex), rsi); | |
464 | 463 |
465 // Get the function and setup the context. | 464 // Get the function and setup the context. |
466 Handle<JSFunction> function = optimization.constant_function(); | 465 Handle<JSFunction> function = optimization.constant_function(); |
467 __ LoadHeapObject(rdi, function); | 466 __ LoadHeapObject(rdi, function); |
468 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 467 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
469 // Construct the FunctionCallbackInfo on the stack. | 468 // Construct the FunctionCallbackInfo on the stack. |
470 __ movq(args.GetArgumentOperand(offset - FCA::kCalleeIndex), rdi); | 469 __ movq(args.GetArgumentOperand(argc + 1 - FCA::kCalleeIndex), rdi); |
471 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); | 470 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
472 Handle<Object> call_data(api_call_info->data(), masm->isolate()); | 471 Handle<Object> call_data(api_call_info->data(), masm->isolate()); |
473 if (masm->isolate()->heap()->InNewSpace(*call_data)) { | 472 if (masm->isolate()->heap()->InNewSpace(*call_data)) { |
474 __ Move(rcx, api_call_info); | 473 __ Move(rcx, api_call_info); |
475 __ movq(rbx, FieldOperand(rcx, CallHandlerInfo::kDataOffset)); | 474 __ movq(rbx, FieldOperand(rcx, CallHandlerInfo::kDataOffset)); |
476 __ movq(args.GetArgumentOperand(offset - FCA::kDataIndex), rbx); | 475 __ movq(args.GetArgumentOperand(argc + 1 - FCA::kDataIndex), rbx); |
477 } else { | 476 } else { |
478 __ Move(args.GetArgumentOperand(offset - FCA::kDataIndex), call_data); | 477 __ Move(args.GetArgumentOperand(argc + 1 - FCA::kDataIndex), call_data); |
479 } | 478 } |
480 __ movq(kScratchRegister, | 479 __ movq(kScratchRegister, |
481 ExternalReference::isolate_address(masm->isolate())); | 480 ExternalReference::isolate_address(masm->isolate())); |
482 __ movq(args.GetArgumentOperand(offset - FCA::kIsolateIndex), | 481 __ movq(args.GetArgumentOperand(argc + 1 - FCA::kIsolateIndex), |
483 kScratchRegister); | 482 kScratchRegister); |
484 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); | 483 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); |
485 __ movq(args.GetArgumentOperand(offset - FCA::kReturnValueDefaultValueIndex), | 484 __ movq( |
486 kScratchRegister); | 485 args.GetArgumentOperand(argc + 1 - FCA::kReturnValueDefaultValueIndex), |
487 __ movq(args.GetArgumentOperand(offset - FCA::kReturnValueOffset), | 486 kScratchRegister); |
| 487 __ movq(args.GetArgumentOperand(argc + 1 - FCA::kReturnValueOffset), |
488 kScratchRegister); | 488 kScratchRegister); |
489 | 489 |
490 // Prepare arguments. | 490 // Prepare arguments. |
491 STATIC_ASSERT(kFastApiCallArguments == 7); | 491 STATIC_ASSERT(kFastApiCallArguments == 7); |
492 __ lea(rbx, Operand(rsp, 1 * kPointerSize)); | 492 __ lea(rbx, Operand(rsp, kFastApiCallArguments * kPointerSize)); |
493 | 493 |
494 // Function address is a foreign pointer outside V8's heap. | 494 // Function address is a foreign pointer outside V8's heap. |
495 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | 495 Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
496 | 496 |
497 // Allocate the v8::Arguments structure in the arguments' space since | 497 // Allocate the v8::Arguments structure in the arguments' space since |
498 // it's not controlled by GC. | 498 // it's not controlled by GC. |
499 const int kApiStackSpace = 4; | 499 const int kApiStackSpace = 4; |
500 | 500 |
501 __ PrepareCallApiFunction(kApiStackSpace); | 501 __ PrepareCallApiFunction(kApiStackSpace); |
502 | 502 |
503 __ movq(StackSpaceOperand(0), rbx); // FunctionCallbackInfo::implicit_args_. | 503 __ movq(StackSpaceOperand(0), rbx); // v8::Arguments::implicit_args_. |
504 __ addq(rbx, Immediate((argc + kFastApiCallArguments - 1) * kPointerSize)); | 504 __ addq(rbx, Immediate(argc * kPointerSize)); |
505 __ movq(StackSpaceOperand(1), rbx); // FunctionCallbackInfo::values_. | 505 __ movq(StackSpaceOperand(1), rbx); // v8::Arguments::values_. |
506 __ Set(StackSpaceOperand(2), argc); // FunctionCallbackInfo::length_. | 506 __ Set(StackSpaceOperand(2), argc); // v8::Arguments::length_. |
507 // FunctionCallbackInfo::is_construct_call_. | 507 // v8::Arguments::is_construct_call_. |
508 __ Set(StackSpaceOperand(3), 0); | 508 __ Set(StackSpaceOperand(3), 0); |
509 | 509 |
510 #if defined(__MINGW64__) || defined(_WIN64) | 510 #if defined(__MINGW64__) || defined(_WIN64) |
511 Register arguments_arg = rcx; | 511 Register arguments_arg = rcx; |
512 Register callback_arg = rdx; | 512 Register callback_arg = rdx; |
513 #else | 513 #else |
514 Register arguments_arg = rdi; | 514 Register arguments_arg = rdi; |
515 Register callback_arg = rsi; | 515 Register callback_arg = rsi; |
516 #endif | 516 #endif |
517 | 517 |
518 // v8::InvocationCallback's argument. | 518 // v8::InvocationCallback's argument. |
519 __ lea(arguments_arg, StackSpaceOperand(0)); | 519 __ lea(arguments_arg, StackSpaceOperand(0)); |
520 | 520 |
521 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); | 521 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); |
522 | 522 |
523 Operand context_restore_operand(rbp, | 523 Operand context_restore_operand( |
524 (2 + FCA::kContextSaveIndex) * kPointerSize); | 524 rbp, (kFastApiCallArguments + 1 + FCA::kContextSaveIndex) * kPointerSize); |
525 Operand return_value_operand(rbp, | 525 Operand return_value_operand( |
526 (2 + FCA::kReturnValueOffset) * kPointerSize); | 526 rbp, |
| 527 (kFastApiCallArguments + 1 + FCA::kReturnValueOffset) * kPointerSize); |
527 __ CallApiFunctionAndReturn( | 528 __ CallApiFunctionAndReturn( |
528 function_address, | 529 function_address, |
529 thunk_address, | 530 thunk_address, |
530 callback_arg, | 531 callback_arg, |
531 argc + kFastApiCallArguments + 1, | 532 argc + kFastApiCallArguments + 1, |
532 return_value_operand, | 533 return_value_operand, |
533 restore_context ? &context_restore_operand : NULL); | 534 restore_context ? &context_restore_operand : NULL); |
534 } | 535 } |
535 | 536 |
536 | 537 |
537 // Generate call to api function. | 538 // Generate call to api function. |
538 static void GenerateFastApiCall(MacroAssembler* masm, | 539 static void GenerateFastApiCall(MacroAssembler* masm, |
539 const CallOptimization& optimization, | 540 const CallOptimization& optimization, |
540 Register receiver, | 541 Register receiver, |
541 Register scratch, | 542 Register scratch, |
542 int argc, | 543 int argc, |
543 Register* values) { | 544 Register* values) { |
544 ASSERT(optimization.is_simple_api_call()); | 545 ASSERT(optimization.is_simple_api_call()); |
545 ASSERT(!receiver.is(scratch)); | 546 ASSERT(!receiver.is(scratch)); |
546 | 547 |
547 const int stack_space = kFastApiCallArguments + argc + 1; | 548 const int stack_space = kFastApiCallArguments + argc + 1; |
548 const int kHolderIndex = FunctionCallbackArguments::kHolderIndex + 1; | 549 const int kHolderIndex = kFastApiCallArguments + |
| 550 FunctionCallbackArguments::kHolderIndex; |
549 // Copy return value. | 551 // Copy return value. |
550 __ movq(scratch, Operand(rsp, 0)); | 552 __ movq(scratch, Operand(rsp, 0)); |
551 // Assign stack space for the call arguments. | 553 // Assign stack space for the call arguments. |
552 __ subq(rsp, Immediate(stack_space * kPointerSize)); | 554 __ subq(rsp, Immediate(stack_space * kPointerSize)); |
553 // Move the return address on top of the stack. | 555 // Move the return address on top of the stack. |
554 __ movq(Operand(rsp, 0), scratch); | 556 __ movq(Operand(rsp, 0), scratch); |
555 // Write holder to stack frame. | 557 // Write holder to stack frame. |
556 __ movq(Operand(rsp, kHolderIndex * kPointerSize), receiver); | 558 __ movq(Operand(rsp, kHolderIndex * kPointerSize), receiver); |
557 // Write receiver to stack frame. | 559 // Write receiver to stack frame. |
558 int index = stack_space; | 560 int index = stack_space; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 Register StubCompiler::CheckPrototypes(Handle<JSObject> object, | 1089 Register StubCompiler::CheckPrototypes(Handle<JSObject> object, |
1088 Register object_reg, | 1090 Register object_reg, |
1089 Handle<JSObject> holder, | 1091 Handle<JSObject> holder, |
1090 Register holder_reg, | 1092 Register holder_reg, |
1091 Register scratch1, | 1093 Register scratch1, |
1092 Register scratch2, | 1094 Register scratch2, |
1093 Handle<Name> name, | 1095 Handle<Name> name, |
1094 int save_at_depth, | 1096 int save_at_depth, |
1095 Label* miss, | 1097 Label* miss, |
1096 PrototypeCheckType check) { | 1098 PrototypeCheckType check) { |
1097 const int kHolderIndex = FunctionCallbackArguments::kHolderIndex + 1; | 1099 const int kHolderIndex = kFastApiCallArguments + |
| 1100 FunctionCallbackArguments::kHolderIndex; |
1098 // Make sure that the type feedback oracle harvests the receiver map. | 1101 // Make sure that the type feedback oracle harvests the receiver map. |
1099 // TODO(svenpanne) Remove this hack when all ICs are reworked. | 1102 // TODO(svenpanne) Remove this hack when all ICs are reworked. |
1100 __ Move(scratch1, Handle<Map>(object->map())); | 1103 __ Move(scratch1, Handle<Map>(object->map())); |
1101 | 1104 |
1102 Handle<JSObject> first = object; | 1105 Handle<JSObject> first = object; |
1103 // Make sure there's no overlap between holder and object registers. | 1106 // Make sure there's no overlap between holder and object registers. |
1104 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); | 1107 ASSERT(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); |
1105 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg) | 1108 ASSERT(!scratch2.is(object_reg) && !scratch2.is(holder_reg) |
1106 && !scratch2.is(scratch1)); | 1109 && !scratch2.is(scratch1)); |
1107 | 1110 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 } | 1326 } |
1324 | 1327 |
1325 | 1328 |
1326 void BaseLoadStubCompiler::GenerateLoadCallback( | 1329 void BaseLoadStubCompiler::GenerateLoadCallback( |
1327 Register reg, | 1330 Register reg, |
1328 Handle<ExecutableAccessorInfo> callback) { | 1331 Handle<ExecutableAccessorInfo> callback) { |
1329 // Insert additional parameters into the stack frame above return address. | 1332 // Insert additional parameters into the stack frame above return address. |
1330 ASSERT(!scratch4().is(reg)); | 1333 ASSERT(!scratch4().is(reg)); |
1331 __ PopReturnAddressTo(scratch4()); | 1334 __ PopReturnAddressTo(scratch4()); |
1332 | 1335 |
1333 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0); | 1336 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 0); |
1334 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1); | 1337 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == -1); |
1335 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2); | 1338 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == -2); |
1336 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3); | 1339 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == -3); |
1337 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4); | 1340 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == -4); |
1338 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5); | 1341 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == -5); |
1339 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6); | |
1340 __ push(receiver()); // receiver | 1342 __ push(receiver()); // receiver |
1341 if (heap()->InNewSpace(callback->data())) { | 1343 if (heap()->InNewSpace(callback->data())) { |
1342 ASSERT(!scratch2().is(reg)); | 1344 ASSERT(!scratch2().is(reg)); |
1343 __ Move(scratch2(), callback); | 1345 __ Move(scratch2(), callback); |
1344 __ push(FieldOperand(scratch2(), | 1346 __ push(FieldOperand(scratch2(), |
1345 ExecutableAccessorInfo::kDataOffset)); // data | 1347 ExecutableAccessorInfo::kDataOffset)); // data |
1346 } else { | 1348 } else { |
1347 __ Push(Handle<Object>(callback->data(), isolate())); | 1349 __ Push(Handle<Object>(callback->data(), isolate())); |
1348 } | 1350 } |
1349 ASSERT(!kScratchRegister.is(reg)); | 1351 ASSERT(!kScratchRegister.is(reg)); |
1350 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); | 1352 __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex); |
1351 __ push(kScratchRegister); // return value | 1353 __ push(kScratchRegister); // return value |
1352 __ push(kScratchRegister); // return value default | 1354 __ push(kScratchRegister); // return value default |
1353 __ PushAddress(ExternalReference::isolate_address(isolate())); | 1355 __ PushAddress(ExternalReference::isolate_address(isolate())); |
1354 __ push(reg); // holder | 1356 __ push(reg); // holder |
1355 __ push(name()); // name | 1357 __ push(name()); // name |
1356 // Save a pointer to where we pushed the arguments pointer. This will be | 1358 // Save a pointer to where we pushed the arguments pointer. This will be |
1357 // passed as the const PropertyAccessorInfo& to the C++ callback. | 1359 // passed as the const ExecutableAccessorInfo& to the C++ callback. |
1358 | 1360 |
1359 Address getter_address = v8::ToCData<Address>(callback->getter()); | 1361 Address getter_address = v8::ToCData<Address>(callback->getter()); |
1360 | 1362 |
1361 #if defined(__MINGW64__) || defined(_WIN64) | 1363 #if defined(__MINGW64__) || defined(_WIN64) |
1362 Register getter_arg = r8; | 1364 Register getter_arg = r8; |
1363 Register accessor_info_arg = rdx; | 1365 Register accessor_info_arg = rdx; |
1364 Register name_arg = rcx; | 1366 Register name_arg = rcx; |
1365 #else | 1367 #else |
1366 Register getter_arg = rdx; | 1368 Register getter_arg = rdx; |
1367 Register accessor_info_arg = rsi; | 1369 Register accessor_info_arg = rsi; |
1368 Register name_arg = rdi; | 1370 Register name_arg = rdi; |
1369 #endif | 1371 #endif |
1370 | 1372 |
1371 ASSERT(!name_arg.is(scratch4())); | 1373 ASSERT(!name_arg.is(scratch4())); |
1372 __ movq(name_arg, rsp); | 1374 __ movq(name_arg, rsp); |
1373 __ PushReturnAddressFrom(scratch4()); | 1375 __ PushReturnAddressFrom(scratch4()); |
1374 | 1376 |
1375 // v8::Arguments::values_ and handler for name. | 1377 // v8::Arguments::values_ and handler for name. |
1376 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1; | 1378 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1; |
1377 | 1379 |
1378 // Allocate v8::AccessorInfo in non-GCed stack space. | 1380 // Allocate v8::AccessorInfo in non-GCed stack space. |
1379 const int kArgStackSpace = 1; | 1381 const int kArgStackSpace = 1; |
1380 | 1382 |
1381 __ PrepareCallApiFunction(kArgStackSpace); | 1383 __ PrepareCallApiFunction(kArgStackSpace); |
1382 __ lea(rax, Operand(name_arg, 1 * kPointerSize)); | 1384 STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6); |
| 1385 __ lea(rax, Operand(name_arg, 6 * kPointerSize)); |
1383 | 1386 |
1384 // v8::PropertyAccessorInfo::args_. | 1387 // v8::AccessorInfo::args_. |
1385 __ movq(StackSpaceOperand(0), rax); | 1388 __ movq(StackSpaceOperand(0), rax); |
1386 | 1389 |
1387 // The context register (rsi) has been saved in PrepareCallApiFunction and | 1390 // The context register (rsi) has been saved in PrepareCallApiFunction and |
1388 // could be used to pass arguments. | 1391 // could be used to pass arguments. |
1389 __ lea(accessor_info_arg, StackSpaceOperand(0)); | 1392 __ lea(accessor_info_arg, StackSpaceOperand(0)); |
1390 | 1393 |
1391 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); | 1394 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); |
1392 | 1395 |
1393 __ CallApiFunctionAndReturn(getter_address, | 1396 __ CallApiFunctionAndReturn(getter_address, |
1394 thunk_address, | 1397 thunk_address, |
(...skipping 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3167 // ----------------------------------- | 3170 // ----------------------------------- |
3168 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric); | 3171 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric); |
3169 } | 3172 } |
3170 | 3173 |
3171 | 3174 |
3172 #undef __ | 3175 #undef __ |
3173 | 3176 |
3174 } } // namespace v8::internal | 3177 } } // namespace v8::internal |
3175 | 3178 |
3176 #endif // V8_TARGET_ARCH_X64 | 3179 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |