Skip to content

Commit

Permalink
[cppgc] Enable HeapTest.CollectNodeAndCssStatistics for the library
Browse files Browse the repository at this point in the history
This implements the ThreadState::CollectNodeAndCssStatistics wrapper
using a new CppHeap API.

Bug: 1181269
Change-Id: I103384c34f3bd1ef0760385649061d41cdc95292
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2879989
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#880760}
  • Loading branch information
ulan authored and Chromium LUCI CQ committed May 9, 2021
1 parent c80501e commit 6fa3441
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
3 changes: 0 additions & 3 deletions third_party/blink/renderer/platform/heap/test/heap_test.cc
Expand Up @@ -3248,8 +3248,6 @@ struct SpaceTrait<blink::FakeNode> {
namespace blink {
#endif

// TODO(1181269): Enable for the library once implemented.
#if !BUILDFLAG(USE_V8_OILPAN)
TEST_F(HeapTest, CollectNodeAndCssStatistics) {
PreciselyCollectGarbage();
size_t node_bytes_before, css_bytes_before;
Expand All @@ -3274,6 +3272,5 @@ TEST_F(HeapTest, CollectNodeAndCssStatistics) {
EXPECT_LE(node_bytes_before + sizeof(FakeNode), node_bytes_after);
EXPECT_LE(css_bytes_before + sizeof(FakeCSSValue), css_bytes_after);
}
#endif

} // namespace blink
Expand Up @@ -204,11 +204,49 @@ void ThreadState::CollectAllGarbageForTesting(BlinkGC::StackState stack_state) {
}
}

namespace {

class CustomSpaceStatisticsReceiverImpl final
: public v8::CustomSpaceStatisticsReceiver {
public:
explicit CustomSpaceStatisticsReceiverImpl(
base::OnceCallback<void(size_t allocated_node_bytes,
size_t allocated_css_bytes)> callback)
: callback_(std::move(callback)) {}

~CustomSpaceStatisticsReceiverImpl() final {
DCHECK(node_bytes_.has_value());
DCHECK(css_bytes_.has_value());
std::move(callback_).Run(*node_bytes_, *css_bytes_);
}

void AllocatedBytes(cppgc::CustomSpaceIndex space_index, size_t bytes) final {
if (space_index.value == NodeSpace::kSpaceIndex.value) {
node_bytes_ = bytes;
} else {
DCHECK_EQ(space_index.value, CSSValueSpace::kSpaceIndex.value);
css_bytes_ = bytes;
}
}

private:
base::OnceCallback<void(size_t allocated_node_bytes,
size_t allocated_css_bytes)>
callback_;
base::Optional<size_t> node_bytes_;
base::Optional<size_t> css_bytes_;
};

} // anonymous namespace

void ThreadState::CollectNodeAndCssStatistics(
base::OnceCallback<void(size_t allocated_node_bytes,
size_t allocated_css_bytes)> callback) {
// TODO(1181269): Implement.
std::move(callback).Run(0u, 0u);
std::vector<cppgc::CustomSpaceIndex> spaces{NodeSpace::kSpaceIndex,
CSSValueSpace::kSpaceIndex};
cpp_heap().CollectCustomSpaceStatisticsAtLastGC(
std::move(spaces),
std::make_unique<CustomSpaceStatisticsReceiverImpl>(std::move(callback)));
}

void ThreadState::EnableDetachedGarbageCollectionsForTesting() {
Expand Down

0 comments on commit 6fa3441

Please sign in to comment.