* ada symbol lookup cache: disable for 7.9? @ 2015-01-18 5:25 Doug Evans 2015-01-19 15:04 ` Joel Brobecker 2015-01-19 17:22 ` [PATCH] [Ada] Do not re-cache symbol-lookup result found from cache lookup Joel Brobecker 0 siblings, 2 replies; 8+ messages in thread From: Doug Evans @ 2015-01-18 5:25 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches Hi. Just a heads up that I've filed three bugs related to ada's symbol lookup cache. I happened on the first one, 17854, while trying to see why my testcase to exercise the failure I'd expect from 17855 wasn't working. It turns out that ada-lang.c accidently never uses its symbol lookup cache (AFAICT!). Rather, it will create a new one for each lookup, not recording the cache in pspace_data, and leaking the memory. Once I fixed 17854 I verified 17855 is real, though I don't yet have a testcase that crashes gdb (we should add some sort of deterministic assert that the cache has been flushed after symbols have been reloaded). I then found 17856, which is that now that the cache is being used, I see ada-lang.c trying to save back in the cache a symbol it just found in the cache. I stopped looking at this point. Anyways, given that until now ada's symbol lookup cache has never been used, if we turn it on I'm not sure if there aren't more bugs, and to fix the mem-leak for 7.9 (which happens for every non-local symbol lookup IIUC), maybe it'd be safer to disable the cache. https://sourceware.org/bugzilla/show_bug.cgi?id=17854 https://sourceware.org/bugzilla/show_bug.cgi?id=17855 https://sourceware.org/bugzilla/show_bug.cgi?id=17856 btw, I'm totally ok with not including the general symbol lookup cache in 7.9. I thought it was sufficiently robust, but once I found 17855 I had to reassess that. :-) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ada symbol lookup cache: disable for 7.9? 2015-01-18 5:25 ada symbol lookup cache: disable for 7.9? Doug Evans @ 2015-01-19 15:04 ` Joel Brobecker 2015-01-20 22:00 ` Doug Evans 2015-02-02 3:33 ` pushed: [Ada] pspace_data->sym_cache is always NULL (was: "ada symbol lookup cache: disable for 7.9?") Joel Brobecker 2015-01-19 17:22 ` [PATCH] [Ada] Do not re-cache symbol-lookup result found from cache lookup Joel Brobecker 1 sibling, 2 replies; 8+ messages in thread From: Joel Brobecker @ 2015-01-19 15:04 UTC (permalink / raw) To: Doug Evans; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 1460 bytes --] > It turns out that ada-lang.c accidently never uses its symbol lookup > cache (AFAICT!). > Rather, it will create a new one for each lookup, not recording the > cache in pspace_data, > and leaking the memory. Indeed! Attached is a patch that fixes this issue. I've tested on x86_64-linux, after having applied your testscase update (https://www.sourceware.org/ml/gdb-patches/2015-01/msg00510.html), as well as the fix you posted in PR 17855 (https://sourceware.org/bugzilla/show_bug.cgi?id=17855). No regression. As to whether we should deactivate it entirely for 7.9, I would personally prefer we tried to fix the bug(s), and see where we get. It used to work fine until I accidently botched the initialization of that cache when I tried to make it per-program-space. That's what I'll do anyway for AdaCore's version. However, if you think it's better to disable it entirely for the FSF version, I will accept that. gdb/ChangeLog: PR gdb/17854: * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache when allocating a new one. We need your fix from PR 17855 before we can commit this one, because your testcase update reveals a regression as soon as the cache gets activated (I tested your patch on x86_64-linux as part of this testing). I'll start looking at re-caching entries obtained from cache. It seems that it's a real waste of memory, but not bad enough to actually cause a functional issue? Thanks, -- Joel [-- Attachment #2: 0001-Ada-pspace_data-sym_cache-is-always-NULL.patch --] [-- Type: text/x-diff, Size: 1877 bytes --] From 13e46b9a4e665ccc9ae6d99f63e240f98f67d184 Mon Sep 17 00:00:00 2001 From: Joel Brobecker <brobecker@adacore.com> Date: Mon, 19 Jan 2015 12:57:44 +0100 Subject: [PATCH] [Ada] pspace_data->sym_cache is always NULL The Ada symbol cache has been designed to have one instance of that of that cache per program space, and for each instance to be created on-demand. ada_get_symbol_cache is the function responsible for both lookup and creation on demand. Unfortunately, ada_get_symbol_cache forgot to store the reference to newly created caches, thus causing it to: - Leak old caches; - Allocate a new cache each time the cache is being searched or a new entry is to be inserted. This patch fixes the issue by avoiding the use of the local variable, which indirectly allowed the bug to happen. We manipulate the reference in the program-space data instead. gdb/ChangeLog: PR gdb/17854: * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache when allocating a new one. --- gdb/ada-lang.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f5753f1..2c98191 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4404,15 +4404,14 @@ static struct ada_symbol_cache * ada_get_symbol_cache (struct program_space *pspace) { struct ada_pspace_data *pspace_data = get_ada_pspace_data (pspace); - struct ada_symbol_cache *sym_cache = pspace_data->sym_cache; - if (sym_cache == NULL) + if (pspace_data->sym_cache == NULL) { - sym_cache = XCNEW (struct ada_symbol_cache); - ada_init_symbol_cache (sym_cache); + pspace_data->sym_cache = XCNEW (struct ada_symbol_cache); + ada_init_symbol_cache (pspace_data->sym_cache); } - return sym_cache; + return pspace_data->sym_cache; } /* Clear all entries from the symbol cache. */ -- 1.9.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ada symbol lookup cache: disable for 7.9? 2015-01-19 15:04 ` Joel Brobecker @ 2015-01-20 22:00 ` Doug Evans 2015-02-02 3:33 ` pushed: [Ada] pspace_data->sym_cache is always NULL (was: "ada symbol lookup cache: disable for 7.9?") Joel Brobecker 1 sibling, 0 replies; 8+ messages in thread From: Doug Evans @ 2015-01-20 22:00 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches On Mon, Jan 19, 2015 at 7:04 AM, Joel Brobecker <brobecker@adacore.com> wrote: > As to whether we should deactivate it entirely for 7.9, I would > personally prefer we tried to fix the bug(s), and see where we get. > It used to work fine until I accidently botched the initialization > of that cache when I tried to make it per-program-space. That's > what I'll do anyway for AdaCore's version. However, if you think > it's better to disable it entirely for the FSF version, I will > accept that. Since this is ada-specific, I don't feel comfortable making such a call. I was just thinking that at least until now it hasn't really been tested in the FSF tree and given how late in the day it is ... But again, it's your call. ^ permalink raw reply [flat|nested] 8+ messages in thread
* pushed: [Ada] pspace_data->sym_cache is always NULL (was: "ada symbol lookup cache: disable for 7.9?") 2015-01-19 15:04 ` Joel Brobecker 2015-01-20 22:00 ` Doug Evans @ 2015-02-02 3:33 ` Joel Brobecker 2015-02-02 3:41 ` pushed/7.9: " Joel Brobecker 1 sibling, 1 reply; 8+ messages in thread From: Joel Brobecker @ 2015-02-02 3:33 UTC (permalink / raw) To: gdb-patches > gdb/ChangeLog: > > PR gdb/17854: > * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache > when allocating a new one. This one is now in. -- Joel ^ permalink raw reply [flat|nested] 8+ messages in thread
* pushed/7.9: [Ada] pspace_data->sym_cache is always NULL (was: "ada symbol lookup cache: disable for 7.9?") 2015-02-02 3:33 ` pushed: [Ada] pspace_data->sym_cache is always NULL (was: "ada symbol lookup cache: disable for 7.9?") Joel Brobecker @ 2015-02-02 3:41 ` Joel Brobecker 0 siblings, 0 replies; 8+ messages in thread From: Joel Brobecker @ 2015-02-02 3:41 UTC (permalink / raw) To: gdb-patches I forgot about pushing them in the gdb-7.9-branch... Now done. On Mon, Feb 02, 2015 at 07:33:05AM +0400, Joel Brobecker wrote: > > gdb/ChangeLog: > > > > PR gdb/17854: > > * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache > > when allocating a new one. > > This one is now in. -- Joel ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] [Ada] Do not re-cache symbol-lookup result found from cache lookup. 2015-01-18 5:25 ada symbol lookup cache: disable for 7.9? Doug Evans 2015-01-19 15:04 ` Joel Brobecker @ 2015-01-19 17:22 ` Joel Brobecker 2015-02-02 3:34 ` pushed: " Joel Brobecker 1 sibling, 1 reply; 8+ messages in thread From: Joel Brobecker @ 2015-01-19 17:22 UTC (permalink / raw) To: gdb-patches; +Cc: Doug Evans When ada-lang.c:ada_lookup_symbol_list_worker finds a match in the symbol cache, it caches the result again, which is unecessary. This patch fixes the code to avoid that. gdb/ChangeLog: PR 17856: * ada-lang.c (ada_lookup_symbol_list_worker): Do not re-cache results found in the cache. Tested on x86_64-linux, no regression. I'll push in a couple of days if no objection. --- gdb/ada-lang.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index ccad0a0..c081c13 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5612,14 +5612,12 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0, const struct block *block; const char *name; const int wild_match_p = should_use_wild_match (name0); - int cacheIfUnique; + int syms_from_global_search = 0; int ndefns; obstack_free (&symbol_list_obstack, NULL); obstack_init (&symbol_list_obstack); - cacheIfUnique = 0; - /* Search specified block and its superiors. */ name = name0; block = block0; @@ -5662,7 +5660,6 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0, already performed this search before. If we have, then return the same result. */ - cacheIfUnique = 1; if (lookup_cached_symbol (name0, namespace, &sym, &block)) { if (sym != NULL) @@ -5670,6 +5667,8 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0, goto done; } + syms_from_global_search = 1; + /* Search symbols from all global blocks. */ add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 1, @@ -5688,10 +5687,10 @@ done: ndefns = remove_extra_symbols (*results, ndefns); - if (ndefns == 0 && full_search) + if (ndefns == 0 && full_search && syms_from_global_search) cache_symbol (name0, namespace, NULL, NULL); - if (ndefns == 1 && full_search && cacheIfUnique) + if (ndefns == 1 && full_search && syms_from_global_search) cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block); ndefns = remove_irrelevant_renamings (*results, ndefns, block0); -- 1.9.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* pushed: [Ada] Do not re-cache symbol-lookup result found from cache lookup. 2015-01-19 17:22 ` [PATCH] [Ada] Do not re-cache symbol-lookup result found from cache lookup Joel Brobecker @ 2015-02-02 3:34 ` Joel Brobecker 2015-02-02 3:41 ` pushed/7.9: " Joel Brobecker 0 siblings, 1 reply; 8+ messages in thread From: Joel Brobecker @ 2015-02-02 3:34 UTC (permalink / raw) To: gdb-patches > gdb/ChangeLog: > > PR 17856: > * ada-lang.c (ada_lookup_symbol_list_worker): Do not re-cache > results found in the cache. > > Tested on x86_64-linux, no regression. Pushed! -- Joel ^ permalink raw reply [flat|nested] 8+ messages in thread
* pushed/7.9: [Ada] Do not re-cache symbol-lookup result found from cache lookup. 2015-02-02 3:34 ` pushed: " Joel Brobecker @ 2015-02-02 3:41 ` Joel Brobecker 0 siblings, 0 replies; 8+ messages in thread From: Joel Brobecker @ 2015-02-02 3:41 UTC (permalink / raw) To: gdb-patches Forgot about the gdb-7.9-branch... Now fixed. On Mon, Feb 02, 2015 at 07:34:17AM +0400, Joel Brobecker wrote: > > gdb/ChangeLog: > > > > PR 17856: > > * ada-lang.c (ada_lookup_symbol_list_worker): Do not re-cache > > results found in the cache. > > > > Tested on x86_64-linux, no regression. > > Pushed! -- Joel ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-02-02 3:41 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-01-18 5:25 ada symbol lookup cache: disable for 7.9? Doug Evans 2015-01-19 15:04 ` Joel Brobecker 2015-01-20 22:00 ` Doug Evans 2015-02-02 3:33 ` pushed: [Ada] pspace_data->sym_cache is always NULL (was: "ada symbol lookup cache: disable for 7.9?") Joel Brobecker 2015-02-02 3:41 ` pushed/7.9: " Joel Brobecker 2015-01-19 17:22 ` [PATCH] [Ada] Do not re-cache symbol-lookup result found from cache lookup Joel Brobecker 2015-02-02 3:34 ` pushed: " Joel Brobecker 2015-02-02 3:41 ` pushed/7.9: " Joel Brobecker
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).