comparison hotspot/src/share/vm/utilities/hashtable.hpp @ 26421:37d88e604ad0

8056084: Refactor Hashtable to allow implementations without rehashing support Reviewed-by: gziemski, jmasa, brutisso, coleenp, tschatzl
author mgerdin
date Fri, 29 Aug 2014 13:08:01 +0200
parents 0f438571f278
children 1c7168ea0034
comparison
equal deleted inserted replaced
17:8b88d1937174 18:b1caa3f43749
176 int _lookup_count; 176 int _lookup_count;
177 int _lookup_length; 177 int _lookup_length;
178 void verify_lookup_length(double load); 178 void verify_lookup_length(double load);
179 #endif 179 #endif
180 180
181 enum {
182 rehash_count = 100,
183 rehash_multiple = 60
184 };
185
186 void initialize(int table_size, int entry_size, int number_of_entries); 181 void initialize(int table_size, int entry_size, int number_of_entries);
187 182
188 // Accessor 183 // Accessor
189 int entry_size() const { return _entry_size; } 184 int entry_size() const { return _entry_size; }
190 185
192 BasicHashtableEntry<F>* bucket(int i); 187 BasicHashtableEntry<F>* bucket(int i);
193 188
194 // The following method is not MT-safe and must be done under lock. 189 // The following method is not MT-safe and must be done under lock.
195 BasicHashtableEntry<F>** bucket_addr(int i) { return _buckets[i].entry_addr(); } 190 BasicHashtableEntry<F>** bucket_addr(int i) { return _buckets[i].entry_addr(); }
196 191
192 // Attempt to get an entry from the free list
193 BasicHashtableEntry<F>* new_entry_free_list();
194
197 // Table entry management 195 // Table entry management
198 BasicHashtableEntry<F>* new_entry(unsigned int hashValue); 196 BasicHashtableEntry<F>* new_entry(unsigned int hashValue);
199
200 // Check that the table is unbalanced
201 bool check_rehash_table(int count);
202 197
203 // Used when moving the entry to another table 198 // Used when moving the entry to another table
204 // Clean up links, but do not add to free_list 199 // Clean up links, but do not add to free_list
205 void unlink_entry(BasicHashtableEntry<F>* entry) { 200 void unlink_entry(BasicHashtableEntry<F>* entry) {
206 entry->set_next(NULL); 201 entry->set_next(NULL);
275 // The following method is not MT-safe and must be done under lock. 270 // The following method is not MT-safe and must be done under lock.
276 HashtableEntry<T, F>** bucket_addr(int i) { 271 HashtableEntry<T, F>** bucket_addr(int i) {
277 return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i); 272 return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i);
278 } 273 }
279 274
275 };
276
277 template <class T, MEMFLAGS F> class RehashableHashtable : public Hashtable<T, F> {
278 protected:
279
280 enum {
281 rehash_count = 100,
282 rehash_multiple = 60
283 };
284
285 // Check that the table is unbalanced
286 bool check_rehash_table(int count);
287
288 public:
289 RehashableHashtable(int table_size, int entry_size)
290 : Hashtable<T, F>(table_size, entry_size) { }
291
292 RehashableHashtable(int table_size, int entry_size,
293 HashtableBucket<F>* buckets, int number_of_entries)
294 : Hashtable<T, F>(table_size, entry_size, buckets, number_of_entries) { }
295
296
280 // Function to move these elements into the new table. 297 // Function to move these elements into the new table.
281 void move_to(Hashtable<T, F>* new_table); 298 void move_to(RehashableHashtable<T, F>* new_table);
282 static bool use_alternate_hashcode() { return _seed != 0; } 299 static bool use_alternate_hashcode() { return _seed != 0; }
283 static juint seed() { return _seed; } 300 static juint seed() { return _seed; }
284 301
285 static int literal_size(Symbol *symbol); 302 static int literal_size(Symbol *symbol);
286 static int literal_size(oop oop); 303 static int literal_size(oop oop);
290 // Hashtable<ConstantPool*, mtClass>::dump_table() even though we never call this function 307 // Hashtable<ConstantPool*, mtClass>::dump_table() even though we never call this function
291 // in the VM code. 308 // in the VM code.
292 static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;} 309 static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;}
293 static int literal_size(Klass *k) {Unimplemented(); return 0;} 310 static int literal_size(Klass *k) {Unimplemented(); return 0;}
294 311
295 public:
296 void dump_table(outputStream* st, const char *table_name); 312 void dump_table(outputStream* st, const char *table_name);
297 313
298 private: 314 private:
299 static juint _seed; 315 static juint _seed;
300 }; 316 };