gcc/libstdc++-v3/include
Jonathan Wakely 2ce0f5185b libstdc++: Reduce memory usage in std::stacktrace::current
This adds an alternative callback for use in the overload of
basic_stacktrace::current that takes a max_depth parameter. The new
callback will not allow the container to grow past the initial capacity,
which is set to the specified maximum depth.  This avoids allocating
memory for hundreds of frames only to discard them again because of a
small maximum depth limit.

For larger maximum depths the normal callback is used, with a smaller
initial capacity that can grow as needed. The container will be resized
to the given max depth after the entire backtrace has been produced
(relying on the fact that std::stacktrace_entry objects are trivially
destructible to elide their destruction).

Currently the value for "larger" limits is 128, so a max depth <= 128
will allocate capacity for exactly that many frames. A larger max depth
(or an unspecified max depth) will use an initial capacity of 64 frames
and grow as needed. Since each frame is only a uintptr_t value it might
be reasonable to increase the first value so that memory usage can be
capped for larger maximum depths.

This change also delays the creation of the libbacktrace state until we
actually need it, so that the state is not created if allocation fails.

libstdc++-v3/ChangeLog:

	* include/std/stacktrace (basic_stacktrace::current): Replace
	calls to _M_reserve and _S_curr_cb with call to _M_prepare.
	Check return value of backtrace_simple when max depth given.
	(basic_stacktrace::_M_reserve): Remove.
	(basic_stacktrace::_S_curr_cb): Remove.
	(basic_stacktrace::_M_prepare(size_type)): New function to
	reserve initial capacity and return callback.
	(basic_stacktrace::_Impl::_M_allocate): Remove check for 0 < n
	and remove redundant zeroing of _M_frames and _M_capacity.
	(basic_stacktrace::_Impl::_M_push_back): Add [[unlikely]]
	attribute. Assign _Impl instead of swapping.
	* testsuite/19_diagnostics/stacktrace/current.cc: New test.
2022-04-12 22:38:31 +01:00
..
backward libstdc++: Add attribute to features deprecated in C++17 [PR91260] 2022-01-14 11:27:50 +00:00
bits libstdc++: Fix filenames in Doxygen @file comments 2022-04-01 11:34:43 +01:00
c
c_compatibility libstdc++: Add atomic_fetch_xor to <stdatomic.h> 2022-02-10 13:01:10 +00:00
c_global libstdc++: Ensure all feature test macros have type long [PR87193] 2022-01-21 16:07:34 +00:00
c_std libstdc++: Declare std::c8rtomb and std::mbrtoc8 if provided by the C library 2022-01-18 16:31:02 +00:00
debug
decimal
experimental libstdc++: Move Filesystem TS path definitions out of class body 2022-04-11 15:53:22 +01:00
ext libstdc++: Add attribute to features deprecated in C++17 [PR91260] 2022-01-14 11:27:50 +00:00
parallel
precompiled libstdc++: Define std::expected for C++23 (P0323R12) 2022-03-27 18:50:31 +01:00
pstl libstdc++: Reduce header dependencies from PSTL headers [PR92546] 2022-03-18 10:16:36 +00:00
std libstdc++: Reduce memory usage in std::stacktrace::current 2022-04-12 22:38:31 +01:00
tr1 libstdc++: Add attribute to features deprecated in C++17 [PR91260] 2022-01-14 11:27:50 +00:00
tr2
Makefile.am libstdc++: Define std::expected for C++23 (P0323R12) 2022-03-27 18:50:31 +01:00
Makefile.in libstdc++: Define std::expected for C++23 (P0323R12) 2022-03-27 18:50:31 +01:00