From ae41e72dd3479879dc0d546bba651076efcecc74 Mon Sep 17 00:00:00 2001 From: theodorerose Date: Wed, 22 Jun 2022 14:49:23 +0000 Subject: [PATCH] Sync from Piper @456510836 PROTOBUF_SYNC_PIPER --- docs/options.md | 4 ++++ src/google/protobuf/arena.cc | 2 +- src/google/protobuf/arenaz_sampler.cc | 12 ++++++------ src/google/protobuf/arenaz_sampler.h | 8 ++++---- src/google/protobuf/arenaz_sampler_test.cc | 11 ++++++----- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/options.md b/docs/options.md index 62a32d37d5..2175c2619e 100644 --- a/docs/options.md +++ b/docs/options.md @@ -332,3 +332,7 @@ with info about your project (name and website) so we can add an entry for you. 1. Ballerina gRPC * Website: https://github.com/ballerina-platform/module-ballerina-grpc * Extension: 1148 + +1. Protoc-gen-referential-integrity + * Website: https://github.com/ComponentCorp/protoc-gen-referential-integrity + * Extension: 1149 diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index 38ea055310..3bcf7eb5f0 100644 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -161,7 +161,7 @@ void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy) { // regular add. auto relaxed = std::memory_order_relaxed; space_allocated_.store(space_allocated_.load(relaxed) + mem.size, relaxed); - ThreadSafeArenaStats::RecordAllocateStats(arena_stats_, /*requested=*/n, + ThreadSafeArenaStats::RecordAllocateStats(arena_stats_, /*used=*/used, /*allocated=*/mem.size, wasted); head_ = new (mem.ptr) Block{head_, mem.size}; ptr_ = head_->Pointer(kBlockHeaderSize); diff --git a/src/google/protobuf/arenaz_sampler.cc b/src/google/protobuf/arenaz_sampler.cc index d78d9fed2f..965a2de69e 100644 --- a/src/google/protobuf/arenaz_sampler.cc +++ b/src/google/protobuf/arenaz_sampler.cc @@ -70,7 +70,7 @@ ThreadSafeArenaStats::~ThreadSafeArenaStats() = default; void ThreadSafeArenaStats::PrepareForSampling(int64_t stride) { num_allocations.store(0, std::memory_order_relaxed); num_resets.store(0, std::memory_order_relaxed); - bytes_requested.store(0, std::memory_order_relaxed); + bytes_used.store(0, std::memory_order_relaxed); bytes_allocated.store(0, std::memory_order_relaxed); bytes_wasted.store(0, std::memory_order_relaxed); max_bytes_allocated.store(0, std::memory_order_relaxed); @@ -90,17 +90,17 @@ void RecordResetSlow(ThreadSafeArenaStats* info) { if (max_bytes < allocated_bytes) { info->max_bytes_allocated.store(allocated_bytes); } - info->bytes_requested.store(0, std::memory_order_relaxed); + info->bytes_used.store(0, std::memory_order_relaxed); info->bytes_allocated.store(0, std::memory_order_relaxed); - info->bytes_wasted.fetch_add(0, std::memory_order_relaxed); - info->num_allocations.fetch_add(0, std::memory_order_relaxed); + info->bytes_wasted.store(0, std::memory_order_relaxed); + info->num_allocations.store(0, std::memory_order_relaxed); info->num_resets.fetch_add(1, std::memory_order_relaxed); } -void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t requested, +void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t used, size_t allocated, size_t wasted) { info->num_allocations.fetch_add(1, std::memory_order_relaxed); - info->bytes_requested.fetch_add(requested, std::memory_order_relaxed); + info->bytes_used.fetch_add(used, std::memory_order_relaxed); info->bytes_allocated.fetch_add(allocated, std::memory_order_relaxed); info->bytes_wasted.fetch_add(wasted, std::memory_order_relaxed); const uint64_t tid = 1ULL << (GetCachedTID() % 63); diff --git a/src/google/protobuf/arenaz_sampler.h b/src/google/protobuf/arenaz_sampler.h index 31c178a009..31097ec169 100644 --- a/src/google/protobuf/arenaz_sampler.h +++ b/src/google/protobuf/arenaz_sampler.h @@ -46,7 +46,7 @@ namespace internal { #if defined(PROTOBUF_ARENAZ_SAMPLE) struct ThreadSafeArenaStats; void RecordResetSlow(ThreadSafeArenaStats* info); -void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t requested, +void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t used, size_t allocated, size_t wasted); // Stores information about a sampled thread safe arena. All mutations to this // *must* be made through `Record*` functions below. All reads from this *must* @@ -68,7 +68,7 @@ struct ThreadSafeArenaStats // thread-safe. std::atomic num_allocations; std::atomic num_resets; - std::atomic bytes_requested; + std::atomic bytes_used; std::atomic bytes_allocated; std::atomic bytes_wasted; // Records the largest size an arena ever had. Maintained across resets. @@ -87,10 +87,10 @@ struct ThreadSafeArenaStats static constexpr int kMaxStackDepth = 64; int32_t depth; void* stack[kMaxStackDepth]; - static void RecordAllocateStats(ThreadSafeArenaStats* info, size_t requested, + static void RecordAllocateStats(ThreadSafeArenaStats* info, size_t used, size_t allocated, size_t wasted) { if (PROTOBUF_PREDICT_TRUE(info == nullptr)) return; - RecordAllocateSlow(info, requested, allocated, wasted); + RecordAllocateSlow(info, used, allocated, wasted); } }; diff --git a/src/google/protobuf/arenaz_sampler_test.cc b/src/google/protobuf/arenaz_sampler_test.cc index 2588c04a75..6eae73c1dc 100644 --- a/src/google/protobuf/arenaz_sampler_test.cc +++ b/src/google/protobuf/arenaz_sampler_test.cc @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -86,7 +87,7 @@ TEST(ThreadSafeArenaStatsTest, PrepareForSampling) { EXPECT_EQ(info.num_allocations.load(), 0); EXPECT_EQ(info.num_resets.load(), 0); - EXPECT_EQ(info.bytes_requested.load(), 0); + EXPECT_EQ(info.bytes_used.load(), 0); EXPECT_EQ(info.bytes_allocated.load(), 0); EXPECT_EQ(info.bytes_wasted.load(), 0); EXPECT_EQ(info.max_bytes_allocated.load(), 0); @@ -94,7 +95,7 @@ TEST(ThreadSafeArenaStatsTest, PrepareForSampling) { info.num_allocations.store(1, std::memory_order_relaxed); info.num_resets.store(1, std::memory_order_relaxed); - info.bytes_requested.store(1, std::memory_order_relaxed); + info.bytes_used.store(1, std::memory_order_relaxed); info.bytes_allocated.store(1, std::memory_order_relaxed); info.bytes_wasted.store(1, std::memory_order_relaxed); info.max_bytes_allocated.store(1, std::memory_order_relaxed); @@ -102,7 +103,7 @@ TEST(ThreadSafeArenaStatsTest, PrepareForSampling) { info.PrepareForSampling(2 * kTestStride); EXPECT_EQ(info.num_allocations.load(), 0); EXPECT_EQ(info.num_resets.load(), 0); - EXPECT_EQ(info.bytes_requested.load(), 0); + EXPECT_EQ(info.bytes_used.load(), 0); EXPECT_EQ(info.bytes_allocated.load(), 0); EXPECT_EQ(info.bytes_wasted.load(), 0); EXPECT_EQ(info.max_bytes_allocated.load(), 0); @@ -117,7 +118,7 @@ TEST(ThreadSafeArenaStatsTest, RecordAllocateSlow) { RecordAllocateSlow(&info, /*requested=*/100, /*allocated=*/128, /*wasted=*/0); EXPECT_EQ(info.num_allocations.load(), 1); EXPECT_EQ(info.num_resets.load(), 0); - EXPECT_EQ(info.bytes_requested.load(), 100); + EXPECT_EQ(info.bytes_used.load(), 100); EXPECT_EQ(info.bytes_allocated.load(), 128); EXPECT_EQ(info.bytes_wasted.load(), 0); EXPECT_EQ(info.max_bytes_allocated.load(), 0); @@ -125,7 +126,7 @@ TEST(ThreadSafeArenaStatsTest, RecordAllocateSlow) { /*wasted=*/28); EXPECT_EQ(info.num_allocations.load(), 2); EXPECT_EQ(info.num_resets.load(), 0); - EXPECT_EQ(info.bytes_requested.load(), 200); + EXPECT_EQ(info.bytes_used.load(), 200); EXPECT_EQ(info.bytes_allocated.load(), 384); EXPECT_EQ(info.bytes_wasted.load(), 28); EXPECT_EQ(info.max_bytes_allocated.load(), 0);