changeset 10712:5518d3ad6fa7

8152380: Shared symbol table should never use alternate hashcode Reviewed-by: coleenp, jiangli
author iklam
date Wed, 23 Mar 2016 09:00:22 -0700
parents fb31034a45ea
children fdeedce78d1e
files src/share/vm/classfile/symbolTable.cpp src/share/vm/classfile/symbolTable.hpp
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/symbolTable.cpp	Fri Mar 25 15:50:31 2016 -0400
+++ b/src/share/vm/classfile/symbolTable.cpp	Wed Mar 23 09:00:22 2016 -0700
@@ -160,6 +160,11 @@
 // Create a new table and using alternate hash code, populate the new table
 // with the existing strings.   Set flag to use the alternate hash code afterwards.
 void SymbolTable::rehash_table() {
+  if (DumpSharedSpaces) {
+    tty->print_cr("Warning: rehash_table should not be called while dumping archive");
+    return;
+  }
+
   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
   // This should never happen with -Xshare:dump but it might in testing mode.
   if (DumpSharedSpaces) return;
@@ -201,6 +206,11 @@
 
 Symbol* SymbolTable::lookup_shared(const char* name,
                                    int len, unsigned int hash) {
+  if (use_alternate_hashcode()) {
+    // hash_code parameter may use alternate hashing algorithm but the shared table
+    // always uses the same original hash code.
+    hash = hash_shared_symbol(name, len);
+  }
   return _shared_table.lookup(name, hash, len);
 }
 
@@ -234,6 +244,10 @@
            java_lang_String::hash_code((const jbyte*)s, len);
 }
 
+unsigned int SymbolTable::hash_shared_symbol(const char* s, int len) {
+  return java_lang_String::hash_code((const jbyte*)s, len);
+}
+
 
 // We take care not to be blocking while holding the
 // SymbolTable_lock. Otherwise, the system might deadlock, since the
@@ -536,7 +550,7 @@
     HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i);
     for ( ; p != NULL; p = p->next()) {
       Symbol* s = (Symbol*)(p->literal());
-      unsigned int fixed_hash = hash_symbol((char*)s->bytes(), s->utf8_length());
+      unsigned int fixed_hash =  hash_shared_symbol((char*)s->bytes(), s->utf8_length());
       assert(fixed_hash == p->hash(), "must not rehash during dumping");
       ch_table.add(fixed_hash, s);
     }
--- a/src/share/vm/classfile/symbolTable.hpp	Fri Mar 25 15:50:31 2016 -0400
+++ b/src/share/vm/classfile/symbolTable.hpp	Wed Mar 23 09:00:22 2016 -0700
@@ -175,6 +175,7 @@
   }
 
   static unsigned int hash_symbol(const char* s, int len);
+  static unsigned int hash_shared_symbol(const char* s, int len);
 
   static Symbol* lookup(const char* name, int len, TRAPS);
   // lookup only, won't add. Also calculate hash.