25 #ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP 26 #define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP 27 28 #include "memory/allocation.inline.hpp" 29 #include "oops/symbol.hpp" 30 #include "utilities/hashtable.hpp" 31 32 // The symbol table holds all Symbol*s and corresponding interned strings. 33 // Symbol*s and literal strings should be canonicalized. 34 // 35 // The interned strings are created lazily. 36 // 37 // It is implemented as an open hash table with a fixed number of buckets. 38 // 39 // %note: 40 // - symbolTableEntrys are allocated in blocks to reduce the space overhead. 41 42 class BoolObjectClosure; 43 class outputStream; 44 45 // Class to hold a newly created or referenced Symbol* temporarily in scope. 46 // new_symbol() and lookup() will create a Symbol* if not already in the 47 // symbol table and add to the symbol's reference count. 48 // probe() and lookup_only() will increment the refcount if symbol is found. 49 class TempNewSymbol : public StackObj { 50 Symbol* _temp; 51 52 public: 53 TempNewSymbol() : _temp(NULL) {} 54 // Creating or looking up a symbol increments the symbol's reference count 55 TempNewSymbol(Symbol *s) : _temp(s) {} 56 57 // Operator= increments reference count. 58 void operator=(const TempNewSymbol &s) { 59 //clear(); //FIXME 60 _temp = s._temp; 61 if (_temp !=NULL) _temp->increment_refcount(); 62 } 63 64 // Decrement reference counter so it can go away if it's unique 65 void clear() { if (_temp != NULL) _temp->decrement_refcount(); _temp = NULL; } 66 67 ~TempNewSymbol() { clear(); } 68 69 // Operators so they can be used like Symbols 70 Symbol* operator -> () const { return _temp; } 71 bool operator == (Symbol* o) const { return _temp == o; } 72 // Sneaky conversion function 73 operator Symbol*() { return _temp; } 74 }; 75 76 template <class T, class N> class CompactHashtable; 77 78 class SymbolTable : public RehashableHashtable<Symbol*, mtSymbol> { 79 friend class VMStructs; 80 friend class ClassFileParser; 81 82 private: 83 // The symbol table 84 static SymbolTable* _the_table; 85 86 // Set if one bucket is out of balance due to hash algorithm deficiency 87 static bool _needs_rehashing; 88 static bool _lookup_shared_first; 89 90 // For statistics 91 static int _symbols_removed; 92 static int _symbols_counted; | 25 #ifndef SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP 26 #define SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP 27 28 #include "memory/allocation.inline.hpp" 29 #include "oops/symbol.hpp" 30 #include "utilities/hashtable.hpp" 31 32 // The symbol table holds all Symbol*s and corresponding interned strings. 33 // Symbol*s and literal strings should be canonicalized. 34 // 35 // The interned strings are created lazily. 36 // 37 // It is implemented as an open hash table with a fixed number of buckets. 38 // 39 // %note: 40 // - symbolTableEntrys are allocated in blocks to reduce the space overhead. 41 42 class BoolObjectClosure; 43 class outputStream; 44 45 // TempNewSymbol acts as a handle class in a handle/body idiom and is 46 // responsible for proper resource management of the body (which is a Symbol*). 47 // The body is resource managed by a reference counting scheme. 48 // TempNewSymbol can therefore be used to properly hold a newly created or referenced 49 // Symbol* temporarily in scope. 50 // 51 // Routines in SymbolTable will initialize the reference count of a Symbol* before 52 // it becomes "managed" by TempNewSymbol instances. As a handle class, TempNewSymbol 53 // needs to maintain proper reference counting in context of copy semantics. 54 // 55 // In SymbolTable, new_symbol() and lookup() will create a Symbol* if not already in the 56 // symbol table and add to the symbol's reference count. 57 // probe() and lookup_only() will increment the refcount if symbol is found. 58 class TempNewSymbol : public StackObj { 59 Symbol* _temp; 60 61 public: 62 TempNewSymbol() : _temp(NULL) {} 63 64 // Conversion from a Symbol* to a TempNewSymbol. 65 // Does not increment the current reference count. 66 TempNewSymbol(Symbol *s) : _temp(s) {} 67 68 // Copy constructor increments reference count. 69 TempNewSymbol(const TempNewSymbol& rhs) : _temp(rhs._temp) { 70 if (_temp != NULL) { 71 _temp->increment_refcount(); 72 } 73 } 74 75 // Assignment operator decrements the reference count for any 76 // existing resource. It increments the reference count 77 // for the newly assigned resource. 78 const TempNewSymbol& operator=(const TempNewSymbol &rhs) { 79 if (this != &rhs && _temp != rhs._temp) { 80 clear(); 81 _temp = rhs._temp; 82 if (_temp != NULL) { 83 _temp->increment_refcount(); 84 } 85 } 86 return *this; 87 } 88 89 // Decrement reference counter so it can go away if it's unique 90 void clear() { 91 if (_temp != NULL) { 92 _temp->decrement_refcount(); 93 } 94 } 95 96 ~TempNewSymbol() { clear(); } 97 98 // Symbol* conversion operators 99 Symbol* operator -> () const { return _temp; } 100 bool operator == (Symbol* o) const { return _temp == o; } 101 operator Symbol*() { return _temp; } 102 }; 103 104 template <class T, class N> class CompactHashtable; 105 106 class SymbolTable : public RehashableHashtable<Symbol*, mtSymbol> { 107 friend class VMStructs; 108 friend class ClassFileParser; 109 110 private: 111 // The symbol table 112 static SymbolTable* _the_table; 113 114 // Set if one bucket is out of balance due to hash algorithm deficiency 115 static bool _needs_rehashing; 116 static bool _lookup_shared_first; 117 118 // For statistics 119 static int _symbols_removed; 120 static int _symbols_counted; |