92 return false; |
92 return false; |
93 } |
93 } |
94 |
94 |
95 template <class T, MEMFLAGS F> jint Hashtable<T, F>::_seed = 0; |
95 template <class T, MEMFLAGS F> jint Hashtable<T, F>::_seed = 0; |
96 |
96 |
97 template <class T, MEMFLAGS F> unsigned int Hashtable<T, F>::new_hash(Symbol* sym) { |
|
98 ResourceMark rm; |
|
99 // Use alternate hashing algorithm on this symbol. |
|
100 return AltHashing::murmur3_32(seed(), (const jbyte*)sym->as_C_string(), sym->utf8_length()); |
|
101 } |
|
102 |
|
103 template <class T, MEMFLAGS F> unsigned int Hashtable<T, F>::new_hash(oop string) { |
|
104 ResourceMark rm; |
|
105 int length; |
|
106 jchar* chars = java_lang_String::as_unicode_string(string, length); |
|
107 // Use alternate hashing algorithm on the string |
|
108 return AltHashing::murmur3_32(seed(), chars, length); |
|
109 } |
|
110 |
|
111 // Create a new table and using alternate hash code, populate the new table |
97 // Create a new table and using alternate hash code, populate the new table |
112 // with the existing elements. This can be used to change the hash code |
98 // with the existing elements. This can be used to change the hash code |
113 // and could in the future change the size of the table. |
99 // and could in the future change the size of the table. |
114 |
100 |
115 template <class T, MEMFLAGS F> void Hashtable<T, F>::move_to(Hashtable<T, F>* new_table) { |
101 template <class T, MEMFLAGS F> void Hashtable<T, F>::move_to(Hashtable<T, F>* new_table) { |
124 for (int i = 0; i < new_table->table_size(); ++i) { |
110 for (int i = 0; i < new_table->table_size(); ++i) { |
125 for (HashtableEntry<T, F>* p = bucket(i); p != NULL; ) { |
111 for (HashtableEntry<T, F>* p = bucket(i); p != NULL; ) { |
126 HashtableEntry<T, F>* next = p->next(); |
112 HashtableEntry<T, F>* next = p->next(); |
127 T string = p->literal(); |
113 T string = p->literal(); |
128 // Use alternate hashing algorithm on the symbol in the first table |
114 // Use alternate hashing algorithm on the symbol in the first table |
129 unsigned int hashValue = new_hash(string); |
115 unsigned int hashValue = string->new_hash(seed()); |
130 // Get a new index relative to the new table (can also change size) |
116 // Get a new index relative to the new table (can also change size) |
131 int index = new_table->hash_to_index(hashValue); |
117 int index = new_table->hash_to_index(hashValue); |
132 p->set_hash(hashValue); |
118 p->set_hash(hashValue); |
133 // Keep the shared bit in the Hashtable entry to indicate that this entry |
119 // Keep the shared bit in the Hashtable entry to indicate that this entry |
134 // can't be deleted. The shared bit is the LSB in the _next field so |
120 // can't be deleted. The shared bit is the LSB in the _next field so |
312 } |
298 } |
313 } |
299 } |
314 |
300 |
315 #endif |
301 #endif |
316 // Explicitly instantiate these types |
302 // Explicitly instantiate these types |
317 template class Hashtable<constantPoolOop, mtClass>; |
303 template class Hashtable<ConstantPool*, mtClass>; |
318 template class Hashtable<Symbol*, mtSymbol>; |
304 template class Hashtable<Symbol*, mtSymbol>; |
319 template class Hashtable<klassOop, mtClass>; |
305 template class Hashtable<Klass*, mtClass>; |
320 template class Hashtable<oop, mtClass>; |
306 template class Hashtable<oop, mtClass>; |
321 #ifdef SOLARIS |
307 #ifdef SOLARIS |
322 template class Hashtable<oop, mtSymbol>; |
308 template class Hashtable<oop, mtSymbol>; |
323 #endif |
309 #endif |
324 template class Hashtable<oopDesc*, mtSymbol>; |
310 template class Hashtable<oopDesc*, mtSymbol>; |