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

Side by Side Diff: src/x64/macro-assembler-x64.cc

Issue 4695003: Removing redundant stubs for API functions. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 1 month 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 MaybeObject* result = stub->TryGetCode(); 320 MaybeObject* result = stub->TryGetCode();
321 if (!result->IsFailure()) { 321 if (!result->IsFailure()) {
322 call(Handle<Code>(Code::cast(result->ToObjectUnchecked())), 322 call(Handle<Code>(Code::cast(result->ToObjectUnchecked())),
323 RelocInfo::CODE_TARGET); 323 RelocInfo::CODE_TARGET);
324 } 324 }
325 return result; 325 return result;
326 } 326 }
327 327
328 328
329 void MacroAssembler::TailCallStub(CodeStub* stub) { 329 void MacroAssembler::TailCallStub(CodeStub* stub) {
330 ASSERT(allow_stub_calls()); // calls are not allowed in some stubs 330 ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs.
331 Jump(stub->GetCode(), RelocInfo::CODE_TARGET); 331 Jump(stub->GetCode(), RelocInfo::CODE_TARGET);
332 } 332 }
333 333
334 334
335 MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) { 335 MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) {
336 ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. 336 ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs.
337 MaybeObject* result = stub->TryGetCode(); 337 MaybeObject* result = stub->TryGetCode();
338 if (!result->IsFailure()) { 338 if (!result->IsFailure()) {
339 jmp(Handle<Code>(Code::cast(result->ToObjectUnchecked())), 339 jmp(Handle<Code>(Code::cast(result->ToObjectUnchecked())),
340 RelocInfo::CODE_TARGET); 340 RelocInfo::CODE_TARGET);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 449
450 // TODO(1236192): Most runtime routines don't need the number of 450 // TODO(1236192): Most runtime routines don't need the number of
451 // arguments passed in because it is constant. At some point we 451 // arguments passed in because it is constant. At some point we
452 // should remove this need and make the runtime routine entry code 452 // should remove this need and make the runtime routine entry code
453 // smarter. 453 // smarter.
454 Set(rax, num_arguments); 454 Set(rax, num_arguments);
455 JumpToExternalReference(ext, result_size); 455 JumpToExternalReference(ext, result_size);
456 } 456 }
457 457
458 458
459 MaybeObject* MacroAssembler::TryTailCallExternalReference(
460 const ExternalReference& ext, int num_arguments, int result_size) {
461 // ----------- S t a t e -------------
462 // -- rsp[0] : return address
463 // -- rsp[8] : argument num_arguments - 1
464 // ...
465 // -- rsp[8 * num_arguments] : argument 0 (receiver)
466 // -----------------------------------
467
468 // TODO(1236192): Most runtime routines don't need the number of
469 // arguments passed in because it is constant. At some point we
470 // should remove this need and make the runtime routine entry code
471 // smarter.
472 Set(rax, num_arguments);
473 return TryJumpToExternalReference(ext, result_size);
474 }
475
476
459 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, 477 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
460 int num_arguments, 478 int num_arguments,
461 int result_size) { 479 int result_size) {
462 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); 480 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size);
463 } 481 }
464 482
465 483
484 MaybeObject* MacroAssembler::TryTailCallRuntime(Runtime::FunctionId fid,
485 int num_arguments,
486 int result_size) {
487 return TryTailCallExternalReference(ExternalReference(fid),
488 num_arguments,
489 result_size);
490 }
491
492
466 static int Offset(ExternalReference ref0, ExternalReference ref1) { 493 static int Offset(ExternalReference ref0, ExternalReference ref1) {
467 int64_t offset = (ref0.address() - ref1.address()); 494 int64_t offset = (ref0.address() - ref1.address());
468 // Check that fits into int. 495 // Check that fits into int.
469 ASSERT(static_cast<int>(offset) == offset); 496 ASSERT(static_cast<int>(offset) == offset);
470 return static_cast<int>(offset); 497 return static_cast<int>(offset);
471 } 498 }
472 499
473 500
474 void MacroAssembler::PrepareCallApiFunction(int stack_space) { 501 void MacroAssembler::PrepareCallApiFunction(int stack_space) {
502 #ifdef _WIN64
503 // We need to prepare a slot for result handle on stack and put
504 // a pointer to it into 1st arg register.
505 EnterApiExitFrame(stack_space, 1);
506 __ movq(rcx, rsp);
antonm 2010/11/10 14:53:54 should we pass a register to store rsp into as an
SeRya 2010/11/11 15:50:39 Added comments.
507 #else
475 EnterApiExitFrame(stack_space, 0); 508 EnterApiExitFrame(stack_space, 0);
509 #endif
476 } 510 }
477 511
478 512
479 void MacroAssembler::CallApiFunctionAndReturn(ApiFunction* function) { 513 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn(
514 ApiFunction* function) {
480 Label empty_result; 515 Label empty_result;
481 Label prologue; 516 Label prologue;
482 Label promote_scheduled_exception; 517 Label promote_scheduled_exception;
483 Label delete_allocated_handles; 518 Label delete_allocated_handles;
484 Label leave_exit_frame; 519 Label leave_exit_frame;
485 Label write_back; 520 Label write_back;
486 521
487 ExternalReference next_address = 522 ExternalReference next_address =
488 ExternalReference::handle_scope_next_address(); 523 ExternalReference::handle_scope_next_address();
489 const int kNextOffset = 0; 524 const int kNextOffset = 0;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 567
533 // Check if the function scheduled an exception. 568 // Check if the function scheduled an exception.
534 movq(rsi, scheduled_exception_address); 569 movq(rsi, scheduled_exception_address);
535 Cmp(Operand(rsi, 0), Factory::the_hole_value()); 570 Cmp(Operand(rsi, 0), Factory::the_hole_value());
536 j(not_equal, &promote_scheduled_exception); 571 j(not_equal, &promote_scheduled_exception);
537 572
538 LeaveExitFrame(); 573 LeaveExitFrame();
539 ret(0); 574 ret(0);
540 575
541 bind(&promote_scheduled_exception); 576 bind(&promote_scheduled_exception);
542 TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1); 577 MaybeObject* result = TryTailCallRuntime(Runtime::kPromoteScheduledException,
578 0, 1);
579 if (result->IsFailure()) {
580 return result;
581 }
543 582
544 bind(&empty_result); 583 bind(&empty_result);
545 // It was zero; the result is undefined. 584 // It was zero; the result is undefined.
546 Move(rax, Factory::undefined_value()); 585 Move(rax, Factory::undefined_value());
547 jmp(&prologue); 586 jmp(&prologue);
548 587
549 // HandleScope limit has changed. Delete allocated extensions. 588 // HandleScope limit has changed. Delete allocated extensions.
550 bind(&delete_allocated_handles); 589 bind(&delete_allocated_handles);
551 movq(Operand(base_reg, kLimitOffset), prev_limit_reg); 590 movq(Operand(base_reg, kLimitOffset), prev_limit_reg);
552 movq(prev_limit_reg, rax); 591 movq(prev_limit_reg, rax);
553 movq(rax, ExternalReference::delete_handle_scope_extensions()); 592 movq(rax, ExternalReference::delete_handle_scope_extensions());
554 call(rax); 593 call(rax);
555 movq(rax, prev_limit_reg); 594 movq(rax, prev_limit_reg);
556 jmp(&leave_exit_frame); 595 jmp(&leave_exit_frame);
596
597 return result;
557 } 598 }
558 599
559 600
560 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext, 601 void MacroAssembler::JumpToExternalReference(const ExternalReference& ext,
561 int result_size) { 602 int result_size) {
562 // Set the entry point and jump to the C entry runtime stub. 603 // Set the entry point and jump to the C entry runtime stub.
563 movq(rbx, ext); 604 movq(rbx, ext);
564 CEntryStub ces(result_size); 605 CEntryStub ces(result_size);
565 jmp(ces.GetCode(), RelocInfo::CODE_TARGET); 606 jmp(ces.GetCode(), RelocInfo::CODE_TARGET);
566 } 607 }
567 608
568 609
610 MaybeObject* MacroAssembler::TryJumpToExternalReference(
611 const ExternalReference& ext, int result_size) {
612 // Set the entry point and jump to the C entry runtime stub.
613 movq(rbx, ext);
614 CEntryStub ces(result_size);
615 return TryTailCallStub(&ces);
616 }
617
618
569 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { 619 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) {
570 // Calls are not allowed in some stubs. 620 // Calls are not allowed in some stubs.
571 ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); 621 ASSERT(flag == JUMP_FUNCTION || allow_stub_calls());
572 622
573 // Rely on the assertion to check that the number of provided 623 // Rely on the assertion to check that the number of provided
574 // arguments match the expected number of arguments. Fake a 624 // arguments match the expected number of arguments. Fake a
575 // parameter count to avoid emitting code to do the check. 625 // parameter count to avoid emitting code to do the check.
576 ParameterCount expected(0); 626 ParameterCount expected(0);
577 GetBuiltinEntry(rdx, id); 627 GetBuiltinEntry(rdx, id);
578 InvokeCode(rdx, expected, expected, flag); 628 InvokeCode(rdx, expected, expected, flag);
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 CPU::FlushICache(address_, size_); 2330 CPU::FlushICache(address_, size_);
2281 2331
2282 // Check that the code was patched as expected. 2332 // Check that the code was patched as expected.
2283 ASSERT(masm_.pc_ == address_ + size_); 2333 ASSERT(masm_.pc_ == address_ + size_);
2284 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); 2334 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
2285 } 2335 }
2286 2336
2287 } } // namespace v8::internal 2337 } } // namespace v8::internal
2288 2338
2289 #endif // V8_TARGET_ARCH_X64 2339 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698