src/hotspot/share/classfile/stringTable.hpp
changeset 54896 ea619918de95
parent 54764 865ec913f916
child 57828 35db8fba55f9
equal deleted inserted replaced
54895:4f1f939d8f5d 54896:ea619918de95
    24 
    24 
    25 #ifndef SHARE_CLASSFILE_STRINGTABLE_HPP
    25 #ifndef SHARE_CLASSFILE_STRINGTABLE_HPP
    26 #define SHARE_CLASSFILE_STRINGTABLE_HPP
    26 #define SHARE_CLASSFILE_STRINGTABLE_HPP
    27 
    27 
    28 #include "gc/shared/oopStorage.hpp"
    28 #include "gc/shared/oopStorage.hpp"
    29 #include "gc/shared/oopStorageParState.hpp"
       
    30 #include "memory/allocation.hpp"
    29 #include "memory/allocation.hpp"
    31 #include "memory/padded.hpp"
    30 #include "memory/padded.hpp"
    32 #include "oops/oop.hpp"
    31 #include "oops/oop.hpp"
    33 #include "oops/weakHandle.hpp"
    32 #include "oops/weakHandle.hpp"
    34 #include "utilities/concurrentHashTable.hpp"
    33 #include "utilities/tableStatistics.hpp"
    35 
    34 
    36 class CompactHashtableWriter;
    35 class CompactHashtableWriter;
    37 class SerializeClosure;
    36 class SerializeClosure;
    38 
    37 
    39 class StringTable;
    38 class StringTable;
    40 class StringTableConfig;
    39 class StringTableConfig;
    41 typedef ConcurrentHashTable<WeakHandle<vm_string_table_data>,
       
    42                             StringTableConfig, mtSymbol> StringTableHash;
       
    43 
       
    44 class StringTableCreateEntry;
    40 class StringTableCreateEntry;
    45 
    41 
    46 class StringTable : public CHeapObj<mtSymbol>{
    42 class StringTable : public CHeapObj<mtSymbol>{
    47   friend class VMStructs;
    43   friend class VMStructs;
    48   friend class Symbol;
    44   friend class Symbol;
    49   friend class StringTableConfig;
    45   friend class StringTableConfig;
    50   friend class StringTableCreateEntry;
    46   friend class StringTableCreateEntry;
    51 
    47 
    52 private:
    48   static volatile bool _has_work;
    53   void grow(JavaThread* jt);
    49   static volatile size_t _uncleaned_items_count;
    54   void clean_dead_entries(JavaThread* jt);
       
    55 
    50 
    56   // The string table
    51   // Set if one bucket is out of balance due to hash algorithm deficiency
    57   static StringTable* _the_table;
    52   static volatile bool _needs_rehashing;
    58   static volatile bool _alt_hash;
       
    59 
    53 
    60 private:
    54   static OopStorage* _weak_handles;
    61 
    55 
    62   StringTableHash* _local_table;
    56   static void grow(JavaThread* jt);
    63   size_t _current_size;
    57   static void clean_dead_entries(JavaThread* jt);
    64   volatile bool _has_work;
       
    65   // Set if one bucket is out of balance due to hash algorithm deficiency
       
    66   volatile bool _needs_rehashing;
       
    67 
    58 
    68   OopStorage* _weak_handles;
    59   static double get_load_factor();
       
    60   static double get_dead_factor();
    69 
    61 
    70   volatile size_t _items_count;
    62   static void check_concurrent_work();
    71   DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t));
    63   static void trigger_concurrent_work();
    72   volatile size_t _uncleaned_items_count;
       
    73   DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t));
       
    74 
       
    75   double get_load_factor() const;
       
    76   double get_dead_factor() const;
       
    77 
       
    78   void check_concurrent_work();
       
    79   void trigger_concurrent_work();
       
    80 
    64 
    81   static size_t item_added();
    65   static size_t item_added();
    82   static void item_removed();
    66   static void item_removed();
    83   size_t add_items_to_clean(size_t ndead);
    67   static size_t add_items_to_clean(size_t ndead);
    84 
       
    85   StringTable();
       
    86 
    68 
    87   static oop intern(Handle string_or_null_h, const jchar* name, int len, TRAPS);
    69   static oop intern(Handle string_or_null_h, const jchar* name, int len, TRAPS);
    88   oop do_intern(Handle string_or_null, const jchar* name, int len, uintx hash, TRAPS);
    70   static oop do_intern(Handle string_or_null, const jchar* name, int len, uintx hash, TRAPS);
    89   oop do_lookup(const jchar* name, int len, uintx hash);
    71   static oop do_lookup(const jchar* name, int len, uintx hash);
    90 
    72 
    91   void concurrent_work(JavaThread* jt);
    73   static void print_table_statistics(outputStream* st, const char* table_name);
    92   void print_table_statistics(outputStream* st, const char* table_name);
       
    93 
    74 
    94   void try_rehash_table();
    75   static bool do_rehash();
    95   bool do_rehash();
       
    96   inline void update_needs_rehash(bool rehash);
       
    97 
    76 
    98  public:
    77  public:
    99   // The string table
    78   static size_t table_size();
   100   static StringTable* the_table() { return _the_table; }
    79   static TableStatistics get_table_statistics();
   101   size_t table_size();
       
   102   TableStatistics get_table_statistics();
       
   103 
    80 
   104   static OopStorage* weak_storage() { return the_table()->_weak_handles; }
    81   static OopStorage* weak_storage() { return _weak_handles; }
   105 
    82 
   106   static void create_table() {
    83   static void create_table();
   107     assert(_the_table == NULL, "One string table allowed.");
       
   108     _the_table = new StringTable();
       
   109   }
       
   110 
    84 
   111   static void do_concurrent_work(JavaThread* jt);
    85   static void do_concurrent_work(JavaThread* jt);
   112   static bool has_work() { return the_table()->_has_work; }
    86   static bool has_work() { return _has_work; }
   113 
    87 
   114   // GC support
    88   // GC support
   115 
    89 
   116   // Must be called before a parallel walk where strings might die.
    90   // Must be called before a parallel walk where strings might die.
   117   static void reset_dead_counter() {
    91   static void reset_dead_counter() { _uncleaned_items_count = 0; }
   118     the_table()->_uncleaned_items_count = 0;
    92 
   119   }
       
   120   // After the parallel walk this method must be called to trigger
    93   // After the parallel walk this method must be called to trigger
   121   // cleaning. Note it might trigger a resize instead.
    94   // cleaning. Note it might trigger a resize instead.
   122   static void finish_dead_counter() {
    95   static void finish_dead_counter() { check_concurrent_work(); }
   123     the_table()->check_concurrent_work();
       
   124   }
       
   125 
    96 
   126   // If GC uses ParState directly it should add the number of cleared
    97   // If GC uses ParState directly it should add the number of cleared
   127   // strings to this method.
    98   // strings to this method.
   128   static void inc_dead_counter(size_t ndead) {
    99   static void inc_dead_counter(size_t ndead) { add_items_to_clean(ndead); }
   129     the_table()->add_items_to_clean(ndead);
       
   130   }
       
   131 
   100 
   132   // Serially invoke "f->do_oop" on the locations of all oops in the table.
   101   // Serially invoke "f->do_oop" on the locations of all oops in the table.
       
   102   // Used by JFR leak profiler.  TODO: it should find these oops through
       
   103   // the WeakProcessor.
   133   static void oops_do(OopClosure* f);
   104   static void oops_do(OopClosure* f);
   134 
       
   135   // Possibly parallel versions of the above
       
   136   static void possibly_parallel_oops_do(
       
   137      OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string,
       
   138      OopClosure* f);
       
   139 
   105 
   140   // Probing
   106   // Probing
   141   static oop lookup(Symbol* symbol);
   107   static oop lookup(Symbol* symbol);
   142   static oop lookup(const jchar* chars, int length);
   108   static oop lookup(const jchar* chars, int length);
   143 
   109 
   146   static oop intern(oop string, TRAPS);
   112   static oop intern(oop string, TRAPS);
   147   static oop intern(const char *utf8_string, TRAPS);
   113   static oop intern(const char *utf8_string, TRAPS);
   148 
   114 
   149   // Rehash the string table if it gets out of balance
   115   // Rehash the string table if it gets out of balance
   150   static void rehash_table();
   116   static void rehash_table();
   151   static bool needs_rehashing()
   117   static bool needs_rehashing() { return _needs_rehashing; }
   152     { return StringTable::the_table()->_needs_rehashing; }
   118   static inline void update_needs_rehash(bool rehash) {
       
   119     if (rehash) {
       
   120       _needs_rehashing = true;
       
   121     }
       
   122   }
   153 
   123 
   154   // Sharing
   124   // Sharing
   155  private:
   125  private:
   156   oop lookup_shared(const jchar* name, int len, unsigned int hash) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
   126   static oop lookup_shared(const jchar* name, int len, unsigned int hash) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
   157   static void copy_shared_string_table(CompactHashtableWriter* ch_table) NOT_CDS_JAVA_HEAP_RETURN;
   127   static void copy_shared_string_table(CompactHashtableWriter* ch_table) NOT_CDS_JAVA_HEAP_RETURN;
   158  public:
   128  public:
   159   static oop create_archived_string(oop s, Thread* THREAD) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
   129   static oop create_archived_string(oop s, Thread* THREAD) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
   160   static void shared_oops_do(OopClosure* f) NOT_CDS_JAVA_HEAP_RETURN;
   130   static void shared_oops_do(OopClosure* f) NOT_CDS_JAVA_HEAP_RETURN;
   161   static void write_to_archive() NOT_CDS_JAVA_HEAP_RETURN;
   131   static void write_to_archive() NOT_CDS_JAVA_HEAP_RETURN;