Skip to content

Commit 8b35091

Browse files
sygV8 LUCI CQ
authored andcommitted
Reland "[Promise.any] Fix errors allocation"
This is a reland of commit e08fa94 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ä <[email protected]> > Auto-Submit: Shu-yu Guo <[email protected]> > Reviewed-by: Marja Hölttä <[email protected]> > 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 <[email protected]> Commit-Queue: Shu-yu Guo <[email protected]> Cr-Commit-Position: refs/heads/main@{#83987}
1 parent 4d5e5a0 commit 8b35091

2 files changed

Lines changed: 38 additions & 25 deletions

File tree

src/builtins/promise-any.tq

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,19 @@ PromiseAnyRejectElementClosure(
119119
kPromiseAnyRejectElementRemainingSlot);
120120

121121
// 9. Set errors[index] to x.
122-
const newCapacity = IntPtrMax(SmiUntag(remainingElementsCount), index + 1);
122+
123+
// The max computation below is an optimization to avoid excessive allocations
124+
// in the case of input promises being asynchronously rejected in ascending
125+
// index order.
126+
//
127+
// Note that subtracting 1 from remainingElementsCount is intentional. The
128+
// value of remainingElementsCount is 1 larger than the actual value during
129+
// iteration. So in the case of synchronous rejection, newCapacity is the
130+
// correct size by subtracting 1. In the case of asynchronous rejection this
131+
// is 1 smaller than the correct size, but is not incorrect as it is maxed
132+
// with index + 1.
133+
const newCapacity =
134+
IntPtrMax(SmiUntag(remainingElementsCount) - 1, index + 1);
123135
if (newCapacity > errors.length_intptr) deferred {
124136
errors = ExtractFixedArray(errors, 0, errors.length_intptr, newCapacity);
125137
*ContextSlot(
@@ -306,6 +318,7 @@ Reject(JSAny) {
306318
PromiseAnyRejectElementContextSlots::
307319
kPromiseAnyRejectElementErrorsSlot);
308320

321+
check(errors.length == index - 1);
309322
const error = ConstructAggregateError(errors);
310323
// 3. Return ThrowCompletion(error).
311324
goto Reject(error);

tools/v8heapconst.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -554,30 +554,30 @@
554554
("old_space", 0x045a1): "StringSplitCache",
555555
("old_space", 0x049a9): "RegExpMultipleCache",
556556
("old_space", 0x04db1): "BuiltinsConstantsTable",
557-
("old_space", 0x05211): "AsyncFunctionAwaitRejectSharedFun",
558-
("old_space", 0x05235): "AsyncFunctionAwaitResolveSharedFun",
559-
("old_space", 0x05259): "AsyncGeneratorAwaitRejectSharedFun",
560-
("old_space", 0x0527d): "AsyncGeneratorAwaitResolveSharedFun",
561-
("old_space", 0x052a1): "AsyncGeneratorYieldWithAwaitResolveSharedFun",
562-
("old_space", 0x052c5): "AsyncGeneratorReturnResolveSharedFun",
563-
("old_space", 0x052e9): "AsyncGeneratorReturnClosedRejectSharedFun",
564-
("old_space", 0x0530d): "AsyncGeneratorReturnClosedResolveSharedFun",
565-
("old_space", 0x05331): "AsyncIteratorValueUnwrapSharedFun",
566-
("old_space", 0x05355): "PromiseAllResolveElementSharedFun",
567-
("old_space", 0x05379): "PromiseAllSettledResolveElementSharedFun",
568-
("old_space", 0x0539d): "PromiseAllSettledRejectElementSharedFun",
569-
("old_space", 0x053c1): "PromiseAnyRejectElementSharedFun",
570-
("old_space", 0x053e5): "PromiseCapabilityDefaultRejectSharedFun",
571-
("old_space", 0x05409): "PromiseCapabilityDefaultResolveSharedFun",
572-
("old_space", 0x0542d): "PromiseCatchFinallySharedFun",
573-
("old_space", 0x05451): "PromiseGetCapabilitiesExecutorSharedFun",
574-
("old_space", 0x05475): "PromiseThenFinallySharedFun",
575-
("old_space", 0x05499): "PromiseThrowerFinallySharedFun",
576-
("old_space", 0x054bd): "PromiseValueThunkFinallySharedFun",
577-
("old_space", 0x054e1): "ProxyRevokeSharedFun",
578-
("old_space", 0x05505): "ShadowRealmImportValueFulfilledSFI",
579-
("old_space", 0x05529): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
580-
("old_space", 0x0554d): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
557+
("old_space", 0x05215): "AsyncFunctionAwaitRejectSharedFun",
558+
("old_space", 0x05239): "AsyncFunctionAwaitResolveSharedFun",
559+
("old_space", 0x0525d): "AsyncGeneratorAwaitRejectSharedFun",
560+
("old_space", 0x05281): "AsyncGeneratorAwaitResolveSharedFun",
561+
("old_space", 0x052a5): "AsyncGeneratorYieldWithAwaitResolveSharedFun",
562+
("old_space", 0x052c9): "AsyncGeneratorReturnResolveSharedFun",
563+
("old_space", 0x052ed): "AsyncGeneratorReturnClosedRejectSharedFun",
564+
("old_space", 0x05311): "AsyncGeneratorReturnClosedResolveSharedFun",
565+
("old_space", 0x05335): "AsyncIteratorValueUnwrapSharedFun",
566+
("old_space", 0x05359): "PromiseAllResolveElementSharedFun",
567+
("old_space", 0x0537d): "PromiseAllSettledResolveElementSharedFun",
568+
("old_space", 0x053a1): "PromiseAllSettledRejectElementSharedFun",
569+
("old_space", 0x053c5): "PromiseAnyRejectElementSharedFun",
570+
("old_space", 0x053e9): "PromiseCapabilityDefaultRejectSharedFun",
571+
("old_space", 0x0540d): "PromiseCapabilityDefaultResolveSharedFun",
572+
("old_space", 0x05431): "PromiseCatchFinallySharedFun",
573+
("old_space", 0x05455): "PromiseGetCapabilitiesExecutorSharedFun",
574+
("old_space", 0x05479): "PromiseThenFinallySharedFun",
575+
("old_space", 0x0549d): "PromiseThrowerFinallySharedFun",
576+
("old_space", 0x054c1): "PromiseValueThunkFinallySharedFun",
577+
("old_space", 0x054e5): "ProxyRevokeSharedFun",
578+
("old_space", 0x05509): "ShadowRealmImportValueFulfilledSFI",
579+
("old_space", 0x0552d): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
580+
("old_space", 0x05551): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
581581
}
582582

583583
# Lower 32 bits of first page addresses for various heap spaces.

0 commit comments

Comments
 (0)