Precompute hash value for symbol_set_names
authorChristian Biesinger <cbiesinger@google.com>
Thu, 3 Oct 2019 18:05:06 +0000 (13:05 -0500)
committerChristian Biesinger <cbiesinger@google.com>
Wed, 27 Nov 2019 21:36:59 +0000 (15:36 -0600)
We can also compute the hash for the mangled name on a background
thread so make this function even faster (about a 7% speedup).

gdb/ChangeLog:

2019-11-27  Christian Biesinger  <cbiesinger@google.com>

* minsyms.c (minimal_symbol_reader::install): Also compute the hash
of the mangled name on the background thread.
* symtab.c (symbol_set_names): Allow passing in the hash of the
linkage_name.
* symtab.h (symbol_set_names): Likewise.

Change-Id: I044449e7eb60cffc1c43efd3412f2b485bd9faac

gdb/ChangeLog
gdb/minsyms.c
gdb/symtab.c
gdb/symtab.h

index 0816e73381b249de88b30c7407ea632d9b45455b..c278a7746c6764d78233311f4f1579af824280c2 100644 (file)
@@ -1,3 +1,11 @@
+2019-11-27  Christian Biesinger  <cbiesinger@google.com>
+
+       * minsyms.c (minimal_symbol_reader::install): Also compute the hash
+       of the mangled name on the background thread.
+       * symtab.c (symbol_set_names): Allow passing in the hash of the
+       linkage_name.
+       * symtab.h (symbol_set_names): Likewise.
+
 2019-11-27  Kevin Buettner  <kevinb@redhat.com>
 
        * dwarf2read.c (inherit_abstract_dies): Ensure that delayed
index 03a193270e5acb1521728fc8be82f8ddc59a2d57..141c3d2193537cf69bb04e84efff349f03da097c 100644 (file)
@@ -1258,6 +1258,16 @@ clear_minimal_symbol_hash_tables (struct objfile *objfile)
     }
 }
 
+/* This struct is used to store values we compute for msymbols on the
+   background threads but don't need to keep around long term.  */
+struct computed_hash_values
+{
+  /* Length of the linkage_name of the symbol.  */
+  size_t name_length;
+  /* Hash code (using fast_hash) of the linkage_name.  */
+  hashval_t mangled_name_hash;
+};
+
 /* Build (or rebuild) the minimal symbol hash tables.  This is necessary
    after compacting or sorting the table since the entries move around
    thus causing the internal minimal_symbol pointers to become jumbled.  */
@@ -1370,6 +1380,8 @@ minimal_symbol_reader::install ()
       std::mutex demangled_mutex;
 #endif
 
+      std::vector<computed_hash_values> hash_values (mcount);
+
       msymbols = m_objfile->per_bfd->msymbols.get ();
       gdb::parallel_for_each
        (&msymbols[0], &msymbols[mcount],
@@ -1377,6 +1389,8 @@ minimal_symbol_reader::install ()
         {
           for (minimal_symbol *msym = start; msym < end; ++msym)
             {
+              size_t idx = msym - msymbols;
+              hash_values[idx].name_length = strlen (msym->name);
               if (!msym->name_set)
                 {
                   /* This will be freed later, by symbol_set_names.  */
@@ -1386,6 +1400,9 @@ minimal_symbol_reader::install ()
                     (msym, demangled_name,
                      &m_objfile->per_bfd->storage_obstack);
                   msym->name_set = 1;
+
+                  hash_values[idx].mangled_name_hash
+                    = fast_hash (msym->name, hash_values[idx].name_length);
                 }
             }
           {
@@ -1396,8 +1413,14 @@ minimal_symbol_reader::install ()
 #endif
             for (minimal_symbol *msym = start; msym < end; ++msym)
               {
-                symbol_set_names (msym, msym->name, false,
-                                  m_objfile->per_bfd);
+                size_t idx = msym - msymbols;
+                symbol_set_names
+                  (msym,
+                   gdb::string_view(msym->name,
+                                    hash_values[idx].name_length),
+                   false,
+                   m_objfile->per_bfd,
+                   hash_values[idx].mangled_name_hash);
               }
           }
         });
index 8f46321f43d79019446180e62296d3f6a7c0a4d0..894a3230038eb312e7e593f531dd698acef4cc0a 100644 (file)
@@ -836,7 +836,8 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
 void
 symbol_set_names (struct general_symbol_info *gsymbol,
                  gdb::string_view linkage_name, bool copy_name,
-                 struct objfile_per_bfd_storage *per_bfd)
+                 struct objfile_per_bfd_storage *per_bfd,
+                 gdb::optional<hashval_t> hash)
 {
   struct demangled_name_entry **slot;
 
@@ -864,9 +865,11 @@ symbol_set_names (struct general_symbol_info *gsymbol,
     create_demangled_names_hash (per_bfd);
 
   struct demangled_name_entry entry (linkage_name);
+  if (!hash.has_value ())
+    hash = hash_demangled_name_entry (&entry);
   slot = ((struct demangled_name_entry **)
-         htab_find_slot (per_bfd->demangled_names_hash.get (),
-                         &entry, INSERT));
+          htab_find_slot_with_hash (per_bfd->demangled_names_hash.get (),
+                                   &entry, *hash, INSERT));
 
   /* If this name is not in the hash table, add it.  */
   if (*slot == NULL
index 7a5145663a17d1df38f95faa52a10e6bc3f0aa7b..4cfdf06b4a80a35faa5c2c64e7bc2bbfee9c12c9 100644 (file)
@@ -553,7 +553,9 @@ extern char *symbol_find_demangled_name (struct general_symbol_info *gsymbol,
                    (objfile)->per_bfd)
 extern void symbol_set_names (struct general_symbol_info *symbol,
                              gdb::string_view linkage_name, bool copy_name,
-                             struct objfile_per_bfd_storage *per_bfd);
+                             struct objfile_per_bfd_storage *per_bfd,
+                             gdb::optional<hashval_t> hash
+                               = gdb::optional<hashval_t> ());
 
 /* Return true if NAME matches the "search" name of SYMBOL, according
    to the symbol's language.  */
This page took 0.036354 seconds and 4 git commands to generate.