v8/src/builtins/builtins-call-gen.h
Benedikt Meurer a2d9924c42 [turbofan] Introduce a CallFunctionTemplate builtin.
When calling into API callbacks from TurboFan optimized, we can
currently only take a fast-path when TurboFan is able to find some
information about the receiver in the graph, or when the API callback
specifies that it neither requires an access check (aka "accepts any
receiver") nor an interface check (aka "compatible receiver check").

This change introduces a new CallFunctionTemplate builtin that sits
in front of the CallApiCallback builtin and does both the access as well
as the interface check as necessary (and raises appropriate exceptions).
This way TurboFan can still call into the API callback via the fast-path
even without ahead knowledge about the receiver, which is significantly
faster than the generic call machinery for API callbacks.

On the test case from the Angular team[1], the interesting metrics
improve from

  DOM_mono: 0.273 ms
  DOM_mega: 0.571 ms
  DOM_call: 0.649 ms

to

  DOM_mono: 0.264 ms
  DOM_mega: 0.572 ms
  DOM_call: 0.368 ms

so the DOM_call is only about **1.4 times slower** than the DOM_mono and
about **1.5 times faster** than the DOM_mega case (compared to **2.4
times slower**). Execution time in the DOM_call was reduced by around
**~45%**.

Currently this new code path is limited to TurboFan optimized code, but
the idea is to eventually migrate the API calls from baseline to also
use the new CSA functionality, but there are lot's of subleties to take
into account, so starting with small changes to get coverage for the
basic building blocks.

[1]: https://mhevery.github.io/perf-tests/DOM-megamorphic.html

Bug: v8:8820
Change-Id: Ie1029cf182ce05a6e519fd9a9d4fa825db8adb4c
Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/1470129
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59598}
2019-02-14 12:42:57 +00:00

52 lines
2.0 KiB
C++

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_BUILTINS_BUILTINS_CALL_GEN_H_
#define V8_BUILTINS_BUILTINS_CALL_GEN_H_
#include "src/code-stub-assembler.h"
namespace v8 {
namespace internal {
class CallOrConstructBuiltinsAssembler : public CodeStubAssembler {
public:
explicit CallOrConstructBuiltinsAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {}
void CallOrConstructWithArrayLike(TNode<Object> target,
SloppyTNode<Object> new_target,
TNode<Object> arguments_list,
TNode<Context> context);
void CallOrConstructDoubleVarargs(TNode<Object> target,
SloppyTNode<Object> new_target,
TNode<FixedDoubleArray> elements,
TNode<Int32T> length,
TNode<Int32T> args_count,
TNode<Context> context, TNode<Int32T> kind);
void CallOrConstructWithSpread(TNode<Object> target, TNode<Object> new_target,
TNode<Object> spread, TNode<Int32T> args_count,
TNode<Context> context);
enum class CallFunctionTemplateMode : uint8_t {
kCheckAccess,
kCheckCompatibleReceiver,
kCheckAccessAndCompatibleReceiver,
};
void CallFunctionTemplate(CallFunctionTemplateMode mode,
TNode<FunctionTemplateInfo> function_template_info,
TNode<IntPtrT> argc, TNode<Context> context);
private:
TNode<JSReceiver> GetCompatibleReceiver(TNode<JSReceiver> receiver,
TNode<HeapObject> signature,
TNode<Context> context);
};
} // namespace internal
} // namespace v8
#endif // V8_BUILTINS_BUILTINS_CALL_GEN_H_