@@ -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