From patchwork Mon Feb 24 02:58:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 38281 Received: (qmail 79694 invoked by alias); 24 Feb 2020 02:58:30 -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 79667 invoked by uid 89); 24 Feb 2020 02:58:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.9 required=5.0 tests=AWL, BAYES_00, FILL_THIS_FORM_SHORT, 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=strip, consolidation, lifetime, sym X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.164) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Feb 2020 02:58:24 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 6CDAE522C for ; Sun, 23 Feb 2020 20:58:22 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 63wsjpCdLEfyq63wsjvl2r; Sun, 23 Feb 2020 20:58:22 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=g/nkAzSm8akewFodTSEeWzdGDe1KoimfezK/TqQkSQ0=; b=yPh3895Fv+CFwBedtiX6cj54pW P/TMC7mlqDot/KHs7XRqk8dbV42RSf0gEonqvU36B78O45YI0UTXlKyVnd2lzrYR01xVOlsEAFEBb VFwvUejTfuQJ/mfXjF2JUPR08; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:52408 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1j63ws-003Unr-7I; Sun, 23 Feb 2020 19:58:22 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Introduce objfile::intern Date: Sun, 23 Feb 2020 19:58:19 -0700 Message-Id: <20200224025819.18873-1-tom@tromey.com> This introduces a string cache on the per-BFD object, replacing the macro and filename caches. Both of these caches just store strings, so this consolidation by itself saves a little memory (about the size of a bcache per objfile). Then this patch switches some allocations on the objfile obstack to use this bcache instead. This saves more space; and turns out to be a bit faster as well. Here are the before and after "maint time" + "maint space" results of "file ./gdb": Command execution time: 4.664021 (cpu), 4.728518 (wall) Space used: 39190528 (+29212672 for this command) Command execution time: 4.216209 (cpu), 4.107023 (wall) Space used: 36667392 (+26689536 for this command) The main interface to the string cache is a new pair of overloaded methods, objfile::intern. gdb/ChangeLog 2020-02-23 Tom Tromey * symmisc.c (print_symbol_bcache_statistics) (print_objfile_statistics): Update. * symfile.c (allocate_symtab): Use intern. * psymtab.c (partial_symtab::partial_symtab): Use intern. * objfiles.h (struct objfile_per_bfd_storage) : Remove. : New member. (struct objfile) : New methods. * elfread.c (elf_symtab_read): Use intern. * dwarf2/read.c (fixup_go_packaging): Intern package name. (dwarf2_compute_name, dwarf2_physname) (create_dwo_unit_in_dwp_v1, create_dwo_unit_in_dwp_v2): Intern names. (guess_partial_die_structure_name): Update. (partial_die_info::fixup): Intern name. (dwarf2_canonicalize_name): Change parameter to objfile. Intern name. (dwarf2_name): Intern name. Update. * buildsym.c (buildsym_compunit::get_macro_table): Use string_cache. --- gdb/ChangeLog | 23 +++++++++++++++++++++++ gdb/buildsym.c | 2 +- gdb/dwarf2/read.c | 43 ++++++++++++++++--------------------------- gdb/elfread.c | 6 +----- gdb/objfiles.h | 24 ++++++++++++++++++------ gdb/psymtab.c | 4 +--- gdb/symfile.c | 4 +--- gdb/symmisc.c | 10 +++------- 8 files changed, 64 insertions(+), 52 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 4965b552b32..84cb44277a4 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -120,7 +120,7 @@ buildsym_compunit::get_macro_table () { if (m_pending_macros == nullptr) m_pending_macros = new_macro_table (&m_objfile->per_bfd->storage_obstack, - &m_objfile->per_bfd->macro_cache, + &m_objfile->per_bfd->string_cache, m_compunit_symtab); return m_pending_macros; } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 46d510eb274..fe54680eb1d 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1449,7 +1449,7 @@ static const gdb_byte *read_full_die (const struct die_reader_specs *, static void process_die (struct die_info *, struct dwarf2_cu *); static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu *, - struct obstack *); + struct objfile *); static const char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); @@ -9056,8 +9056,7 @@ fixup_go_packaging (struct dwarf2_cu *cu) if (package_name != NULL) { struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; - const char *saved_package_name - = obstack_strdup (&objfile->per_bfd->storage_obstack, package_name.get ()); + const char *saved_package_name = objfile->intern (package_name.get ()); struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0, saved_package_name); struct symbol *sym; @@ -10183,14 +10182,13 @@ dwarf2_compute_name (const char *name, if (cu->language == language_cplus) canonical_name = dwarf2_canonicalize_name (intermediate_name.c_str (), cu, - &objfile->per_bfd->storage_obstack); + objfile); /* If we only computed INTERMEDIATE_NAME, or if INTERMEDIATE_NAME is already canonical, then we need to - copy it to the appropriate obstack. */ + intern it. */ if (canonical_name == NULL || canonical_name == intermediate_name.c_str ()) - name = obstack_strdup (&objfile->per_bfd->storage_obstack, - intermediate_name); + name = objfile->intern (intermediate_name); else name = canonical_name; } @@ -10310,7 +10308,7 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) retval = canon; if (need_copy) - retval = obstack_strdup (&objfile->per_bfd->storage_obstack, retval); + retval = objfile->intern (retval); return retval; } @@ -11636,8 +11634,7 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile, virtual_dwo_name.c_str ()); } dwo_file = new struct dwo_file; - dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack, - virtual_dwo_name); + dwo_file->dwo_name = objfile->intern (virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = sections.abbrev; dwo_file->sections.line = sections.line; @@ -11832,8 +11829,7 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile, virtual_dwo_name.c_str ()); } dwo_file = new struct dwo_file; - dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack, - virtual_dwo_name); + dwo_file->dwo_name = objfile->intern (virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.abbrev, @@ -17953,8 +17949,7 @@ partial_die_info::read (const struct die_reader_specs *reader, struct objfile *objfile = dwarf2_per_objfile->objfile; name - = dwarf2_canonicalize_name (DW_STRING (&attr), cu, - &objfile->per_bfd->storage_obstack); + = dwarf2_canonicalize_name (DW_STRING (&attr), cu, objfile); } break; } @@ -18279,9 +18274,7 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi, if (actual_class_name != NULL) { struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; - struct_pdi->name - = obstack_strdup (&objfile->per_bfd->storage_obstack, - actual_class_name.get ()); + struct_pdi->name = objfile->intern (actual_class_name.get ()); } break; } @@ -18361,7 +18354,7 @@ partial_die_info::fixup (struct dwarf2_cu *cu) base = demangled.get (); struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile; - name = obstack_strdup (&objfile->per_bfd->storage_obstack, base); + name = objfile->intern (base); } } @@ -21678,7 +21671,7 @@ sibling_die (struct die_info *die) static const char * dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu, - struct obstack *obstack) + struct objfile *objfile) { if (name && cu->language == language_cplus) { @@ -21687,7 +21680,7 @@ dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu, if (!canon_name.empty ()) { if (canon_name != name) - name = obstack_strdup (obstack, canon_name); + name = objfile->intern (canon_name); } } @@ -21761,10 +21754,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) const char *base; - /* FIXME: we already did this for the partial symbol... */ - DW_STRING (attr) - = obstack_strdup (&objfile->per_bfd->storage_obstack, - demangled.get ()); + DW_STRING (attr) = objfile->intern (demangled.get ()); DW_STRING_IS_CANONICAL (attr) = 1; /* Strip any leading namespaces/classes, keep only the base name. @@ -21784,9 +21774,8 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) if (!DW_STRING_IS_CANONICAL (attr)) { - DW_STRING (attr) - = dwarf2_canonicalize_name (DW_STRING (attr), cu, - &objfile->per_bfd->storage_obstack); + DW_STRING (attr) = dwarf2_canonicalize_name (DW_STRING (attr), cu, + objfile); DW_STRING_IS_CANONICAL (attr) = 1; } return DW_STRING (attr); diff --git a/gdb/elfread.c b/gdb/elfread.c index 453bca527e9..710ecbf6e17 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -353,11 +353,7 @@ elf_symtab_read (minimal_symbol_reader &reader, if (type == ST_DYNAMIC && !stripped) continue; if (sym->flags & BSF_FILE) - { - filesymname - = ((const char *) objfile->per_bfd->filename_cache.insert - (sym->name, strlen (sym->name) + 1)); - } + filesymname = objfile->intern (sym->name); else if (sym->flags & BSF_SECTION_SYM) continue; else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK diff --git a/gdb/objfiles.h b/gdb/objfiles.h index b71a8a9edb8..a568fa4bcda 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -275,13 +275,9 @@ struct objfile_per_bfd_storage auto_obstack storage_obstack; - /* Byte cache for file names. */ + /* String cache. */ - gdb::bcache filename_cache; - - /* Byte cache for macros. */ - - gdb::bcache macro_cache; + gdb::bcache string_cache; /* The gdbarch associated with the BFD. Note that this gdbarch is determined solely from BFD information, without looking at target @@ -533,6 +529,22 @@ public: return section_offsets[SECT_OFF_DATA (this)]; } + /* Intern STRING and return the unique copy. The copy has the same + lifetime as the per-BFD object. */ + const char *intern (const char *str) + { + return (const char *) per_bfd->string_cache.insert (str, strlen (str) + 1); + } + + /* Intern STRING and return the unique copy. The copy has the same + lifetime as the per-BFD object. */ + const char *intern (const std::string &str) + { + return (const char *) per_bfd->string_cache.insert (str.c_str (), + str.size () + 1); + } + + /* The object file's original name as specified by the user, made absolute, and tilde-expanded. However, it is not canonicalized (i.e., it has not been passed through gdb_realpath). diff --git a/gdb/psymtab.c b/gdb/psymtab.c index fd7fc8feff2..69176dbee47 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1656,9 +1656,7 @@ partial_symtab::partial_symtab (const char *filename_, struct objfile *objfile) { objfile->partial_symtabs->install_psymtab (this); - filename - = ((const char *) objfile->per_bfd->filename_cache.insert - (filename_, strlen (filename_) + 1)); + filename = objfile->intern (filename_); if (symtab_create_debug) { diff --git a/gdb/symfile.c b/gdb/symfile.c index f7bada75f35..dc423f0344a 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2778,9 +2778,7 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename) struct symtab *symtab = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symtab); - symtab->filename - = ((const char *) objfile->per_bfd->filename_cache.insert - (filename, strlen (filename) + 1)); + symtab->filename = objfile->intern (filename); symtab->fullname = NULL; symtab->language = deduce_language_from_filename (filename); diff --git a/gdb/symmisc.c b/gdb/symmisc.c index a6a7e728c4a..1d7c3816670 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -71,9 +71,7 @@ print_symbol_bcache_statistics (void) objfile_name (objfile)); objfile->partial_symtabs->psymbol_cache.print_statistics ("partial symbol cache"); - objfile->per_bfd->macro_cache.print_statistics - ("preprocessor macro cache"); - objfile->per_bfd->filename_cache.print_statistics ("file name cache"); + objfile->per_bfd->string_cache.print_statistics ("string cache"); } } @@ -135,10 +133,8 @@ print_objfile_statistics (void) printf_filtered (_(" Total memory used for psymbol cache: %d\n"), objfile->partial_symtabs->psymbol_cache.memory_used ()); - printf_filtered (_(" Total memory used for macro cache: %d\n"), - objfile->per_bfd->macro_cache.memory_used ()); - printf_filtered (_(" Total memory used for file name cache: %d\n"), - objfile->per_bfd->filename_cache.memory_used ()); + printf_filtered (_(" Total memory used for string cache: %d\n"), + objfile->per_bfd->string_cache.memory_used ()); } }