< prev index next >

src/share/vm/classfile/stringTable.cpp

Print this page
rev 12679 : 8176593: Throwable::getStackTrace performance regression
Reviewed-by: jiangli, iklam


 100                                     java_lang_String::hash_code(s, len);
 101 }
 102 
 103 unsigned int StringTable::hash_string(oop string) {
 104   EXCEPTION_MARK;
 105   if (string == NULL) {
 106     return hash_string((jchar*)NULL, 0);
 107   }
 108   ResourceMark rm(THREAD);
 109   // All String oops are hashed as unicode
 110   int length;
 111   jchar* chars = java_lang_String::as_unicode_string(string, length, THREAD);
 112   if (chars != NULL) {
 113     return hash_string(chars, length);
 114   } else {
 115     vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "unable to create Unicode string for verification");
 116     return 0;
 117   }
 118 }
 119 
 120 oop StringTable::lookup_shared(jchar* name, int len) {
 121   // java_lang_String::hash_code() was used to compute hash values in the shared table. Don't
 122   // use the hash value from StringTable::hash_string() as it might use alternate hashcode.
 123   return _shared_table.lookup((const char*)name,
 124                               java_lang_String::hash_code(name, len), len);
 125 }
 126 
 127 oop StringTable::lookup_in_main_table(int index, jchar* name,
 128                                 int len, unsigned int hash) {
 129   int count = 0;
 130   for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
 131     count++;
 132     if (l->hash() == hash) {
 133       if (java_lang_String::equals(l->literal(), name, len)) {
 134         return l->literal();
 135       }
 136     }
 137   }
 138   // If the bucket size is too deep check if this hash code is insufficient.
 139   if (count >= rehash_count && !needs_rehashing()) {
 140     _needs_rehashing = check_rehash_table(count);
 141   }
 142   return NULL;
 143 }
 144 


 182 oop StringTable::lookup(Symbol* symbol) {
 183   ResourceMark rm;
 184   int length;
 185   jchar* chars = symbol->as_unicode(length);
 186   return lookup(chars, length);
 187 }
 188 
 189 // Tell the GC that this string was looked up in the StringTable.
 190 static void ensure_string_alive(oop string) {
 191   // A lookup in the StringTable could return an object that was previously
 192   // considered dead. The SATB part of G1 needs to get notified about this
 193   // potential resurrection, otherwise the marking might not find the object.
 194 #if INCLUDE_ALL_GCS
 195   if (UseG1GC && string != NULL) {
 196     G1SATBCardTableModRefBS::enqueue(string);
 197   }
 198 #endif
 199 }
 200 
 201 oop StringTable::lookup(jchar* name, int len) {
 202   oop string = lookup_shared(name, len);

 203   if (string != NULL) {
 204     return string;
 205   }
 206 
 207   unsigned int hash = hash_string(name, len);

 208   int index = the_table()->hash_to_index(hash);
 209   string = the_table()->lookup_in_main_table(index, name, len, hash);
 210 
 211   ensure_string_alive(string);
 212 
 213   return string;
 214 }
 215 
 216 oop StringTable::intern(Handle string_or_null, jchar* name,
 217                         int len, TRAPS) {
 218   oop found_string = lookup_shared(name, len);

 219   if (found_string != NULL) {
 220     return found_string;
 221   }
 222 
 223   unsigned int hashValue = hash_string(name, len);

 224   int index = the_table()->hash_to_index(hashValue);
 225   found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
 226 
 227   // Found
 228   if (found_string != NULL) {
 229     if (found_string != string_or_null()) {
 230       ensure_string_alive(found_string);
 231     }
 232     return found_string;
 233   }
 234 
 235   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 236   assert(!Universe::heap()->is_in_reserved(name),
 237          "proposed name of symbol must be stable");
 238 
 239   Handle string;
 240   // try to reuse the string if possible
 241   if (!string_or_null.is_null()) {
 242     string = string_or_null;
 243   } else {




 100                                     java_lang_String::hash_code(s, len);
 101 }
 102 
 103 unsigned int StringTable::hash_string(oop string) {
 104   EXCEPTION_MARK;
 105   if (string == NULL) {
 106     return hash_string((jchar*)NULL, 0);
 107   }
 108   ResourceMark rm(THREAD);
 109   // All String oops are hashed as unicode
 110   int length;
 111   jchar* chars = java_lang_String::as_unicode_string(string, length, THREAD);
 112   if (chars != NULL) {
 113     return hash_string(chars, length);
 114   } else {
 115     vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "unable to create Unicode string for verification");
 116     return 0;
 117   }
 118 }
 119 
 120 oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) {
 121   assert(hash == java_lang_String::hash_code(name, len),
 122          "hash must be computed using java_lang_String::hash_code");
 123   return _shared_table.lookup((const char*)name, hash, len);

 124 }
 125 
 126 oop StringTable::lookup_in_main_table(int index, jchar* name,
 127                                 int len, unsigned int hash) {
 128   int count = 0;
 129   for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
 130     count++;
 131     if (l->hash() == hash) {
 132       if (java_lang_String::equals(l->literal(), name, len)) {
 133         return l->literal();
 134       }
 135     }
 136   }
 137   // If the bucket size is too deep check if this hash code is insufficient.
 138   if (count >= rehash_count && !needs_rehashing()) {
 139     _needs_rehashing = check_rehash_table(count);
 140   }
 141   return NULL;
 142 }
 143 


 181 oop StringTable::lookup(Symbol* symbol) {
 182   ResourceMark rm;
 183   int length;
 184   jchar* chars = symbol->as_unicode(length);
 185   return lookup(chars, length);
 186 }
 187 
 188 // Tell the GC that this string was looked up in the StringTable.
 189 static void ensure_string_alive(oop string) {
 190   // A lookup in the StringTable could return an object that was previously
 191   // considered dead. The SATB part of G1 needs to get notified about this
 192   // potential resurrection, otherwise the marking might not find the object.
 193 #if INCLUDE_ALL_GCS
 194   if (UseG1GC && string != NULL) {
 195     G1SATBCardTableModRefBS::enqueue(string);
 196   }
 197 #endif
 198 }
 199 
 200 oop StringTable::lookup(jchar* name, int len) {
 201   unsigned int hash = java_lang_String::hash_code(name, len);
 202   oop string = lookup_shared(name, len, hash);
 203   if (string != NULL) {
 204     return string;
 205   }
 206   if (use_alternate_hashcode()) {
 207       hash = hash_string(name, len);
 208   }
 209   int index = the_table()->hash_to_index(hash);
 210   string = the_table()->lookup_in_main_table(index, name, len, hash);
 211 
 212   ensure_string_alive(string);
 213 
 214   return string;
 215 }
 216 
 217 oop StringTable::intern(Handle string_or_null, jchar* name,
 218                         int len, TRAPS) {
 219   unsigned int hashValue = java_lang_String::hash_code(name, len);
 220   oop found_string = lookup_shared(name, len, hashValue);
 221   if (found_string != NULL) {
 222     return found_string;
 223   }
 224   if (use_alternate_hashcode()) {
 225       hashValue = hash_string(name, len);
 226   }
 227   int index = the_table()->hash_to_index(hashValue);
 228   found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
 229 
 230   // Found
 231   if (found_string != NULL) {
 232     if (found_string != string_or_null()) {
 233       ensure_string_alive(found_string);
 234     }
 235     return found_string;
 236   }
 237 
 238   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 239   assert(!Universe::heap()->is_in_reserved(name),
 240          "proposed name of symbol must be stable");
 241 
 242   Handle string;
 243   // try to reuse the string if possible
 244   if (!string_or_null.is_null()) {
 245     string = string_or_null;
 246   } else {


< prev index next >