From patchwork Wed Nov 27 21:40:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36328 Received: (qmail 69541 invoked by alias); 27 Nov 2019 21:40:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 68624 invoked by uid 89); 27 Nov 2019 21:40:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Nov 2019 21:40:10 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id F13DF20555; Wed, 27 Nov 2019 16:40:08 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 3BBF6201F1; Wed, 27 Nov 2019 16:40:07 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id D72C020AF6; Wed, 27 Nov 2019 16:40:06 -0500 (EST) X-Gerrit-PatchSet: 6 Date: Wed, 27 Nov 2019 16:40:06 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Christian Biesinger , Tom Tromey , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [pushed] Precompute hash value for symbol_set_names X-Gerrit-Change-Id: I044449e7eb60cffc1c43efd3412f2b485bd9faac X-Gerrit-Change-Number: 307 X-Gerrit-ChangeURL: X-Gerrit-Commit: e76b224615f88255a3fd20d613983dde6cc240b3 In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191127214006.D72C020AF6@gnutoolchain-gerrit.osci.io> The original change was created by Christian Biesinger. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/307 ...................................................................... Precompute hash value for symbol_set_names 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 * 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 --- M gdb/ChangeLog M gdb/minsyms.c M gdb/symtab.c M gdb/symtab.h 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0816e73..c278a77 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2019-11-27 Christian Biesinger + + * 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 * dwarf2read.c (inherit_abstract_dies): Ensure that delayed diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 03a1932..141c3d2 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -1258,6 +1258,16 @@ } } +/* 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 @@ std::mutex demangled_mutex; #endif + std::vector hash_values (mcount); + msymbols = m_objfile->per_bfd->msymbols.get (); gdb::parallel_for_each (&msymbols[0], &msymbols[mcount], @@ -1377,6 +1389,8 @@ { 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 @@ (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 @@ #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); } } }); diff --git a/gdb/symtab.c b/gdb/symtab.c index 8f46321..894a323 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -836,7 +836,8 @@ 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 hash) { struct demangled_name_entry **slot; @@ -864,9 +865,11 @@ 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 diff --git a/gdb/symtab.h b/gdb/symtab.h index 7a51456..4cfdf06 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -553,7 +553,9 @@ (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 hash + = gdb::optional ()); /* Return true if NAME matches the "search" name of SYMBOL, according to the symbol's language. */