--- a/hotspot/src/share/vm/classfile/symbolTable.hpp Thu Jan 27 13:42:28 2011 -0800
+++ b/hotspot/src/share/vm/classfile/symbolTable.hpp Thu Jan 27 16:11:27 2011 -0800
@@ -26,11 +26,11 @@
#define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
#include "memory/allocation.inline.hpp"
-#include "oops/symbolOop.hpp"
+#include "oops/symbol.hpp"
#include "utilities/hashtable.hpp"
-// The symbol table holds all symbolOops and corresponding interned strings.
-// symbolOops and literal strings should be canonicalized.
+// The symbol table holds all Symbol*s and corresponding interned strings.
+// Symbol*s and literal strings should be canonicalized.
//
// The interned strings are created lazily.
//
@@ -42,32 +42,76 @@
class BoolObjectClosure;
-class SymbolTable : public Hashtable {
+// Class to hold a newly created or referenced Symbol* temporarily in scope.
+// new_symbol() and lookup() will create a Symbol* if not already in the
+// symbol table and add to the symbol's reference count.
+// probe() and lookup_only() will increment the refcount if symbol is found.
+class TempNewSymbol : public StackObj {
+ Symbol* _temp;
+
+ public:
+ TempNewSymbol() : _temp(NULL) {}
+ // Creating or looking up a symbol increments the symbol's reference count
+ TempNewSymbol(Symbol *s) : _temp(s) {}
+
+ // Operator= increments reference count.
+ void operator=(const TempNewSymbol &s) {
+ _temp = s._temp;
+ if (_temp !=NULL) _temp->increment_refcount();
+ }
+
+ // Decrement reference counter so it can go away if it's unique
+ ~TempNewSymbol() { if (_temp != NULL) _temp->decrement_refcount(); }
+
+ // Operators so they can be used like Symbols
+ Symbol* operator -> () const { return _temp; }
+ bool operator == (Symbol* o) const { return _temp == o; }
+ // Sneaky conversion function
+ operator Symbol*() { return _temp; }
+};
+
+class SymbolTable : public Hashtable<Symbol*> {
friend class VMStructs;
+ friend class ClassFileParser;
private:
// The symbol table
static SymbolTable* _the_table;
+ // For statistics
+ static int symbols_removed;
+ static int symbols_counted;
+
+ Symbol* allocate_symbol(const u1* name, int len, TRAPS); // Assumes no characters larger than 0x7F
+ bool allocate_symbols(int names_count, const u1** names, int* lengths, Symbol** syms, TRAPS);
+
// Adding elements
- symbolOop basic_add(int index, u1* name, int len,
+ Symbol* basic_add(int index, u1* name, int len,
unsigned int hashValue, TRAPS);
bool basic_add(constantPoolHandle cp, int names_count,
const char** names, int* lengths, int* cp_indices,
unsigned int* hashValues, TRAPS);
+ static void new_symbols(constantPoolHandle cp, int names_count,
+ const char** name, int* lengths,
+ int* cp_indices, unsigned int* hashValues,
+ TRAPS) {
+ add(cp, names_count, name, lengths, cp_indices, hashValues, THREAD);
+ }
+
+
// Table size
enum {
symbol_table_size = 20011
};
- symbolOop lookup(int index, const char* name, int len, unsigned int hash);
+ Symbol* lookup(int index, const char* name, int len, unsigned int hash);
SymbolTable()
- : Hashtable(symbol_table_size, sizeof (HashtableEntry)) {}
+ : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>)) {}
SymbolTable(HashtableBucket* t, int number_of_entries)
- : Hashtable(symbol_table_size, sizeof (HashtableEntry), t,
+ : Hashtable<Symbol*>(symbol_table_size, sizeof (HashtableEntry<Symbol*>), t,
number_of_entries) {}
@@ -92,66 +136,76 @@
_the_table = new SymbolTable(t, number_of_entries);
}
- static symbolOop lookup(const char* name, int len, TRAPS);
+ static Symbol* lookup(const char* name, int len, TRAPS);
// lookup only, won't add. Also calculate hash.
- static symbolOop lookup_only(const char* name, int len, unsigned int& hash);
+ static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
// Only copy to C string to be added if lookup failed.
- static symbolOop lookup(symbolHandle sym, int begin, int end, TRAPS);
+ static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS);
+
+ static void release(Symbol* sym);
// jchar (utf16) version of lookups
- static symbolOop lookup_unicode(const jchar* name, int len, TRAPS);
- static symbolOop lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
+ static Symbol* lookup_unicode(const jchar* name, int len, TRAPS);
+ static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
static void add(constantPoolHandle cp, int names_count,
const char** names, int* lengths, int* cp_indices,
unsigned int* hashValues, TRAPS);
- // GC support
- // Delete pointers to otherwise-unreachable objects.
- static void unlink(BoolObjectClosure* cl) {
- the_table()->Hashtable::unlink(cl);
+ // Release any dead symbols
+ static void unlink();
+
+ // iterate over symbols
+ static void symbols_do(SymbolClosure *cl);
+
+ // Symbol creation
+ static Symbol* new_symbol(const char* utf8_buffer, int length, TRAPS) {
+ assert(utf8_buffer != NULL, "just checking");
+ return lookup(utf8_buffer, length, THREAD);
}
-
- // Invoke "f->do_oop" on the locations of all oops in the table.
- static void oops_do(OopClosure* f) {
- the_table()->Hashtable::oops_do(f);
+ static Symbol* new_symbol(const char* name, TRAPS) {
+ return new_symbol(name, (int)strlen(name), THREAD);
+ }
+ static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) {
+ assert(begin <= end && end <= sym->utf8_length(), "just checking");
+ return lookup(sym, begin, end, THREAD);
}
// Symbol lookup
- static symbolOop lookup(int index, const char* name, int len, TRAPS);
+ static Symbol* lookup(int index, const char* name, int len, TRAPS);
// Needed for preloading classes in signatures when compiling.
// Returns the symbol is already present in symbol table, otherwise
// NULL. NO ALLOCATION IS GUARANTEED!
- static symbolOop probe(const char* name, int len) {
+ static Symbol* probe(const char* name, int len) {
unsigned int ignore_hash;
return lookup_only(name, len, ignore_hash);
}
- static symbolOop probe_unicode(const jchar* name, int len) {
+ static Symbol* probe_unicode(const jchar* name, int len) {
unsigned int ignore_hash;
return lookup_only_unicode(name, len, ignore_hash);
}
// Histogram
static void print_histogram() PRODUCT_RETURN;
+ static void print() PRODUCT_RETURN;
// Debugging
static void verify();
// Sharing
static void copy_buckets(char** top, char*end) {
- the_table()->Hashtable::copy_buckets(top, end);
+ the_table()->Hashtable<Symbol*>::copy_buckets(top, end);
}
static void copy_table(char** top, char*end) {
- the_table()->Hashtable::copy_table(top, end);
+ the_table()->Hashtable<Symbol*>::copy_table(top, end);
}
static void reverse(void* boundary = NULL) {
- ((Hashtable*)the_table())->reverse(boundary);
+ the_table()->Hashtable<Symbol*>::reverse(boundary);
}
};
-
-class StringTable : public Hashtable {
+class StringTable : public Hashtable<oop> {
friend class VMStructs;
private:
@@ -169,10 +223,10 @@
oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
- StringTable() : Hashtable(string_table_size, sizeof (HashtableEntry)) {}
+ StringTable() : Hashtable<oop>(string_table_size, sizeof (HashtableEntry<oop>)) {}
StringTable(HashtableBucket* t, int number_of_entries)
- : Hashtable(string_table_size, sizeof (HashtableEntry), t,
+ : Hashtable<oop>(string_table_size, sizeof (HashtableEntry<oop>), t,
number_of_entries) {}
public:
@@ -192,26 +246,20 @@
_the_table = new StringTable(t, number_of_entries);
}
-
static int hash_string(jchar* s, int len);
-
// GC support
// Delete pointers to otherwise-unreachable objects.
- static void unlink(BoolObjectClosure* cl) {
- the_table()->Hashtable::unlink(cl);
- }
+ static void unlink(BoolObjectClosure* cl);
// Invoke "f->do_oop" on the locations of all oops in the table.
- static void oops_do(OopClosure* f) {
- the_table()->Hashtable::oops_do(f);
- }
+ static void oops_do(OopClosure* f);
// Probing
- static oop lookup(symbolOop symbol);
+ static oop lookup(Symbol* symbol);
// Interning
- static oop intern(symbolOop symbol, TRAPS);
+ static oop intern(Symbol* symbol, TRAPS);
static oop intern(oop string, TRAPS);
static oop intern(const char *utf8_string, TRAPS);
@@ -220,13 +268,13 @@
// Sharing
static void copy_buckets(char** top, char*end) {
- the_table()->Hashtable::copy_buckets(top, end);
+ the_table()->Hashtable<oop>::copy_buckets(top, end);
}
static void copy_table(char** top, char*end) {
- the_table()->Hashtable::copy_table(top, end);
+ the_table()->Hashtable<oop>::copy_table(top, end);
}
static void reverse() {
- ((BasicHashtable*)the_table())->reverse();
+ the_table()->Hashtable<oop>::reverse();
}
};