[Heap] Unify allocation retry loops [v8/v8 : main]

0 views
Skip to first unread message

Etienne Pierre-Doray (Gerrit)

unread,
Oct 6, 2025, 3:10:13 PMOct 6
to Dominik Inführ, V8 LUCI CQ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com
Attention needed from Dominik Inführ

Etienne Pierre-Doray voted and added 1 comment

Votes added by Etienne Pierre-Doray

Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 9 (Latest):
Etienne Pierre-Doray . resolved

PTAL

Open in Gerrit

Related details

Attention is currently required from:
  • Dominik Inführ
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
Gerrit-Change-Number: 7011414
Gerrit-PatchSet: 9
Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
Gerrit-CC: Hannes Payer <hpa...@chromium.org>
Gerrit-Attention: Dominik Inführ <dinf...@chromium.org>
Gerrit-Comment-Date: Mon, 06 Oct 2025 19:10:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
unsatisfied_requirement
open
diffy

Dominik Inführ (Gerrit)

unread,
Oct 7, 2025, 2:32:01 AMOct 7
to Etienne Pierre-Doray, V8 LUCI CQ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com
Attention needed from Etienne Pierre-Doray

Dominik Inführ added 2 comments

Patchset-level comments
Dominik Inführ . resolved

Thanks, this is indeed much cleaner! I just have one comment.

File src/heap/heap-allocator-inl.h
Line 364, Patchset 9 (Latest):V8_WARN_UNUSED_RESULT auto HeapAllocator::CustomAllocateWithRetry(
Dominik Inführ . unresolved

I understand that this was not introduced by your CL but since we are adapting this once more now and I wanted to do this for a while: What about making this non-templatized so we can easily put the retry logic back into the heap-allocator.cc file instead? We could simply expect `base::FunctionRef<bool()>` as allocation function. The bool return value would just tell us whether the allocation was successful or not. The actual allocation address could also be written into some captured local variable by the allocate-lambda. A non-templatized version could probably also be exposed a bit more easily on the API (since you mentioned that).

Performance-wise this shouldn't matter because in `HeapAllocator::AllocateRaw` we already use that method only after the allocation failed already once. At this point we need to do a GC, so inling or not for that function shouldn't matter at all. We should probably invoke "allocate()" manually first before using `CustomAllocateWithRetry()` in the other uses as well to handle the most likely case (that allocation succeeds) without regression. This should be: AllocateExternalBackingStore(), CppHeap::AllocateWithRetry and NewJSDispatchHandle.

Open in Gerrit

Related details

Attention is currently required from:
  • Etienne Pierre-Doray
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
    Gerrit-Change-Number: 7011414
    Gerrit-PatchSet: 9
    Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
    Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
    Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
    Gerrit-CC: Hannes Payer <hpa...@chromium.org>
    Gerrit-Attention: Etienne Pierre-Doray <etie...@chromium.org>
    Gerrit-Comment-Date: Tue, 07 Oct 2025 06:31:51 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Etienne Pierre-Doray (Gerrit)

    unread,
    Oct 7, 2025, 11:04:43 AM (14 days ago) Oct 7
    to Dominik Inführ, V8 LUCI CQ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Dominik Inführ

    Etienne Pierre-Doray added 3 comments

    Patchset-level comments
    File-level comment, Patchset 11 (Latest):
    Etienne Pierre-Doray . resolved

    PTAnL?

    File src/heap/heap-allocator-inl.h
    Line 231, Patchset 11 (Parent): if (allocation == AllocationType::kYoung) {
    result = AllocateRaw<AllocationType::kYoung>(size, origin, alignment, hint);
    if (result.To(&object)) {
    return object;
    }
    } else if (allocation == AllocationType::kOld) {
    result = AllocateRaw<AllocationType::kOld>(size, origin, alignment, hint);
    if (result.To(&object)) {
    return object;
    }
    }
    Etienne Pierre-Doray . resolved

    It seems to me like this + all the "other" allocation can simply be replaced by `AllocateRaw()` without regression -> this doesn't add any condition and AllocateRaw() is inline.

    Line 364, Patchset 9:V8_WARN_UNUSED_RESULT auto HeapAllocator::CustomAllocateWithRetry(
    Dominik Inführ . resolved

    I understand that this was not introduced by your CL but since we are adapting this once more now and I wanted to do this for a while: What about making this non-templatized so we can easily put the retry logic back into the heap-allocator.cc file instead? We could simply expect `base::FunctionRef<bool()>` as allocation function. The bool return value would just tell us whether the allocation was successful or not. The actual allocation address could also be written into some captured local variable by the allocate-lambda. A non-templatized version could probably also be exposed a bit more easily on the API (since you mentioned that).

    Performance-wise this shouldn't matter because in `HeapAllocator::AllocateRaw` we already use that method only after the allocation failed already once. At this point we need to do a GC, so inling or not for that function shouldn't matter at all. We should probably invoke "allocate()" manually first before using `CustomAllocateWithRetry()` in the other uses as well to handle the most likely case (that allocation succeeds) without regression. This should be: AllocateExternalBackingStore(), CppHeap::AllocateWithRetry and NewJSDispatchHandle.

    Etienne Pierre-Doray
    We could simply expect base::FunctionRef<bool()> as allocation function.

    Done

    Performance-wise this shouldn't matter because in HeapAllocator::AllocateRaw we already use that method only after the allocation failed already once.

    This is more or less true, because only kYoung and kOld have a fast path; although I don't see why we couldn't add the fast path for all allocation types (done in latest patchset).

    We should probably invoke "allocate()" manually first before using CustomAllocateWithRetry() in the other uses as well

    Done, but I renamed to RetryAllocate to make this clear.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Dominik Inführ
    Submit Requirements:
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
      Gerrit-Change-Number: 7011414
      Gerrit-PatchSet: 11
      Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
      Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-CC: Hannes Payer <hpa...@chromium.org>
      Gerrit-Attention: Dominik Inführ <dinf...@chromium.org>
      Gerrit-Comment-Date: Tue, 07 Oct 2025 15:04:41 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Dominik Inführ <dinf...@chromium.org>
      unsatisfied_requirement
      open
      diffy

      Dominik Inführ (Gerrit)

      unread,
      Oct 8, 2025, 2:27:02 AM (13 days ago) Oct 8
      to Etienne Pierre-Doray, V8 LUCI CQ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com
      Attention needed from Etienne Pierre-Doray

      Dominik Inführ voted and added 2 comments

      Votes added by Dominik Inführ

      Code-Review+1

      2 comments

      Patchset-level comments
      File-level comment, Patchset 15 (Latest):
      Dominik Inführ . resolved

      Thanks a lot! LGTM

      File src/heap/heap-allocator-inl.h
      Line 231, Patchset 11 (Parent): if (allocation == AllocationType::kYoung) {
      result = AllocateRaw<AllocationType::kYoung>(size, origin, alignment, hint);
      if (result.To(&object)) {
      return object;
      }
      } else if (allocation == AllocationType::kOld) {
      result = AllocateRaw<AllocationType::kOld>(size, origin, alignment, hint);
      if (result.To(&object)) {
      return object;
      }
      }
      Etienne Pierre-Doray . unresolved

      It seems to me like this + all the "other" allocation can simply be replaced by `AllocateRaw()` without regression -> this doesn't add any condition and AllocateRaw() is inline.

      Dominik Inführ

      Good catch! I missed that we have the fast path only for Young and Old. I think I agree with you but IIRC that code path was added for performance reasons. Not really sure what benchmark that was. I think it would be less controversial if we would keep it as is but add the AllocateRaw in an else-branch after handling Young/Old.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Etienne Pierre-Doray
      Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
      Gerrit-Change-Number: 7011414
      Gerrit-PatchSet: 15
      Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
      Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-CC: Hannes Payer <hpa...@chromium.org>
      Gerrit-Attention: Etienne Pierre-Doray <etie...@chromium.org>
      Gerrit-Comment-Date: Wed, 08 Oct 2025 06:26:38 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Etienne Pierre-Doray <etie...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Etienne Pierre-Doray (Gerrit)

      unread,
      Oct 8, 2025, 7:36:23 AM (13 days ago) Oct 8
      to Dominik Inführ, V8 LUCI CQ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com

      Etienne Pierre-Doray added 1 comment

      File src/heap/heap-allocator-inl.h
      Line 231, Patchset 11 (Parent): if (allocation == AllocationType::kYoung) {
      result = AllocateRaw<AllocationType::kYoung>(size, origin, alignment, hint);
      if (result.To(&object)) {
      return object;
      }
      } else if (allocation == AllocationType::kOld) {
      result = AllocateRaw<AllocationType::kOld>(size, origin, alignment, hint);
      if (result.To(&object)) {
      return object;
      }
      }
      Etienne Pierre-Doray . resolved

      It seems to me like this + all the "other" allocation can simply be replaced by `AllocateRaw()` without regression -> this doesn't add any condition and AllocateRaw() is inline.

      Dominik Inführ

      Good catch! I missed that we have the fast path only for Young and Old. I think I agree with you but IIRC that code path was added for performance reasons. Not really sure what benchmark that was. I think it would be less controversial if we would keep it as is but add the AllocateRaw in an else-branch after handling Young/Old.

      Etienne Pierre-Doray

      Done

      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: v8/v8
        Gerrit-Branch: main
        Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
        Gerrit-Change-Number: 7011414
        Gerrit-PatchSet: 16
        Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
        Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-CC: Hannes Payer <hpa...@chromium.org>
        Gerrit-Comment-Date: Wed, 08 Oct 2025 11:36:20 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Etienne Pierre-Doray <etie...@chromium.org>
        Comment-In-Reply-To: Dominik Inführ <dinf...@chromium.org>
        satisfied_requirement
        open
        diffy

        Etienne Pierre-Doray (Gerrit)

        unread,
        Oct 8, 2025, 7:36:48 AM (13 days ago) Oct 8
        to Dominik Inführ, V8 LUCI CQ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com

        Etienne Pierre-Doray voted Commit-Queue+2

        Commit-Queue+2
        Open in Gerrit

        Related details

        Attention set is empty
        Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: v8/v8
        Gerrit-Branch: main
        Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
        Gerrit-Change-Number: 7011414
        Gerrit-PatchSet: 16
        Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
        Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-CC: Hannes Payer <hpa...@chromium.org>
        Gerrit-Comment-Date: Wed, 08 Oct 2025 11:36:46 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        Etienne Pierre-Doray (Gerrit)

        unread,
        Oct 8, 2025, 7:42:05 AM (13 days ago) Oct 8
        to Dominik Inführ, V8 LUCI CQ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com

        Etienne Pierre-Doray voted Commit-Queue+2

        Commit-Queue+2
        Open in Gerrit

        Related details

        Attention set is empty
        Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: v8/v8
        Gerrit-Branch: main
        Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
        Gerrit-Change-Number: 7011414
        Gerrit-PatchSet: 17
        Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
        Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-CC: Hannes Payer <hpa...@chromium.org>
        Gerrit-Comment-Date: Wed, 08 Oct 2025 11:42:02 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        V8 LUCI CQ (Gerrit)

        unread,
        Oct 8, 2025, 8:32:36 AM (13 days ago) Oct 8
        to Etienne Pierre-Doray, Dominik Inführ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com

        V8 LUCI CQ submitted the change with unreviewed changes

        Unreviewed changes

        15 is the latest approved patch-set.
        The change was submitted with unreviewed changes in the following files:

        ```
        The name of the file: src/heap/heap-allocator-inl.h
        Insertions: 16, Deletions: 4.

        @@ -225,12 +225,24 @@
        AllocationOrigin origin,
        AllocationAlignment alignment,
        AllocationHint hint) {
        + AllocationResult result;
        Tagged<HeapObject> object;
        size = ALIGN_TO_ALLOCATION_ALIGNMENT(size);
        - AllocationResult result =
        - AllocateRaw(size, allocation, origin, alignment, hint);
        - if (result.To(&object)) [[likely]] {
        - return object;
        + if (allocation == AllocationType::kYoung) {
        + result = AllocateRaw<AllocationType::kYoung>(size, origin, alignment, hint);
        + if (result.To(&object)) {
        + return object;
        + }
        + } else if (allocation == AllocationType::kOld) {
        + result = AllocateRaw<AllocationType::kOld>(size, origin, alignment, hint);
        + if (result.To(&object)) {
        + return object;
        + }
        + } else {
        + result = AllocateRaw(size, allocation, origin, alignment, hint);
        + if (result.To(&object)) {
        + return object;
        + }
        }
        switch (mode) {
        case kLightRetry:
        ```

        Change information

        Commit message:
        [Heap] Unify allocation retry loops

        This CL reuses HeapAllocator retry loop in several places, including
        oilpan. This ensure they are all aligned under 1 implementation.
        Follow-up: this should also be exposed on v8-isolate so that it can be used here: https://chromium-review.googlesource.com/c/chromium/src/+/6164814
        Bug: 448848875
        Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
        Reviewed-by: Dominik Inführ <dinf...@chromium.org>
        Commit-Queue: Etienne Pierre-Doray <etie...@chromium.org>
        Cr-Commit-Position: refs/heads/main@{#102997}
        Files:
        • M src/heap/cppgc-js/cpp-heap.cc
        • M src/heap/cppgc-js/cpp-heap.h
        • M src/heap/cppgc/garbage-collector.h
        • M src/heap/cppgc/gc-invoker.cc
        • M src/heap/cppgc/gc-invoker.h
        • M src/heap/cppgc/heap.cc
        • M src/heap/cppgc/heap.h
        • M src/heap/cppgc/object-allocator.cc
        • M src/heap/factory-base.cc
        • M src/heap/heap-allocator-inl.h
        • M src/heap/heap-allocator.cc
        • M src/heap/heap-allocator.h
        • M src/heap/heap.cc
        • M test/unittests/heap/cppgc/gc-invoker-unittest.cc
        • M test/unittests/heap/cppgc/heap-growing-unittest.cc
        Change size: L
        Delta: 15 files changed, 150 insertions(+), 144 deletions(-)
        Branch: refs/heads/main
        Submit Requirements:
        • requirement satisfiedCode-Review: +1 by Dominik Inführ
        Open in Gerrit
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: merged
        Gerrit-Project: v8/v8
        Gerrit-Branch: main
        Gerrit-Change-Id: I646f05b052fa70cae151c1c5ba019f3e9aa5aa37
        Gerrit-Change-Number: 7011414
        Gerrit-PatchSet: 18
        Gerrit-Owner: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-Reviewer: Dominik Inführ <dinf...@chromium.org>
        Gerrit-Reviewer: Etienne Pierre-Doray <etie...@chromium.org>
        Gerrit-CC: Hannes Payer <hpa...@chromium.org>
        open
        diffy
        satisfied_requirement

        Benoit Lize (Gerrit)

        unread,
        Oct 9, 2025, 7:55:14 AM (12 days ago) Oct 9
        to V8 LUCI CQ, Etienne Pierre-Doray, Dominik Inführ, Hannes Payer, mlippau...@chromium.org, oilpan-r...@chromium.org, v8-re...@googlegroups.com

        Benoit Lize has created a revert of this change

        Related details

        Attention set is empty
        Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: revert
        satisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages