Mercurial > hg > graal-compiler
diff src/share/vm/classfile/symbolTable.hpp @ 6162:e9140bf80b4a
7158800: Improve storage of symbol tables
Summary: Use an alternate version of hashing algorithm for symbol string tables and after a certain bucket size to improve performance
Reviewed-by: pbk, kamg, dlong, kvn, fparain
author | coleenp |
---|---|
date | Wed, 13 Jun 2012 19:52:59 -0400 |
parents | fc9d8850ab8b |
children | 246d977b51f2 |
line wrap: on
line diff
--- a/src/share/vm/classfile/symbolTable.hpp Mon Jun 11 13:10:14 2012 -0400 +++ b/src/share/vm/classfile/symbolTable.hpp Wed Jun 13 19:52:59 2012 -0400 @@ -40,6 +40,7 @@ // - symbolTableEntrys are allocated in blocks to reduce the space overhead. class BoolObjectClosure; +class outputStream; // Class to hold a newly created or referenced Symbol* temporarily in scope. @@ -78,6 +79,10 @@ // The symbol table static SymbolTable* _the_table; + // 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; static int symbols_counted; @@ -119,6 +124,11 @@ static Arena* arena() { return _arena; } // called for statistics 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: enum { symbol_alloc_batch_size = 8, @@ -146,6 +156,8 @@ initialize_symbols(); } + static unsigned int hash_symbol(const char* s, int len, unsigned int hashValue = 0); + static Symbol* lookup(const char* name, int len, TRAPS); // lookup only, won't add. Also calculate hash. static Symbol* lookup_only(const char* name, int len, unsigned int& hash); @@ -208,6 +220,7 @@ // Debugging static void verify(); + static void dump(outputStream* st); // Sharing static void copy_buckets(char** top, char*end) { @@ -219,8 +232,13 @@ static void reverse(void* boundary = NULL) { the_table()->Hashtable<Symbol*>::reverse(boundary); } + + // Rehash the symbol table if it gets out of balance + static void rehash_table(); + static bool needs_rehashing() { return _needs_rehashing; } }; + class StringTable : public Hashtable<oop> { friend class VMStructs; @@ -228,6 +246,10 @@ // The string table static StringTable* _the_table; + // 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, unsigned int hashValue, TRAPS); @@ -241,6 +263,10 @@ : 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; } @@ -265,6 +291,14 @@ // Invoke "f->do_oop" on the locations of all oops in the table. static void oops_do(OopClosure* f); + // Hashing algorithm, used as the hash value used by the + // StringTable for bucket selection and comparison (stored in the + // HashtableEntry structures). This is used in the String.intern() method. + static unsigned int hash_string(const jchar* s, int len, unsigned int hashValue = 0); + + // Internal test. + static void test_alt_hash() PRODUCT_RETURN; + // Probing static oop lookup(Symbol* symbol); @@ -275,6 +309,7 @@ // Debugging static void verify(); + static void dump(outputStream* st); // Sharing static void copy_buckets(char** top, char*end) { @@ -286,6 +321,9 @@ static void reverse() { the_table()->Hashtable<oop>::reverse(); } + + // Rehash the symbol table if it gets out of balance + static void rehash_table(); + static bool needs_rehashing() { return _needs_rehashing; } }; - #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP