1 /* |
1 /* |
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
94 |
94 |
95 CompactHashtable<oop, char> StringTable::_shared_table; |
95 CompactHashtable<oop, char> StringTable::_shared_table; |
96 |
96 |
97 // Pick hashing algorithm |
97 // Pick hashing algorithm |
98 unsigned int StringTable::hash_string(const jchar* s, int len) { |
98 unsigned int StringTable::hash_string(const jchar* s, int len) { |
99 return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) : |
99 return use_alternate_hashcode() ? alt_hash_string(s, len) : |
100 java_lang_String::hash_code(s, len); |
100 java_lang_String::hash_code(s, len); |
|
101 } |
|
102 |
|
103 unsigned int StringTable::alt_hash_string(const jchar* s, int len) { |
|
104 return AltHashing::murmur3_32(seed(), s, len); |
101 } |
105 } |
102 |
106 |
103 unsigned int StringTable::hash_string(oop string) { |
107 unsigned int StringTable::hash_string(oop string) { |
104 EXCEPTION_MARK; |
108 EXCEPTION_MARK; |
105 if (string == NULL) { |
109 if (string == NULL) { |
115 vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "unable to create Unicode string for verification"); |
119 vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "unable to create Unicode string for verification"); |
116 return 0; |
120 return 0; |
117 } |
121 } |
118 } |
122 } |
119 |
123 |
120 oop StringTable::lookup_shared(jchar* name, int len) { |
124 oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) { |
121 // java_lang_String::hash_code() was used to compute hash values in the shared table. Don't |
125 assert(hash == java_lang_String::hash_code(name, len), |
122 // use the hash value from StringTable::hash_string() as it might use alternate hashcode. |
126 "hash must be computed using java_lang_String::hash_code"); |
123 return _shared_table.lookup((const char*)name, |
127 return _shared_table.lookup((const char*)name, hash, len); |
124 java_lang_String::hash_code(name, len), len); |
|
125 } |
128 } |
126 |
129 |
127 oop StringTable::lookup_in_main_table(int index, jchar* name, |
130 oop StringTable::lookup_in_main_table(int index, jchar* name, |
128 int len, unsigned int hash) { |
131 int len, unsigned int hash) { |
129 int count = 0; |
132 int count = 0; |
154 // Check if the symbol table has been rehashed, if so, need to recalculate |
157 // Check if the symbol table has been rehashed, if so, need to recalculate |
155 // the hash value and index before second lookup. |
158 // the hash value and index before second lookup. |
156 unsigned int hashValue; |
159 unsigned int hashValue; |
157 int index; |
160 int index; |
158 if (use_alternate_hashcode()) { |
161 if (use_alternate_hashcode()) { |
159 hashValue = hash_string(name, len); |
162 hashValue = alt_hash_string(name, len); |
160 index = hash_to_index(hashValue); |
163 index = hash_to_index(hashValue); |
161 } else { |
164 } else { |
162 hashValue = hashValue_arg; |
165 hashValue = hashValue_arg; |
163 index = index_arg; |
166 index = index_arg; |
164 } |
167 } |
197 } |
200 } |
198 #endif |
201 #endif |
199 } |
202 } |
200 |
203 |
201 oop StringTable::lookup(jchar* name, int len) { |
204 oop StringTable::lookup(jchar* name, int len) { |
202 oop string = lookup_shared(name, len); |
205 // shared table always uses java_lang_String::hash_code |
|
206 unsigned int hash = java_lang_String::hash_code(name, len); |
|
207 oop string = lookup_shared(name, len, hash); |
203 if (string != NULL) { |
208 if (string != NULL) { |
204 return string; |
209 return string; |
205 } |
210 } |
206 |
211 if (use_alternate_hashcode()) { |
207 unsigned int hash = hash_string(name, len); |
212 hash = alt_hash_string(name, len); |
|
213 } |
208 int index = the_table()->hash_to_index(hash); |
214 int index = the_table()->hash_to_index(hash); |
209 string = the_table()->lookup_in_main_table(index, name, len, hash); |
215 string = the_table()->lookup_in_main_table(index, name, len, hash); |
210 |
216 |
211 ensure_string_alive(string); |
217 ensure_string_alive(string); |
212 |
218 |
213 return string; |
219 return string; |
214 } |
220 } |
215 |
221 |
216 oop StringTable::intern(Handle string_or_null, jchar* name, |
222 oop StringTable::intern(Handle string_or_null, jchar* name, |
217 int len, TRAPS) { |
223 int len, TRAPS) { |
218 oop found_string = lookup_shared(name, len); |
224 // shared table always uses java_lang_String::hash_code |
|
225 unsigned int hashValue = java_lang_String::hash_code(name, len); |
|
226 oop found_string = lookup_shared(name, len, hashValue); |
219 if (found_string != NULL) { |
227 if (found_string != NULL) { |
220 return found_string; |
228 return found_string; |
221 } |
229 } |
222 |
230 if (use_alternate_hashcode()) { |
223 unsigned int hashValue = hash_string(name, len); |
231 hashValue = alt_hash_string(name, len); |
|
232 } |
224 int index = the_table()->hash_to_index(hashValue); |
233 int index = the_table()->hash_to_index(hashValue); |
225 found_string = the_table()->lookup_in_main_table(index, name, len, hashValue); |
234 found_string = the_table()->lookup_in_main_table(index, name, len, hashValue); |
226 |
235 |
227 // Found |
236 // Found |
228 if (found_string != NULL) { |
237 if (found_string != NULL) { |