From 08e2faa90ee10be6bad9be67bb2864fe31e5bae8 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Thu, 11 Jan 2024 15:11:57 +0000 Subject: [PATCH] tbv2: correctly account for list overhead `std::list` has per element overhead for the individual heap allocations. This was already calculated in the container implementation but not used. Allocate the overhead of each element in the `std::list` to the `std::list` itself as with other sequential containers. Test Plan: - CI - Updated test cases --- test/integration/std_list.toml | 12 ++++++------ test/integration/std_list_del_allocator.toml | 6 +++--- types/cxx11_list_type.toml | 13 +------------ types/list_type.toml | 13 +------------ 4 files changed, 11 insertions(+), 33 deletions(-) diff --git a/test/integration/std_list.toml b/test/integration/std_list.toml index 92c039a..562ccc9 100644 --- a/test/integration/std_list.toml +++ b/test/integration/std_list.toml @@ -18,7 +18,7 @@ definitions = ''' param_types = ["const std::list&"] setup = "return {{1,2,3}};" expect_json = '[{"staticSize":24, "dynamicSize":12, "length":3, "capacity":3, "elementStaticSize":4}]' - expect_json_v2 = '''[{"staticSize":24, "exclusiveSize":24, "size":36, "length":3, "capacity":3, "members":[ + expect_json_v2 = '''[{"staticSize":24, "exclusiveSize":84, "size":96, "length":3, "capacity":3, "members":[ {"staticSize":4, "exclusiveSize":4, "size":4}, {"staticSize":4, "exclusiveSize":4, "size":4}, {"staticSize":4, "exclusiveSize":4, "size":4} @@ -27,7 +27,7 @@ definitions = ''' param_types = ["const std::list&"] setup = "return {{{}, {}, {}}};" expect_json = '[{"staticSize":24, "dynamicSize":48, "length":3, "capacity":3, "elementStaticSize":16}]' - expect_json_v2 = '''[{"staticSize":24, "exclusiveSize":24, "size":72, "length":3, "capacity":3, "members":[ + expect_json_v2 = '''[{"staticSize":24, "exclusiveSize":72, "size":120, "length":3, "capacity":3, "members":[ {"staticSize":16, "exclusiveSize":3, "size":16}, {"staticSize":16, "exclusiveSize":3, "size":16}, {"staticSize":16, "exclusiveSize":3, "size":16} @@ -52,8 +52,8 @@ definitions = ''' {"staticSize":24, "dynamicSize":4, "exclusiveSize":28, "length":1, "capacity":1, "elementStaticSize":4}, {"staticSize":24, "dynamicSize":8, "exclusiveSize":32, "length":2, "capacity":2, "elementStaticSize":4} ]}]''' - expect_json_v2 = '''[{"staticSize":24, "exclusiveSize":24, "size":120, "length":3, "capacity": 3, "members":[ - {"staticSize":24, "exclusiveSize":24, "size":36, "length":3, "capacity": 3}, - {"staticSize":24, "exclusiveSize":24, "size":28, "length":1, "capacity": 1}, - {"staticSize":24, "exclusiveSize":24, "size":32, "length":2, "capacity": 2} + expect_json_v2 = '''[{"staticSize":24, "exclusiveSize":72, "size":288, "length":3, "capacity": 3, "members":[ + {"staticSize":24, "exclusiveSize":84, "size":96, "length":3, "capacity": 3}, + {"staticSize":24, "exclusiveSize":44, "size":48, "length":1, "capacity": 1}, + {"staticSize":24, "exclusiveSize":64, "size":72, "length":2, "capacity": 2} ]}]''' diff --git a/test/integration/std_list_del_allocator.toml b/test/integration/std_list_del_allocator.toml index c85d3ab..9298902 100644 --- a/test/integration/std_list_del_allocator.toml +++ b/test/integration/std_list_del_allocator.toml @@ -60,8 +60,8 @@ includes = ["list"] expect_json_v2 = '''[{ "staticSize": 48, "exclusiveSize": 0, - "size": 60, + "size": 120, "members": [ - {"name": "v1", "staticSize": 24, "exclusiveSize": 24, "size": 28, "length": 1, "capacity": 1}, - {"name": "v2", "staticSize": 24, "exclusiveSize": 24, "size": 32, "length": 2, "capacity": 2} + {"name": "v1", "staticSize": 24, "exclusiveSize": 44, "size": 48, "length": 1, "capacity": 1}, + {"name": "v2", "staticSize": 24, "exclusiveSize": 64, "size": 72, "length": 2, "capacity": 2} ]}]''' diff --git a/types/cxx11_list_type.toml b/types/cxx11_list_type.toml index 6788750..e55f145 100644 --- a/types/cxx11_list_type.toml +++ b/types/cxx11_list_type.toml @@ -61,17 +61,6 @@ static constexpr size_t element_size = sizeof(std::_List_node); static_assert(false && "No known element_size for list. See types/cxx11_list_type.toml"); #endif -static constexpr std::array child_field{ - make_field("*"), -}; -static constexpr inst::Field element{ - element_size, - element_size - sizeof(T0), - "[]", - std::array{}, - child_field, - std::array{}, -}; static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); @@ -79,7 +68,7 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = list.length, .length = list.length, }); -el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0); +el.exclusive_size += el.container_stats->length * (element_size - sizeof(T0)); stack_ins(inst::Repeat{ list.length, childField }); """ diff --git a/types/list_type.toml b/types/list_type.toml index 3e0da3c..1161cca 100644 --- a/types/list_type.toml +++ b/types/list_type.toml @@ -61,17 +61,6 @@ static constexpr size_t element_size = sizeof(std::_List_node); static_assert(false && "No known element_size for list. See types/cxx11_list_type.toml"); #endif -static constexpr std::array child_field{ - make_field("*"), -}; -static constexpr inst::Field element{ - element_size, - element_size - sizeof(T0), - "[]", - std::array{}, - child_field, - std::array{}, -}; static constexpr auto childField = make_field("[]"); auto list = std::get(d.val); @@ -79,7 +68,7 @@ el.container_stats.emplace(result::Element::ContainerStats{ .capacity = list.length, .length = list.length, }); -el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0); +el.exclusive_size += el.container_stats->length * (element_size - sizeof(T0)); stack_ins(inst::Repeat{ list.length, childField }); """