From patchwork Sat Mar 9 17:22:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31801 Received: (qmail 29454 invoked by alias); 9 Mar 2019 17:23:08 -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 29360 invoked by uid 89); 9 Mar 2019 17:23:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=recording, 20190303 X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Mar 2019 17:23:05 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway34.websitewelcome.com (Postfix) with ESMTP id DE5521657DA for ; Sat, 9 Mar 2019 11:23:03 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 2fgdhUUDv2qH72fgdhxqKO; Sat, 09 Mar 2019 11:23:03 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=0YSVAzmTPGnP2zZuu1YbZ896OAKPkDXwwYdAIpHIkP4=; b=FcHXDzK0csF1/duOo3fkBodRI7 uux4BgDLLse4uWVUJL38lHGgloUtWNHocmB03yDmSQu58mJr43H51ShTdD1J5XWG7f7oXvotVOZhJ 1YzZioH63foYhKSDxmGrJf3Jn; Received: from 75-166-85-218.hlrn.qwest.net ([75.166.85.218]:56494 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1h2fgd-003et2-7D; Sat, 09 Mar 2019 11:23:03 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 3/6] Lock the demangled hash table Date: Sat, 9 Mar 2019 10:22:57 -0700 Message-Id: <20190309172300.2764-4-tom@tromey.com> In-Reply-To: <20190309172300.2764-1-tom@tromey.com> References: <20190309172300.2764-1-tom@tromey.com> This introduces a lock that is used when modifying the demangled hash table. 2019-03-03 Tom Tromey * symtab.c (demangled_mutex): New global. (symbol_set_names): Use a lock_guard. --- gdb/ChangeLog | 5 ++ gdb/symtab.c | 128 +++++++++++++++++++++++++++----------------------- 2 files changed, 75 insertions(+), 58 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 449bc4cd2b3..0dcdc1e8b01 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -69,6 +69,7 @@ #include "arch-utils.h" #include #include "common/pathstuff.h" +#include /* Forward declarations for local functions. */ @@ -697,6 +698,9 @@ symbol_set_language (struct general_symbol_info *gsymbol, /* Functions to initialize a symbol's mangled name. */ +/* Mutex that is used when modifying the demangled hash table. */ +static std::mutex demangled_mutex; + /* Objects of this type are stored in the demangled name hash table. */ struct demangled_name_entry { @@ -825,9 +829,6 @@ symbol_set_names (struct general_symbol_info *gsymbol, return; } - if (per_bfd->demangled_names_hash == NULL) - create_demangled_names_hash (per_bfd); - if (linkage_name[len] != '\0') { char *alloc_name; @@ -846,64 +847,75 @@ symbol_set_names (struct general_symbol_info *gsymbol, = symbol_find_demangled_name (gsymbol, linkage_name_copy); gdb::unique_xmalloc_ptr demangled_name (demangled_name_ptr); - entry.mangled = linkage_name_copy; - slot = ((struct demangled_name_entry **) - htab_find_slot (per_bfd->demangled_names_hash.get (), - &entry, INSERT)); - - /* If this name is not in the hash table, add it. */ - if (*slot == NULL - /* A C version of the symbol may have already snuck into the table. - This happens to, e.g., main.init (__go_init_main). Cope. */ - || (gsymbol->language == language_go - && (*slot)->demangled[0] == '\0')) - { - int demangled_len = demangled_name ? strlen (demangled_name.get ()) : 0; - - /* Suppose we have demangled_name==NULL, copy_name==0, and - linkage_name_copy==linkage_name. In this case, we already have the - mangled name saved, and we don't have a demangled name. So, - you might think we could save a little space by not recording - this in the hash table at all. + struct demangled_name_entry *found_entry; + + { + std::lock_guard guard (demangled_mutex); + + if (per_bfd->demangled_names_hash == NULL) + create_demangled_names_hash (per_bfd); + + entry.mangled = linkage_name_copy; + slot = ((struct demangled_name_entry **) + htab_find_slot (per_bfd->demangled_names_hash.get (), + &entry, INSERT)); + + /* If this name is not in the hash table, add it. */ + if (*slot == NULL + /* A C version of the symbol may have already snuck into the table. + This happens to, e.g., main.init (__go_init_main). Cope. */ + || (gsymbol->language == language_go + && (*slot)->demangled[0] == '\0')) + { + int demangled_len = demangled_name ? strlen (demangled_name.get ()) : 0; + + /* Suppose we have demangled_name==NULL, copy_name==0, and + linkage_name_copy==linkage_name. In this case, we already have the + mangled name saved, and we don't have a demangled name. So, + you might think we could save a little space by not recording + this in the hash table at all. - It turns out that it is actually important to still save such - an entry in the hash table, because storing this name gives - us better bcache hit rates for partial symbols. */ - if (!copy_name && linkage_name_copy == linkage_name) - { - *slot - = ((struct demangled_name_entry *) - obstack_alloc (&per_bfd->storage_obstack, - offsetof (struct demangled_name_entry, demangled) - + demangled_len + 1)); - (*slot)->mangled = linkage_name; - } - else - { - char *mangled_ptr; - - /* If we must copy the mangled name, put it directly after - the demangled name so we can have a single - allocation. */ - *slot - = ((struct demangled_name_entry *) - obstack_alloc (&per_bfd->storage_obstack, - offsetof (struct demangled_name_entry, demangled) - + len + demangled_len + 2)); - mangled_ptr = &((*slot)->demangled[demangled_len + 1]); - strcpy (mangled_ptr, linkage_name_copy); - (*slot)->mangled = mangled_ptr; - } + It turns out that it is actually important to still save such + an entry in the hash table, because storing this name gives + us better bcache hit rates for partial symbols. */ + if (!copy_name && linkage_name_copy == linkage_name) + { + *slot + = ((struct demangled_name_entry *) + obstack_alloc (&per_bfd->storage_obstack, + offsetof (struct demangled_name_entry, demangled) + + demangled_len + 1)); + (*slot)->mangled = linkage_name; + } + else + { + char *mangled_ptr; + + /* If we must copy the mangled name, put it directly after + the demangled name so we can have a single + allocation. */ + *slot + = ((struct demangled_name_entry *) + obstack_alloc (&per_bfd->storage_obstack, + offsetof (struct demangled_name_entry, demangled) + + len + demangled_len + 2)); + mangled_ptr = &((*slot)->demangled[demangled_len + 1]); + strcpy (mangled_ptr, linkage_name_copy); + (*slot)->mangled = mangled_ptr; + } - if (demangled_name != NULL) - strcpy ((*slot)->demangled, demangled_name.get()); - else - (*slot)->demangled[0] = '\0'; - } + if (demangled_name != NULL) + strcpy ((*slot)->demangled, demangled_name.get()); + else + (*slot)->demangled[0] = '\0'; + } + + found_entry = *slot; + } - gsymbol->name = (*slot)->mangled; - if ((*slot)->demangled[0] != '\0') - symbol_set_demangled_name (gsymbol, (*slot)->demangled, + gsymbol->name = found_entry->mangled; + if (found_entry->demangled[0] != '\0') + symbol_set_demangled_name (gsymbol, found_entry->demangled, &per_bfd->storage_obstack); else symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack);