Remove unused MOA code.

PiperOrigin-RevId: 494296827
pull/11231/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 5bac838d48
commit e5b3edd0ed
  1. 16
      src/google/protobuf/arena.cc
  2. 16
      src/google/protobuf/arena.h
  3. 24
      src/google/protobuf/arena_impl.h
  4. 8
      src/google/protobuf/compiler/cpp/string_field.cc
  5. 7
      src/google/protobuf/generated_message_reflection.cc
  6. 4
      src/google/protobuf/map.h
  7. 10
      src/google/protobuf/repeated_field.h
  8. 10
      src/google/protobuf/repeated_ptr_field.h

@ -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

@ -505,14 +505,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
return InternalHelper<T>::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);
}

@ -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>{},
"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) {

@ -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");
}

@ -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();
}

@ -1227,9 +1227,7 @@ class Map {
key_type>::type;
Node* node = this->template Alloc<Node>(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<Key*>(&node->kv.first),
this->alloc_.arena(),
static_cast<TypeToInit>(std::forward<K>(k)));

@ -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.
//

@ -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_; }

Loading…
Cancel
Save