cppgc: Fix allocated_memory_size()

Bug: chromium:1056170
Change-Id: I4b43b78be23b8220b89f1ee5177f6b9b3c18146d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2764748
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73452}
This commit is contained in:
Omer Katz 2021-03-16 19:37:16 +01:00 committed by Commit Bot
parent 0b56c19165
commit c764215ebc
2 changed files with 9 additions and 1 deletions

View File

@ -224,7 +224,7 @@ void StatsCollector::NotifySweepingCompleted() {
}
size_t StatsCollector::allocated_memory_size() const {
return memory_allocated_bytes_;
return memory_allocated_bytes_ - memory_freed_bytes_since_end_of_marking_;
}
size_t StatsCollector::allocated_object_size() const {

View File

@ -227,5 +227,13 @@ TEST_F(StatsCollectorTest, ObserverTriggersGC) {
stats.UnregisterObserver(&mock_observer);
}
TEST_F(StatsCollectorTest, AllocatedMemorySize) {
EXPECT_EQ(0u, stats.allocated_memory_size());
stats.NotifyAllocatedMemory(1024);
EXPECT_EQ(1024u, stats.allocated_memory_size());
stats.NotifyFreedMemory(1024);
EXPECT_EQ(0u, stats.allocated_memory_size());
}
} // namespace internal
} // namespace cppgc