Index: src/x64/macro-assembler-x64.cc |
=================================================================== |
--- src/x64/macro-assembler-x64.cc (revision 5791) |
+++ src/x64/macro-assembler-x64.cc (working copy) |
@@ -327,7 +327,7 @@ |
void MacroAssembler::TailCallStub(CodeStub* stub) { |
- ASSERT(allow_stub_calls()); // calls are not allowed in some stubs |
+ ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
Jump(stub->GetCode(), RelocInfo::CODE_TARGET); |
} |
@@ -456,6 +456,24 @@ |
} |
+MaybeObject* MacroAssembler::TryTailCallExternalReference( |
+ const ExternalReference& ext, int num_arguments, int result_size) { |
+ // ----------- S t a t e ------------- |
+ // -- rsp[0] : return address |
+ // -- rsp[8] : argument num_arguments - 1 |
+ // ... |
+ // -- rsp[8 * num_arguments] : argument 0 (receiver) |
+ // ----------------------------------- |
+ |
+ // TODO(1236192): Most runtime routines don't need the number of |
+ // arguments passed in because it is constant. At some point we |
+ // should remove this need and make the runtime routine entry code |
+ // smarter. |
+ Set(rax, num_arguments); |
+ return TryJumpToExternalReference(ext, result_size); |
+} |
+ |
+ |
void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
int num_arguments, |
int result_size) { |
@@ -463,6 +481,15 @@ |
} |
+MaybeObject* MacroAssembler::TryTailCallRuntime(Runtime::FunctionId fid, |
+ int num_arguments, |
+ int result_size) { |
+ return TryTailCallExternalReference(ExternalReference(fid), |
+ num_arguments, |
+ result_size); |
+} |
+ |
+ |
static int Offset(ExternalReference ref0, ExternalReference ref1) { |
int64_t offset = (ref0.address() - ref1.address()); |
// Check that fits into int. |
@@ -472,11 +499,19 @@ |
void MacroAssembler::PrepareCallApiFunction(int stack_space) { |
+#ifdef _WIN64 |
+ // We need to prepare a slot for result handle on stack and put |
+ // a pointer to it into 1st arg register. |
+ EnterApiExitFrame(stack_space, 1); |
+ __ 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.
|
+#else |
EnterApiExitFrame(stack_space, 0); |
+#endif |
} |
-void MacroAssembler::CallApiFunctionAndReturn(ApiFunction* function) { |
+MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
+ ApiFunction* function) { |
Label empty_result; |
Label prologue; |
Label promote_scheduled_exception; |
@@ -539,7 +574,11 @@ |
ret(0); |
bind(&promote_scheduled_exception); |
- TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1); |
+ MaybeObject* result = TryTailCallRuntime(Runtime::kPromoteScheduledException, |
+ 0, 1); |
+ if (result->IsFailure()) { |
+ return result; |
+ } |
bind(&empty_result); |
// It was zero; the result is undefined. |
@@ -554,6 +593,8 @@ |
call(rax); |
movq(rax, prev_limit_reg); |
jmp(&leave_exit_frame); |
+ |
+ return result; |
} |
@@ -566,6 +607,15 @@ |
} |
+MaybeObject* MacroAssembler::TryJumpToExternalReference( |
+ const ExternalReference& ext, int result_size) { |
+ // Set the entry point and jump to the C entry runtime stub. |
+ movq(rbx, ext); |
+ CEntryStub ces(result_size); |
+ return TryTailCallStub(&ces); |
+} |
+ |
+ |
void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { |
// Calls are not allowed in some stubs. |
ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); |