From patchwork Thu Oct 3 18:15:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 34822 Received: (qmail 85923 invoked by alias); 3 Oct 2019 18:15:26 -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 85756 invoked by uid 89); 3 Oct 2019 18:15:18 -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, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=*linkage_name, 13426 X-HELO: mail-yb1-f201.google.com Received: from mail-yb1-f201.google.com (HELO mail-yb1-f201.google.com) (209.85.219.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Oct 2019 18:15:16 +0000 Received: by mail-yb1-f201.google.com with SMTP id a18so2419088ybe.13 for ; Thu, 03 Oct 2019 11:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ViYb5MOJvwCMalv0sKId2HRpoBuENhGb+BY52BiOg3E=; b=S7ibtjCKsR+ItTiXTMzbz7qsxQmP6ftq8irikb/hOhrRtQXGZHMVNmMn7Ey9oPvF47 FnRHNf/QxbDStj2LKtAf2CkTb8/Lpn5Y8lgo9cZZTMCSzT+q6oG7bUsXrUFMQy3jtGti xyQMdGxl+n+IOTZsdP9MUNTsAYlGbKAI9l/ghgJMGsZvQrAYgCtt50mVF1H4PCuEkChc 85u/XUs7XGUOK4WT2zEMehtZgRJH+6dhlbwbA7mVxC1RkdOMNNnmP8KS8UhOLhsWbENE PgLhYxyLQLZ1xSc26yHMds49HKNAkZnFY8geG1K8a23HM8vkIhc730P/J8dla6Yh1qmU RRFw== Date: Thu, 3 Oct 2019 13:15:04 -0500 In-Reply-To: Message-Id: <20191003181504.185026-2-cbiesinger@google.com> Mime-Version: 1.0 References: Subject: [PATCH v2 2/2] Precompute hash value for symbol_set_names X-Patchwork-Original-From: "Christian Biesinger via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: Christian Biesinger To: gdb-patches@sourceware.org Cc: Christian Biesinger X-IsSubscribed: yes 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-10-03 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. --- gdb/minsyms.c | 12 +++++++++++- gdb/symtab.c | 8 +++++--- gdb/symtab.h | 7 +++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 95ca9f6c93..b60381a0c9 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -1342,6 +1342,11 @@ minimal_symbol_reader::install () std::mutex demangled_mutex; #endif + struct computed_hash_values { + hashval_t mangled_name_hash; + }; + std::vector hash_values (mcount); + msymbols = m_objfile->per_bfd->msymbols.get (); gdb::parallel_for_each (&msymbols[0], &msymbols[mcount], @@ -1361,6 +1366,9 @@ minimal_symbol_reader::install () symbol_set_demangled_name (msym, demangled_name, &m_objfile->per_bfd->storage_obstack); msym->name_set = 1; + + size_t idx = msym - msymbols; + hash_values[idx].mangled_name_hash = htab_hash_string (msym->name); } } { @@ -1371,9 +1379,11 @@ minimal_symbol_reader::install () #endif for (minimal_symbol *msym = start; msym < end; ++msym) { + size_t idx = msym - msymbols; symbol_set_names (msym, msym->name, strlen (msym->name), 0, - m_objfile->per_bfd); + m_objfile->per_bfd, + hash_values[idx].mangled_name_hash); } } }); diff --git a/gdb/symtab.c b/gdb/symtab.c index 47da5cf4e8..40cc34b205 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -808,7 +808,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol, void symbol_set_names (struct general_symbol_info *gsymbol, const char *linkage_name, int len, bool copy_name, - struct objfile_per_bfd_storage *per_bfd) + struct objfile_per_bfd_storage *per_bfd, hashval_t hash) { struct demangled_name_entry **slot; /* A 0-terminated copy of the linkage name. */ @@ -854,9 +854,11 @@ symbol_set_names (struct general_symbol_info *gsymbol, create_demangled_names_hash (per_bfd); entry.mangled = linkage_name_copy; + if (hash == 0) + 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 17903df92d..2814f401fe 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -502,13 +502,16 @@ extern char *symbol_find_demangled_name (struct general_symbol_info *gsymbol, (symbol)->ginfo.name = (linkage_name) /* Set the linkage and natural names of a symbol, by demangling - the linkage name. */ + the linkage name. Optionally, HASH can be set to the value + of htab_hash_string (linkage_name) (if nullterminated), to + speed up this function. */ #define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \ symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, \ (objfile)->per_bfd) extern void symbol_set_names (struct general_symbol_info *symbol, const char *linkage_name, int len, bool copy_name, - struct objfile_per_bfd_storage *per_bfd); + struct objfile_per_bfd_storage *per_bfd, + hashval_t hash = 0); /* Now come lots of name accessor macros. Short version as to when to use which: Use SYMBOL_NATURAL_NAME to refer to the name of the