src/share/vm/classfile/symbolTable.hpp

Print this page




  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 class SymbolTable : public RehashableHashtable<Symbol*, mtSymbol> {
  77   friend class VMStructs;
  78   friend class ClassFileParser;
  79 
  80 private:
  81   // The symbol table
  82   static SymbolTable* _the_table;
  83 
  84   // Set if one bucket is out of balance due to hash algorithm deficiency
  85   static bool _needs_rehashing;

  86 
  87   // For statistics
  88   static int _symbols_removed;
  89   static int _symbols_counted;
  90 



  91   Symbol* allocate_symbol(const u1* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F
  92 
  93   // Adding elements
  94   Symbol* basic_add(int index, u1* name, int len, unsigned int hashValue,
  95                     bool c_heap, TRAPS);
  96   bool basic_add(ClassLoaderData* loader_data,
  97                  constantPoolHandle cp, int names_count,
  98                  const char** names, int* lengths, int* cp_indices,
  99                  unsigned int* hashValues, TRAPS);
 100 
 101   static void new_symbols(ClassLoaderData* loader_data,
 102                           constantPoolHandle cp, int names_count,
 103                           const char** name, int* lengths,
 104                           int* cp_indices, unsigned int* hashValues,
 105                           TRAPS) {
 106     add(loader_data, cp, names_count, name, lengths, cp_indices, hashValues, THREAD);
 107   }
 108 


 109   Symbol* lookup(int index, const char* name, int len, unsigned int hash);
 110 
 111   SymbolTable()
 112     : RehashableHashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {}
 113 
 114   SymbolTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
 115     : RehashableHashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>), t,
 116                 number_of_entries) {}
 117 
 118   // Arena for permanent symbols (null class loader) that are never unloaded
 119   static Arena*  _arena;
 120   static Arena* arena() { return _arena; }  // called for statistics
 121 
 122   static void initialize_symbols(int arena_alloc_size = 0);
 123 
 124   static volatile int _parallel_claimed_idx;
 125 
 126   // Release any dead symbols
 127   static void buckets_unlink(int start_idx, int end_idx, int* processed, int* removed, size_t* memory_total);
 128 public:
 129   enum {
 130     symbol_alloc_batch_size = 8,
 131     // Pick initial size based on java -version size measurements
 132     symbol_alloc_arena_size = 360*K
 133   };
 134 
 135   // The symbol table
 136   static SymbolTable* the_table() { return _the_table; }
 137 
 138   // Size of one bucket in the string table.  Used when checking for rollover.
 139   static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
 140 
 141   static void create_table() {
 142     assert(_the_table == NULL, "One symbol table allowed.");
 143     _the_table = new SymbolTable();
 144     initialize_symbols(symbol_alloc_arena_size);
 145   }
 146 
 147   static void create_table(HashtableBucket<mtSymbol>* t, int length,
 148                            int number_of_entries) {
 149     assert(_the_table == NULL, "One symbol table allowed.");
 150 
 151     // If CDS archive used a different symbol table size, use that size instead
 152     // which is better than giving an error.
 153     SymbolTableSize = length/bucket_size();
 154 
 155     _the_table = new SymbolTable(t, number_of_entries);
 156     // if CDS give symbol table a default arena size since most symbols
 157     // are already allocated in the shared misc section.
 158     initialize_symbols();
 159   }
 160 
 161   static unsigned int hash_symbol(const char* s, int len);
 162 
 163   static Symbol* lookup(const char* name, int len, TRAPS);
 164   // lookup only, won't add. Also calculate hash.
 165   static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
 166   // Only copy to C string to be added if lookup failed.
 167   static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS);
 168 
 169   static void release(Symbol* sym);
 170 
 171   // Look up the address of the literal in the SymbolTable for this Symbol*
 172   static Symbol** lookup_symbol_addr(Symbol* sym);
 173 
 174   // jchar (utf16) version of lookups
 175   static Symbol* lookup_unicode(const jchar* name, int len, TRAPS);
 176   static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
 177 
 178   static void add(ClassLoaderData* loader_data,
 179                   constantPoolHandle cp, int names_count,
 180                   const char** names, int* lengths, int* cp_indices,


 213   static Symbol* lookup(int index, const char* name, int len, TRAPS);
 214 
 215   // Needed for preloading classes in signatures when compiling.
 216   // Returns the symbol is already present in symbol table, otherwise
 217   // NULL.  NO ALLOCATION IS GUARANTEED!
 218   static Symbol* probe(const char* name, int len) {
 219     unsigned int ignore_hash;
 220     return lookup_only(name, len, ignore_hash);
 221   }
 222   static Symbol* probe_unicode(const jchar* name, int len) {
 223     unsigned int ignore_hash;
 224     return lookup_only_unicode(name, len, ignore_hash);
 225   }
 226 
 227   // Histogram
 228   static void print_histogram()     PRODUCT_RETURN;
 229   static void print()     PRODUCT_RETURN;
 230 
 231   // Debugging
 232   static void verify();
 233   static void dump(outputStream* st);

 234 
 235   // Sharing
 236   static void copy_buckets(char** top, char*end) {
 237     the_table()->Hashtable<Symbol*, mtSymbol>::copy_buckets(top, end);
 238   }
 239   static void copy_table(char** top, char*end) {
 240     the_table()->Hashtable<Symbol*, mtSymbol>::copy_table(top, end);
 241   }
 242   static void reverse(void* boundary = NULL) {
 243     the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary);
 244   }
 245 
 246   // Rehash the symbol table if it gets out of balance
 247   static void rehash_table();
 248   static bool needs_rehashing()         { return _needs_rehashing; }
 249   // Parallel chunked scanning
 250   static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; }
 251   static int parallel_claimed_index()        { return _parallel_claimed_idx; }
 252 };
 253 
 254 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP


  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;
  93 
  94   // shared symbol table.
  95   static CompactHashtable<Symbol*, char> _shared_table;
  96 
  97   Symbol* allocate_symbol(const u1* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F
  98 
  99   // Adding elements
 100   Symbol* basic_add(int index, u1* name, int len, unsigned int hashValue,
 101                     bool c_heap, TRAPS);
 102   bool basic_add(ClassLoaderData* loader_data,
 103                  constantPoolHandle cp, int names_count,
 104                  const char** names, int* lengths, int* cp_indices,
 105                  unsigned int* hashValues, TRAPS);
 106 
 107   static void new_symbols(ClassLoaderData* loader_data,
 108                           constantPoolHandle cp, int names_count,
 109                           const char** name, int* lengths,
 110                           int* cp_indices, unsigned int* hashValues,
 111                           TRAPS) {
 112     add(loader_data, cp, names_count, name, lengths, cp_indices, hashValues, THREAD);
 113   }
 114 
 115   static Symbol* lookup_shared(const char* name, int len, unsigned int hash);
 116   Symbol* lookup_dynamic(int index, const char* name, int len, unsigned int hash);
 117   Symbol* lookup(int index, const char* name, int len, unsigned int hash);
 118 
 119   SymbolTable()
 120     : RehashableHashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {}
 121 
 122   SymbolTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
 123     : RehashableHashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>), t,
 124                 number_of_entries) {}
 125 
 126   // Arena for permanent symbols (null class loader) that are never unloaded
 127   static Arena*  _arena;
 128   static Arena* arena() { return _arena; }  // called for statistics
 129 
 130   static void initialize_symbols(int arena_alloc_size = 0);
 131 
 132   static volatile int _parallel_claimed_idx;
 133 
 134   // Release any dead symbols
 135   static void buckets_unlink(int start_idx, int end_idx, int* processed, int* removed, size_t* memory_total);
 136 public:
 137   enum {
 138     symbol_alloc_batch_size = 8,
 139     // Pick initial size based on java -version size measurements
 140     symbol_alloc_arena_size = 360*K
 141   };
 142 
 143   // The symbol table
 144   static SymbolTable* the_table() { return _the_table; }
 145 
 146   // Size of one bucket in the string table.  Used when checking for rollover.
 147   static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
 148 
 149   static void create_table() {
 150     assert(_the_table == NULL, "One symbol table allowed.");
 151     _the_table = new SymbolTable();
 152     initialize_symbols(symbol_alloc_arena_size);
 153   }
 154 














 155   static unsigned int hash_symbol(const char* s, int len);
 156 
 157   static Symbol* lookup(const char* name, int len, TRAPS);
 158   // lookup only, won't add. Also calculate hash.
 159   static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
 160   // Only copy to C string to be added if lookup failed.
 161   static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS);
 162 
 163   static void release(Symbol* sym);
 164 
 165   // Look up the address of the literal in the SymbolTable for this Symbol*
 166   static Symbol** lookup_symbol_addr(Symbol* sym);
 167 
 168   // jchar (utf16) version of lookups
 169   static Symbol* lookup_unicode(const jchar* name, int len, TRAPS);
 170   static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
 171 
 172   static void add(ClassLoaderData* loader_data,
 173                   constantPoolHandle cp, int names_count,
 174                   const char** names, int* lengths, int* cp_indices,


 207   static Symbol* lookup(int index, const char* name, int len, TRAPS);
 208 
 209   // Needed for preloading classes in signatures when compiling.
 210   // Returns the symbol is already present in symbol table, otherwise
 211   // NULL.  NO ALLOCATION IS GUARANTEED!
 212   static Symbol* probe(const char* name, int len) {
 213     unsigned int ignore_hash;
 214     return lookup_only(name, len, ignore_hash);
 215   }
 216   static Symbol* probe_unicode(const jchar* name, int len) {
 217     unsigned int ignore_hash;
 218     return lookup_only_unicode(name, len, ignore_hash);
 219   }
 220 
 221   // Histogram
 222   static void print_histogram()     PRODUCT_RETURN;
 223   static void print()     PRODUCT_RETURN;
 224 
 225   // Debugging
 226   static void verify();
 227   static void dump(outputStream* st, bool verbose=false);
 228   static void read(const char* filename, TRAPS);
 229 
 230   // Sharing
 231   static bool copy_compact_table(char** top, char* end);
 232   static const char* init_shared_table(const char* buffer);







 233 
 234   // Rehash the symbol table if it gets out of balance
 235   static void rehash_table();
 236   static bool needs_rehashing()         { return _needs_rehashing; }
 237   // Parallel chunked scanning
 238   static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; }
 239   static int parallel_claimed_index()        { return _parallel_claimed_idx; }
 240 };
 241 
 242 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP