Commit a5d29c16 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap: Untangle HeapAllocator object size computation from Oilpan

- Move kMaxHeapObjectSize to HeapAllocator as Oilpan has no internal
  restrictions on object sizing other than ultimately running OOM.
- Size quantization for Oilpan can just return whatever is required to
  match capacity needs. Internally, sizes may be padded and aligned
  accordingly.

Bug: 1056170
Change-Id: I5c833a2b6cb5354bd24b117406e68fe18e622f71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551121Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829657}
parent 5d65e587
......@@ -68,6 +68,10 @@ class PLATFORM_EXPORT HeapAllocator {
using Visitor = blink::Visitor;
static constexpr bool kIsGarbageCollected = true;
// See wtf/size_t.h for details.
static constexpr size_t kMaxHeapObjectSizeLog2 = 27;
static constexpr size_t kMaxHeapObjectSize = 1 << kMaxHeapObjectSizeLog2;
template <typename T>
static size_t MaxElementCountInBackingStore() {
return kMaxHeapObjectSize / sizeof(T);
......@@ -75,10 +79,12 @@ class PLATFORM_EXPORT HeapAllocator {
template <typename T>
static size_t QuantizedSize(size_t count) {
CHECK(count <= MaxElementCountInBackingStore<T>());
return ThreadHeap::AllocationSizeFromSize(count * sizeof(T)) -
sizeof(HeapObjectHeader);
CHECK_LE(count, MaxElementCountInBackingStore<T>());
// Oilpan's internal size is independent of MaxElementCountInBackingStore()
// and the required size to match capacity needs.
return count * sizeof(T);
}
template <typename T>
static T* AllocateVectorBacking(size_t size) {
return reinterpret_cast<T*>(
......
......@@ -92,8 +92,6 @@ BlinkGuardPageSize() {
static_assert(8 == sizeof(double), "We expect sizeof(double) to be 8");
constexpr size_t kAllocationGranularity = sizeof(double);
constexpr size_t kAllocationMask = kAllocationGranularity - 1;
constexpr size_t kMaxHeapObjectSizeLog2 = 27;
constexpr size_t kMaxHeapObjectSize = 1 << kMaxHeapObjectSizeLog2;
constexpr size_t kLargeObjectSizeThreshold = kBlinkPageSize / 2;
// A zap value used for freed memory that is allowed to be added to the free
......
......@@ -2191,7 +2191,7 @@ TEST_F(HeapTest, MAYBE_LargeHashMap) {
// Try to allocate a HashTable larger than kMaxHeapObjectSize
// (crbug.com/597953).
wtf_size_t size = kMaxHeapObjectSize /
wtf_size_t size = HeapAllocator::kMaxHeapObjectSize /
sizeof(HeapHashMap<int, Member<IntWrapper>>::ValueType);
Persistent<HeapHashMap<int, Member<IntWrapper>>> map =
MakeGarbageCollected<HeapHashMap<int, Member<IntWrapper>>>();
......@@ -2204,7 +2204,8 @@ TEST_F(HeapTest, LargeVector) {
// Try to allocate a HeapVectors larger than kMaxHeapObjectSize
// (crbug.com/597953).
const wtf_size_t size = kMaxHeapObjectSize / sizeof(Member<IntWrapper>);
const wtf_size_t size =
HeapAllocator::kMaxHeapObjectSize / sizeof(Member<IntWrapper>);
Persistent<HeapVector<Member<IntWrapper>>> vector =
MakeGarbageCollected<HeapVector<Member<IntWrapper>>>(size);
EXPECT_LE(size, vector->capacity());
......
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