Commit 4c2177f5 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

fix Arena bytes-used accounting across clear

Summary: Fix `Arena` bytes-used accounting across calls to member `clear` after a sequence of all-large allocations.

Reviewed By: luciang

Differential Revision: D25656875

fbshipit-source-id: e79aca5f58b61bf1bd4790f8badd0dad6063a6ed
parent c55c0192
...@@ -121,11 +121,11 @@ class Arena { ...@@ -121,11 +121,11 @@ class Arena {
void merge(Arena&& other); void merge(Arena&& other);
void clear() { void clear() {
bytesUsed_ = 0;
freeLargeBlocks(); // We don't reuse large blocks freeLargeBlocks(); // We don't reuse large blocks
if (blocks_.empty()) { if (blocks_.empty()) {
return; return;
} }
bytesUsed_ = 0;
currentBlock_ = blocks_.begin(); currentBlock_ = blocks_.begin();
char* start = currentBlock_->start(); char* start = currentBlock_->start();
ptr_ = start; ptr_ = start;
......
...@@ -222,6 +222,17 @@ TEST(Arena, Clear) { ...@@ -222,6 +222,17 @@ TEST(Arena, Clear) {
} }
} }
TEST(Arena, ClearAfterLarge) {
constexpr size_t blockSize = 1024;
constexpr size_t mult = 10;
SysArena arena(blockSize);
EXPECT_EQ(0, arena.bytesUsed());
arena.allocate(blockSize * mult);
EXPECT_EQ(blockSize * mult, arena.bytesUsed());
arena.clear();
EXPECT_EQ(0, arena.bytesUsed());
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
......
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