Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: src/ia32/stub-cache-ia32.cc

Issue 140613004: stub fast api calls (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/macro-assembler-ia32.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 Register name, 407 Register name,
408 Handle<JSObject> holder_obj, 408 Handle<JSObject> holder_obj,
409 IC::UtilityId id) { 409 IC::UtilityId id) {
410 PushInterceptorArguments(masm, receiver, holder, name, holder_obj); 410 PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
411 __ CallExternalReference( 411 __ CallExternalReference(
412 ExternalReference(IC_Utility(id), masm->isolate()), 412 ExternalReference(IC_Utility(id), masm->isolate()),
413 StubCache::kInterceptorArgsLength); 413 StubCache::kInterceptorArgsLength);
414 } 414 }
415 415
416 416
417 // Number of pointers to be reserved on stack for fast API call.
418 static const int kFastApiCallArguments = FunctionCallbackArguments::kArgsLength;
419
420
421 static void GenerateFastApiCallBody(MacroAssembler* masm, 417 static void GenerateFastApiCallBody(MacroAssembler* masm,
422 const CallOptimization& optimization, 418 const CallOptimization& optimization,
423 int argc, 419 int argc,
424 Register holder, 420 Register holder_in,
425 Register scratch1, 421 bool restore_context) {
426 Register scratch2, 422 ASSERT(optimization.is_simple_api_call());
427 Register scratch3, 423
428 bool restore_context); 424 // Abi for CallApiFunctionStub.
425 Register callee = eax;
426 Register call_data = ebx;
427 Register holder = ecx;
428 Register api_function_address = edx;
429
430 // Put holder in place.
431 __ Move(holder, holder_in);
432
433 Register scratch = edi;
434
435 Isolate* isolate = masm->isolate();
436 Handle<JSFunction> function = optimization.constant_function();
437 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
438 Handle<Object> call_data_obj(api_call_info->data(), isolate);
439
440 // Put callee in place.
441 __ LoadHeapObject(callee, function);
442
443 bool call_data_undefined = false;
444 // Put call_data in place.
445 if (isolate->heap()->InNewSpace(*call_data_obj)) {
446 __ mov(scratch, api_call_info);
447 __ mov(call_data, FieldOperand(scratch, CallHandlerInfo::kDataOffset));
448 } else if (call_data_obj->IsUndefined()) {
449 call_data_undefined = true;
450 __ mov(call_data, Immediate(isolate->factory()->undefined_value()));
451 } else {
452 __ mov(call_data, call_data_obj);
453 }
454
455 // Put api_function_address in place.
456 Address function_address = v8::ToCData<Address>(api_call_info->callback());
457 __ mov(api_function_address, Immediate(function_address));
458
459 // Jump to stub.
460 CallApiFunctionStub stub(restore_context, call_data_undefined, argc);
461 __ TailCallStub(&stub);
462 }
463
429 464
430 // Generates call to API function. 465 // Generates call to API function.
431 static void GenerateFastApiCall(MacroAssembler* masm, 466 static void GenerateFastApiCall(MacroAssembler* masm,
432 const CallOptimization& optimization, 467 const CallOptimization& optimization,
433 int argc, 468 int argc,
434 Handle<Map> map_to_holder, 469 Handle<Map> map_to_holder,
435 CallOptimization::HolderLookup holder_lookup) { 470 CallOptimization::HolderLookup holder_lookup) {
436 Counters* counters = masm->isolate()->counters(); 471 Counters* counters = masm->isolate()->counters();
437 __ IncrementCounter(counters->call_const_fast_api(), 1); 472 __ IncrementCounter(counters->call_const_fast_api(), 1);
438 473
439 // Move holder to a register 474 // Move holder to a register
440 Register holder_reg = eax; 475 Register holder_reg = ecx;
441 switch (holder_lookup) { 476 switch (holder_lookup) {
442 case CallOptimization::kHolderIsReceiver: 477 case CallOptimization::kHolderIsReceiver:
443 { 478 {
444 ASSERT(map_to_holder.is_null()); 479 ASSERT(map_to_holder.is_null());
445 __ mov(holder_reg, Operand(esp, (argc + 1)* kPointerSize)); 480 __ mov(holder_reg, Operand(esp, (argc + 1)* kPointerSize));
446 } 481 }
447 break; 482 break;
448 case CallOptimization::kHolderIsPrototypeOfMap: 483 case CallOptimization::kHolderIsPrototypeOfMap:
449 { 484 {
450 Handle<JSObject> holder(JSObject::cast(map_to_holder->prototype())); 485 Handle<JSObject> holder(JSObject::cast(map_to_holder->prototype()));
451 if (!masm->isolate()->heap()->InNewSpace(*holder)) { 486 if (!masm->isolate()->heap()->InNewSpace(*holder)) {
452 __ mov(holder_reg, holder); 487 __ mov(holder_reg, holder);
453 } else { 488 } else {
454 __ mov(holder_reg, map_to_holder); 489 __ mov(holder_reg, map_to_holder);
455 __ mov(holder_reg, FieldOperand(holder_reg, Map::kPrototypeOffset)); 490 __ mov(holder_reg, FieldOperand(holder_reg, Map::kPrototypeOffset));
456 } 491 }
457 } 492 }
458 break; 493 break;
459 case CallOptimization::kHolderNotFound: 494 case CallOptimization::kHolderNotFound:
460 UNREACHABLE(); 495 UNREACHABLE();
461 } 496 }
462 GenerateFastApiCallBody(masm, 497 GenerateFastApiCallBody(masm,
463 optimization, 498 optimization,
464 argc, 499 argc,
465 holder_reg, 500 holder_reg,
466 ebx,
467 ecx,
468 edx,
469 false); 501 false);
470 } 502 }
471 503
472 504
473 // Generate call to api function. 505 // Generate call to api function.
474 // This function uses push() to generate smaller, faster code than 506 // This function uses push() to generate smaller, faster code than
475 // the version above. It is an optimization that should will be removed 507 // the version above. It is an optimization that should will be removed
476 // when api call ICs are generated in hydrogen. 508 // when api call ICs are generated in hydrogen.
477 static void GenerateFastApiCall(MacroAssembler* masm, 509 static void GenerateFastApiCall(MacroAssembler* masm,
478 const CallOptimization& optimization, 510 const CallOptimization& optimization,
479 Register receiver, 511 Register receiver,
480 Register scratch1, 512 Register scratch1,
481 Register scratch2,
482 Register scratch3,
483 int argc, 513 int argc,
484 Register* values) { 514 Register* values) {
485 // Copy return value. 515 // Copy return value.
486 __ pop(scratch1); 516 __ pop(scratch1);
487 // receiver 517 // receiver
488 __ push(receiver); 518 __ push(receiver);
489 // Write the arguments to stack frame. 519 // Write the arguments to stack frame.
490 for (int i = 0; i < argc; i++) { 520 for (int i = 0; i < argc; i++) {
491 Register arg = values[argc-1-i]; 521 Register arg = values[argc-1-i];
492 ASSERT(!receiver.is(arg)); 522 ASSERT(!receiver.is(arg));
493 ASSERT(!scratch1.is(arg)); 523 ASSERT(!scratch1.is(arg));
494 ASSERT(!scratch2.is(arg));
495 ASSERT(!scratch3.is(arg));
496 __ push(arg); 524 __ push(arg);
497 } 525 }
498 __ push(scratch1); 526 __ push(scratch1);
499 // Stack now matches JSFunction abi. 527 // Stack now matches JSFunction abi.
500 GenerateFastApiCallBody(masm, 528 GenerateFastApiCallBody(masm,
501 optimization, 529 optimization,
502 argc, 530 argc,
503 receiver, 531 receiver,
504 scratch1,
505 scratch2,
506 scratch3,
507 true); 532 true);
508 } 533 }
509 534
510 535
511 static void GenerateFastApiCallBody(MacroAssembler* masm,
512 const CallOptimization& optimization,
513 int argc,
514 Register holder,
515 Register scratch1,
516 Register scratch2,
517 Register scratch3,
518 bool restore_context) {
519 // ----------- S t a t e -------------
520 // -- esp[0] : return address
521 // -- esp[4] : last argument
522 // -- ...
523 // -- esp[argc * 4] : first argument
524 // -- esp[(argc + 1) * 4] : receiver
525 ASSERT(optimization.is_simple_api_call());
526
527 typedef FunctionCallbackArguments FCA;
528
529 STATIC_ASSERT(FCA::kHolderIndex == 0);
530 STATIC_ASSERT(FCA::kIsolateIndex == 1);
531 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
532 STATIC_ASSERT(FCA::kReturnValueOffset == 3);
533 STATIC_ASSERT(FCA::kDataIndex == 4);
534 STATIC_ASSERT(FCA::kCalleeIndex == 5);
535 STATIC_ASSERT(FCA::kContextSaveIndex == 6);
536 STATIC_ASSERT(FCA::kArgsLength == 7);
537
538 __ pop(scratch1);
539
540 ASSERT(!holder.is(esi));
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(holder);
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 // API function gets reference to the v8::Arguments. If CPU profiler
579 // is enabled wrapper function will be called and we need to pass
580 // address of the callback as additional parameter, always allocate
581 // space for it.
582 const int kApiArgc = 1 + 1;
583
584 // Allocate the v8::Arguments structure in the arguments' space since
585 // it's not controlled by GC.
586 const int kApiStackSpace = 4;
587
588 // Function address is a foreign pointer outside V8's heap.
589 Address function_address = v8::ToCData<Address>(api_call_info->callback());
590 __ PrepareCallApiFunction(kApiArgc + kApiStackSpace);
591
592 // FunctionCallbackInfo::implicit_args_.
593 __ mov(ApiParameterOperand(2), eax);
594 __ add(eax, Immediate((argc + kFastApiCallArguments - 1) * kPointerSize));
595 // FunctionCallbackInfo::values_.
596 __ mov(ApiParameterOperand(3), eax);
597 // FunctionCallbackInfo::length_.
598 __ Set(ApiParameterOperand(4), Immediate(argc));
599 // FunctionCallbackInfo::is_construct_call_.
600 __ Set(ApiParameterOperand(5), Immediate(0));
601
602 // v8::InvocationCallback's argument.
603 __ lea(eax, ApiParameterOperand(2));
604 __ mov(ApiParameterOperand(0), eax);
605
606 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
607
608 Operand context_restore_operand(ebp,
609 (2 + FCA::kContextSaveIndex) * kPointerSize);
610 Operand return_value_operand(ebp,
611 (2 + FCA::kReturnValueOffset) * kPointerSize);
612 __ CallApiFunctionAndReturn(function_address,
613 thunk_address,
614 ApiParameterOperand(1),
615 argc + kFastApiCallArguments + 1,
616 return_value_operand,
617 restore_context ?
618 &context_restore_operand : NULL);
619 }
620
621
622 class CallInterceptorCompiler BASE_EMBEDDED { 536 class CallInterceptorCompiler BASE_EMBEDDED {
623 public: 537 public:
624 CallInterceptorCompiler(CallStubCompiler* stub_compiler, 538 CallInterceptorCompiler(CallStubCompiler* stub_compiler,
625 const ParameterCount& arguments, 539 const ParameterCount& arguments,
626 Register name) 540 Register name)
627 : stub_compiler_(stub_compiler), 541 : stub_compiler_(stub_compiler),
628 arguments_(arguments), 542 arguments_(arguments),
629 name_(name) {} 543 name_(name) {}
630 544
631 void Compile(MacroAssembler* masm, 545 void Compile(MacroAssembler* masm,
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 field.translate(holder), 1268 field.translate(holder),
1355 representation); 1269 representation);
1356 GenerateTailCall(masm(), stub.GetCode(isolate())); 1270 GenerateTailCall(masm(), stub.GetCode(isolate()));
1357 } 1271 }
1358 } 1272 }
1359 1273
1360 1274
1361 void LoadStubCompiler::GenerateLoadCallback( 1275 void LoadStubCompiler::GenerateLoadCallback(
1362 const CallOptimization& call_optimization) { 1276 const CallOptimization& call_optimization) {
1363 GenerateFastApiCall( 1277 GenerateFastApiCall(
1364 masm(), call_optimization, receiver(), scratch1(), 1278 masm(), call_optimization, receiver(),
1365 scratch2(), name(), 0, NULL); 1279 scratch1(), 0, NULL);
1366 } 1280 }
1367 1281
1368 1282
1369 void LoadStubCompiler::GenerateLoadCallback( 1283 void LoadStubCompiler::GenerateLoadCallback(
1370 Register reg, 1284 Register reg,
1371 Handle<ExecutableAccessorInfo> callback) { 1285 Handle<ExecutableAccessorInfo> callback) {
1372 // Insert additional parameters into the stack frame above return address. 1286 // Insert additional parameters into the stack frame above return address.
1373 ASSERT(!scratch3().is(reg)); 1287 ASSERT(!scratch3().is(reg));
1374 __ pop(scratch3()); // Get return address to place it below. 1288 __ pop(scratch3()); // Get return address to place it below.
1375 1289
(...skipping 27 matching lines...) Expand all
1403 1317
1404 __ push(scratch3()); // Restore return address. 1318 __ push(scratch3()); // Restore return address.
1405 1319
1406 // array for v8::Arguments::values_, handler for name and pointer 1320 // array for v8::Arguments::values_, handler for name and pointer
1407 // to the values (it considered as smi in GC). 1321 // to the values (it considered as smi in GC).
1408 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 2; 1322 const int kStackSpace = PropertyCallbackArguments::kArgsLength + 2;
1409 // Allocate space for opional callback address parameter in case 1323 // Allocate space for opional callback address parameter in case
1410 // CPU profiler is active. 1324 // CPU profiler is active.
1411 const int kApiArgc = 2 + 1; 1325 const int kApiArgc = 2 + 1;
1412 1326
1413 Address getter_address = v8::ToCData<Address>(callback->getter());
1414 __ PrepareCallApiFunction(kApiArgc); 1327 __ PrepareCallApiFunction(kApiArgc);
1415 __ mov(ApiParameterOperand(0), ebx); // name. 1328 __ mov(ApiParameterOperand(0), ebx); // name.
1416 __ add(ebx, Immediate(kPointerSize)); 1329 __ add(ebx, Immediate(kPointerSize));
1417 __ mov(ApiParameterOperand(1), ebx); // arguments pointer. 1330 __ mov(ApiParameterOperand(1), ebx); // arguments pointer.
1418 1331
1419 // Emitting a stub call may try to allocate (if the code is not 1332 // Emitting a stub call may try to allocate (if the code is not
1420 // already generated). Do not allow the assembler to perform a 1333 // already generated). Do not allow the assembler to perform a
1421 // garbage collection but instead return the allocation failure 1334 // garbage collection but instead return the allocation failure
1422 // object. 1335 // object.
1423 1336
1337 Register getter_address = edx;
1338 Address function_address = v8::ToCData<Address>(callback->getter());
1339 __ mov(getter_address, Immediate(function_address));
1340
1424 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); 1341 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
1425 1342
1426 __ CallApiFunctionAndReturn(getter_address, 1343 __ CallApiFunctionAndReturn(getter_address,
1427 thunk_address, 1344 thunk_address,
1428 ApiParameterOperand(2), 1345 ApiParameterOperand(2),
1429 kStackSpace, 1346 kStackSpace,
1430 Operand(ebp, 7 * kPointerSize), 1347 Operand(ebp, 7 * kPointerSize),
1431 NULL); 1348 NULL);
1432 } 1349 }
1433 1350
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 Handle<Code> StoreStubCompiler::CompileStoreCallback( 1786 Handle<Code> StoreStubCompiler::CompileStoreCallback(
1870 Handle<JSObject> object, 1787 Handle<JSObject> object,
1871 Handle<JSObject> holder, 1788 Handle<JSObject> holder,
1872 Handle<Name> name, 1789 Handle<Name> name,
1873 const CallOptimization& call_optimization) { 1790 const CallOptimization& call_optimization) {
1874 HandlerFrontend(IC::CurrentTypeOf(object, isolate()), 1791 HandlerFrontend(IC::CurrentTypeOf(object, isolate()),
1875 receiver(), holder, name); 1792 receiver(), holder, name);
1876 1793
1877 Register values[] = { value() }; 1794 Register values[] = { value() };
1878 GenerateFastApiCall( 1795 GenerateFastApiCall(
1879 masm(), call_optimization, receiver(), scratch1(), 1796 masm(), call_optimization, receiver(),
1880 scratch2(), this->name(), 1, values); 1797 scratch1(), 1, values);
1881 1798
1882 // Return the generated code. 1799 // Return the generated code.
1883 return GetCode(kind(), Code::FAST, name); 1800 return GetCode(kind(), Code::FAST, name);
1884 } 1801 }
1885 1802
1886 1803
1887 #undef __ 1804 #undef __
1888 #define __ ACCESS_MASM(masm) 1805 #define __ ACCESS_MASM(masm)
1889 1806
1890 1807
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 // ----------------------------------- 2103 // -----------------------------------
2187 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); 2104 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
2188 } 2105 }
2189 2106
2190 2107
2191 #undef __ 2108 #undef __
2192 2109
2193 } } // namespace v8::internal 2110 } } // namespace v8::internal
2194 2111
2195 #endif // V8_TARGET_ARCH_IA32 2112 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/macro-assembler-ia32.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698