src/share/vm/classfile/symbolTable.cpp

Print this page
rev 3899 : 8004661: Comment and function name java_lang_String::toHash is wrong
Summary: Renamed the functions and comments to use hashCode


 162     if (e->hash() == hash) {
 163       Symbol* sym = e->literal();
 164       if (sym->equals(name, len)) {
 165         // something is referencing this symbol now.
 166         sym->increment_refcount();
 167         return sym;
 168       }
 169     }
 170   }
 171   // If the bucket size is too deep check if this hash code is insufficient.
 172   if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) {
 173     _needs_rehashing = check_rehash_table(count);
 174   }
 175   return NULL;
 176 }
 177 
 178 // Pick hashing algorithm.
 179 unsigned int SymbolTable::hash_symbol(const char* s, int len) {
 180   return use_alternate_hashcode() ?
 181            AltHashing::murmur3_32(seed(), (const jbyte*)s, len) :
 182            java_lang_String::to_hash(s, len);
 183 }
 184 
 185 
 186 // We take care not to be blocking while holding the
 187 // SymbolTable_lock. Otherwise, the system might deadlock, since the
 188 // symboltable is used during compilation (VM_thread) The lock free
 189 // synchronization is simplified by the fact that we do not delete
 190 // entries in the symbol table during normal execution (only during
 191 // safepoints).
 192 
 193 Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) {
 194   unsigned int hashValue = hash_symbol(name, len);
 195   int index = the_table()->hash_to_index(hashValue);
 196 
 197   Symbol* s = the_table()->lookup(index, name, len, hashValue);
 198 
 199   // Found
 200   if (s != NULL) return s;
 201 
 202   // Grab SymbolTable_lock first.


 600 
 601   bool verify() {
 602     u1 check_buf[sizeof(_save_buf)];
 603     int check_size = sample(check_buf);
 604     return (0 == memcmp(_save_buf, check_buf, check_size));
 605   }
 606 
 607   void set_region(const void* region) { _region = (address) region; }
 608 };
 609 #endif
 610 
 611 
 612 // --------------------------------------------------------------------------
 613 StringTable* StringTable::_the_table = NULL;
 614 
 615 bool StringTable::_needs_rehashing = false;
 616 
 617 // Pick hashing algorithm
 618 unsigned int StringTable::hash_string(const jchar* s, int len) {
 619   return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) :
 620                                     java_lang_String::to_hash(s, len);
 621 }
 622 
 623 oop StringTable::lookup(int index, jchar* name,
 624                         int len, unsigned int hash) {
 625   int count = 0;
 626   for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
 627     count++;
 628     if (l->hash() == hash) {
 629       if (java_lang_String::equals(l->literal(), name, len)) {
 630         return l->literal();
 631       }
 632     }
 633   }
 634   // If the bucket size is too deep check if this hash code is insufficient.
 635   if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) {
 636     _needs_rehashing = check_rehash_table(count);
 637   }
 638   return NULL;
 639 }
 640 




 162     if (e->hash() == hash) {
 163       Symbol* sym = e->literal();
 164       if (sym->equals(name, len)) {
 165         // something is referencing this symbol now.
 166         sym->increment_refcount();
 167         return sym;
 168       }
 169     }
 170   }
 171   // If the bucket size is too deep check if this hash code is insufficient.
 172   if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) {
 173     _needs_rehashing = check_rehash_table(count);
 174   }
 175   return NULL;
 176 }
 177 
 178 // Pick hashing algorithm.
 179 unsigned int SymbolTable::hash_symbol(const char* s, int len) {
 180   return use_alternate_hashcode() ?
 181            AltHashing::murmur3_32(seed(), (const jbyte*)s, len) :
 182            java_lang_String::hashCode(s, len);
 183 }
 184 
 185 
 186 // We take care not to be blocking while holding the
 187 // SymbolTable_lock. Otherwise, the system might deadlock, since the
 188 // symboltable is used during compilation (VM_thread) The lock free
 189 // synchronization is simplified by the fact that we do not delete
 190 // entries in the symbol table during normal execution (only during
 191 // safepoints).
 192 
 193 Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) {
 194   unsigned int hashValue = hash_symbol(name, len);
 195   int index = the_table()->hash_to_index(hashValue);
 196 
 197   Symbol* s = the_table()->lookup(index, name, len, hashValue);
 198 
 199   // Found
 200   if (s != NULL) return s;
 201 
 202   // Grab SymbolTable_lock first.


 600 
 601   bool verify() {
 602     u1 check_buf[sizeof(_save_buf)];
 603     int check_size = sample(check_buf);
 604     return (0 == memcmp(_save_buf, check_buf, check_size));
 605   }
 606 
 607   void set_region(const void* region) { _region = (address) region; }
 608 };
 609 #endif
 610 
 611 
 612 // --------------------------------------------------------------------------
 613 StringTable* StringTable::_the_table = NULL;
 614 
 615 bool StringTable::_needs_rehashing = false;
 616 
 617 // Pick hashing algorithm
 618 unsigned int StringTable::hash_string(const jchar* s, int len) {
 619   return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) :
 620                                     java_lang_String::hashCode(s, len);
 621 }
 622 
 623 oop StringTable::lookup(int index, jchar* name,
 624                         int len, unsigned int hash) {
 625   int count = 0;
 626   for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
 627     count++;
 628     if (l->hash() == hash) {
 629       if (java_lang_String::equals(l->literal(), name, len)) {
 630         return l->literal();
 631       }
 632     }
 633   }
 634   // If the bucket size is too deep check if this hash code is insufficient.
 635   if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) {
 636     _needs_rehashing = check_rehash_table(count);
 637   }
 638   return NULL;
 639 }
 640