Commit d0c5b343 authored by Omer Katz's avatar Omer Katz Committed by V8 LUCI CQ

cppgc: Move CollectCustomSpaceStatisticsAtLastGC to intenral::CppHeap

Ulan's CL implemented CollectCustomSpaceStatisticsAtLastGC in CppHeap.
All our other methods just delegate to internal::CppHeap. This CL moves
CollectCustomSpaceStatisticsAtLastGC as well to align it with the rest
of our methods.

Bug: chromium:1056170
Change-Id: I4b92d1779247fe26abcb8c6754f2abbc0d80adbd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2882802
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74469}
parent 1ced5f83
......@@ -69,20 +69,8 @@ cppgc::HeapStatistics CppHeap::CollectStatistics(
void CppHeap::CollectCustomSpaceStatisticsAtLastGC(
std::vector<cppgc::CustomSpaceIndex> custom_spaces,
std::unique_ptr<CustomSpaceStatisticsReceiver> receiver) {
cppgc::internal::HeapBase& heap_base =
internal::CppHeap::From(this)->AsBase();
// TODO(1181269): Use tasks to help the sweeper incrementally instead of
// finalizing atomically.
heap_base.sweeper().FinishIfRunning();
for (auto custom_space_index : custom_spaces) {
const cppgc::internal::BaseSpace* space =
heap_base.raw_heap().CustomSpace(custom_space_index);
size_t allocated_bytes = std::accumulate(
space->begin(), space->end(), 0, [](size_t sum, auto* page) {
return sum + page->AllocatedBytesAtLastGC();
});
receiver->AllocatedBytes(custom_space_index, allocated_bytes);
}
return internal::CppHeap::From(this)->CollectCustomSpaceStatisticsAtLastGC(
std::move(custom_spaces), std::move(receiver));
}
void CppHeap::EnableDetachedGarbageCollectionsForTesting() {
......@@ -503,5 +491,22 @@ void CppHeap::FinalizeIncrementalGarbageCollectionForTesting(
sweeper_.FinishIfRunning();
}
void CppHeap::CollectCustomSpaceStatisticsAtLastGC(
std::vector<cppgc::CustomSpaceIndex> custom_spaces,
std::unique_ptr<CustomSpaceStatisticsReceiver> receiver) {
// TODO(1181269): Use tasks to help the sweeper incrementally instead of
// finalizing atomically.
sweeper().FinishIfRunning();
for (auto custom_space_index : custom_spaces) {
const cppgc::internal::BaseSpace* space =
raw_heap().CustomSpace(custom_space_index);
size_t allocated_bytes = std::accumulate(
space->begin(), space->end(), 0, [](size_t sum, auto* page) {
return sum + page->AllocatedBytesAtLastGC();
});
receiver->AllocatedBytes(custom_space_index, allocated_bytes);
}
}
} // namespace internal
} // namespace v8
......@@ -60,6 +60,10 @@ class V8_EXPORT_PRIVATE CppHeap final
void CollectGarbageForTesting(
cppgc::internal::GarbageCollector::Config::StackState);
void CollectCustomSpaceStatisticsAtLastGC(
std::vector<cppgc::CustomSpaceIndex>,
std::unique_ptr<CustomSpaceStatisticsReceiver>);
// v8::EmbedderHeapTracer interface.
void RegisterV8References(
const std::vector<std::pair<void*, void*> >& embedder_fields) final;
......
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