Reland "[Promise.any] Fix errors allocation"

This is a reland of commit e08fa94bbc

Changes since revert:

Use max(remainingElements - 1, index + 1) instead of index + 1 as
newCapacity computation to avoid excessive allocations causing the
timeout.

Original change's description:
> [Promise.any] Fix errors allocation
>
> Bug: chromium:1379054
> Change-Id: Ibfcdd4ddc3c9a26471094074c8e7810d93abc898
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3988924
> Commit-Queue: Marja Hölttä <marja@chromium.org>
> Auto-Submit: Shu-yu Guo <syg@chromium.org>
> Reviewed-by: Marja Hölttä <marja@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#83968}

Bug: chromium:1379054
Change-Id: Ic788b8d0b42f4e24eaf8b2f2d05b24390fda247b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3990627
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83987}
This commit is contained in:
Shu-yu Guo 2022-10-28 10:21:27 -07:00 committed by V8 LUCI CQ
parent 4d5e5a0940
commit 8b35091b2d
2 changed files with 38 additions and 25 deletions

View File

@ -119,7 +119,19 @@ PromiseAnyRejectElementClosure(
kPromiseAnyRejectElementRemainingSlot);
// 9. Set errors[index] to x.
const newCapacity = IntPtrMax(SmiUntag(remainingElementsCount), index + 1);
// The max computation below is an optimization to avoid excessive allocations
// in the case of input promises being asynchronously rejected in ascending
// index order.
//
// Note that subtracting 1 from remainingElementsCount is intentional. The
// value of remainingElementsCount is 1 larger than the actual value during
// iteration. So in the case of synchronous rejection, newCapacity is the
// correct size by subtracting 1. In the case of asynchronous rejection this
// is 1 smaller than the correct size, but is not incorrect as it is maxed
// with index + 1.
const newCapacity =
IntPtrMax(SmiUntag(remainingElementsCount) - 1, index + 1);
if (newCapacity > errors.length_intptr) deferred {
errors = ExtractFixedArray(errors, 0, errors.length_intptr, newCapacity);
*ContextSlot(
@ -306,6 +318,7 @@ Reject(JSAny) {
PromiseAnyRejectElementContextSlots::
kPromiseAnyRejectElementErrorsSlot);
check(errors.length == index - 1);
const error = ConstructAggregateError(errors);
// 3. Return ThrowCompletion(error).
goto Reject(error);

View File

@ -554,30 +554,30 @@ KNOWN_OBJECTS = {
("old_space", 0x045a1): "StringSplitCache",
("old_space", 0x049a9): "RegExpMultipleCache",
("old_space", 0x04db1): "BuiltinsConstantsTable",
("old_space", 0x05211): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x05235): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x05259): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x0527d): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x052a1): "AsyncGeneratorYieldWithAwaitResolveSharedFun",
("old_space", 0x052c5): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x052e9): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x0530d): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x05331): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x05355): "PromiseAllResolveElementSharedFun",
("old_space", 0x05379): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x0539d): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x053c1): "PromiseAnyRejectElementSharedFun",
("old_space", 0x053e5): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x05409): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x0542d): "PromiseCatchFinallySharedFun",
("old_space", 0x05451): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x05475): "PromiseThenFinallySharedFun",
("old_space", 0x05499): "PromiseThrowerFinallySharedFun",
("old_space", 0x054bd): "PromiseValueThunkFinallySharedFun",
("old_space", 0x054e1): "ProxyRevokeSharedFun",
("old_space", 0x05505): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x05529): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x0554d): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
("old_space", 0x05215): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x05239): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x0525d): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x05281): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x052a5): "AsyncGeneratorYieldWithAwaitResolveSharedFun",
("old_space", 0x052c9): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x052ed): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x05311): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x05335): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x05359): "PromiseAllResolveElementSharedFun",
("old_space", 0x0537d): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x053a1): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x053c5): "PromiseAnyRejectElementSharedFun",
("old_space", 0x053e9): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x0540d): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x05431): "PromiseCatchFinallySharedFun",
("old_space", 0x05455): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x05479): "PromiseThenFinallySharedFun",
("old_space", 0x0549d): "PromiseThrowerFinallySharedFun",
("old_space", 0x054c1): "PromiseValueThunkFinallySharedFun",
("old_space", 0x054e5): "ProxyRevokeSharedFun",
("old_space", 0x05509): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x0552d): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x05551): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
}
# Lower 32 bits of first page addresses for various heap spaces.