Commit 8201da29 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[async] Reduce generated size of `await` builtins.

There's a AsyncBuiltinsAssembler::InitializeNativeClosure() helper which
is used by the `await` builtins to initialize the native closures, which
are registered as fulfill/reject handlers. This helper initializes a
JSFunction based on the builtin SharedFunctionInfo. Since we are dealing
with builtins here, there's no point in using the fully generic helper
CodeStubAssembler::GetSharedFunctionInfoCode(), but we can immediately
assume that the SharedFunctionInfo::function_data() field contains a Smi
builtin index (guarded by TNode CASTs).

This almost cuts the generated code size for the `await` builtins in a
half, and might also yield some performance improvements due to reduced
register and instruction cache pressure.

Bug: v8:7253, v8:8238
Change-Id: I3415c2f9e0f04a7154c4bf4c3fe8156854dbfe13
Reviewed-on: https://chromium-review.googlesource.com/c/1281604Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56662}
parent c36b21d6
......@@ -250,8 +250,8 @@ void AsyncBuiltinsAssembler::InitializeNativeClosure(Node* context,
Node* native_context,
Node* function,
Node* context_index) {
Node* const function_map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<Map> function_map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
// Ensure that we don't have to initialize prototype_or_initial_map field of
// JSFunction.
CSA_ASSERT(this, WordEqual(LoadMapInstanceSizeInWords(function_map),
......@@ -266,13 +266,20 @@ void AsyncBuiltinsAssembler::InitializeNativeClosure(Node* context,
StoreObjectFieldRoot(function, JSFunction::kFeedbackCellOffset,
RootIndex::kManyClosuresCell);
Node* shared_info = LoadContextElement(native_context, context_index);
CSA_ASSERT(this, IsSharedFunctionInfo(shared_info));
TNode<SharedFunctionInfo> shared_info =
CAST(LoadContextElement(native_context, context_index));
StoreObjectFieldNoWriteBarrier(
function, JSFunction::kSharedFunctionInfoOffset, shared_info);
StoreObjectFieldNoWriteBarrier(function, JSFunction::kContextOffset, context);
Node* const code = GetSharedFunctionInfoCode(shared_info);
// For the native closures that are initialized here (for `await`)
// we know that their SharedFunctionInfo::function_data() slot
// contains a builtin index (as Smi), so there's no need to use
// CodeStubAssembler::GetSharedFunctionInfoCode() helper here,
// which almost doubles the size of `await` builtins (unnecessarily).
TNode<Smi> builtin_id = LoadObjectField<Smi>(
shared_info, SharedFunctionInfo::kFunctionDataOffset);
TNode<Code> code = LoadBuiltin(builtin_id);
StoreObjectFieldNoWriteBarrier(function, JSFunction::kCodeOffset, code);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment