Skip to content

Commit deb0813

Browse files
LeszekSwirskiCommit Bot
authored andcommitted
[heap] Add proper rebind support to StrongRootBlockAllocator
MSVC's STL in debug mode rebinds the allocator passed to vectors to allocate helper structures, so we need StrongRootBlockAllocator to have proper rebind support rather than assuming it always rebinds to Address. Bug: v8:11241 Change-Id: I15688e43fe2c71ec4ff0c287a03e36ca57427417 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2622915 Auto-Submit: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/master@{#72060}
1 parent e61272a commit deb0813

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/heap/heap.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,10 +2649,7 @@ class StrongRootBlockAllocator {
26492649
using size_type = size_t;
26502650
using difference_type = ptrdiff_t;
26512651
template <class U>
2652-
struct rebind {
2653-
STATIC_ASSERT((std::is_same<Address, U>::value));
2654-
using other = StrongRootBlockAllocator;
2655-
};
2652+
struct rebind;
26562653

26572654
explicit StrongRootBlockAllocator(Heap* heap) : heap_(heap) {}
26582655

@@ -2663,6 +2660,23 @@ class StrongRootBlockAllocator {
26632660
Heap* heap_;
26642661
};
26652662

2663+
// Rebinding to Address gives another StrongRootBlockAllocator.
2664+
template <>
2665+
struct StrongRootBlockAllocator::rebind<Address> {
2666+
using other = StrongRootBlockAllocator;
2667+
};
2668+
2669+
// Rebinding to something other than Address gives a std::allocator that
2670+
// is copy-constructable from StrongRootBlockAllocator.
2671+
template <class U>
2672+
struct StrongRootBlockAllocator::rebind {
2673+
class other : public std::allocator<U> {
2674+
public:
2675+
// NOLINTNEXTLINE
2676+
other(const StrongRootBlockAllocator&) {}
2677+
};
2678+
};
2679+
26662680
} // namespace internal
26672681
} // namespace v8
26682682

0 commit comments

Comments
 (0)