提交 f033456c 编写于 作者: C coleenp

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
上级 b2c392c3
...@@ -43,7 +43,6 @@ SymbolTable* SymbolTable::_the_table = NULL; ...@@ -43,7 +43,6 @@ SymbolTable* SymbolTable::_the_table = NULL;
// Static arena for symbols that are not deallocated // Static arena for symbols that are not deallocated
Arena* SymbolTable::_arena = NULL; Arena* SymbolTable::_arena = NULL;
bool SymbolTable::_needs_rehashing = false; bool SymbolTable::_needs_rehashing = false;
jint SymbolTable::_seed = 0;
Symbol* SymbolTable::allocate_symbol(const u1* name, int len, bool c_heap, TRAPS) { Symbol* SymbolTable::allocate_symbol(const u1* name, int len, bool c_heap, TRAPS) {
assert (len <= Symbol::max_length(), "should be checked by caller"); assert (len <= Symbol::max_length(), "should be checked by caller");
...@@ -130,12 +129,6 @@ void SymbolTable::unlink() { ...@@ -130,12 +129,6 @@ void SymbolTable::unlink() {
} }
} }
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 // 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. // with the existing strings. Set flag to use the alternate hash code afterwards.
void SymbolTable::rehash_table() { void SymbolTable::rehash_table() {
...@@ -145,10 +138,6 @@ void SymbolTable::rehash_table() { ...@@ -145,10 +138,6 @@ void SymbolTable::rehash_table() {
// Create a new symbol table // Create a new symbol table
SymbolTable* new_table = new SymbolTable(); 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); the_table()->move_to(new_table);
// Delete the table and buckets (entries are reused in new table). // Delete the table and buckets (entries are reused in new table).
...@@ -620,7 +609,6 @@ class StableMemoryChecker : public StackObj { ...@@ -620,7 +609,6 @@ class StableMemoryChecker : public StackObj {
StringTable* StringTable::_the_table = NULL; StringTable* StringTable::_the_table = NULL;
bool StringTable::_needs_rehashing = false; bool StringTable::_needs_rehashing = false;
jint StringTable::_seed = 0;
// Pick hashing algorithm // Pick hashing algorithm
unsigned int StringTable::hash_string(const jchar* s, int len) { unsigned int StringTable::hash_string(const jchar* s, int len) {
...@@ -837,14 +825,6 @@ void StringTable::dump(outputStream* st) { ...@@ -837,14 +825,6 @@ void StringTable::dump(outputStream* st) {
} }
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 // 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. // with the existing strings. Set flag to use the alternate hash code afterwards.
void StringTable::rehash_table() { void StringTable::rehash_table() {
...@@ -853,10 +833,6 @@ void StringTable::rehash_table() { ...@@ -853,10 +833,6 @@ void StringTable::rehash_table() {
if (DumpSharedSpaces) return; if (DumpSharedSpaces) return;
StringTable* new_table = new StringTable(); 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 // Rehash the table
the_table()->move_to(new_table); the_table()->move_to(new_table);
......
...@@ -81,7 +81,6 @@ private: ...@@ -81,7 +81,6 @@ private:
// Set if one bucket is out of balance due to hash algorithm deficiency // Set if one bucket is out of balance due to hash algorithm deficiency
static bool _needs_rehashing; static bool _needs_rehashing;
static jint _seed;
// For statistics // For statistics
static int symbols_removed; static int symbols_removed;
...@@ -124,11 +123,6 @@ private: ...@@ -124,11 +123,6 @@ private:
static Arena* arena() { return _arena; } // called for statistics static Arena* arena() { return _arena; } // called for statistics
static void initialize_symbols(int arena_alloc_size = 0); static void initialize_symbols(int arena_alloc_size = 0);
static bool use_alternate_hashcode() { return _seed != 0; }
static jint seed() { return _seed; }
unsigned int new_hash(Symbol* sym);
public: public:
enum { enum {
symbol_alloc_batch_size = 8, symbol_alloc_batch_size = 8,
...@@ -247,7 +241,6 @@ private: ...@@ -247,7 +241,6 @@ private:
// Set if one bucket is out of balance due to hash algorithm deficiency // Set if one bucket is out of balance due to hash algorithm deficiency
static bool _needs_rehashing; static bool _needs_rehashing;
static jint _seed;
static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS); 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, oop basic_add(int index, Handle string_or_null, jchar* name, int len,
...@@ -261,11 +254,6 @@ private: ...@@ -261,11 +254,6 @@ private:
StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries) StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
: Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t, : Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
number_of_entries) {} number_of_entries) {}
static bool use_alternate_hashcode() { return _seed != 0; }
static jint seed() { return _seed; }
unsigned int new_hash(oop s);
public: public:
// The string table // The string table
static StringTable* the_table() { return _the_table; } static StringTable* the_table() { return _the_table; }
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
*/ */
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/altHashing.hpp"
#include "classfile/javaClasses.hpp"
#include "memory/allocation.inline.hpp" #include "memory/allocation.inline.hpp"
#include "memory/filemap.hpp" #include "memory/filemap.hpp"
#include "memory/resourceArea.hpp" #include "memory/resourceArea.hpp"
...@@ -90,12 +92,33 @@ template <MEMFLAGS F> bool BasicHashtable<F>::check_rehash_table(int count) { ...@@ -90,12 +92,33 @@ template <MEMFLAGS F> bool BasicHashtable<F>::check_rehash_table(int count) {
return false; return false;
} }
template <class T, MEMFLAGS F> jint Hashtable<T, F>::_seed = 0;
template <class T, MEMFLAGS F> unsigned int Hashtable<T, F>::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, MEMFLAGS F> unsigned int Hashtable<T, F>::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 // 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 // with the existing elements. This can be used to change the hash code
// and could in the future change the size of the table. // and could in the future change the size of the table.
template <class T, MEMFLAGS F> void Hashtable<T, F>::move_to(Hashtable<T, F>* new_table) { template <class T, MEMFLAGS F> void Hashtable<T, F>::move_to(Hashtable<T, F>* new_table) {
int saved_entry_count = BasicHashtable<F>::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 // Iterate through the table and create a new entry for the new table
for (int i = 0; i < new_table->table_size(); ++i) { for (int i = 0; i < new_table->table_size(); ++i) {
......
...@@ -278,7 +278,14 @@ protected: ...@@ -278,7 +278,14 @@ protected:
// Function to move these elements into the new table. // Function to move these elements into the new table.
void move_to(Hashtable<T, F>* new_table); void move_to(Hashtable<T, F>* 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);
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册