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

Unified Diff: src/builtins/mips64/builtins-mips64.cc

Issue 2841913003: [WIP] Initial CallFunctionCallback builtin.
Patch Set: Fix wrong register for arm64. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/mips/builtins-mips.cc ('k') | src/builtins/x64/builtins-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/mips64/builtins-mips64.cc
diff --git a/src/builtins/mips64/builtins-mips64.cc b/src/builtins/mips64/builtins-mips64.cc
index 498073a08b6e4ad90b40c11ea51f3008860e2e10..7f4b22a20713067dc733c08b5f617abf55b02974 100644
--- a/src/builtins/mips64/builtins-mips64.cc
+++ b/src/builtins/mips64/builtins-mips64.cc
@@ -4,6 +4,7 @@
#if V8_TARGET_ARCH_MIPS64
+#include "src/api-arguments.h"
#include "src/codegen.h"
#include "src/debug/debug.h"
#include "src/deoptimizer.h"
@@ -2726,6 +2727,155 @@ void Builtins::Generate_CallWithSpread(MacroAssembler* masm) {
RelocInfo::CODE_TARGET);
}
+// static
+void Builtins::Generate_CallFunctionCallback(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- a0 : the number of arguments (not incl. the receiver)
+ // -- a1 : api function address
+ // -- sp[0] : holder
+ // -- sp[8] : isolate
+ // -- sp[16] : return value default
+ // -- sp[24] : return value
+ // -- sp[32] : call data
+ // -- sp[40] : target
+ // -- sp[48] : context save
+ // -- sp[56] : new.target
+ // -- sp[64] : last argument
+ // -- sp[56 + argc * 4] : first argument
+ // -- sp[64 + argc * 4] : receiver
+ // -----------------------------------
+ typedef FunctionCallbackArguments FCA;
+
+ STATIC_ASSERT(FCA::kNewTargetIndex == 7);
+ STATIC_ASSERT(FCA::kContextSaveIndex == 6);
+ STATIC_ASSERT(FCA::kCalleeIndex == 5);
+ STATIC_ASSERT(FCA::kDataIndex == 4);
+ STATIC_ASSERT(FCA::kReturnValueOffset == 3);
+ STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
+ STATIC_ASSERT(FCA::kIsolateIndex == 1);
+ STATIC_ASSERT(FCA::kHolderIndex == 0);
+ STATIC_ASSERT(FCA::kArgsLength == 8);
+
+ // Compute the pointer to the implicit args on the stack.
+ __ mov(a2, sp);
+
+ // Allocate the v8::FunctionCallbackInfo structure in the arguments' space
+ // since it's not controlled by the GC.
+ const int kApiStackSpace = 3;
+ FrameScope frame_scope(masm, StackFrame::MANUAL);
+ __ EnterExitFrame(false, kApiStackSpace);
+ // a3 = FunctionCallbackInfo&
+ // Arguments is after the return address.
+ __ Daddu(a3, sp, Operand(1 * kPointerSize));
+ // Initialize FunctionCallbackInfo::implicit_args_.
+ __ Sd(a2, MemOperand(a3, 0 * kPointerSize));
+ // Initialize FunctionCallbackInfo::values_.
+ __ Dlsa(at, a2, a0, kPointerSizeLog2);
+ __ Daddu(at, at, Operand((FCA::kArgsLength - 1) * kPointerSize));
+ __ Sd(at, MemOperand(a3, 1 * kPointerSize));
+ // Initialize FunctionCallbackInfo::length_.
+ __ Sw(a0, MemOperand(a3, 2 * kPointerSize));
+
+ // Load first argument with pointer to FunctionCallbackInfo.
+ __ mov(a0, a3);
+
+ // TODO(bmeurer): Do we need this?
+ AllowExternalCallThatCantCauseGC scope(masm);
+
+ const int kNextOffset = 0;
+ const int kLimitOffset = AddressOffset(
+ ExternalReference::handle_scope_limit_address(masm->isolate()),
+ ExternalReference::handle_scope_next_address(masm->isolate()));
+ const int kLevelOffset = AddressOffset(
+ ExternalReference::handle_scope_level_address(masm->isolate()),
+ ExternalReference::handle_scope_next_address(masm->isolate()));
+
+ // Allocate HandleScope in callee-save registers.
+ __ li(s3,
+ Operand(ExternalReference::handle_scope_next_address(masm->isolate())));
+ __ Ld(s0, MemOperand(s3, kNextOffset));
+ __ Ld(s1, MemOperand(s3, kLimitOffset));
+ __ Lw(s2, MemOperand(s3, kLevelOffset));
+ __ Addu(s2, s2, Operand(1));
+ __ Sw(s2, MemOperand(s3, kLevelOffset));
+
+ // Check if profiling is active, and if so call the function indirectly
+ // via the invoke_function_callback helper.
+ Label call_indirect, done_call;
+ __ li(t9, Operand(ExternalReference::is_profiling_address(masm->isolate())));
+ __ lb(t9, MemOperand(t9, 0));
+ __ Branch(&call_indirect, ne, t9, Operand(zero_reg));
+ {
+ // Call the API function directly.
+ // TODO(all): Deprecate DirectCEntryStub usage here, since this builtin
+ // is part of the snapshot and thus isn't relocated by the GC ever.
+ DirectCEntryStub stub(masm->isolate());
+ stub.GenerateCall(masm, a1);
+ }
+ __ b(&done_call);
+ __ bind(&call_indirect);
+ {
+ // Call the API function indirectly when profiling is on.
+ // TODO(all): Deprecate DirectCEntryStub usage here, since this builtin
+ // is part of the snapshot and thus isn't relocated by the GC ever.
+ DirectCEntryStub stub(masm->isolate());
+ __ li(
+ a3,
+ Operand(ExternalReference::invoke_function_callback(masm->isolate())));
+ stub.GenerateCall(masm, a3);
+ }
+ __ bind(&done_call);
+
+ // No more valid handles (the result handle was the last one). Restore
+ // previous handle scope.
+ Label delete_allocated_handles;
+ __ Sd(s0, MemOperand(s3, kNextOffset));
+ __ Subu(s2, s2, Operand(1));
+ __ Sw(s2, MemOperand(s3, kLevelOffset));
+ __ Ld(t1, MemOperand(s3, kLimitOffset));
+ __ Branch(&delete_allocated_handles, ne, s1, Operand(t1));
+
+ // Leave the API exit frame.
+ Label leave_exit_frame;
+ __ bind(&leave_exit_frame);
+ __ Ld(v0, MemOperand(fp, (2 + FCA::kReturnValueOffset) * kPointerSize));
+ __ Ld(cp, MemOperand(fp, (2 + FCA::kContextSaveIndex) * kPointerSize));
+ __ Lw(s0, MemOperand(sp, 3 * kPointerSize));
+ __ LeaveExitFrame(false, no_reg, false);
+
+ // Check if the function scheduled an exception.
+ Label promote_scheduled_exception;
+ __ li(
+ t1,
+ Operand(ExternalReference::scheduled_exception_address(masm->isolate())));
+ __ Ld(t1, MemOperand(t1));
+ __ JumpIfNotRoot(t1, Heap::kTheHoleValueRootIndex,
+ &promote_scheduled_exception);
+
+ // Check if the function returned a valid JavaScript value.
+ __ AssertApiCallResult(v0);
+
+ // Drop the arguments and return.
+ __ Daddu(sp, sp, Operand((FCA::kArgsLength + 1) * kPointerSize));
+ __ Dlsa(sp, sp, s0, kPointerSizeLog2);
+ __ Ret();
+
+ // Re-throw by promoting a scheduled exception.
+ __ bind(&promote_scheduled_exception);
+ __ TailCallRuntime(Runtime::kPromoteScheduledException);
+
+ // HandleScope limit has changed. Delete allocated extensions.
+ __ bind(&delete_allocated_handles);
+ {
+ __ Sd(s1, MemOperand(s3, kLimitOffset));
+ __ PrepareCallCFunction(1, s1);
+ __ li(a0, Operand(ExternalReference::isolate_address(masm->isolate())));
+ __ CallCFunction(
+ ExternalReference::delete_handle_scope_extensions(masm->isolate()), 1);
+ }
+ __ b(&leave_exit_frame);
+}
+
void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- a0 : the number of arguments (not including the receiver)
« no previous file with comments | « src/builtins/mips/builtins-mips.cc ('k') | src/builtins/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698