Skip to content

Commit e8e23f7

Browse files
ckennellycopybara-github
authored andcommitted
Avoid reentrancy in hashtable profiling during profile generation.
PiperOrigin-RevId: 854217867 Change-Id: I85d7a5a9025ccb107daf49dfe2ce11b0405f4de2
1 parent 26e36bb commit e8e23f7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

absl/profiling/internal/profile_builder.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,31 @@ class ProfileBuilder {
116116
void set_default_sample_type_id(StringId default_sample_type_id);
117117

118118
private:
119-
absl::flat_hash_map<std::string, StringId> string_table_{{"", StringId(0)}};
120-
absl::flat_hash_map<uintptr_t, LocationId> location_table_;
119+
// We turn off hashtable profiling for the ProfileBuilder's own tables.
120+
//
121+
// This is necessary since we use this class to construct hashtable profiles,
122+
// which entails walking the hashtable profiling data and we don't want to
123+
// encounter it reentrantly.
124+
template <typename T>
125+
struct HashtablezBarrier : std::allocator<T> {
126+
HashtablezBarrier() = default;
127+
128+
template <typename U>
129+
HashtablezBarrier(const HashtablezBarrier<U>&) {}
130+
131+
template <class U>
132+
struct rebind {
133+
using other = HashtablezBarrier<U>;
134+
};
135+
};
136+
137+
template <typename K, typename V>
138+
using UnprofiledHashMap = absl::flat_hash_map<
139+
K, V, DefaultHashContainerHash<K>, DefaultHashContainerEq<K>,
140+
HashtablezBarrier<std::pair<const K, V>>>;
141+
142+
UnprofiledHashMap<std::string, StringId> string_table_{{"", StringId(0)}};
143+
UnprofiledHashMap<uintptr_t, LocationId> location_table_;
121144
// mapping_table_ stores the start address of each mapping in mapping_
122145
// to its index.
123146
absl::btree_map<uintptr_t, size_t> mapping_table_;

0 commit comments

Comments
 (0)