gcc/libstdc++-v3/testsuite/20_util
Jonathan Wakely 1e718ec51a libstdc++: Reduce monotonic_buffer_resource overallocation [PR 96942]
The primary reason for this change is to reduce the size of buffers
allocated by std::pmr::monotonic_buffer_resource. Previously, a new
buffer would always add the size of the linked list node (11 bytes) and
then round up to the next power of two. This results in a huge increase
if the expected size of the next buffer is already a power of two. For
example, if the resource is constructed with a desired initial size of
4096 the first buffer it allocates will be std::bit_ceil(4096+11) which
is 8192.  If the user has carefully selected the initial size to match
their expected memory requirements then allocating double that amount
wastes a lot of memory.

After this patch the allocated size will be rounded up to a 64-byte
boundary, instead of to a power of two. This means for an initial size
of 4096 only 4160 bytes get allocated.

Previously only the base-2 logarithm of the size was stored, which could
be stored in a single 8-bit integer. Now that the size isn't always a
power of two we need to use more bits to store it. As the size is always
a multiple of 64 the low six bits are not needed, and so we can use the
same approach that the pool resources already use of storing the base-2
logarithm of the alignment in the low bits that are not used for the
size. To avoid code duplication, a new aligned_size<N> helper class is
introduced by this patch, which is then used by both the pool resources'
big_block type and the monotonic_buffer_resource::_Chunk type.

Originally the big_block type used two bit-fields to store the size and
alignment in the space of a single size_t member. The aligned_size type
uses a single size_t member and uses masks and bitwise operations to
manipulate the size and alignment values. This results in better code
than the old version, because the bit-fields weren't optimally ordered
for little endian architectures, so the alignment was actually stored in
the high bits, not the unused low bits, requiring additional shifts to
calculate the values. Using bitwise operations directly avoids needing
to reorder the bit-fields depending on the endianness.

While adapting the _Chunk and big_block types to use aligned_size<N> I
also added checks for size overflows (technically, unsigned wraparound).
The memory resources now ensure that when they require an allocation
that is too large to represent in size_t they will request SIZE_MAX
bytes from the upstream resource, rather than requesting a small value
that results from wrapround. The testsuite is enhanced to verify this.

libstdc++-v3/ChangeLog:

	PR libstdc++/96942
	* include/std/memory_resource (monotonic_buffer_resource::do_allocate):
	Use __builtin_expect when checking if a new buffer needs to be
	allocated from the upstream resource, and for checks for edge
	cases like zero sized buffers and allocations.
	* src/c++17/memory_resource.cc (aligned_size): New class template.
	(aligned_ceil): New helper function to round up to a given
	alignment.
	(monotonic_buffer_resource::chunk): Replace _M_size and _M_align
	with an aligned_size member. Remove _M_canary member. Change _M_next
	to pointer instead of unaligned buffer.
	(monotonic_buffer_resource::chunk::allocate): Round up to multiple
	of 64 instead of to power of two. Check for size overflow. Remove
	redundant check for minimum required alignment.
	(monotonic_buffer_resource::chunk::release): Adjust for changes
	to data members.
	(monotonic_buffer_resource::_M_new_buffer): Use aligned_ceil.
	(big_block): Replace _M_size and _M_align with aligned_size
	member.
	(big_block::big_block): Check for size overflow.
	(big_block::size, big_block::align): Adjust to use aligned_size.
	(big_block::alloc_size): Use aligned_ceil.
	(munge_options): Use aligned_ceil.
	(__pool_resource::allocate): Use big_block::align for alignment.
	* testsuite/20_util/monotonic_buffer_resource/allocate.cc: Check
	upstream resource gets expected values for impossible sizes.
	* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
	Likewise. Adjust checks for expected alignment in existing test.
2020-09-10 15:41:53 +01:00
..
add_const Update copyright years. 2020-01-01 12:51:42 +01:00
add_cv Update copyright years. 2020-01-01 12:51:42 +01:00
add_lvalue_reference Update copyright years. 2020-01-01 12:51:42 +01:00
add_pointer Update copyright years. 2020-01-01 12:51:42 +01:00
add_rvalue_reference Update copyright years. 2020-01-01 12:51:42 +01:00
add_volatile Update copyright years. 2020-01-01 12:51:42 +01:00
addressof Update copyright years. 2020-01-01 12:51:42 +01:00
align Update copyright years. 2020-01-01 12:51:42 +01:00
aligned_storage Update copyright years. 2020-01-01 12:51:42 +01:00
aligned_union Update copyright years. 2020-01-01 12:51:42 +01:00
alignment_of Update copyright years. 2020-01-01 12:51:42 +01:00
allocator libstdc++: Avoid errors in allocator's noexcept-specifier (PR 89510) 2020-04-30 16:01:43 +01:00
allocator_traits Library-side tests for parenthesized aggregate init 2020-03-31 17:07:52 +03:00
any libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
as_const libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
assume_aligned debug/96383 - emit debug info for used external functions 2020-07-31 15:19:13 +02:00
auto_ptr Update copyright years. 2020-01-01 12:51:42 +01:00
bad_function_call Update copyright years. 2020-01-01 12:51:42 +01:00
bind libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
bool_constant libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
common_reference/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
common_type/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
conditional/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
decay/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
declval/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
default_delete libstdc++: Fix failing tests 2020-06-08 21:34:46 +01:00
duration libstdc++: Constrain chrono::duration conversions [LWG 2094] 2020-09-01 18:18:26 +01:00
duration_cast libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
enable_if/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
enable_shared_from_this libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
exchange libstdc++: Do not define __cpp_lib_constexpr_algorithms in <utility> 2020-04-22 22:54:35 +01:00
extent Update copyright years. 2020-01-01 12:51:42 +01:00
forward Update copyright years. 2020-01-01 12:51:42 +01:00
from_chars libstdc++: Fix test for old string ABI 2020-07-30 16:04:59 +01:00
function Update copyright years. 2020-01-01 12:51:42 +01:00
function_objects libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
has_unique_object_representations Update copyright years. 2020-01-01 12:51:42 +01:00
has_virtual_destructor Update copyright years. 2020-01-01 12:51:42 +01:00
hash Update copyright years. 2020-01-01 12:51:42 +01:00
headers libstdc++: Require c++98_only effective target for some tests 2020-07-02 21:27:12 +01:00
in_place libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
integer_comparisons libstdc++: Fix new tests that fail for ILP32 targets 2020-02-18 18:57:30 +00:00
integer_sequence Update copyright years. 2020-01-01 12:51:42 +01:00
integral_constant Update copyright years. 2020-01-01 12:51:42 +01:00
invoke_result libstdc++: assert that type traits are not misused with incomplete types [PR 71579] 2020-08-19 12:12:40 +01:00
is_abstract Update copyright years. 2020-01-01 12:51:42 +01:00
is_aggregate libstdc++: Adjust tests that give different results in C++20 2020-07-31 17:51:00 +01:00
is_arithmetic Update copyright years. 2020-01-01 12:51:42 +01:00
is_array Update copyright years. 2020-01-01 12:51:42 +01:00
is_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_base_of Update copyright years. 2020-01-01 12:51:42 +01:00
is_bounded_array Update copyright years. 2020-01-01 12:51:42 +01:00
is_class Update copyright years. 2020-01-01 12:51:42 +01:00
is_complete_or_unbounded Update copyright years. 2020-01-01 12:51:42 +01:00
is_compound Update copyright years. 2020-01-01 12:51:42 +01:00
is_const Update copyright years. 2020-01-01 12:51:42 +01:00
is_constant_evaluated Update copyright years. 2020-01-01 12:51:42 +01:00
is_constructible c++: Improve access checking inside templates [PR41437] 2020-06-16 08:21:33 -04:00
is_convertible Update copyright years. 2020-01-01 12:51:42 +01:00
is_copy_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_copy_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_default_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_destructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_empty Update copyright years. 2020-01-01 12:51:42 +01:00
is_enum Update copyright years. 2020-01-01 12:51:42 +01:00
is_final Update copyright years. 2020-01-01 12:51:42 +01:00
is_floating_point Update copyright years. 2020-01-01 12:51:42 +01:00
is_function x32 does not support MS ABI, skip testcases that require it. 2020-03-16 14:38:06 +01:00
is_fundamental Update copyright years. 2020-01-01 12:51:42 +01:00
is_implicitly_default_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_integral Update copyright years. 2020-01-01 12:51:42 +01:00
is_invocable libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
is_literal_type PR libstdc++/95915 2020-06-29 00:36:38 +03:00
is_lvalue_reference Update copyright years. 2020-01-01 12:51:42 +01:00
is_member_function_pointer x32 does not support MS ABI, skip testcases that require it. 2020-03-16 14:38:06 +01:00
is_member_object_pointer Update copyright years. 2020-01-01 12:51:42 +01:00
is_member_pointer Update copyright years. 2020-01-01 12:51:42 +01:00
is_move_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_move_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_constructible libstdc++: Support arrays in std::is_nothrow_constructible (PR 94149) 2020-04-21 22:18:51 +01:00
is_nothrow_convertible Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_copy_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_copy_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_default_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_destructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_invocable libstdc++: assert that type traits are not misused with incomplete types [PR 71579] 2020-08-19 12:12:40 +01:00
is_nothrow_move_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_move_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_nothrow_swappable libstdc++: assert that type traits are not misused with incomplete types [PR 71579] 2020-08-19 12:12:40 +01:00
is_nothrow_swappable_with libstdc++: assert that type traits are not misused with incomplete types [PR 71579] 2020-08-19 12:12:40 +01:00
is_null_pointer Update copyright years. 2020-01-01 12:51:42 +01:00
is_object x32 does not support MS ABI, skip testcases that require it. 2020-03-16 14:38:06 +01:00
is_pod libstdc++: Fix testsuite failures and warnings due to is_pod deprecation 2020-01-09 21:31:50 +00:00
is_pointer Update copyright years. 2020-01-01 12:51:42 +01:00
is_polymorphic Update copyright years. 2020-01-01 12:51:42 +01:00
is_reference Update copyright years. 2020-01-01 12:51:42 +01:00
is_rvalue_reference Update copyright years. 2020-01-01 12:51:42 +01:00
is_same Update copyright years. 2020-01-01 12:51:42 +01:00
is_scalar Update copyright years. 2020-01-01 12:51:42 +01:00
is_signed Update copyright years. 2020-01-01 12:51:42 +01:00
is_standard_layout Update copyright years. 2020-01-01 12:51:42 +01:00
is_swappable libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
is_swappable_with libstdc++: assert that type traits are not misused with incomplete types [PR 71579] 2020-08-19 12:12:40 +01:00
is_trivial Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_copy_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_copy_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_copyable Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_default_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_destructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_move_assignable Update copyright years. 2020-01-01 12:51:42 +01:00
is_trivially_move_constructible Update copyright years. 2020-01-01 12:51:42 +01:00
is_unbounded_array Update copyright years. 2020-01-01 12:51:42 +01:00
is_union Update copyright years. 2020-01-01 12:51:42 +01:00
is_unsigned Update copyright years. 2020-01-01 12:51:42 +01:00
is_void Update copyright years. 2020-01-01 12:51:42 +01:00
is_volatile Update copyright years. 2020-01-01 12:51:42 +01:00
logical_traits libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
make_signed/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
make_unsigned/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
memory_resource Update copyright years. 2020-01-01 12:51:42 +01:00
monotonic_buffer_resource libstdc++: Reduce monotonic_buffer_resource overallocation [PR 96942] 2020-09-10 15:41:53 +01:00
move Update copyright years. 2020-01-01 12:51:42 +01:00
move_if_noexcept Update copyright years. 2020-01-01 12:51:42 +01:00
nonesuch Update copyright years. 2020-01-01 12:51:42 +01:00
optional libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
owner_less Update copyright years. 2020-01-01 12:51:42 +01:00
pair libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
pointer_safety Update copyright years. 2020-01-01 12:51:42 +01:00
pointer_traits Update copyright years. 2020-01-01 12:51:42 +01:00
polymorphic_allocator libstdc++: make polymorphic_allocator throw consistent type (LWG 3237) 2020-02-19 15:34:08 +00:00
rank Update copyright years. 2020-01-01 12:51:42 +01:00
ratio libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
raw_storage_iterator Update copyright years. 2020-01-01 12:51:42 +01:00
reference_wrapper libstdc++: Use c++NN_only effective target to tests 2020-07-31 19:58:02 +01:00
remove_all_extents Update copyright years. 2020-01-01 12:51:42 +01:00
remove_const Update copyright years. 2020-01-01 12:51:42 +01:00
remove_cv Update copyright years. 2020-01-01 12:51:42 +01:00
remove_cvref Update copyright years. 2020-01-01 12:51:42 +01:00
remove_extent Update copyright years. 2020-01-01 12:51:42 +01:00
remove_pointer Update copyright years. 2020-01-01 12:51:42 +01:00
remove_reference Update copyright years. 2020-01-01 12:51:42 +01:00
remove_volatile Update copyright years. 2020-01-01 12:51:42 +01:00
result_of Update copyright years. 2020-01-01 12:51:42 +01:00
scoped_allocator Update copyright years. 2020-01-01 12:51:42 +01:00
shared_ptr Fix libstdc++ testsuite to handle VxWorks gthreads implementation 2020-08-23 23:18:48 -03:00
specialized_algorithms libstdc++: Fix test that fails for C++98 2020-07-31 19:58:03 +01:00
steady_clock Update copyright years. 2020-01-01 12:51:42 +01:00
synchronized_pool_resource libstdc++: Make pmr::synchronized_pool_resource work without libpthread (PR 94936) 2020-05-04 13:37:31 +01:00
system_clock Update copyright years. 2020-01-01 12:51:42 +01:00
time_point libstdc++: Add more C++20 additions to <chrono> 2020-08-25 10:23:59 -04:00
time_point_cast libstdc++: Remove duplicate dg-do directive 2020-07-31 17:51:00 +01:00
to_address libstdc++: Add missing feature test macros 2020-04-22 22:54:34 +01:00
to_chars libstdc++: Fix std::to_chars buffer overflow (PR 95851) 2020-06-24 12:28:13 +01:00
tuple libstdc++: Add workaround for weird std::tuple error [PR 96592] 2020-09-03 16:26:16 +01:00
type_identity/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
typeindex libstdc++: Add spaceship operator to std::type_index 2020-04-15 19:47:47 +01:00
underlying_type/requirements Update copyright years. 2020-01-01 12:51:42 +01:00
unique_ptr libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
unsynchronized_pool_resource libstdc++: Reduce monotonic_buffer_resource overallocation [PR 96942] 2020-09-10 15:41:53 +01:00
unwrap_reference libstdc++: Add __cpp_lib_unwrap_ref feature test macro 2020-02-19 15:28:54 +00:00
uses_allocator libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
variant libstdc++: Break header cycle between <new> and <exception> 2020-09-02 13:56:32 +01:00
void_t libstdc++: Ensure c++NN effective target present in all C++17 tests 2020-07-31 19:58:02 +01:00
weak_ptr Update copyright years. 2020-01-01 12:51:42 +01:00
rel_ops.cc Update copyright years. 2020-01-01 12:51:42 +01:00
temporary_buffer.cc Update copyright years. 2020-01-01 12:51:42 +01:00
variable_templates_for_traits.cc libstdc++: Add -Wno-deprecated for tests that warn in C++20 2020-07-31 17:51:00 +01:00