diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index c47cfbf85a..8479f5dd00 100644 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -461,12 +461,6 @@ ABSL_CONST_INIT PROTOBUF_THREAD_LOCAL ThreadSafeArena::ThreadSafeArena() : first_arena_(*this) { Init(); } -// Constructor solely used by message-owned arena. -ThreadSafeArena::ThreadSafeArena(internal::MessageOwned) - : tag_and_id_(kMessageOwnedArena), first_arena_(*this) { - Init(); -} - ThreadSafeArena::ThreadSafeArena(char* mem, size_t size) : first_arena_(FirstSerialArena{}, FirstBlock(mem, size), *this) { Init(); @@ -608,16 +602,10 @@ void ThreadSafeArena::AddSerialArena(void* id, SerialArena* serial) { } void ThreadSafeArena::Init() { - const bool message_owned = IsMessageOwned(); - if (!message_owned) { - // Message-owned arenas bypass thread cache and do not need life cycle ID. - tag_and_id_ = GetNextLifeCycleId(); - } else { - GOOGLE_DCHECK_EQ(tag_and_id_, kMessageOwnedArena); - } + // Message-owned arenas bypass thread cache and do not need life cycle ID. + tag_and_id_ = GetNextLifeCycleId(); arena_stats_ = Sample(); head_.store(SentrySerialArenaChunk(), std::memory_order_relaxed); - GOOGLE_DCHECK_EQ(message_owned, IsMessageOwned()); first_owner_ = &thread_cache(); // Record allocation for the first block that was either user-provided or diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index ee41320288..d17f63f756 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -505,14 +505,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { return InternalHelper::GetArenaForAllocation(p); } - // Creates message-owned arena. For internal use only. - static Arena* InternalCreateMessageOwnedArena() { - return new Arena(internal::MessageOwned{}); - } - - // Checks whether this arena is message-owned. For internal use only. - bool InternalIsMessageOwnedArena() { return IsMessageOwned(); } - // Helper typetraits that indicates support for arenas in a type T at compile // time. This is public only to allow construction of higher-level templated // utilities. @@ -534,14 +526,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { private: internal::ThreadSafeArena impl_; - // Constructor solely used by message-owned arena. - inline Arena(internal::MessageOwned) : impl_(internal::MessageOwned{}) {} - - // Checks whether this arena is message-owned. - PROTOBUF_ALWAYS_INLINE bool IsMessageOwned() const { - return impl_.IsMessageOwned(); - } - void ReturnArrayMemory(void* p, size_t size) { impl_.ReturnArrayMemory(p, size); } diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h index a9ca93ba99..a75f233a0f 100644 --- a/src/google/protobuf/arena_impl.h +++ b/src/google/protobuf/arena_impl.h @@ -387,13 +387,6 @@ class PROTOBUF_EXPORT SerialArena { static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(ArenaBlock)); }; -// Tag type used to invoke the constructor of message-owned arena. -// Only message-owned arenas use this constructor for creation. -// Such constructors are internal implementation details of the library. -struct MessageOwned { - explicit MessageOwned() = default; -}; - // This class provides the core Arena memory allocation library. Different // implementations only need to implement the public interface below. // Arena is not a template type as that would only be useful if all protos @@ -404,9 +397,6 @@ class PROTOBUF_EXPORT ThreadSafeArena { public: ThreadSafeArena(); - // Constructor solely used by message-owned arena. - explicit ThreadSafeArena(internal::MessageOwned); - ThreadSafeArena(char* mem, size_t size); explicit ThreadSafeArena(void* mem, size_t size, @@ -466,11 +456,6 @@ class PROTOBUF_EXPORT ThreadSafeArena { // Add object pointer and cleanup function pointer to the list. void AddCleanup(void* elem, void (*cleanup)(void*)); - // Checks whether this arena is message-owned. - PROTOBUF_ALWAYS_INLINE bool IsMessageOwned() const { - return tag_and_id_ & kMessageOwnedArena; - } - private: friend class ArenaBenchmark; friend class TcParser; @@ -515,9 +500,6 @@ class PROTOBUF_EXPORT ThreadSafeArena { // user-provided initial block. SerialArena first_arena_; - // The LSB of tag_and_id_ indicates if the arena is message-owned. - enum : uint64_t { kMessageOwnedArena = 1 }; - static_assert(std::is_trivially_destructible{}, "SerialArena needs to be trivially destructible."); @@ -532,10 +514,8 @@ class PROTOBUF_EXPORT ThreadSafeArena { void CleanupList(); inline void CacheSerialArena(SerialArena* serial) { - if (!IsMessageOwned()) { - thread_cache().last_serial_arena = serial; - thread_cache().last_lifecycle_id_seen = tag_and_id_; - } + thread_cache().last_serial_arena = serial; + thread_cache().last_lifecycle_id_seen = tag_and_id_; } PROTOBUF_NDEBUG_INLINE bool GetSerialArenaFast(SerialArena** arena) { diff --git a/src/google/protobuf/compiler/cpp/string_field.cc b/src/google/protobuf/compiler/cpp/string_field.cc index 3446285ad8..0ddb8586dc 100644 --- a/src/google/protobuf/compiler/cpp/string_field.cc +++ b/src/google/protobuf/compiler/cpp/string_field.cc @@ -116,9 +116,7 @@ void StringFieldGenerator::GeneratePrivateMembers(io::Printer* printer) const { format("::$proto_ns$::internal::ArenaStringPtr $name$_;\n"); } else { // Skips the automatic destruction; rather calls it explicitly if - // allocating arena is null. This is required to support message-owned - // arena (go/path-to-arenas) where a root proto is destroyed but - // InlinedStringField may have arena-allocated memory. + // allocating arena is null. format("::$proto_ns$::internal::InlinedStringField $name$_;\n"); } } @@ -497,9 +495,7 @@ void StringFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { return; } // Explicitly calls ~InlinedStringField as its automatic call is disabled. - // Destructor has been implicitly skipped as a union, and even the - // message-owned arena is enabled, arena could still be missing for - // Arena::CreateMessage(nullptr). + // Destructor has been implicitly skipped as a union. GOOGLE_ABSL_DCHECK(!ShouldSplit(descriptor_, options_)); format("$field$.~InlinedStringField();\n"); } diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index dc6462bb2c..392fe9f8b1 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -342,13 +342,6 @@ size_t Reflection::SpaceUsedLong(const Message& message) const { total_size += GetUnknownFields(message).SpaceUsedExcludingSelfLong(); - // If this message owns an arena, add any unused space that's been allocated. - auto* arena = Arena::InternalGetArenaForAllocation(&message); - if (arena != nullptr && Arena::InternalGetOwningArena(&message) == nullptr && - arena->InternalIsMessageOwnedArena()) { - total_size += arena->SpaceAllocated() - arena->SpaceUsed(); - } - if (schema_.HasExtensionSet()) { total_size += GetExtensionSet(message).SpaceUsedExcludingSelfLong(); } diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index f03f9e6025..43cb58037b 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -1227,9 +1227,7 @@ class Map { key_type>::type; Node* node = this->template Alloc(1); // Even when arena is nullptr, CreateInArenaStorage is still used to - // ensure the arena of submessage will be consistent. Otherwise, - // submessage may have its own arena when message-owned arena is enabled. - // Note: This only works if `Key` is not arena constructible. + // ensure the arena of submessage will be consistent. Arena::CreateInArenaStorage(const_cast(&node->kv.first), this->alloc_.arena(), static_cast(std::forward(k))); diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index da2dfcbf7b..d08628a7b8 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -288,15 +288,7 @@ class RepeatedField final { iterator erase(const_iterator first, const_iterator last); // Gets the Arena on which this RepeatedField stores its elements. - // Message-owned arenas are not exposed by this method, which will return - // nullptr for messages owned by MOAs. - inline Arena* GetArena() const { - Arena* arena = GetOwningArena(); - if (arena == nullptr || arena->InternalIsMessageOwnedArena()) { - return nullptr; - } - return arena; - } + inline Arena* GetArena() const { return GetOwningArena(); } // For internal use only. // diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index f8019312c7..886cf40b05 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -640,15 +640,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { } // Gets the Arena on which this RepeatedPtrField stores its elements. - // Message-owned arenas are not exposed by this method, which will return - // nullptr for messages owned by MOAs. - inline Arena* GetArena() const { - Arena* arena = GetOwningArena(); - if (arena == nullptr || arena->InternalIsMessageOwnedArena()) { - return nullptr; - } - return arena; - } + inline Arena* GetArena() const { return GetOwningArena(); } protected: inline Arena* GetOwningArena() const { return arena_; }