< prev index next >

src/share/vm/utilities/hashtable.hpp

Print this page




 236   int number_of_entries() { return _number_of_entries; }
 237 
 238   template <class T> void verify_table(const char* table_name) PRODUCT_RETURN;
 239 };
 240 
 241 
 242 template <class T, MEMFLAGS F> class Hashtable : public BasicHashtable<F> {
 243   friend class VMStructs;
 244 
 245 public:
 246   Hashtable(int table_size, int entry_size)
 247     : BasicHashtable<F>(table_size, entry_size) { }
 248 
 249   Hashtable(int table_size, int entry_size,
 250                    HashtableBucket<F>* buckets, int number_of_entries)
 251     : BasicHashtable<F>(table_size, entry_size, buckets, number_of_entries) { }
 252 
 253   // Debugging
 254   void print()               PRODUCT_RETURN;
 255 
 256 protected:
 257 
 258   unsigned int compute_hash(Symbol* name) {
 259     return (unsigned int) name->identity_hash();
 260   }
 261 
 262   int index_for(Symbol* name) {
 263     return this->hash_to_index(compute_hash(name));
 264   }
 265 


 266   // Table entry management
 267   HashtableEntry<T, F>* new_entry(unsigned int hashValue, T obj);


 268 
 269   // The following method is MT-safe and may be used with caution.
 270   HashtableEntry<T, F>* bucket(int i) const {
 271     return (HashtableEntry<T, F>*)BasicHashtable<F>::bucket(i);
 272   }
 273 
 274   // The following method is not MT-safe and must be done under lock.
 275   HashtableEntry<T, F>** bucket_addr(int i) {
 276     return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i);
 277   }
 278 
 279 };
 280 
 281 template <class T, MEMFLAGS F> class RehashableHashtable : public Hashtable<T, F> {
 282  friend class VMStructs;
 283  protected:
 284 
 285   enum {
 286     rehash_count = 100,
 287     rehash_multiple = 60


 306 
 307   static int literal_size(Symbol *symbol);
 308   static int literal_size(oop oop);
 309 
 310   // The following two are currently not used, but are needed anyway because some
 311   // C++ compilers (MacOS and Solaris) force the instantiation of
 312   // Hashtable<ConstantPool*, mtClass>::dump_table() even though we never call this function
 313   // in the VM code.
 314   static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;}
 315   static int literal_size(Klass *k)         {Unimplemented(); return 0;}
 316 
 317   void dump_table(outputStream* st, const char *table_name);
 318 
 319  private:
 320   static juint _seed;
 321 };
 322 
 323 template <class T, MEMFLAGS F> juint RehashableHashtable<T, F>::_seed = 0;
 324 template <class T, MEMFLAGS F> juint RehashableHashtable<T, F>::seed() { return _seed; };
 325 template <class T, MEMFLAGS F> bool  RehashableHashtable<T, F>::use_alternate_hashcode() { return _seed != 0; };
 326 
 327 // Versions of hashtable where two handles are used to compute the index.
 328 
 329 template <class T, MEMFLAGS F> class TwoOopHashtable : public Hashtable<T, F> {
 330   friend class VMStructs;
 331 protected:
 332   TwoOopHashtable(int table_size, int entry_size)
 333     : Hashtable<T, F>(table_size, entry_size) {}
 334 
 335   TwoOopHashtable(int table_size, int entry_size, HashtableBucket<F>* t,
 336                   int number_of_entries)
 337     : Hashtable<T, F>(table_size, entry_size, t, number_of_entries) {}
 338 
 339 public:
 340   unsigned int compute_hash(const Symbol* name, const ClassLoaderData* loader_data) const {
 341     unsigned int name_hash = name->identity_hash();
 342     // loader is null with CDS
 343     assert(loader_data != NULL || UseSharedSpaces || DumpSharedSpaces,
 344            "only allowed with shared spaces");
 345     unsigned int loader_hash = loader_data == NULL ? 0 : loader_data->identity_hash();
 346     return name_hash ^ loader_hash;
 347   }
 348 
 349   int index_for(Symbol* name, ClassLoaderData* loader_data) {
 350     return this->hash_to_index(compute_hash(name, loader_data));
 351   }
 352 };
 353 
 354 #endif // SHARE_VM_UTILITIES_HASHTABLE_HPP


 236   int number_of_entries() { return _number_of_entries; }
 237 
 238   template <class T> void verify_table(const char* table_name) PRODUCT_RETURN;
 239 };
 240 
 241 
 242 template <class T, MEMFLAGS F> class Hashtable : public BasicHashtable<F> {
 243   friend class VMStructs;
 244 
 245 public:
 246   Hashtable(int table_size, int entry_size)
 247     : BasicHashtable<F>(table_size, entry_size) { }
 248 
 249   Hashtable(int table_size, int entry_size,
 250                    HashtableBucket<F>* buckets, int number_of_entries)
 251     : BasicHashtable<F>(table_size, entry_size, buckets, number_of_entries) { }
 252 
 253   // Debugging
 254   void print()               PRODUCT_RETURN;
 255 
 256   unsigned int compute_hash(const Symbol* name) const {


 257     return (unsigned int) name->identity_hash();
 258   }
 259 
 260   int index_for(const Symbol* name) const {
 261     return this->hash_to_index(compute_hash(name));
 262   }
 263 
 264 protected:
 265 
 266   // Table entry management
 267   HashtableEntry<T, F>* new_entry(unsigned int hashValue, T obj);
 268   // Don't create and use freelist
 269   HashtableEntry<T, F>* allocate_new_entry(unsigned int hashValue, T obj);
 270 
 271   // The following method is MT-safe and may be used with caution.
 272   HashtableEntry<T, F>* bucket(int i) const {
 273     return (HashtableEntry<T, F>*)BasicHashtable<F>::bucket(i);
 274   }
 275 
 276   // The following method is not MT-safe and must be done under lock.
 277   HashtableEntry<T, F>** bucket_addr(int i) {
 278     return (HashtableEntry<T, F>**)BasicHashtable<F>::bucket_addr(i);
 279   }
 280 
 281 };
 282 
 283 template <class T, MEMFLAGS F> class RehashableHashtable : public Hashtable<T, F> {
 284  friend class VMStructs;
 285  protected:
 286 
 287   enum {
 288     rehash_count = 100,
 289     rehash_multiple = 60


 308 
 309   static int literal_size(Symbol *symbol);
 310   static int literal_size(oop oop);
 311 
 312   // The following two are currently not used, but are needed anyway because some
 313   // C++ compilers (MacOS and Solaris) force the instantiation of
 314   // Hashtable<ConstantPool*, mtClass>::dump_table() even though we never call this function
 315   // in the VM code.
 316   static int literal_size(ConstantPool *cp) {Unimplemented(); return 0;}
 317   static int literal_size(Klass *k)         {Unimplemented(); return 0;}
 318 
 319   void dump_table(outputStream* st, const char *table_name);
 320 
 321  private:
 322   static juint _seed;
 323 };
 324 
 325 template <class T, MEMFLAGS F> juint RehashableHashtable<T, F>::_seed = 0;
 326 template <class T, MEMFLAGS F> juint RehashableHashtable<T, F>::seed() { return _seed; };
 327 template <class T, MEMFLAGS F> bool  RehashableHashtable<T, F>::use_alternate_hashcode() { return _seed != 0; };



























 328 
 329 #endif // SHARE_VM_UTILITIES_HASHTABLE_HPP
< prev index next >