changeset 3474:571bc10e2a37

7181200: JVM new hashing code breaks SA in product mode Summary: Made new_hash() overloaded rather than a virtual function so SA code doesn't need to be changed. Reviewed-by: kvn, acorn, dholmes, fparain Contributed-by: coleen.phillimore@oracle.com
author kamg
date Wed, 11 Jul 2012 09:17:40 -0400
parents 3f142ec74a26
children cfb2ea9dfefd
files src/share/vm/classfile/symbolTable.cpp src/share/vm/classfile/symbolTable.hpp src/share/vm/utilities/hashtable.cpp src/share/vm/utilities/hashtable.hpp
diffstat 4 files changed, 32 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/symbolTable.cpp	Mon Jul 09 18:03:04 2012 -0400
+++ b/src/share/vm/classfile/symbolTable.cpp	Wed Jul 11 09:17:40 2012 -0400
@@ -40,7 +40,6 @@
 
 SymbolTable* SymbolTable::_the_table = NULL;
 bool SymbolTable::_needs_rehashing = false;
-jint SymbolTable::_seed = 0;
 
 Symbol* SymbolTable::allocate_symbol(const u1* name, int len, TRAPS) {
   assert (len <= Symbol::max_length(), "should be checked by caller");
@@ -112,12 +111,6 @@
   }
 }
 
-unsigned int SymbolTable::new_hash(Symbol* sym) {
-  ResourceMark rm;
-  // Use alternate hashing algorithm on this symbol.
-  return AltHashing::murmur3_32(seed(), (const jbyte*)sym->as_C_string(), sym->utf8_length());
-}
-
 // 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() {
@@ -127,10 +120,6 @@
   // Create a new symbol table
   SymbolTable* new_table = new SymbolTable();
 
-  // Initialize the global seed for hashing.
-  _seed = AltHashing::compute_seed();
-  assert(seed() != 0, "shouldn't be zero");
-
   the_table()->move_to(new_table);
 
   // Delete the table and buckets (entries are reused in new table).
@@ -582,7 +571,6 @@
 StringTable* StringTable::_the_table = NULL;
 
 bool StringTable::_needs_rehashing = false;
-jint StringTable::_seed = 0;
 
 // Pick hashing algorithm
 unsigned int StringTable::hash_string(const jchar* s, int len) {
@@ -799,14 +787,6 @@
 }
 
 
-unsigned int StringTable::new_hash(oop string) {
-  ResourceMark rm;
-  int length;
-  jchar* chars = java_lang_String::as_unicode_string(string, length);
-  // Use alternate hashing algorithm on the string
-  return AltHashing::murmur3_32(seed(), chars, length);
-}
-
 // 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 StringTable::rehash_table() {
@@ -815,10 +795,6 @@
   if (DumpSharedSpaces) return;
   StringTable* new_table = new StringTable();
 
-  // Initialize new global seed for hashing.
-  _seed = AltHashing::compute_seed();
-  assert(seed() != 0, "shouldn't be zero");
-
   // Rehash the table
   the_table()->move_to(new_table);
 
--- a/src/share/vm/classfile/symbolTable.hpp	Mon Jul 09 18:03:04 2012 -0400
+++ b/src/share/vm/classfile/symbolTable.hpp	Wed Jul 11 09:17:40 2012 -0400
@@ -81,7 +81,6 @@
 
   // Set if one bucket is out of balance due to hash algorithm deficiency
   static bool _needs_rehashing;
-  static jint _seed;
 
   // For statistics
   static int symbols_removed;
@@ -118,10 +117,6 @@
     : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>), t,
                 number_of_entries) {}
 
-  static bool use_alternate_hashcode()  { return _seed != 0; }
-  static jint seed()                    { return _seed; }
-
-  unsigned int new_hash(Symbol* sym);
 public:
   enum {
     symbol_alloc_batch_size = 8
@@ -232,7 +227,6 @@
 
   // Set if one bucket is out of balance due to hash algorithm deficiency
   static bool _needs_rehashing;
-  static jint _seed;
 
   static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
   oop basic_add(int index, Handle string_or_null, jchar* name, int len,
@@ -246,11 +240,6 @@
   StringTable(HashtableBucket* t, int number_of_entries)
     : Hashtable<oop>((int)StringTableSize, sizeof (HashtableEntry<oop>), t,
                      number_of_entries) {}
-
-  static bool use_alternate_hashcode()  { return _seed != 0; }
-  static jint seed()                    { return _seed; }
-
-  unsigned int new_hash(oop s);
 public:
   // The string table
   static StringTable* the_table() { return _the_table; }
--- a/src/share/vm/utilities/hashtable.cpp	Mon Jul 09 18:03:04 2012 -0400
+++ b/src/share/vm/utilities/hashtable.cpp	Wed Jul 11 09:17:40 2012 -0400
@@ -23,6 +23,8 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/altHashing.hpp"
+#include "classfile/javaClasses.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
 #include "memory/resourceArea.hpp"
@@ -103,12 +105,33 @@
   return false;
 }
 
+template <class T> jint Hashtable<T>::_seed = 0;
+
+template <class T> unsigned int Hashtable<T>::new_hash(Symbol* sym) {
+  ResourceMark rm;
+  // Use alternate hashing algorithm on this symbol.
+  return AltHashing::murmur3_32(seed(), (const jbyte*)sym->as_C_string(), sym->utf8_length());
+}
+
+template <class T> unsigned int Hashtable<T>::new_hash(oop string) {
+  ResourceMark rm;
+  int length;
+  jchar* chars = java_lang_String::as_unicode_string(string, length);
+  // Use alternate hashing algorithm on the string
+  return AltHashing::murmur3_32(seed(), chars, length);
+}
+
 // Create a new table and using alternate hash code, populate the new table
 // with the existing elements.   This can be used to change the hash code
 // and could in the future change the size of the table.
 
 template <class T> void Hashtable<T>::move_to(Hashtable<T>* new_table) {
-  int saved_entry_count = number_of_entries();
+
+  // Initialize the global seed for hashing.
+  _seed = AltHashing::compute_seed();
+  assert(seed() != 0, "shouldn't be zero");
+
+  int saved_entry_count = this->number_of_entries();
 
   // Iterate through the table and create a new entry for the new table
   for (int i = 0; i < new_table->table_size(); ++i) {
--- a/src/share/vm/utilities/hashtable.hpp	Mon Jul 09 18:03:04 2012 -0400
+++ b/src/share/vm/utilities/hashtable.hpp	Wed Jul 11 09:17:40 2012 -0400
@@ -278,7 +278,14 @@
 
   // Function to move these elements into the new table.
   void move_to(Hashtable<T>* new_table);
-  virtual unsigned int new_hash(T) { ShouldNotReachHere(); return 0; } // should be overridden
+  static bool use_alternate_hashcode()  { return _seed != 0; }
+  static jint seed()                    { return _seed; }
+
+ private:
+  static jint _seed;
+
+  unsigned int new_hash(Symbol* s);
+  unsigned int new_hash(oop string);
 };