src/hotspot/share/classfile/symbolTable.hpp
changeset 54847 59ea39bb2809
parent 54764 865ec913f916
child 54896 ea619918de95
equal deleted inserted replaced
54846:e4049522b074 54847:59ea39bb2809
    41 //
    41 //
    42 // Routines in SymbolTable will initialize the reference count of a Symbol* before
    42 // Routines in SymbolTable will initialize the reference count of a Symbol* before
    43 // it becomes "managed" by TempNewSymbol instances. As a handle class, TempNewSymbol
    43 // it becomes "managed" by TempNewSymbol instances. As a handle class, TempNewSymbol
    44 // needs to maintain proper reference counting in context of copy semantics.
    44 // needs to maintain proper reference counting in context of copy semantics.
    45 //
    45 //
    46 // In SymbolTable, new_symbol() and lookup() will create a Symbol* if not already in the
    46 // In SymbolTable, new_symbol() will create a Symbol* if not already in the
    47 // symbol table and add to the symbol's reference count.
    47 // symbol table and add to the symbol's reference count.
    48 // probe() and lookup_only() will increment the refcount if symbol is found.
    48 // probe() and lookup_only() will increment the refcount if symbol is found.
    49 class TempNewSymbol : public StackObj {
    49 class TempNewSymbol : public StackObj {
    50   Symbol* _temp;
    50   Symbol* _temp;
    51 
    51 
   137   void mark_has_items_to_clean();
   137   void mark_has_items_to_clean();
   138   bool has_items_to_clean() const;
   138   bool has_items_to_clean() const;
   139 
   139 
   140   SymbolTable();
   140   SymbolTable();
   141 
   141 
   142   Symbol* allocate_symbol(const char* name, int len, bool c_heap, TRAPS); // Assumes no characters larger than 0x7F
   142   Symbol* allocate_symbol(const char* name, int len, bool c_heap); // Assumes no characters larger than 0x7F
   143   Symbol* do_lookup(const char* name, int len, uintx hash);
   143   Symbol* do_lookup(const char* name, int len, uintx hash);
   144   Symbol* do_add_if_needed(const char* name, int len, uintx hash, bool heap, TRAPS);
   144   Symbol* do_add_if_needed(const char* name, int len, uintx hash, bool heap);
       
   145 
       
   146   // lookup only, won't add. Also calculate hash. Used by the ClassfileParser.
       
   147   static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
       
   148   static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
   145 
   149 
   146   // Adding elements
   150   // Adding elements
   147   static void new_symbols(ClassLoaderData* loader_data,
   151   static void new_symbols(ClassLoaderData* loader_data,
   148                           const constantPoolHandle& cp, int names_count,
   152                           const constantPoolHandle& cp, int names_count,
   149                           const char** name, int* lengths,
   153                           const char** name, int* lengths,
   150                           int* cp_indices, unsigned int* hashValues,
   154                           int* cp_indices, unsigned int* hashValues);
   151                           TRAPS);
       
   152 
   155 
   153   static Symbol* lookup_shared(const char* name, int len, unsigned int hash);
   156   static Symbol* lookup_shared(const char* name, int len, unsigned int hash);
   154   Symbol* lookup_dynamic(const char* name, int len, unsigned int hash);
   157   Symbol* lookup_dynamic(const char* name, int len, unsigned int hash);
   155   Symbol* lookup_common(const char* name, int len, unsigned int hash);
   158   Symbol* lookup_common(const char* name, int len, unsigned int hash);
   156 
   159 
   188   static void do_concurrent_work(JavaThread* jt);
   191   static void do_concurrent_work(JavaThread* jt);
   189   static bool has_work() { return the_table()->_has_work; }
   192   static bool has_work() { return the_table()->_has_work; }
   190   static void trigger_cleanup();
   193   static void trigger_cleanup();
   191 
   194 
   192   // Probing
   195   // Probing
   193   static Symbol* lookup(const char* name, int len, TRAPS);
       
   194   // lookup only, won't add. Also calculate hash.
       
   195   static Symbol* lookup_only(const char* name, int len, unsigned int& hash);
       
   196   // adds new symbol if not found
       
   197   static Symbol* lookup(const Symbol* sym, int begin, int end, TRAPS);
       
   198   // jchar (UTF16) version of lookups
       
   199   static Symbol* lookup_unicode(const jchar* name, int len, TRAPS);
       
   200   static Symbol* lookup_only_unicode(const jchar* name, int len, unsigned int& hash);
       
   201   // Needed for preloading classes in signatures when compiling.
   196   // Needed for preloading classes in signatures when compiling.
   202   // Returns the symbol is already present in symbol table, otherwise
   197   // Returns the symbol is already present in symbol table, otherwise
   203   // NULL.  NO ALLOCATION IS GUARANTEED!
   198   // NULL.  NO ALLOCATION IS GUARANTEED!
   204   static Symbol* probe(const char* name, int len) {
   199   static Symbol* probe(const char* name, int len) {
   205     unsigned int ignore_hash;
   200     unsigned int ignore_hash;
   208   static Symbol* probe_unicode(const jchar* name, int len) {
   203   static Symbol* probe_unicode(const jchar* name, int len) {
   209     unsigned int ignore_hash;
   204     unsigned int ignore_hash;
   210     return lookup_only_unicode(name, len, ignore_hash);
   205     return lookup_only_unicode(name, len, ignore_hash);
   211   }
   206   }
   212 
   207 
   213   // Symbol creation
   208   // Symbol lookup and create if not found.
   214   static Symbol* new_symbol(const char* utf8_buffer, int length, TRAPS) {
   209   // jchar (UTF16) version of lookup
   215     assert(utf8_buffer != NULL, "just checking");
   210   static Symbol* new_symbol(const jchar* name, int len);
   216     return lookup(utf8_buffer, length, THREAD);
   211   // char (UTF8) versions
   217   }
   212   static Symbol* new_symbol(const Symbol* sym, int begin, int end);
   218   static Symbol* new_symbol(const char* name, TRAPS) {
   213   static Symbol* new_symbol(const char* utf8_buffer, int length);
   219     return new_symbol(name, (int)strlen(name), THREAD);
   214   static Symbol* new_symbol(const char* name) {
   220   }
   215     return new_symbol(name, (int)strlen(name));
   221   static Symbol* new_symbol(const Symbol* sym, int begin, int end, TRAPS) {
   216   }
   222     assert(begin <= end && end <= sym->utf8_length(), "just checking");
   217 
   223     return lookup(sym, begin, end, THREAD);
       
   224   }
       
   225   // Create a symbol in the arena for symbols that are not deleted
   218   // Create a symbol in the arena for symbols that are not deleted
   226   static Symbol* new_permanent_symbol(const char* name, TRAPS);
   219   static Symbol* new_permanent_symbol(const char* name);
   227 
   220 
   228   // Rehash the string table if it gets out of balance
   221   // Rehash the string table if it gets out of balance
   229   static void rehash_table();
   222   static void rehash_table();
   230   static bool needs_rehashing()
   223   static bool needs_rehashing()
   231     { return SymbolTable::the_table()->_needs_rehashing; }
   224     { return SymbolTable::the_table()->_needs_rehashing; }
   243 
   236 
   244   // Jcmd
   237   // Jcmd
   245   static void dump(outputStream* st, bool verbose=false);
   238   static void dump(outputStream* st, bool verbose=false);
   246   // Debugging
   239   // Debugging
   247   static void verify();
   240   static void verify();
   248   static void read(const char* filename, TRAPS);
       
   249 
   241 
   250   // Histogram
   242   // Histogram
   251   static void print_histogram() PRODUCT_RETURN;
   243   static void print_histogram() PRODUCT_RETURN;
   252 };
   244 };
   253 
   245