[PATCH v1 21/26] perf annotate: Use generic hashmap for browser type_hash

From: Ian Rogers

Date: Fri Nov 13 2026 - 16:51:46 EST


Convert annotate_browser::type_hash and annotation_print_data::type_hash
in util/annotate.{c,h} and ui/browsers/annotate.c to
DECLARE_HASHMAP(type_hash_map, long, struct type_hash_entry *).

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/ui/browsers/annotate.c | 18 +++++++++---------
tools/perf/util/annotate.c | 5 -----
tools/perf/util/annotate.h | 8 +++++++-
3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 8b0c933caf2e..7899c3e2b07a 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -39,7 +39,7 @@ struct annotate_browser {
struct hist_entry *he;
struct debuginfo *dbg;
struct evsel *evsel;
- struct hashmap *type_hash;
+ struct type_hash_map *type_hash;
bool searching_backwards;
char search_bf[128];
};
@@ -1131,8 +1131,8 @@ static int annotate_browser__run(struct annotate_browser *browser,
if (browser->dbg == NULL)
browser->dbg = dso__debuginfo(map__dso(ms->map));
if (browser->type_hash == NULL) {
- browser->type_hash = hashmap__new(type_hash, type_equal,
- /*ctx=*/NULL);
+ browser->type_hash = type_hash_map__new(type_hash, type_equal,
+ /*ctx=*/NULL);
}
annotate_browser__show(browser, title, help);
annotate_browser__debuginfo_warning(browser);
@@ -1233,7 +1233,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,

if (annotate_opts.code_with_type) {
browser.dbg = dso__debuginfo(dso);
- browser.type_hash = hashmap__new(type_hash, type_equal, /*ctx=*/NULL);
+ browser.type_hash = type_hash_map__new(type_hash, type_equal, /*ctx=*/NULL);
}

browser.b.width = notes->src->widths.max_line_len +
@@ -1265,12 +1265,12 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
debuginfo__delete(browser.dbg);

if (browser.type_hash) {
- struct hashmap_entry *cur;
- size_t bkt;
+ long key;
+ struct type_hash_entry *val;

- hashmap__for_each_entry(browser.type_hash, cur, bkt)
- zfree(&cur->pvalue);
- hashmap__free(browser.type_hash);
+ hashmap__for_each(browser.type_hash, key, val)
+ free(val);
+ type_hash_map__free(browser.type_hash);
}

if (not_annotated && !notes->src->tried_source)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index c6325040452f..ee47dcdc1f18 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2075,11 +2075,6 @@ int annotation_br_cntr_entry(char **str, int br_cntr_nr,
return -ENOMEM;
}

-struct type_hash_entry {
- struct annotated_data_type *type;
- int offset;
-};
-
static int disasm_line__snprint_type_info(struct disasm_line *dl,
char *buf, int len,
struct annotation_print_data *apd)
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 495c8602864c..2757fb07d4ec 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -202,13 +202,19 @@ struct annotation_write_ops {
void (*write_graph)(void *obj, int graph);
};

+struct type_hash_entry {
+ struct annotated_data_type *type;
+ int offset;
+};
+DECLARE_HASHMAP(type_hash_map, long, struct type_hash_entry *);
+
struct annotation_print_data {
struct hist_entry *he;
struct evsel *evsel;
const struct arch *arch;
struct debuginfo *dbg;
/* save data type info keyed by al->offset */
- struct hashmap *type_hash;
+ struct type_hash_map *type_hash;
/* It'll be set in hist_entry__annotate_printf() */
int addr_fmt_width;
};
--
2.56.1.703.gf848ed807c-goog