hotspot/src/share/vm/classfile/symbolTable.cpp
changeset 37198 b96542d1afa1
parent 35898 ddc274f0052f
child 37248 11a660dbbb8e
equal deleted inserted replaced
37197:282fa21230c3 37198:b96542d1afa1
   158 }
   158 }
   159 
   159 
   160 // Create a new table and using alternate hash code, populate the new table
   160 // Create a new table and using alternate hash code, populate the new table
   161 // with the existing strings.   Set flag to use the alternate hash code afterwards.
   161 // with the existing strings.   Set flag to use the alternate hash code afterwards.
   162 void SymbolTable::rehash_table() {
   162 void SymbolTable::rehash_table() {
       
   163   if (DumpSharedSpaces) {
       
   164     tty->print_cr("Warning: rehash_table should not be called while dumping archive");
       
   165     return;
       
   166   }
       
   167 
   163   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
   168   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
   164   // This should never happen with -Xshare:dump but it might in testing mode.
   169   // This should never happen with -Xshare:dump but it might in testing mode.
   165   if (DumpSharedSpaces) return;
   170   if (DumpSharedSpaces) return;
   166   // Create a new symbol table
   171   // Create a new symbol table
   167   SymbolTable* new_table = new SymbolTable();
   172   SymbolTable* new_table = new SymbolTable();
   199   return NULL;
   204   return NULL;
   200 }
   205 }
   201 
   206 
   202 Symbol* SymbolTable::lookup_shared(const char* name,
   207 Symbol* SymbolTable::lookup_shared(const char* name,
   203                                    int len, unsigned int hash) {
   208                                    int len, unsigned int hash) {
       
   209   if (use_alternate_hashcode()) {
       
   210     // hash_code parameter may use alternate hashing algorithm but the shared table
       
   211     // always uses the same original hash code.
       
   212     hash = hash_shared_symbol(name, len);
       
   213   }
   204   return _shared_table.lookup(name, hash, len);
   214   return _shared_table.lookup(name, hash, len);
   205 }
   215 }
   206 
   216 
   207 Symbol* SymbolTable::lookup(int index, const char* name,
   217 Symbol* SymbolTable::lookup(int index, const char* name,
   208                             int len, unsigned int hash) {
   218                             int len, unsigned int hash) {
   230 // Pick hashing algorithm.
   240 // Pick hashing algorithm.
   231 unsigned int SymbolTable::hash_symbol(const char* s, int len) {
   241 unsigned int SymbolTable::hash_symbol(const char* s, int len) {
   232   return use_alternate_hashcode() ?
   242   return use_alternate_hashcode() ?
   233            AltHashing::murmur3_32(seed(), (const jbyte*)s, len) :
   243            AltHashing::murmur3_32(seed(), (const jbyte*)s, len) :
   234            java_lang_String::hash_code((const jbyte*)s, len);
   244            java_lang_String::hash_code((const jbyte*)s, len);
       
   245 }
       
   246 
       
   247 unsigned int SymbolTable::hash_shared_symbol(const char* s, int len) {
       
   248   return java_lang_String::hash_code((const jbyte*)s, len);
   235 }
   249 }
   236 
   250 
   237 
   251 
   238 // We take care not to be blocking while holding the
   252 // We take care not to be blocking while holding the
   239 // SymbolTable_lock. Otherwise, the system might deadlock, since the
   253 // SymbolTable_lock. Otherwise, the system might deadlock, since the
   534 
   548 
   535   for (int i = 0; i < the_table()->table_size(); ++i) {
   549   for (int i = 0; i < the_table()->table_size(); ++i) {
   536     HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i);
   550     HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i);
   537     for ( ; p != NULL; p = p->next()) {
   551     for ( ; p != NULL; p = p->next()) {
   538       Symbol* s = (Symbol*)(p->literal());
   552       Symbol* s = (Symbol*)(p->literal());
   539       unsigned int fixed_hash = hash_symbol((char*)s->bytes(), s->utf8_length());
   553       unsigned int fixed_hash =  hash_shared_symbol((char*)s->bytes(), s->utf8_length());
   540       assert(fixed_hash == p->hash(), "must not rehash during dumping");
   554       assert(fixed_hash == p->hash(), "must not rehash during dumping");
   541       ch_table.add(fixed_hash, s);
   555       ch_table.add(fixed_hash, s);
   542     }
   556     }
   543   }
   557   }
   544 
   558