From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by sourceware.org (Postfix) with ESMTPS id B3BC63858421 for ; Fri, 7 Apr 2023 15:25:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3BC63858421 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id 1F6AA1004954F for ; Fri, 7 Apr 2023 15:25:43 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id knyBpLk6QChTwknyBplpXM; Fri, 07 Apr 2023 15:25:43 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=BK12EHcG c=1 sm=1 tr=0 ts=643035f7 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=dKHAf1wccvYA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=sbcTgWqzmVlm1C441K8A:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc: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=S3epSMILyZ4VzkJTifoSjbLMRjOyLC8Lv7KyOgIxNp8=; b=wzWiuazWVi+plkobD/t4Stufxx usuUHDsUUQj9Spca5Hz8aoZJ+cdmSXimiuQwxithTWJaEcu8MpmxtnyZYu59ps34huxDhOO54/2EV Qb8lQUGE9fk72/5EIJd8WbM32; Received: from 75-166-159-36.hlrn.qwest.net ([75.166.159.36]:60392 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pknyA-001hDU-VK for gdb-patches@sourceware.org; Fri, 07 Apr 2023 09:25:42 -0600 From: Tom Tromey Date: Fri, 07 Apr 2023 09:25:51 -0600 Subject: [PATCH 19/19] Convert gdb_bfd.c to new hash table MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230407-t-robin-hood-hash-v1-19-900d93ef1510@tromey.com> References: <20230407-t-robin-hood-hash-v1-0-900d93ef1510@tromey.com> In-Reply-To: <20230407-t-robin-hood-hash-v1-0-900d93ef1510@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.159.36 X-Source-L: No X-Exim-ID: 1pknyA-001hDU-VK X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-159-36.hlrn.qwest.net ([192.168.0.21]) [75.166.159.36]:60392 X-Source-Auth: tom+tromey.com X-Email-Count: 20 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This converts the BFD cache in gdb_bfd.c to use the new hash table. --- gdb/gdb_bfd.c | 92 +++++++++++++++++++++-------------------------------------- 1 file changed, 33 insertions(+), 59 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 1c8c59cdb6e..8c93e7cd8f1 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -124,10 +124,6 @@ registry_accessor::get (bfd *abfd) return &gdata->registry_fields; } -/* A hash table storing all the BFDs maintained in the cache. */ - -static htab_t gdb_bfd_cache; - /* When true gdb will reuse an existing bfd object if the filename, modification time, and file size all match. */ @@ -173,34 +169,38 @@ struct gdb_bfd_cache_search dev_t device_id; }; -/* A hash function for BFDs. */ +/* Traits for the BFD cache hash table. */ -static hashval_t -hash_bfd (const void *b) +struct gdb_bfd_cache_traits { - const bfd *abfd = (const struct bfd *) b; + typedef bfd *value_type; - /* It is simplest to just hash the filename. */ - return htab_hash_string (bfd_get_filename (abfd)); -} + static bool is_empty (const bfd *val) + { return val == nullptr; } -/* An equality function for BFDs. Note that this expects the caller - to search using struct gdb_bfd_cache_search only, not BFDs. */ + static size_t hash (const bfd *abfd) + { return htab_hash_string (bfd_get_filename (abfd)); } -static int -eq_bfd (const void *a, const void *b) -{ - const bfd *abfd = (const struct bfd *) a; - const struct gdb_bfd_cache_search *s - = (const struct gdb_bfd_cache_search *) b; - struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd); + static size_t hash (const gdb_bfd_cache_search &val) + { return htab_hash_string (val.filename); } - return (gdata->mtime == s->mtime - && gdata->size == s->size - && gdata->inode == s->inode - && gdata->device_id == s->device_id - && strcmp (bfd_get_filename (abfd), s->filename) == 0); -} + static bool equals (const bfd *a, const bfd *b) + { return a == b; } + + static bool equals (const bfd *abfd, const gdb_bfd_cache_search &s) + { + struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd); + return (gdata->mtime == s.mtime + && gdata->size == s.size + && gdata->inode == s.inode + && gdata->device_id == s.device_id + && strcmp (bfd_get_filename (abfd), s.filename) == 0); + } +}; + +/* A hash table storing all the BFDs maintained in the cache. */ + +static gdb::traited_hash_table gdb_bfd_cache; /* See gdb_bfd.h. */ @@ -490,8 +490,6 @@ gdb_bfd_ref_ptr gdb_bfd_open (const char *name, const char *target, int fd, bool warn_if_slow) { - hashval_t hash; - void **slot; bfd *abfd; struct gdb_bfd_cache_search search; struct stat st; @@ -514,10 +512,6 @@ gdb_bfd_open (const char *name, const char *target, int fd, name += strlen (TARGET_SYSROOT_PREFIX); } - if (gdb_bfd_cache == NULL) - gdb_bfd_cache = htab_create_alloc (1, hash_bfd, eq_bfd, NULL, - xcalloc, xfree); - if (fd == -1) { fd = gdb_open_cloexec (name, O_RDONLY | O_BINARY, 0).release (); @@ -544,14 +538,10 @@ gdb_bfd_open (const char *name, const char *target, int fd, search.inode = st.st_ino; search.device_id = st.st_dev; - /* Note that this must compute the same result as hash_bfd. */ - hash = htab_hash_string (name); - /* Note that we cannot use htab_find_slot_with_hash here, because - opening the BFD may fail; and this would violate hashtab - invariants. */ - abfd = (struct bfd *) htab_find_with_hash (gdb_bfd_cache, &search, hash); - if (bfd_sharing && abfd != NULL) + auto iter = gdb_bfd_cache.find (search); + if (bfd_sharing && iter != gdb_bfd_cache.end ()) { + abfd = *iter; bfd_cache_debug_printf ("Reusing cached bfd %s for %s", host_address_to_string (abfd), bfd_get_filename (abfd)); @@ -569,9 +559,8 @@ gdb_bfd_open (const char *name, const char *target, int fd, if (bfd_sharing) { - slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT); - gdb_assert (!*slot); - *slot = abfd; + auto insert_pair = gdb_bfd_cache.insert (abfd); + gdb_assert (insert_pair.second); } /* It's important to pass the already-computed stat info here, @@ -662,7 +651,6 @@ void gdb_bfd_unref (struct bfd *abfd) { struct gdb_bfd_data *gdata; - struct gdb_bfd_cache_search search; bfd *archive_bfd; if (abfd == NULL) @@ -685,23 +673,9 @@ gdb_bfd_unref (struct bfd *abfd) bfd_get_filename (abfd)); archive_bfd = gdata->archive_bfd; - search.filename = bfd_get_filename (abfd); - if (gdb_bfd_cache && search.filename) - { - hashval_t hash = htab_hash_string (search.filename); - void **slot; - - search.mtime = gdata->mtime; - search.size = gdata->size; - search.inode = gdata->inode; - search.device_id = gdata->device_id; - slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, - NO_INSERT); - - if (slot && *slot) - htab_clear_slot (gdb_bfd_cache, slot); - } + if (bfd_get_filename (abfd) != nullptr) + gdb_bfd_cache.erase (abfd); delete gdata; bfd_set_usrdata (abfd, NULL); /* Paranoia. */ -- 2.39.2