35 #include "oops/oop.inline2.hpp" |
35 #include "oops/oop.inline2.hpp" |
36 #include "runtime/atomic.inline.hpp" |
36 #include "runtime/atomic.inline.hpp" |
37 #include "runtime/mutexLocker.hpp" |
37 #include "runtime/mutexLocker.hpp" |
38 #include "utilities/hashtable.inline.hpp" |
38 #include "utilities/hashtable.inline.hpp" |
39 #if INCLUDE_ALL_GCS |
39 #if INCLUDE_ALL_GCS |
|
40 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
40 #include "gc_implementation/g1/g1StringDedup.hpp" |
41 #include "gc_implementation/g1/g1StringDedup.hpp" |
41 #endif |
42 #endif |
42 |
43 |
43 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
44 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
44 |
45 |
155 int length; |
156 int length; |
156 jchar* chars = symbol->as_unicode(length); |
157 jchar* chars = symbol->as_unicode(length); |
157 return lookup(chars, length); |
158 return lookup(chars, length); |
158 } |
159 } |
159 |
160 |
|
161 // Tell the GC that this string was looked up in the StringTable. |
|
162 static void ensure_string_alive(oop string) { |
|
163 // A lookup in the StringTable could return an object that was previously |
|
164 // considered dead. The SATB part of G1 needs to get notified about this |
|
165 // potential resurrection, otherwise the marking might not find the object. |
|
166 #if INCLUDE_ALL_GCS |
|
167 if (UseG1GC && string != NULL) { |
|
168 G1SATBCardTableModRefBS::enqueue(string); |
|
169 } |
|
170 #endif |
|
171 } |
160 |
172 |
161 oop StringTable::lookup(jchar* name, int len) { |
173 oop StringTable::lookup(jchar* name, int len) { |
162 unsigned int hash = hash_string(name, len); |
174 unsigned int hash = hash_string(name, len); |
163 int index = the_table()->hash_to_index(hash); |
175 int index = the_table()->hash_to_index(hash); |
164 return the_table()->lookup(index, name, len, hash); |
176 oop string = the_table()->lookup(index, name, len, hash); |
|
177 |
|
178 ensure_string_alive(string); |
|
179 |
|
180 return string; |
165 } |
181 } |
166 |
182 |
167 |
183 |
168 oop StringTable::intern(Handle string_or_null, jchar* name, |
184 oop StringTable::intern(Handle string_or_null, jchar* name, |
169 int len, TRAPS) { |
185 int len, TRAPS) { |
170 unsigned int hashValue = hash_string(name, len); |
186 unsigned int hashValue = hash_string(name, len); |
171 int index = the_table()->hash_to_index(hashValue); |
187 int index = the_table()->hash_to_index(hashValue); |
172 oop found_string = the_table()->lookup(index, name, len, hashValue); |
188 oop found_string = the_table()->lookup(index, name, len, hashValue); |
173 |
189 |
174 // Found |
190 // Found |
175 if (found_string != NULL) return found_string; |
191 if (found_string != NULL) { |
|
192 ensure_string_alive(found_string); |
|
193 return found_string; |
|
194 } |
176 |
195 |
177 debug_only(StableMemoryChecker smc(name, len * sizeof(name[0]))); |
196 debug_only(StableMemoryChecker smc(name, len * sizeof(name[0]))); |
178 assert(!Universe::heap()->is_in_reserved(name), |
197 assert(!Universe::heap()->is_in_reserved(name), |
179 "proposed name of symbol must be stable"); |
198 "proposed name of symbol must be stable"); |
180 |
199 |
195 } |
214 } |
196 #endif |
215 #endif |
197 |
216 |
198 // Grab the StringTable_lock before getting the_table() because it could |
217 // Grab the StringTable_lock before getting the_table() because it could |
199 // change at safepoint. |
218 // change at safepoint. |
200 MutexLocker ml(StringTable_lock, THREAD); |
219 oop added_or_found; |
201 |
220 { |
202 // Otherwise, add to symbol to table |
221 MutexLocker ml(StringTable_lock, THREAD); |
203 return the_table()->basic_add(index, string, name, len, |
222 // Otherwise, add to symbol to table |
204 hashValue, CHECK_NULL); |
223 added_or_found = the_table()->basic_add(index, string, name, len, |
|
224 hashValue, CHECK_NULL); |
|
225 } |
|
226 |
|
227 ensure_string_alive(added_or_found); |
|
228 |
|
229 return added_or_found; |
205 } |
230 } |
206 |
231 |
207 oop StringTable::intern(Symbol* symbol, TRAPS) { |
232 oop StringTable::intern(Symbol* symbol, TRAPS) { |
208 if (symbol == NULL) return NULL; |
233 if (symbol == NULL) return NULL; |
209 ResourceMark rm(THREAD); |
234 ResourceMark rm(THREAD); |