This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/rfc[ Opaque bcache


Hello,

This makes the bcache object opaque. Testing so far hasn't shown problems. I'll look to commit it in a few days.

comments? Hmm, did I remember to update the makefile ....

Andrew
2002-07-10  Andrew Cagney  <ac131313@redhat.com>

	* symmisc.c: Update copyright.
	(print_symbol_bcache_statistics): Pass psymbol_cache by value.
	(print_objfile_statistics): Use bcache_memory_used.

	* symfile.c: Include "bcache.h".
	(reread_symbols): Use bcache_xfree.
	(reread_symbols): Use bcache_xmalloc and bcache_xfree.
	(add_psymbol_to_list): Pass psymbol_cache by value.
	(add_psymbol_with_dem_name_to_list): Ditto.

	* objfiles.h: Update copyright.
	(struct bcache): Declare opaque.  Do not include "bcache.h".
	(struct objfile): Change psymbol_cache and macro_cache to ``struct
	bcache'' pointers.
	* dwarf2read.c (macro_start_file): Pass macro_cache by value.

	* objfiles.c: Include "bcache.h".  Update copyright.
	(allocate_objfile): Use bcache_xmalloc to create psymbol_cache and
	macro_cache.
	(free_objfile): Use bcache_xfree.

	* bcache.c: Update copyright.
	(struct bstring, struct bcache): Moved to here from "bcache.h".
	(bcache_xmalloc, bcache_memory_used): New functions.
	(bcache_xfree): Replace function free_bcache.
	
	* bcache.h: Update copyright.
	(struct bstring, struct bcache): Move definition to "bcache.c".
	Replaced by opaque declaration.
	(bcache_xfree): Replace free_bcache.
	(bcache_xmalloc, bcache_memory_used): Declare.
	
Index: bcache.c
===================================================================
RCS file: /cvs/src/src/gdb/bcache.c,v
retrieving revision 1.8
diff -u -r1.8 bcache.c
--- bcache.c	15 Apr 2002 05:23:01 -0000	1.8
+++ bcache.c	10 Jul 2002 22:10:35 -0000
@@ -29,6 +29,54 @@
 #include <stddef.h>
 #include <stdlib.h>
 
+/* The type used to hold a single bcache string.  The user data is
+   stored in d.data.  Since it can be any type, it needs to have the
+   same alignment as the most strict alignment of any type on the host
+   machine.  I don't know of any really correct way to do this in
+   stock ANSI C, so just do it the same way obstack.h does.
+
+   It would be nicer to have this stuff hidden away in bcache.c, but
+   struct objstack contains a struct bcache directly --- not a pointer
+   to one --- and then the memory-mapped stuff makes this a real pain.
+   We don't strictly need to expose struct bstring, but it's better to
+   have it all in one place.  */
+
+struct bstring
+{
+  struct bstring *next;
+  size_t length;
+
+  union
+  {
+    char data[1];
+    double dummy;
+  }
+  d;
+};
+
+
+/* The structure for a bcache itself.
+   To initialize a bcache, just fill it with zeros.  */
+struct bcache
+{
+  /* All the bstrings are allocated here.  */
+  struct obstack cache;
+
+  /* How many hash buckets we're using.  */
+  unsigned int num_buckets;
+  
+  /* Hash buckets.  This table is allocated using malloc, so when we
+     grow the table we can return the old table to the system.  */
+  struct bstring **bucket;
+
+  /* Statistics.  */
+  unsigned long unique_count;	/* number of unique strings */
+  long total_count;	/* total number of strings cached, including dups */
+  long unique_size;	/* size of unique strings, in bytes */
+  long total_size;      /* total number of bytes cached, including dups */
+  long structure_size;	/* total size of bcache, including infrastructure */
+};
+
 /* The old hash function was stolen from SDBM. This is what DB 3.0 uses now,
  * and is better than the old one. 
  */
@@ -166,19 +214,26 @@
 }
 
 
-/* Freeing bcaches.  */
+/* Allocating and freeing bcaches.  */
+
+struct bcache *
+bcache_xmalloc (void)
+{
+  /* Allocate the bcache pre-zeroed.  */
+  struct bcache *b = XCALLOC (1, struct bcache);
+  obstack_specify_allocation (&b->cache, 0, 0, xmalloc, xfree);
+  return b;
+}
 
 /* Free all the storage associated with BCACHE.  */
 void
-free_bcache (struct bcache *bcache)
+bcache_xfree (struct bcache *bcache)
 {
+  if (bcache == NULL)
+    return;
   obstack_free (&bcache->cache, 0);
-  if (bcache->bucket)
-    xfree (bcache->bucket);
-
-  /* This isn't necessary, but at least the bcache is always in a
-     consistent state.  */
-  memset (bcache, 0, sizeof (*bcache));
+  xfree (bcache->bucket);
+  xfree (bcache);
 }
 
 
@@ -290,4 +345,10 @@
     printf_filtered ("(not applicable)\n");
   printf_filtered ("    Maximum hash chain length: %3d\n", max_chain_length);
   printf_filtered ("\n");
+}
+
+int
+bcache_memory_used (struct bcache *bcache)
+{
+  return obstack_memory_used (&bcache->cache);
 }
Index: bcache.h
===================================================================
RCS file: /cvs/src/src/gdb/bcache.h,v
retrieving revision 1.5
diff -u -r1.5 bcache.h
--- bcache.h	23 Feb 2002 03:57:26 -0000	1.5
+++ bcache.h	10 Jul 2002 22:10:35 -0000
@@ -1,7 +1,8 @@
 /* Include file cached obstack implementation.
    Written by Fred Fish <fnf@cygnus.com>
    Rewritten by Jim Blandy <jimb@cygnus.com>
-   Copyright 1999, 2000 Free Software Foundation, Inc.
+
+   Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -63,68 +64,27 @@
      any chance of sharing its space with future duplicates.  */
 
 
-/* The type used to hold a single bcache string.  The user data is
-   stored in d.data.  Since it can be any type, it needs to have the
-   same alignment as the most strict alignment of any type on the host
-   machine.  I don't know of any really correct way to do this in
-   stock ANSI C, so just do it the same way obstack.h does.
-
-   It would be nicer to have this stuff hidden away in bcache.c, but
-   struct objstack contains a struct bcache directly --- not a pointer
-   to one --- and then the memory-mapped stuff makes this a real pain.
-   We don't strictly need to expose struct bstring, but it's better to
-   have it all in one place.  */
-
-struct bstring {
-  struct bstring *next;
-  size_t length;
-
-  union
-  {
-    char data[1];
-    double dummy;
-  }
-  d;
-};
-
-
-/* The structure for a bcache itself.
-   To initialize a bcache, just fill it with zeros.  */
-struct bcache {
-  /* All the bstrings are allocated here.  */
-  struct obstack cache;
-
-  /* How many hash buckets we're using.  */
-  unsigned int num_buckets;
-  
-  /* Hash buckets.  This table is allocated using malloc, so when we
-     grow the table we can return the old table to the system.  */
-  struct bstring **bucket;
-
-  /* Statistics.  */
-  unsigned long unique_count;	/* number of unique strings */
-  long total_count;	/* total number of strings cached, including dups */
-  long unique_size;	/* size of unique strings, in bytes */
-  long total_size;      /* total number of bytes cached, including dups */
-  long structure_size;	/* total size of bcache, including infrastructure */
-};
-
+struct bcache;
 
 /* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
    never seen those bytes before, add a copy of them to BCACHE.  In
    either case, return a pointer to BCACHE's copy of that string.  */
 extern void *bcache (const void *addr, int length, struct bcache *bcache);
 
-/* Free all the storage that BCACHE refers to.  The result is a valid,
-   but empty, bcache.  This does not free BCACHE itself, since that
-   might be part of some larger object.  */
-extern void free_bcache (struct bcache *bcache);
+/* Free all the storage used by BCACHE.  */
+extern void bcache_xfree (struct bcache *bcache);
+
+/* Create a new bcache object.  */
+extern struct bcache *bcache_xmalloc (void);
 
 /* Print statistics on BCACHE's memory usage and efficacity at
    eliminating duplication.  TYPE should be a string describing the
    kind of data BCACHE holds.  Statistics are printed using
    `printf_filtered' and its ilk.  */
 extern void print_bcache_statistics (struct bcache *bcache, char *type);
+extern int bcache_memory_used (struct bcache *bcache);
+
 /* The hash function */
 extern unsigned long hash(const void *addr, int length);
+
 #endif /* BCACHE_H */
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.60
diff -u -r1.60 dwarf2read.c
--- dwarf2read.c	22 Jun 2002 00:05:59 -0000	1.60
+++ dwarf2read.c	10 Jul 2002 22:10:39 -0000
@@ -6476,7 +6476,7 @@
      at all until we actually get a filename.  */
   if (! pending_macros)
     pending_macros = new_macro_table (&objfile->symbol_obstack,
-                                      &objfile->macro_cache);
+                                      objfile->macro_cache);
 
   if (! current_file)
     /* If we have no current file, then this must be the start_file
Index: objfiles.c
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.c,v
retrieving revision 1.20
diff -u -r1.20 objfiles.c
--- objfiles.c	15 May 2002 21:19:18 -0000	1.20
+++ objfiles.c	10 Jul 2002 22:10:40 -0000
@@ -1,6 +1,8 @@
 /* GDB routines for manipulating objfiles.
-   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   Free Software Foundation, Inc.
+
+   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+   2001, 2002 Free Software Foundation, Inc.
+
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
@@ -30,6 +32,7 @@
 #include "objfiles.h"
 #include "gdb-stabs.h"
 #include "target.h"
+#include "bcache.h"
 
 #include <sys/types.h>
 #include "gdb_stat.h"
@@ -269,10 +272,8 @@
       objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
       memset (objfile, 0, sizeof (struct objfile));
       objfile->md = NULL;
-      obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0,
-				  xmalloc, xfree);
-      obstack_specify_allocation (&objfile->macro_cache.cache, 0, 0,
-				  xmalloc, xfree);
+      objfile->psymbol_cache = bcache_xmalloc ();
+      objfile->macro_cache = bcache_xmalloc ();
       obstack_specify_allocation (&objfile->psymbol_obstack, 0, 0, xmalloc,
 				  xfree);
       obstack_specify_allocation (&objfile->symbol_obstack, 0, 0, xmalloc,
@@ -483,8 +484,8 @@
       if (objfile->static_psymbols.list)
 	xmfree (objfile->md, objfile->static_psymbols.list);
       /* Free the obstacks for non-reusable objfiles */
-      free_bcache (&objfile->psymbol_cache);
-      free_bcache (&objfile->macro_cache);
+      bcache_xfree (objfile->psymbol_cache);
+      bcache_xfree (objfile->macro_cache);
       obstack_free (&objfile->psymbol_obstack, 0);
       obstack_free (&objfile->symbol_obstack, 0);
       obstack_free (&objfile->type_obstack, 0);
Index: objfiles.h
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.h,v
retrieving revision 1.12
diff -u -r1.12 objfiles.h
--- objfiles.h	28 Jun 2002 22:09:11 -0000	1.12
+++ objfiles.h	10 Jul 2002 22:10:40 -0000
@@ -1,6 +1,7 @@
 /* Definitions for symbol file management in GDB.
-   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
-   Free Software Foundation, Inc.
+
+   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+   2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -22,7 +23,7 @@
 #if !defined (OBJFILES_H)
 #define OBJFILES_H
 
-#include "bcache.h"
+struct bcache;
 
 /* This structure maintains information on a per-objfile basis about the
    "entry point" of the objfile, and the scope within which the entry point
@@ -278,8 +279,8 @@
     /* 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 bcache macro_cache;          /* Byte cache for macros */
+    struct bcache *psymbol_cache;	/* Byte cache for partial syms */
+    struct bcache *macro_cache;          /* Byte cache for macros */
 
     /* Vectors of all partial symbols read in from file.  The actual data
        is stored in the psymbol_obstack. */
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.62
diff -u -r1.62 symfile.c
--- symfile.c	15 May 2002 21:19:20 -0000	1.62
+++ symfile.c	10 Jul 2002 22:10:43 -0000
@@ -40,6 +40,7 @@
 #include "gdb-stabs.h"
 #include "obstack.h"
 #include "completer.h"
+#include "bcache.h"
 
 #include <sys/types.h>
 #include <fcntl.h>
@@ -1740,8 +1741,10 @@
 		      sizeof (objfile->static_psymbols));
 
 	      /* Free the obstacks for non-reusable objfiles */
-	      free_bcache (&objfile->psymbol_cache);
-	      free_bcache (&objfile->macro_cache);
+	      bcache_xfree (objfile->psymbol_cache);
+	      objfile->psymbol_cache = bcache_xmalloc ();
+	      bcache_xfree (objfile->macro_cache);
+	      objfile->macro_cache = bcache_xmalloc ();
 	      obstack_free (&objfile->psymbol_obstack, 0);
 	      obstack_free (&objfile->symbol_obstack, 0);
 	      obstack_free (&objfile->type_obstack, 0);
@@ -1765,10 +1768,8 @@
 	      objfile->md = NULL;
 	      /* obstack_specify_allocation also initializes the obstack so
 	         it is empty.  */
-	      obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0,
-					  xmalloc, xfree);
-	      obstack_specify_allocation (&objfile->macro_cache.cache, 0, 0,
-					  xmalloc, xfree);
+	      objfile->psymbol_cache = bcache_xmalloc ();
+	      objfile->macro_cache = bcache_xmalloc ();
 	      obstack_specify_allocation (&objfile->psymbol_obstack, 0, 0,
 					  xmalloc, xfree);
 	      obstack_specify_allocation (&objfile->symbol_obstack, 0, 0,
@@ -2377,7 +2378,7 @@
   /* Create local copy of the partial symbol */
   memcpy (buf, name, namelength);
   buf[namelength] = '\0';
-  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache);
+  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache);
   /* val and coreaddr are mutually exclusive, one of them *will* be zero */
   if (val != 0)
     {
@@ -2394,7 +2395,7 @@
   SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
 
   /* Stash the partial symbol away in the cache */
-  psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache);
+  psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache);
 
   /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
   if (list->next >= list->list + list->size)
@@ -2429,7 +2430,7 @@
 
   memcpy (buf, name, namelength);
   buf[namelength] = '\0';
-  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, &objfile->psymbol_cache);
+  SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache);
 
   buf = alloca (dem_namelength + 1);
   memcpy (buf, dem_name, dem_namelength);
@@ -2440,11 +2441,11 @@
     case language_c:
     case language_cplus:
       SYMBOL_CPLUS_DEMANGLED_NAME (&psymbol) =
-	bcache (buf, dem_namelength + 1, &objfile->psymbol_cache);
+	bcache (buf, dem_namelength + 1, objfile->psymbol_cache);
       break;
     case language_chill:
       SYMBOL_CHILL_DEMANGLED_NAME (&psymbol) =
-	bcache (buf, dem_namelength + 1, &objfile->psymbol_cache);
+	bcache (buf, dem_namelength + 1, objfile->psymbol_cache);
 
       /* FIXME What should be done for the default case? Ignoring for now. */
     }
@@ -2465,7 +2466,7 @@
   SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
 
   /* Stash the partial symbol away in the cache */
-  psym = bcache (&psymbol, sizeof (struct partial_symbol), &objfile->psymbol_cache);
+  psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache);
 
   /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
   if (list->next >= list->list + list->size)
Index: symmisc.c
===================================================================
RCS file: /cvs/src/src/gdb/symmisc.c,v
retrieving revision 1.9
diff -u -r1.9 symmisc.c
--- symmisc.c	15 May 2002 21:19:21 -0000	1.9
+++ symmisc.c	10 Jul 2002 22:10:43 -0000
@@ -1,6 +1,8 @@
 /* Do various things to symbol tables (other than lookup), for GDB.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
+   1995, 1996, 1997, 1998, 1999, 2000, 2002 Free Software Foundation,
+   Inc.
 
    This file is part of GDB.
 
@@ -161,7 +163,7 @@
   ALL_OBJFILES (objfile)
   {
     printf_filtered ("Byte cache statistics for '%s':\n", objfile->name);
-    print_bcache_statistics (&objfile->psymbol_cache, "partial symbol cache");
+    print_bcache_statistics (objfile->psymbol_cache, "partial symbol cache");
   }
   immediate_quit--;
 }
@@ -196,9 +198,9 @@
     printf_filtered ("  Total memory used for psymbol obstack: %d\n",
 		     obstack_memory_used (&objfile->psymbol_obstack));
     printf_filtered ("  Total memory used for psymbol cache: %d\n",
-		     obstack_memory_used (&objfile->psymbol_cache.cache));
+		     bcache_memory_used (objfile->psymbol_cache));
     printf_filtered ("  Total memory used for macro cache: %d\n",
-		     obstack_memory_used (&objfile->macro_cache.cache));
+		     bcache_memory_used (objfile->macro_cache));
     printf_filtered ("  Total memory used for symbol obstack: %d\n",
 		     obstack_memory_used (&objfile->symbol_obstack));
     printf_filtered ("  Total memory used for type obstack: %d\n",

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]