41 class StringTableConfig; 42 typedef ConcurrentHashTable<WeakHandle<vm_string_table_data>, 43 StringTableConfig, mtSymbol> StringTableHash; 44 45 class StringTableCreateEntry; 46 47 class StringTable : public CHeapObj<mtSymbol>{ 48 friend class VMStructs; 49 friend class Symbol; 50 friend class StringTableConfig; 51 friend class StringTableCreateEntry; 52 53 private: 54 void grow(JavaThread* jt); 55 void clean_dead_entries(JavaThread* jt); 56 57 // The string table 58 static StringTable* _the_table; 59 // Shared string table 60 static CompactHashtable<oop, char> _shared_table; 61 static bool _shared_string_mapped; 62 static bool _alt_hash; 63 private: 64 65 // Set if one bucket is out of balance due to hash algorithm deficiency 66 StringTableHash* _local_table; 67 size_t _current_size; 68 volatile bool _has_work; 69 volatile bool _needs_rehashing; 70 71 OopStorage* _weak_handles; 72 73 volatile size_t _items; 74 DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t)); 75 volatile size_t _uncleaned_items; 76 DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t)); 77 78 double get_load_factor(); 79 double get_dead_factor(); 80 81 void check_concurrent_work(); 82 void trigger_concurrent_work(); 83 84 static size_t item_added(); 85 static void item_removed(); 86 size_t add_items_to_clean(size_t ndead); 87 88 StringTable(); 89 90 static oop intern(Handle string_or_null_h, jchar* name, int len, TRAPS); 91 oop do_intern(Handle string_or_null, jchar* name, int len, uintx hash, TRAPS); 92 oop do_lookup(jchar* name, int len, uintx hash); 93 94 void concurrent_work(JavaThread* jt); 95 void print_table_statistics(outputStream* st, const char* table_name); 96 97 void try_rehash_table(); 98 bool do_rehash(); 99 100 public: 101 // The string table 102 static StringTable* the_table() { return _the_table; } 103 size_t table_size(Thread* thread = NULL); 104 105 static OopStorage* weak_storage() { return the_table()->_weak_handles; } 106 107 static void create_table() { 108 assert(_the_table == NULL, "One string table allowed."); 109 _the_table = new StringTable(); 110 } 111 112 static void do_concurrent_work(JavaThread* jt); 113 static bool has_work() { return the_table()->_has_work; } 114 115 // GC support 116 117 // Must be called before a parallel walk where strings might die. 118 static void reset_dead_counter() { 119 the_table()->_uncleaned_items = 0; 120 } 121 // After the parallel walk this method must be called to trigger 122 // cleaning. Note it might trigger a resize instead. 123 static void finish_dead_counter() { 124 the_table()->check_concurrent_work(); 125 } 126 127 // If GC uses ParState directly it should add the number of cleared 128 // strings to this method. 129 static void inc_dead_counter(size_t ndead) { 130 the_table()->add_items_to_clean(ndead); 131 } 132 133 // Delete pointers to otherwise-unreachable objects. 134 static void unlink(BoolObjectClosure* cl) { 135 unlink_or_oops_do(cl); 136 } 137 static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f = NULL, 138 int* processed = NULL, int* removed = NULL); 139 140 // Serially invoke "f->do_oop" on the locations of all oops in the table. 141 static void oops_do(OopClosure* f); 142 143 // Possibly parallel versions of the above 144 static void possibly_parallel_unlink( 145 OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string, 146 BoolObjectClosure* cl, int* processed, int* removed); 147 static void possibly_parallel_oops_do( 148 OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string, 149 OopClosure* f); 150 | 41 class StringTableConfig; 42 typedef ConcurrentHashTable<WeakHandle<vm_string_table_data>, 43 StringTableConfig, mtSymbol> StringTableHash; 44 45 class StringTableCreateEntry; 46 47 class StringTable : public CHeapObj<mtSymbol>{ 48 friend class VMStructs; 49 friend class Symbol; 50 friend class StringTableConfig; 51 friend class StringTableCreateEntry; 52 53 private: 54 void grow(JavaThread* jt); 55 void clean_dead_entries(JavaThread* jt); 56 57 // The string table 58 static StringTable* _the_table; 59 // Shared string table 60 static CompactHashtable<oop, char> _shared_table; 61 static volatile bool _shared_string_mapped; 62 static volatile bool _alt_hash; 63 64 private: 65 66 StringTableHash* _local_table; 67 size_t _current_size; 68 volatile bool _has_work; 69 // Set if one bucket is out of balance due to hash algorithm deficiency 70 volatile bool _needs_rehashing; 71 72 OopStorage* _weak_handles; 73 74 volatile size_t _items_count; 75 DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t)); 76 volatile size_t _uncleaned_items_count; 77 DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t)); 78 79 double get_load_factor(); 80 double get_dead_factor(); 81 82 void check_concurrent_work(); 83 void trigger_concurrent_work(); 84 85 static size_t item_added(); 86 static void item_removed(); 87 size_t add_items_count_to_clean(size_t ndead); 88 89 StringTable(); 90 91 static oop intern(Handle string_or_null_h, jchar* name, int len, TRAPS); 92 oop do_intern(Handle string_or_null, jchar* name, int len, uintx hash, TRAPS); 93 oop do_lookup(jchar* name, int len, uintx hash); 94 95 void concurrent_work(JavaThread* jt); 96 void print_table_statistics(outputStream* st, const char* table_name); 97 98 void try_rehash_table(); 99 bool do_rehash(); 100 101 public: 102 // The string table 103 static StringTable* the_table() { return _the_table; } 104 size_t table_size(Thread* thread = NULL); 105 106 static OopStorage* weak_storage() { return the_table()->_weak_handles; } 107 108 static void create_table() { 109 assert(_the_table == NULL, "One string table allowed."); 110 _the_table = new StringTable(); 111 } 112 113 static void do_concurrent_work(JavaThread* jt); 114 static bool has_work() { return the_table()->_has_work; } 115 116 // GC support 117 118 // Must be called before a parallel walk where strings might die. 119 static void reset_dead_counter() { 120 the_table()->_uncleaned_items_count = 0; 121 } 122 // After the parallel walk this method must be called to trigger 123 // cleaning. Note it might trigger a resize instead. 124 static void finish_dead_counter() { 125 the_table()->check_concurrent_work(); 126 } 127 128 // If GC uses ParState directly it should add the number of cleared 129 // strings to this method. 130 static void inc_dead_counter(size_t ndead) { 131 the_table()->add_items_count_to_clean(ndead); 132 } 133 134 // Delete pointers to otherwise-unreachable objects. 135 static void unlink(BoolObjectClosure* cl) { 136 unlink_or_oops_do(cl); 137 } 138 static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f = NULL, 139 int* processed = NULL, int* removed = NULL); 140 141 // Serially invoke "f->do_oop" on the locations of all oops in the table. 142 static void oops_do(OopClosure* f); 143 144 // Possibly parallel versions of the above 145 static void possibly_parallel_unlink( 146 OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string, 147 BoolObjectClosure* cl, int* processed, int* removed); 148 static void possibly_parallel_oops_do( 149 OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string, 150 OopClosure* f); 151 |