Protozero: fall back on the heap when nesting too deep
This CL lifts the historic restriction on the max nesting
of protozero messages. It does so by removing the
stack-based |nested_message_arena_| hack and instead using
an explicit MessgeArena object that is responsible for
memory ownership of protozero Message objects.
The difference between root and nested messages is made
explicit by introducing RootMessage<T> (as opposite to
just Message<T>), which owns the storage for all the
submessages.
This CL still maintains the property of "(mostly) zero
allocations": the MessageArena 0th block is allocated
when the TraceWriterImpl is constructed an in most cases
never expanded. It gets expanded allocating new blocks
only when writing a message that is nested too deep.
Turns out the change is quite self-contained as most
tracing obtains Message objects via
TraceWriter::NewTracePacket(). The places that require
code changes are very limited.
Bug: 163125063
Bug: 125322557
Bug: crbug.com/960303
Change-Id: I8d7a313d81d0c407ef2c549ff5bc9febb30a54a0
diff --git a/BUILD b/BUILD
index 576dc0e..0ce0dc9 100644
--- a/BUILD
+++ b/BUILD
@@ -413,10 +413,12 @@
"include/perfetto/protozero/cpp_message_obj.h",
"include/perfetto/protozero/field.h",
"include/perfetto/protozero/message.h",
+ "include/perfetto/protozero/message_arena.h",
"include/perfetto/protozero/message_handle.h",
"include/perfetto/protozero/packed_repeated_fields.h",
"include/perfetto/protozero/proto_decoder.h",
"include/perfetto/protozero/proto_utils.h",
+ "include/perfetto/protozero/root_message.h",
"include/perfetto/protozero/scattered_heap_buffer.h",
"include/perfetto/protozero/scattered_stream_null_delegate.h",
"include/perfetto/protozero/scattered_stream_writer.h",
@@ -665,6 +667,7 @@
srcs = [
"src/protozero/field.cc",
"src/protozero/message.cc",
+ "src/protozero/message_arena.cc",
"src/protozero/message_handle.cc",
"src/protozero/packed_repeated_fields.cc",
"src/protozero/proto_decoder.cc",