static fileCC *CC_table[N_FILE_ENTRIES];
//------------------------------------------------------------
-// Primary data structre #2: Instr-info table
+// Primary data structure #2: Instr-info table
// - Holds the cached info about each instr that is used for simulation.
// - table(BB_start_addr, list(instr_info))
// - For each BB, each instr_info in the list holds info about the
VG_(sprintf)(cachegrind_out_file, "%s/cachegrind.out.%d",
base_dir, VG_(getpid)());
- instr_info_table = VG_(HT_construct)();
+ instr_info_table = VG_(HT_construct)( 4999 ); // prime, biggish
}
VG_DETERMINE_INTERFACE_VERSION(cg_pre_clo_init, 0)
/*--------------------------------------------------------------------*/
-/*--- end cg_main.c ---*/
+/*--- end ---*/
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
-/*--- A separately chained hash table. m_hashtable.c ---*/
+/*--- A separately-chained hash table. m_hashtable.c ---*/
/*--------------------------------------------------------------------*/
/*
/*--- Declarations ---*/
/*--------------------------------------------------------------------*/
-/* Holds malloc'd but not freed blocks. Static, so zero-inited by default. */
-
-//#define VG_N_CHAINS 80021 /*4999*/ /* a prime number */
-
#define CHAIN_NO(key,tbl) (((UWord)(key)) % tbl->n_chains)
-struct {
+struct _VgHashTable {
UInt n_chains; // should be prime
VgHashNode* chains[0];
-}
-_VgHashTable;
-
-typedef (struct _VgHashTable *) VgHashTable;
+};
/*--------------------------------------------------------------------*/
/*--- Functions ---*/
VgHashTable VG_(HT_construct)(UInt n_chains)
{
/* Initialises to zero, ie. all entries NULL */
- VgHashTable* table =
- VG_(calloc)(sizeof(struct _VgHashTable) + n_chains*sizeof(VgHashNode*));
+ SizeT sz = sizeof(struct _VgHashTable) + n_chains*sizeof(VgHashNode*);
+ VgHashTable table = VG_(calloc)(1, sz);
table->n_chains = n_chains;
+ return table;
}
Int VG_(HT_count_nodes) ( VgHashTable table )
return n;
}
-/* Puts a new, heap allocated VgHashNode, into the malloclist. */
+/* Puts a new, heap allocated VgHashNode, into the VgHashTable. Prepends
+ the node to the appropriate chain. */
void VG_(HT_add_node) ( VgHashTable table, VgHashNode* node )
{
- UInt chain = CHAIN_NO(node->key);
- node->next = table->chains[chain];
- table[chain] = node;
+ UInt chain = CHAIN_NO(node->key, table);
+ node->next = table->chains[chain];
+ table->chains[chain] = node;
}
/* Looks up a VgHashNode in the table. Also returns the address of
VgHashNode *prev, *curr;
Int chain;
- chain = CHAIN_NO(key);
+ chain = CHAIN_NO(key, table);
prev = NULL;
curr = table->chains[chain];
}
if (NULL == prev)
- *next_ptr = & (table->chain[chain]);
+ *next_ptr = & (table->chains[chain]);
else
*next_ptr = & (prev->next);
}
init_shadow_memory();
- hg_malloc_list = VG_(HT_construct)();
+ hg_malloc_list = VG_(HT_construct)( 80021 ); // prime, big
}
/* Uses a 1:1 mapping */
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.
+// Problems with this data structure:
// - 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
}
VgHashNode;
-typedef
- VgHashNode**
- VgHashTable;
+typedef struct _VgHashTable * VgHashTable;
/* Make a new table. Allocates the memory with VG_(calloc)(), so can be freed
- * with VG_(free)(). */
-extern VgHashTable VG_(HT_construct) ( void );
+ with VG_(free)(). n_chains should be prime. */
+extern VgHashTable VG_(HT_construct) ( UInt n_chains );
/* Count the number of nodes in a table. */
extern Int VG_(HT_count_nodes) ( VgHashTable table );
VG_(register_profile_event)(VgpPrintXPts, "print-XPts");
// HP_Chunks
- malloc_list = VG_(HT_construct)();
+ malloc_list = VG_(HT_construct)( 80021 ); // prime, big
// Dummy node at top of the context structure.
alloc_xpt = new_XPt(0, NULL, /*is_bottom*/False);
mp->pool = pool;
mp->rzB = rzB;
mp->is_zeroed = is_zeroed;
- mp->chunks = VG_(HT_construct)();
+ mp->chunks = VG_(HT_construct)( 3001 ); // prime, not so big
/* Paranoia ... ensure this area is off-limits to the client, so
the mp->data field isn't visible to the leak checker. If memory
void MAC_(common_pre_clo_init)(void)
{
- MAC_(malloc_list) = VG_(HT_construct)();
- MAC_(mempool_list) = VG_(HT_construct)();
+ MAC_(malloc_list) = VG_(HT_construct)( 80021 ); // prime, big
+ MAC_(mempool_list) = VG_(HT_construct)( 1009 ); // prime, not so big
init_prof_mem();
}