+2010-08-31 Sami Wagiaalla <swagiaal@redhat.com>
+
+ * symfile.c (reread_symbols): Use psymbol_bcache_free, and
+ psymbol_bcache_init.
+ * psymtab.h (psymbol_bcache_init): New function prototype.
+ (psymbol_bcache_free): New function prototype.
+ (psymbol_bcache_get_bcache): New function prototype.
+ * psymtab.c (psymbol_bcache_init): New function.
+ (psymbol_bcache_free): New function.
+ (psymbol_bcache_full): New function.
+ (psymbol_bcache_get_bcache): New function.
+ (add_psymbol_to_bcache): use psymbol_bcache_full.
+ * objfiles.h (psymbol_cache): Change type of psymbol_cache to
+ psymbol_bcache.
+ * symmisc.c (print_symbol_bcache_statistics): Updated.
+ (print_objfile_statistics): Updated.
+ * objfiles.c (allocate_objfile): Use psymbol_bcache_init to initialize
+ psymbol_cache.
+ (free_objfile): Use psymbol_bcache_free.
+
2010-08-31 Tom Tromey <tromey@redhat.com>
PR c++/11961:
struct objfile *objfile;
objfile = (struct objfile *) xzalloc (sizeof (struct objfile));
- objfile->psymbol_cache = bcache_xmalloc (psymbol_hash, psymbol_compare);
+ objfile->psymbol_cache = psymbol_bcache_init ();
objfile->macro_cache = bcache_xmalloc (NULL, NULL);
objfile->filename_cache = bcache_xmalloc (NULL, NULL);
/* We could use obstack_specify_allocation here instead, but
if (objfile->static_psymbols.list)
xfree (objfile->static_psymbols.list);
/* Free the obstacks for non-reusable objfiles */
- bcache_xfree (objfile->psymbol_cache);
+ psymbol_bcache_free (objfile->psymbol_cache);
bcache_xfree (objfile->macro_cache);
bcache_xfree (objfile->filename_cache);
if (objfile->demangled_names_hash)
/* A byte cache where we can stash arbitrary "chunks" of bytes that
will not change. */
- struct bcache *psymbol_cache; /* Byte cache for partial syms */
+ struct psymbol_bcache *psymbol_cache; /* Byte cache for partial syms */
struct bcache *macro_cache; /* Byte cache for macros */
struct bcache *filename_cache; /* Byte cache for file names. */
#define DEV_TTY "/dev/tty"
#endif
+struct psymbol_bcache
+{
+ struct bcache *bcache;
+};
+
/* A fast way to get from a psymtab to its symtab (after the first time). */
#define PSYMTAB_TO_SYMTAB(pst) \
((pst) -> symtab != NULL ? (pst) -> symtab : psymtab_to_symtab (pst))
and name. These are the values which are set by
add_psymbol_to_bcache. */
-unsigned long
+static unsigned long
psymbol_hash (const void *addr, int length)
{
unsigned long h = 0;
For the comparison this function uses a symbols value,
language, domain, class and name. */
-int
+static int
psymbol_compare (const void *addr1, const void *addr2, int length)
{
struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
&& sym1->ginfo.name == sym2->ginfo.name);
}
+/* Initialize a partial symbol bcache. */
+
+struct psymbol_bcache *
+psymbol_bcache_init (void)
+{
+ struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
+ bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
+ return bcache;
+}
+
+/* Free a partial symbol bcache. */
+void
+psymbol_bcache_free (struct psymbol_bcache *bcache)
+{
+ if (bcache == NULL)
+ return;
+
+ bcache_xfree (bcache->bcache);
+ xfree (bcache);
+}
+
+/* Return the internal bcache of the psymbol_bcache BCACHE*/
+
+struct bcache *
+psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
+{
+ return bcache->bcache;
+}
+
+/* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
+ symbol before, add a copy to BCACHE. In either case, return a pointer
+ to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
+ 1 in case of new entry or 0 if returning an old entry. */
+
+static const struct partial_symbol *
+psymbol_bcache_full (struct partial_symbol *sym,
+ struct psymbol_bcache *bcache,
+ int *added)
+{
+ return bcache_full (sym,
+ sizeof (struct partial_symbol),
+ bcache->bcache,
+ added);
+}
+
/* Helper function, initialises partial symbol structure and stashes
it into objfile's bcache. Note that our caching mechanism will
use all fields of struct partial_symbol to determine hash value of the
SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
/* Stash the partial symbol away in the cache */
- return bcache_full (&psymbol, sizeof (struct partial_symbol),
- objfile->psymbol_cache, added);
+ return psymbol_bcache_full (&psymbol,
+ objfile->psymbol_cache,
+ added);
}
/* Helper function, adds partial symbol to the given partial symbol
#ifndef PSYMTAB_H
#define PSYMTAB_H
-extern unsigned long psymbol_hash (const void *addr, int length);
-extern int psymbol_compare (const void *addr1, const void *addr2, int length);
+/* A bcache for partial symbols. */
+
+struct psymbol_bcache;
+
+extern struct psymbol_bcache *psymbol_bcache_init (void);
+extern void psymbol_bcache_free (struct psymbol_bcache *);
+extern struct bcache *psymbol_bcache_get_bcache (struct psymbol_bcache *);
void map_partial_symbol_names (void (*) (const char *, void *), void *);
sizeof (objfile->static_psymbols));
/* Free the obstacks for non-reusable objfiles */
- bcache_xfree (objfile->psymbol_cache);
- objfile->psymbol_cache = bcache_xmalloc (psymbol_hash,
- psymbol_compare);
+ psymbol_bcache_free (objfile->psymbol_cache);
+ objfile->psymbol_cache = psymbol_bcache_init ();
bcache_xfree (objfile->macro_cache);
objfile->macro_cache = bcache_xmalloc (NULL, NULL);
bcache_xfree (objfile->filename_cache);
memset (&objfile->msymbol_demangled_hash, 0,
sizeof (objfile->msymbol_demangled_hash));
- objfile->psymbol_cache = bcache_xmalloc (psymbol_hash,
- psymbol_compare);
+ objfile->psymbol_cache = psymbol_bcache_init ();
objfile->macro_cache = bcache_xmalloc (NULL, NULL);
objfile->filename_cache = bcache_xmalloc (NULL, NULL);
/* obstack_init also initializes the obstack so it is
ALL_PSPACE_OBJFILES (pspace, objfile)
{
printf_filtered (_("Byte cache statistics for '%s':\n"), objfile->name);
- print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
+ print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
+ "partial symbol cache");
print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
print_bcache_statistics (objfile->filename_cache, "file name cache");
}
printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
obstack_memory_used (&objfile->objfile_obstack));
printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
- bcache_memory_used (objfile->psymbol_cache));
+ bcache_memory_used (psymbol_bcache_get_bcache
+ (objfile->psymbol_cache)));
printf_filtered (_(" Total memory used for macro cache: %d\n"),
bcache_memory_used (objfile->macro_cache));
printf_filtered (_(" Total memory used for file name cache: %d\n"),