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

Unified Diff: src/builtins/arm/builtins-arm.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/assembler.h ('k') | src/builtins/arm64/builtins-arm64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/arm/builtins-arm.cc
diff --git a/src/builtins/arm/builtins-arm.cc b/src/builtins/arm/builtins-arm.cc
index 04cf3240ff3623780dc4254c692dd1cc688ffa70..2ce355b3e293b1c7ee8ee47adb4c774b6acfa67b 100644
--- a/src/builtins/arm/builtins-arm.cc
+++ b/src/builtins/arm/builtins-arm.cc
@@ -4,6 +4,7 @@
#if V8_TARGET_ARCH_ARM
+#include "src/api-arguments.h"
#include "src/assembler-inl.h"
#include "src/codegen.h"
#include "src/counters.h"
@@ -2710,6 +2711,158 @@ void Builtins::Generate_CallWithSpread(MacroAssembler* masm) {
}
// static
+void Builtins::Generate_CallFunctionCallback(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- r0 : the number of arguments (not incl. the receiver)
+ // -- r1 : api function address
+ // -- sp[0] : holder
+ // -- sp[4] : isolate
+ // -- sp[8] : return value default
+ // -- sp[12] : return value
+ // -- sp[16] : call data
+ // -- sp[20] : target
+ // -- sp[24] : context save
+ // -- sp[28] : new.target
+ // -- sp[32] : last argument
+ // -- sp[28 + argc * 4] : first argument
+ // -- sp[32 + 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(r2, 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);
+ // r3 = FunctionCallbackInfo&
+ // Arguments is after the return address.
+ __ add(r3, sp, Operand(1 * kPointerSize));
+ // Initialize FunctionCallbackInfo::implicit_args_.
+ __ str(r2, MemOperand(r3, 0 * kPointerSize));
+ // Initialize FunctionCallbackInfo::values_.
+ __ add(r2, r2, Operand(r0, LSL, kPointerSizeLog2));
+ __ add(r2, r2, Operand((FCA::kArgsLength - 1) * kPointerSize));
+ __ str(r2, MemOperand(r3, 1 * kPointerSize));
+ // Initialize FunctionCallbackInfo::length_.
+ __ str(r0, MemOperand(r3, 2 * kPointerSize));
+
+ // Load first argument with pointer to FunctionCallbackInfo.
+ __ mov(r0, r3);
+
+ // 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.
+ __ mov(
+ r9,
+ Operand(ExternalReference::handle_scope_next_address(masm->isolate())));
+ __ ldr(r4, MemOperand(r9, kNextOffset));
+ __ ldr(r5, MemOperand(r9, kLimitOffset));
+ __ ldr(r6, MemOperand(r9, kLevelOffset));
+ __ add(r6, r6, Operand(1));
+ __ str(r6, MemOperand(r9, kLevelOffset));
+
+ // Check if profiling is active, and if so call the function indirectly
+ // via the invoke_function_callback helper.
+ Label call_indirect, done_call;
+ __ mov(ip, Operand(ExternalReference::is_profiling_address(masm->isolate())));
+ __ ldrb(ip, MemOperand(ip, 0));
+ __ cmp(ip, Operand(0));
+ __ b(ne, &call_indirect);
+ {
+ // 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, r1);
+ }
+ __ 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());
+ __ mov(
+ r3,
+ Operand(ExternalReference::invoke_function_callback(masm->isolate())));
+ stub.GenerateCall(masm, r3);
+ }
+ __ bind(&done_call);
+
+ // No more valid handles (the result handle was the last one). Restore
+ // previous handle scope.
+ Label delete_allocated_handles;
+ __ str(r4, MemOperand(r9, kNextOffset));
+ __ sub(r6, r6, Operand(1));
+ __ str(r6, MemOperand(r9, kLevelOffset));
+ __ ldr(ip, MemOperand(r9, kLimitOffset));
+ __ cmp(r5, ip);
+ __ b(ne, &delete_allocated_handles);
+
+ // Leave the API exit frame.
+ Label leave_exit_frame;
+ __ bind(&leave_exit_frame);
+ __ ldr(r0, MemOperand(fp, (2 + FCA::kReturnValueOffset) * kPointerSize));
+ __ ldr(cp, MemOperand(fp, (2 + FCA::kContextSaveIndex) * kPointerSize));
+ __ ldr(r4, MemOperand(sp, 3 * kPointerSize));
+ __ LeaveExitFrame(false, no_reg, false);
+
+ // Check if the function scheduled an exception.
+ Label promote_scheduled_exception;
+ __ mov(
+ ip,
+ Operand(ExternalReference::scheduled_exception_address(masm->isolate())));
+ __ ldr(r5, MemOperand(ip));
+ __ JumpIfNotRoot(r5, Heap::kTheHoleValueRootIndex,
+ &promote_scheduled_exception);
+
+ // Check if the function returned a valid JavaScript value.
+ __ AssertApiCallResult(r0);
+
+ // Drop the arguments and return.
+ __ add(sp, sp, Operand((FCA::kArgsLength + 1) * kPointerSize));
+ __ add(sp, sp, Operand(r4, LSL, 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);
+ {
+ __ str(r5, MemOperand(r9, kLimitOffset));
+ __ PrepareCallCFunction(1, r5);
+ __ mov(r0, Operand(ExternalReference::isolate_address(masm->isolate())));
+ __ CallCFunction(
+ ExternalReference::delete_handle_scope_extensions(masm->isolate()), 1);
+ }
+ __ b(&leave_exit_frame);
+}
+
+// static
void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r0 : the number of arguments (not including the receiver)
« no previous file with comments | « src/assembler.h ('k') | src/builtins/arm64/builtins-arm64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698