cppgc: Allocation cleanups
Bug: chromium:1056170 Change-Id: I99d073e268f5779f0985d6197432c50036060b60 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2192663 Commit-Queue: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Anton Bikineev <bikineev@chromium.org> Reviewed-by: Omer Katz <omerkatz@chromium.org> Cr-Commit-Position: refs/heads/master@{#67713}
This commit is contained in:
parent
6a6c151dda
commit
d65ea662c5
@ -9,7 +9,10 @@
|
||||
|
||||
namespace cppgc {
|
||||
|
||||
using CustomSpaceIndex = size_t;
|
||||
struct CustomSpaceIndex {
|
||||
CustomSpaceIndex(size_t value) : value(value) {} // NOLINT
|
||||
size_t value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Top-level base class for custom spaces. Users must inherit from CustomSpace
|
||||
|
@ -24,7 +24,7 @@ void VerifyCustomSpaces(
|
||||
// starting at 0.
|
||||
#ifdef DEBUG
|
||||
for (size_t i = 0; i < custom_spaces.size(); ++i) {
|
||||
DCHECK_EQ(i, custom_spaces[i]->GetCustomSpaceIndex());
|
||||
DCHECK_EQ(i, custom_spaces[i]->GetCustomSpaceIndex().value);
|
||||
}
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace internal {
|
||||
|
||||
void* ObjectAllocator::AllocateObject(size_t size, GCInfoIndex gcinfo) {
|
||||
const size_t allocation_size =
|
||||
RoundUp(size + sizeof(HeapObjectHeader), kAllocationGranularity);
|
||||
RoundUp<kAllocationGranularity>(size + sizeof(HeapObjectHeader));
|
||||
const RawHeap::RegularSpaceType type =
|
||||
GetInitialSpaceIndexForSize(allocation_size);
|
||||
return AllocateObjectOnSpace(NormalPageSpace::From(raw_heap_->Space(type)),
|
||||
@ -28,11 +28,9 @@ void* ObjectAllocator::AllocateObject(size_t size, GCInfoIndex gcinfo) {
|
||||
void* ObjectAllocator::AllocateObject(size_t size, GCInfoIndex gcinfo,
|
||||
CustomSpaceIndex space_index) {
|
||||
const size_t allocation_size =
|
||||
RoundUp(size + sizeof(HeapObjectHeader), kAllocationGranularity);
|
||||
const size_t internal_space_index =
|
||||
raw_heap_->SpaceIndexForCustomSpace(space_index);
|
||||
RoundUp<kAllocationGranularity>(size + sizeof(HeapObjectHeader));
|
||||
return AllocateObjectOnSpace(
|
||||
NormalPageSpace::From(raw_heap_->Space(internal_space_index)),
|
||||
NormalPageSpace::From(raw_heap_->CustomSpace(space_index)),
|
||||
allocation_size, gcinfo);
|
||||
}
|
||||
|
||||
|
@ -64,14 +64,28 @@ class V8_EXPORT_PRIVATE RawHeap final {
|
||||
BaseSpace* Space(RegularSpaceType type) {
|
||||
const size_t index = static_cast<size_t>(type);
|
||||
DCHECK_GT(kNumberOfRegularSpaces, index);
|
||||
BaseSpace* space = spaces_[index].get();
|
||||
DCHECK(space);
|
||||
return space;
|
||||
return Space(index);
|
||||
}
|
||||
const BaseSpace* Space(RegularSpaceType space) const {
|
||||
return const_cast<RawHeap&>(*this).Space(space);
|
||||
}
|
||||
|
||||
BaseSpace* CustomSpace(CustomSpaceIndex space_index) {
|
||||
return Space(SpaceIndexForCustomSpace(space_index));
|
||||
}
|
||||
const BaseSpace* CustomSpace(CustomSpaceIndex space_index) const {
|
||||
return const_cast<RawHeap&>(*this).CustomSpace(space_index);
|
||||
}
|
||||
|
||||
Heap* heap() { return main_heap_; }
|
||||
const Heap* heap() const { return main_heap_; }
|
||||
|
||||
private:
|
||||
size_t SpaceIndexForCustomSpace(CustomSpaceIndex space_index) const {
|
||||
DCHECK_LT(space_index.value, spaces_.size() - kNumberOfRegularSpaces);
|
||||
return kNumberOfRegularSpaces + space_index.value;
|
||||
}
|
||||
|
||||
BaseSpace* Space(size_t space_index) {
|
||||
DCHECK_GT(spaces_.size(), space_index);
|
||||
BaseSpace* space = spaces_[space_index].get();
|
||||
@ -82,15 +96,6 @@ class V8_EXPORT_PRIVATE RawHeap final {
|
||||
return const_cast<RawHeap&>(*this).Space(space_index);
|
||||
}
|
||||
|
||||
size_t SpaceIndexForCustomSpace(CustomSpaceIndex space_index) const {
|
||||
DCHECK_LT(space_index, spaces_.size() - kNumberOfRegularSpaces);
|
||||
return kNumberOfRegularSpaces + space_index;
|
||||
}
|
||||
|
||||
Heap* heap() { return main_heap_; }
|
||||
const Heap* heap() const { return main_heap_; }
|
||||
|
||||
private:
|
||||
Heap* main_heap_;
|
||||
Spaces spaces_;
|
||||
};
|
||||
|
@ -46,7 +46,6 @@ TEST_F(PageTest, SpaceIndexing) {
|
||||
RawHeap& heap = GetRawHeap();
|
||||
size_t space = 0u;
|
||||
for (const auto& ptr : heap) {
|
||||
EXPECT_EQ(ptr.get(), heap.Space(space));
|
||||
EXPECT_EQ(&heap, ptr.get()->raw_heap());
|
||||
EXPECT_EQ(space, ptr->index());
|
||||
++space;
|
||||
|
Loading…
Reference in New Issue
Block a user