This is the mail archive of the gdb-patches@sourceware.org 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]

FYI: reference counting for pieced values


I'm checking this in.

The contents of a `struct piece_closure' are immutable, so there is no
reason to copy it when copying a value.  Instead we can just reference
count it.  This is somewhat more efficient.  This patch changes the
implementation of pieced values to do this.

Built and regtested on x86-64 (compile farm).

Tom

2010-05-27  Tom Tromey  <tromey@redhat.com>

	* dwarf2loc.c (struct piece_closure) <refc>: New field.
	(allocate_piece_closure): Initialize refc.
	(copy_pieced_value_closure): Use refc.
	(free_pieced_value_closure): Likewise.

Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.83
diff -u -r1.83 dwarf2loc.c
--- dwarf2loc.c	26 May 2010 15:21:13 -0000	1.83
+++ dwarf2loc.c	27 May 2010 19:11:00 -0000
@@ -231,6 +231,9 @@
 
 struct piece_closure
 {
+  /* Reference count.  */
+  int refc;
+
   /* The number of pieces used to describe this variable.  */
   int n_pieces;
 
@@ -250,6 +253,7 @@
 {
   struct piece_closure *c = XZALLOC (struct piece_closure);
 
+  c->refc = 1;
   c->n_pieces = n_pieces;
   c->addr_size = addr_size;
   c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
@@ -747,7 +751,8 @@
 {
   struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
   
-  return allocate_piece_closure (c->n_pieces, c->pieces, c->addr_size);
+  ++c->refc;
+  return c;
 }
 
 static void
@@ -755,8 +760,12 @@
 {
   struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
 
-  xfree (c->pieces);
-  xfree (c);
+  --c->refc;
+  if (c->refc == 0)
+    {
+      xfree (c->pieces);
+      xfree (c);
+    }
 }
 
 /* Functions for accessing a variable described by DW_OP_piece.  */


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