< prev index next >

src/share/vm/classfile/stringTable.cpp

Print this page
rev 10186 : [mq]: webrev.01
rev 10187 : [mq]: webrev.02


 183     G1SATBCardTableModRefBS::enqueue(string);
 184   }
 185 #endif
 186 }
 187 
 188 oop StringTable::lookup(jchar* name, int len) {
 189   oop string = lookup_shared(name, len);
 190   if (string != NULL) {
 191     return string;
 192   }
 193 
 194   unsigned int hash = hash_string(name, len);
 195   int index = the_table()->hash_to_index(hash);
 196   string = the_table()->lookup_in_main_table(index, name, len, hash);
 197 
 198   ensure_string_alive(string);
 199 
 200   return string;
 201 }
 202 
 203 
 204 oop StringTable::intern(Handle string_or_null, jchar* name,
 205                         int len, TRAPS) {
 206   oop found_string = lookup_shared(name, len);
 207   if (found_string != NULL) {
 208     return found_string;
 209   }
 210 
 211   unsigned int hashValue = hash_string(name, len);
 212   int index = the_table()->hash_to_index(hashValue);
 213   found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
 214 
 215   // Found
 216   if (found_string != NULL) {

 217     ensure_string_alive(found_string);

 218     return found_string;
 219   }
 220 
 221   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 222   assert(!Universe::heap()->is_in_reserved(name),
 223          "proposed name of symbol must be stable");
 224 
 225   Handle string;
 226   // try to reuse the string if possible
 227   if (!string_or_null.is_null()) {
 228     string = string_or_null;
 229   } else {
 230     string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
 231   }
 232 
 233 #if INCLUDE_ALL_GCS
 234   if (G1StringDedup::is_enabled()) {
 235     // Deduplicate the string before it is interned. Note that we should never
 236     // deduplicate a string after it has been interned. Doing so will counteract
 237     // compiler optimizations done on e.g. interned string literals.
 238     G1StringDedup::deduplicate(string());
 239   }
 240 #endif
 241 
 242   // Grab the StringTable_lock before getting the_table() because it could
 243   // change at safepoint.
 244   oop added_or_found;
 245   {
 246     MutexLocker ml(StringTable_lock, THREAD);
 247     // Otherwise, add to symbol to table
 248     added_or_found = the_table()->basic_add(index, string, name, len,
 249                                   hashValue, CHECK_NULL);
 250   }
 251 

 252   ensure_string_alive(added_or_found);

 253 
 254   return added_or_found;
 255 }
 256 
 257 oop StringTable::intern(Symbol* symbol, TRAPS) {
 258   if (symbol == NULL) return NULL;
 259   ResourceMark rm(THREAD);
 260   int length;
 261   jchar* chars = symbol->as_unicode(length);
 262   Handle string;
 263   oop result = intern(string, chars, length, CHECK_NULL);
 264   return result;
 265 }
 266 
 267 
 268 oop StringTable::intern(oop string, TRAPS)
 269 {
 270   if (string == NULL) return NULL;
 271   ResourceMark rm(THREAD);
 272   int length;




 183     G1SATBCardTableModRefBS::enqueue(string);
 184   }
 185 #endif
 186 }
 187 
 188 oop StringTable::lookup(jchar* name, int len) {
 189   oop string = lookup_shared(name, len);
 190   if (string != NULL) {
 191     return string;
 192   }
 193 
 194   unsigned int hash = hash_string(name, len);
 195   int index = the_table()->hash_to_index(hash);
 196   string = the_table()->lookup_in_main_table(index, name, len, hash);
 197 
 198   ensure_string_alive(string);
 199 
 200   return string;
 201 }
 202 

 203 oop StringTable::intern(Handle string_or_null, jchar* name,
 204                         int len, TRAPS) {
 205   oop found_string = lookup_shared(name, len);
 206   if (found_string != NULL) {
 207     return found_string;
 208   }
 209 
 210   unsigned int hashValue = hash_string(name, len);
 211   int index = the_table()->hash_to_index(hashValue);
 212   found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
 213 
 214   // Found
 215   if (found_string != NULL) {
 216     if (found_string != string_or_null()) {
 217       ensure_string_alive(found_string);
 218     }
 219     return found_string;
 220   }
 221 
 222   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 223   assert(!Universe::heap()->is_in_reserved(name),
 224          "proposed name of symbol must be stable");
 225 
 226   Handle string;
 227   // try to reuse the string if possible
 228   if (!string_or_null.is_null()) {
 229     string = string_or_null;
 230   } else {
 231     string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
 232   }
 233 
 234 #if INCLUDE_ALL_GCS
 235   if (G1StringDedup::is_enabled()) {
 236     // Deduplicate the string before it is interned. Note that we should never
 237     // deduplicate a string after it has been interned. Doing so will counteract
 238     // compiler optimizations done on e.g. interned string literals.
 239     G1StringDedup::deduplicate(string());
 240   }
 241 #endif
 242 
 243   // Grab the StringTable_lock before getting the_table() because it could
 244   // change at safepoint.
 245   oop added_or_found;
 246   {
 247     MutexLocker ml(StringTable_lock, THREAD);
 248     // Otherwise, add to symbol to table
 249     added_or_found = the_table()->basic_add(index, string, name, len,
 250                                   hashValue, CHECK_NULL);
 251   }
 252 
 253   if (added_or_found != string()) { 
 254     ensure_string_alive(added_or_found);
 255   }
 256 
 257   return added_or_found;
 258 }
 259 
 260 oop StringTable::intern(Symbol* symbol, TRAPS) {
 261   if (symbol == NULL) return NULL;
 262   ResourceMark rm(THREAD);
 263   int length;
 264   jchar* chars = symbol->as_unicode(length);
 265   Handle string;
 266   oop result = intern(string, chars, length, CHECK_NULL);
 267   return result;
 268 }
 269 
 270 
 271 oop StringTable::intern(oop string, TRAPS)
 272 {
 273   if (string == NULL) return NULL;
 274   ResourceMark rm(THREAD);
 275   int length;


< prev index next >