src/share/vm/utilities/hashtable.cpp

changeset 3904
ace99a6ffc83
parent 3900
d2a62e0f25eb
child 3963
5e2dc722e70d
equal deleted inserted replaced
3903:65906dc96aa1 3904:ace99a6ffc83
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "classfile/altHashing.hpp"
27 #include "classfile/javaClasses.hpp"
26 #include "memory/allocation.inline.hpp" 28 #include "memory/allocation.inline.hpp"
27 #include "memory/filemap.hpp" 29 #include "memory/filemap.hpp"
28 #include "memory/resourceArea.hpp" 30 #include "memory/resourceArea.hpp"
29 #include "oops/oop.inline.hpp" 31 #include "oops/oop.inline.hpp"
30 #include "runtime/safepoint.hpp" 32 #include "runtime/safepoint.hpp"
88 return true; 90 return true;
89 } 91 }
90 return false; 92 return false;
91 } 93 }
92 94
95 template <class T, MEMFLAGS F> jint Hashtable<T, F>::_seed = 0;
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
93 // Create a new table and using alternate hash code, populate the new table 111 // Create a new table and using alternate hash code, populate the new table
94 // with the existing elements. This can be used to change the hash code 112 // with the existing elements. This can be used to change the hash code
95 // and could in the future change the size of the table. 113 // and could in the future change the size of the table.
96 114
97 template <class T, MEMFLAGS F> void Hashtable<T, F>::move_to(Hashtable<T, F>* new_table) { 115 template <class T, MEMFLAGS F> void Hashtable<T, F>::move_to(Hashtable<T, F>* new_table) {
98 int saved_entry_count = BasicHashtable<F>::number_of_entries(); 116
117 // Initialize the global seed for hashing.
118 _seed = AltHashing::compute_seed();
119 assert(seed() != 0, "shouldn't be zero");
120
121 int saved_entry_count = this->number_of_entries();
99 122
100 // Iterate through the table and create a new entry for the new table 123 // Iterate through the table and create a new entry for the new table
101 for (int i = 0; i < new_table->table_size(); ++i) { 124 for (int i = 0; i < new_table->table_size(); ++i) {
102 for (HashtableEntry<T, F>* p = bucket(i); p != NULL; ) { 125 for (HashtableEntry<T, F>* p = bucket(i); p != NULL; ) {
103 HashtableEntry<T, F>* next = p->next(); 126 HashtableEntry<T, F>* next = p->next();

mercurial