]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Modularised vg_hashtable.c as m_hashtable.
authorNicholas Nethercote <njn@valgrind.org>
Sat, 14 May 2005 21:28:43 +0000 (21:28 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sat, 14 May 2005 21:28:43 +0000 (21:28 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3710

cachegrind/cg_main.c
coregrind/Makefile.am
coregrind/m_hashtable.c [moved from coregrind/vg_hashtable.c with 96% similarity]
coregrind/pub_core_hashtable.h [new file with mode: 0644]
helgrind/hg_main.c
include/Makefile.am
include/pub_tool_hashtable.h [new file with mode: 0644]
include/tool.h
massif/ms_main.c
memcheck/mac_shared.h

index a21cb8512e4f2c1035e7e83dfc8de362b2d0d755..0bf049918b47508b66a9c9b84d0a544944f73638 100644 (file)
@@ -30,6 +30,7 @@
 */
 
 #include "tool.h"
+#include "pub_tool_hashtable.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_tooliface.h"
 
index 8c51c7ea23e306e4cc19531e77cffef47ad18ca0..a0b1596cc805b0196c6913ba031357716673187b 100644 (file)
@@ -45,6 +45,7 @@ noinst_HEADERS = \
        pub_core_dispatch_asm.h \
        pub_core_errormgr.h     \
        pub_core_execontext.h   \
+       pub_core_hashtable.h    \
        pub_core_mallocfree.h   \
        pub_core_replacemalloc.h\
        pub_core_sigframe.h     \
@@ -76,6 +77,7 @@ stage2_SOURCES = \
        m_debuglog.c \
        m_errormgr.c \
        m_execontext.c \
+       m_hashtable.c \
        m_mallocfree.c \
        m_skiplist.c \
        m_stacktrace.c \
@@ -85,7 +87,6 @@ stage2_SOURCES = \
        ume.c \
        \
        vg_scheduler.c \
-       vg_hashtable.c \
        vg_main.c \
        vg_messages.c \
        vg_mylibc.c \
similarity index 96%
rename from coregrind/vg_hashtable.c
rename to coregrind/m_hashtable.c
index 7f070df7a630e22cc8f374e189817b67a57b3da1..9e19dd99bbdbf0d522116668bc835f258d5c19d1 100644 (file)
@@ -1,6 +1,6 @@
 
 /*--------------------------------------------------------------------*/
-/*--- A separately chained hash table.              vg_hashtable.c ---*/
+/*--- A separately chained hash table.               m_hashtable.c ---*/
 /*--------------------------------------------------------------------*/
 
 /*
@@ -29,6 +29,7 @@
 */
 
 #include "core.h"
+#include "pub_core_hashtable.h"
 
 /*--------------------------------------------------------------------*/
 /*--- Declarations                                                 ---*/
@@ -176,5 +177,5 @@ void VG_(HT_destruct)(VgHashTable table)
 }
 
 /*--------------------------------------------------------------------*/
-/*--- end                                           vg_hashtable.c ---*/
+/*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
diff --git a/coregrind/pub_core_hashtable.h b/coregrind/pub_core_hashtable.h
new file mode 100644 (file)
index 0000000..46ede3c
--- /dev/null
@@ -0,0 +1,48 @@
+
+/*--------------------------------------------------------------------*/
+/*--- A separately-chained hash table.        pub_core_hashtable.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_HASHTABLE_H
+#define __PUB_CORE_HASHTABLE_H
+
+//--------------------------------------------------------------------
+// PURPOSE:  A generic data structure with fairly fast lookup for not too
+// many elements, eg. up to a few thousand.
+//--------------------------------------------------------------------
+
+#include "pub_tool_hashtable.h"
+
+// No core-only exports;  everything in this module is visible to both
+// the core and tools.
+
+#endif   // __PUB_CORE_HASHTABLE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index 67caa2e7fde25b3d7a9957adcf19eb9d4c57c7d1..314afb35d017367a8416b5da47d55500a4edfaac 100644 (file)
@@ -30,6 +30,7 @@
 */
 
 #include "tool.h"
+#include "pub_tool_hashtable.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_replacemalloc.h"
 #include "pub_tool_tooliface.h"
index 622e8fb4fab8c6a315f1504e2c81dc82fed1386b..9119c44893888f2b5f4039345877f485ddf2c7a8 100644 (file)
@@ -14,6 +14,7 @@ incinc_HEADERS = \
        tool_asm.h              \
        pub_tool_errormgr.h     \
        pub_tool_execontext.h   \
+       pub_tool_hashtable.h    \
        pub_tool_mallocfree.h   \
        pub_tool_replacemalloc.h\
        pub_tool_skiplist.h     \
diff --git a/include/pub_tool_hashtable.h b/include/pub_tool_hashtable.h
new file mode 100644 (file)
index 0000000..d53f0d8
--- /dev/null
@@ -0,0 +1,98 @@
+
+/*--------------------------------------------------------------------*/
+/*--- A hash table implementation.            pub_tool_hashtable.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_HASHTABLE_H
+#define __PUB_TOOL_HASHTABLE_H
+
+/* Generic type for a separately-chained hash table.  Via a kind of dodgy
+   C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
+   as the first two fields match the sizes of these two fields.  Requires
+   a bit of casting by the tool. */
+
+// Problems with this type:
+// - Table is fixed-size.  
+// - Separate chaining gives bad cache behaviour.  Hash tables with linear
+//   probing give better cache behaviour.
+// - It's not very abstract, eg. deleting nodes exposes more internals than
+//   I'd like.
+
+typedef
+   struct _VgHashNode {
+      struct _VgHashNode * next;
+      UWord              key;
+   }
+   VgHashNode;
+
+typedef
+   VgHashNode**
+   VgHashTable;
+
+/* Make a new table.  Allocates the memory with VG_(calloc)(), so can be freed
+ * with VG_(free)(). */
+extern VgHashTable VG_(HT_construct) ( void );
+
+/* Count the number of nodes in a table. */
+extern Int VG_(HT_count_nodes) ( VgHashTable table );
+
+/* Add a node to the table. */
+extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
+
+/* Looks up a node in the hash table.  Also returns the address of the
+   previous node's `next' pointer which allows it to be removed from the
+   list later without having to look it up again.  */
+extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
+                                    /*OUT*/VgHashNode*** next_ptr );
+
+/* Allocates an array of pointers to all the shadow chunks of malloc'd
+   blocks.  Must be freed with VG_(free)(). */
+extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
+
+/* Returns first node that matches predicate `p', or NULL if none do.
+   Extra arguments can be implicitly passed to `p' using `d' which is an
+   opaque pointer passed to `p' each time it is called. */
+extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
+                                         Bool (*p)(VgHashNode*, void*),
+                                         void* d );
+
+/* Applies a function f() once to each node.  Again, `d' can be used
+   to pass extra information to the function. */
+extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
+                                        void (*f)(VgHashNode*, void*),
+                                        void* d );
+
+/* Destroy a table. */
+extern void VG_(HT_destruct) ( VgHashTable t );
+
+
+#endif   // __PUB_TOOL_HASHTABLE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index 98afc8d17723066f2411e970265f71f98583b1ea..0af508d10fe66a73ac30e6b29532b22000862e6d 100644 (file)
@@ -578,62 +578,6 @@ typedef
 
 extern VgSectKind VG_(seg_sect_kind)(Addr);
 
-/*====================================================================*/
-/*=== Generic hash table                                           ===*/
-/*====================================================================*/
-
-/* Generic type for a separately-chained hash table.  Via a kind of dodgy
-   C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
-   as the first two fields match the sizes of these two fields.  Requires
-   a bit of casting by the tool. */
-typedef
-   struct _VgHashNode {
-      struct _VgHashNode * next;
-      UWord              key;
-   }
-   VgHashNode;
-
-typedef
-   VgHashNode**
-   VgHashTable;
-
-/* Make a new table.  Allocates the memory with VG_(calloc)(), so can be freed
- * with VG_(free)(). */
-extern VgHashTable VG_(HT_construct) ( void );
-
-/* Count the number of nodes in a table. */
-extern Int VG_(HT_count_nodes) ( VgHashTable table );
-
-/* Add a node to the table. */
-extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
-
-/* Looks up a node in the hash table.  Also returns the address of the
-   previous node's `next' pointer which allows it to be removed from the
-   list later without having to look it up again.  */
-extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
-                                    /*OUT*/VgHashNode*** next_ptr );
-
-/* Allocates an array of pointers to all the shadow chunks of malloc'd
-   blocks.  Must be freed with VG_(free)(). */
-extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
-
-/* Returns first node that matches predicate `p', or NULL if none do.
-   Extra arguments can be implicitly passed to `p' using `d' which is an
-   opaque pointer passed to `p' each time it is called. */
-extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
-                                         Bool (*p)(VgHashNode*, void*),
-                                         void* d );
-
-/* Applies a function f() once to each node.  Again, `d' can be used
-   to pass extra information to the function. */
-extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
-                                        void (*f)(VgHashNode*, void*),
-                                        void* d );
-
-/* Destroy a table. */
-extern void VG_(HT_destruct) ( VgHashTable t );
-
-
 /*====================================================================*/
 /*=== Functions for shadow registers                               ===*/
 /*====================================================================*/
index 55be3c2ac0fd906a6afed2c8c339a1dd37ac1119..6c1fc6704441685217155f1c2414ed2f80e4b663 100644 (file)
@@ -35,6 +35,7 @@
 // structures below for more info on how things work.
 
 #include "tool.h"
+#include "pub_tool_hashtable.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_replacemalloc.h"
 #include "pub_tool_stacktrace.h"
index 186021d4dcf7bbf650f217ff366209ea4b05bfbe..9a56bc39fdb1ad2b2e05bff978da2733cbc79d94 100644 (file)
@@ -37,6 +37,7 @@
 #define __MAC_SHARED_H
 
 #include "tool.h"
+#include "pub_tool_hashtable.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_replacemalloc.h"
 #include "pub_tool_tooliface.h"