1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/classfile/symbolTable.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,1081 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "classfile/altHashing.hpp" 1.30 +#include "classfile/javaClasses.hpp" 1.31 +#include "classfile/symbolTable.hpp" 1.32 +#include "classfile/systemDictionary.hpp" 1.33 +#include "gc_interface/collectedHeap.inline.hpp" 1.34 +#include "memory/allocation.inline.hpp" 1.35 +#include "memory/filemap.hpp" 1.36 +#include "memory/gcLocker.inline.hpp" 1.37 +#include "oops/oop.inline.hpp" 1.38 +#include "oops/oop.inline2.hpp" 1.39 +#include "runtime/mutexLocker.hpp" 1.40 +#include "utilities/hashtable.inline.hpp" 1.41 +#if INCLUDE_ALL_GCS 1.42 +#include "gc_implementation/g1/g1StringDedup.hpp" 1.43 +#endif 1.44 + 1.45 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 1.46 + 1.47 +// -------------------------------------------------------------------------- 1.48 + 1.49 +// the number of buckets a thread claims 1.50 +const int ClaimChunkSize = 32; 1.51 + 1.52 +SymbolTable* SymbolTable::_the_table = NULL; 1.53 +// Static arena for symbols that are not deallocated 1.54 +Arena* SymbolTable::_arena = NULL; 1.55 +bool SymbolTable::_needs_rehashing = false; 1.56 + 1.57 +Symbol* SymbolTable::allocate_symbol(const u1* name, int len, bool c_heap, TRAPS) { 1.58 + assert (len <= Symbol::max_length(), "should be checked by caller"); 1.59 + 1.60 + Symbol* sym; 1.61 + 1.62 + if (DumpSharedSpaces) { 1.63 + // Allocate all symbols to CLD shared metaspace 1.64 + sym = new (len, ClassLoaderData::the_null_class_loader_data(), THREAD) Symbol(name, len, -1); 1.65 + } else if (c_heap) { 1.66 + // refcount starts as 1 1.67 + sym = new (len, THREAD) Symbol(name, len, 1); 1.68 + assert(sym != NULL, "new should call vm_exit_out_of_memory if C_HEAP is exhausted"); 1.69 + } else { 1.70 + // Allocate to global arena 1.71 + sym = new (len, arena(), THREAD) Symbol(name, len, -1); 1.72 + } 1.73 + return sym; 1.74 +} 1.75 + 1.76 +void SymbolTable::initialize_symbols(int arena_alloc_size) { 1.77 + // Initialize the arena for global symbols, size passed in depends on CDS. 1.78 + if (arena_alloc_size == 0) { 1.79 + _arena = new (mtSymbol) Arena(); 1.80 + } else { 1.81 + _arena = new (mtSymbol) Arena(arena_alloc_size); 1.82 + } 1.83 +} 1.84 + 1.85 +// Call function for all symbols in the symbol table. 1.86 +void SymbolTable::symbols_do(SymbolClosure *cl) { 1.87 + const int n = the_table()->table_size(); 1.88 + for (int i = 0; i < n; i++) { 1.89 + for (HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 1.90 + p != NULL; 1.91 + p = p->next()) { 1.92 + cl->do_symbol(p->literal_addr()); 1.93 + } 1.94 + } 1.95 +} 1.96 + 1.97 +int SymbolTable::_symbols_removed = 0; 1.98 +int SymbolTable::_symbols_counted = 0; 1.99 +volatile int SymbolTable::_parallel_claimed_idx = 0; 1.100 + 1.101 +void SymbolTable::buckets_unlink(int start_idx, int end_idx, int* processed, int* removed, size_t* memory_total) { 1.102 + for (int i = start_idx; i < end_idx; ++i) { 1.103 + HashtableEntry<Symbol*, mtSymbol>** p = the_table()->bucket_addr(i); 1.104 + HashtableEntry<Symbol*, mtSymbol>* entry = the_table()->bucket(i); 1.105 + while (entry != NULL) { 1.106 + // Shared entries are normally at the end of the bucket and if we run into 1.107 + // a shared entry, then there is nothing more to remove. However, if we 1.108 + // have rehashed the table, then the shared entries are no longer at the 1.109 + // end of the bucket. 1.110 + if (entry->is_shared() && !use_alternate_hashcode()) { 1.111 + break; 1.112 + } 1.113 + Symbol* s = entry->literal(); 1.114 + (*memory_total) += s->size(); 1.115 + (*processed)++; 1.116 + assert(s != NULL, "just checking"); 1.117 + // If reference count is zero, remove. 1.118 + if (s->refcount() == 0) { 1.119 + assert(!entry->is_shared(), "shared entries should be kept live"); 1.120 + delete s; 1.121 + (*removed)++; 1.122 + *p = entry->next(); 1.123 + the_table()->free_entry(entry); 1.124 + } else { 1.125 + p = entry->next_addr(); 1.126 + } 1.127 + // get next entry 1.128 + entry = (HashtableEntry<Symbol*, mtSymbol>*)HashtableEntry<Symbol*, mtSymbol>::make_ptr(*p); 1.129 + } 1.130 + } 1.131 +} 1.132 + 1.133 +// Remove unreferenced symbols from the symbol table 1.134 +// This is done late during GC. 1.135 +void SymbolTable::unlink(int* processed, int* removed) { 1.136 + size_t memory_total = 0; 1.137 + buckets_unlink(0, the_table()->table_size(), processed, removed, &memory_total); 1.138 + _symbols_removed += *removed; 1.139 + _symbols_counted += *processed; 1.140 + // Exclude printing for normal PrintGCDetails because people parse 1.141 + // this output. 1.142 + if (PrintGCDetails && Verbose && WizardMode) { 1.143 + gclog_or_tty->print(" [Symbols=%d size=" SIZE_FORMAT "K] ", *processed, 1.144 + (memory_total*HeapWordSize)/1024); 1.145 + } 1.146 +} 1.147 + 1.148 +void SymbolTable::possibly_parallel_unlink(int* processed, int* removed) { 1.149 + const int limit = the_table()->table_size(); 1.150 + 1.151 + size_t memory_total = 0; 1.152 + 1.153 + for (;;) { 1.154 + // Grab next set of buckets to scan 1.155 + int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; 1.156 + if (start_idx >= limit) { 1.157 + // End of table 1.158 + break; 1.159 + } 1.160 + 1.161 + int end_idx = MIN2(limit, start_idx + ClaimChunkSize); 1.162 + buckets_unlink(start_idx, end_idx, processed, removed, &memory_total); 1.163 + } 1.164 + Atomic::add(*processed, &_symbols_counted); 1.165 + Atomic::add(*removed, &_symbols_removed); 1.166 + // Exclude printing for normal PrintGCDetails because people parse 1.167 + // this output. 1.168 + if (PrintGCDetails && Verbose && WizardMode) { 1.169 + gclog_or_tty->print(" [Symbols: scanned=%d removed=%d size=" SIZE_FORMAT "K] ", *processed, *removed, 1.170 + (memory_total*HeapWordSize)/1024); 1.171 + } 1.172 +} 1.173 + 1.174 +// Create a new table and using alternate hash code, populate the new table 1.175 +// with the existing strings. Set flag to use the alternate hash code afterwards. 1.176 +void SymbolTable::rehash_table() { 1.177 + assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1.178 + // This should never happen with -Xshare:dump but it might in testing mode. 1.179 + if (DumpSharedSpaces) return; 1.180 + // Create a new symbol table 1.181 + SymbolTable* new_table = new SymbolTable(); 1.182 + 1.183 + the_table()->move_to(new_table); 1.184 + 1.185 + // Delete the table and buckets (entries are reused in new table). 1.186 + delete _the_table; 1.187 + // Don't check if we need rehashing until the table gets unbalanced again. 1.188 + // Then rehash with a new global seed. 1.189 + _needs_rehashing = false; 1.190 + _the_table = new_table; 1.191 +} 1.192 + 1.193 +// Lookup a symbol in a bucket. 1.194 + 1.195 +Symbol* SymbolTable::lookup(int index, const char* name, 1.196 + int len, unsigned int hash) { 1.197 + int count = 0; 1.198 + for (HashtableEntry<Symbol*, mtSymbol>* e = bucket(index); e != NULL; e = e->next()) { 1.199 + count++; // count all entries in this bucket, not just ones with same hash 1.200 + if (e->hash() == hash) { 1.201 + Symbol* sym = e->literal(); 1.202 + if (sym->equals(name, len)) { 1.203 + // something is referencing this symbol now. 1.204 + sym->increment_refcount(); 1.205 + return sym; 1.206 + } 1.207 + } 1.208 + } 1.209 + // If the bucket size is too deep check if this hash code is insufficient. 1.210 + if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) { 1.211 + _needs_rehashing = check_rehash_table(count); 1.212 + } 1.213 + return NULL; 1.214 +} 1.215 + 1.216 +// Pick hashing algorithm. 1.217 +unsigned int SymbolTable::hash_symbol(const char* s, int len) { 1.218 + return use_alternate_hashcode() ? 1.219 + AltHashing::murmur3_32(seed(), (const jbyte*)s, len) : 1.220 + java_lang_String::hash_code(s, len); 1.221 +} 1.222 + 1.223 + 1.224 +// We take care not to be blocking while holding the 1.225 +// SymbolTable_lock. Otherwise, the system might deadlock, since the 1.226 +// symboltable is used during compilation (VM_thread) The lock free 1.227 +// synchronization is simplified by the fact that we do not delete 1.228 +// entries in the symbol table during normal execution (only during 1.229 +// safepoints). 1.230 + 1.231 +Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) { 1.232 + unsigned int hashValue = hash_symbol(name, len); 1.233 + int index = the_table()->hash_to_index(hashValue); 1.234 + 1.235 + Symbol* s = the_table()->lookup(index, name, len, hashValue); 1.236 + 1.237 + // Found 1.238 + if (s != NULL) return s; 1.239 + 1.240 + // Grab SymbolTable_lock first. 1.241 + MutexLocker ml(SymbolTable_lock, THREAD); 1.242 + 1.243 + // Otherwise, add to symbol to table 1.244 + return the_table()->basic_add(index, (u1*)name, len, hashValue, true, CHECK_NULL); 1.245 +} 1.246 + 1.247 +Symbol* SymbolTable::lookup(const Symbol* sym, int begin, int end, TRAPS) { 1.248 + char* buffer; 1.249 + int index, len; 1.250 + unsigned int hashValue; 1.251 + char* name; 1.252 + { 1.253 + debug_only(No_Safepoint_Verifier nsv;) 1.254 + 1.255 + name = (char*)sym->base() + begin; 1.256 + len = end - begin; 1.257 + hashValue = hash_symbol(name, len); 1.258 + index = the_table()->hash_to_index(hashValue); 1.259 + Symbol* s = the_table()->lookup(index, name, len, hashValue); 1.260 + 1.261 + // Found 1.262 + if (s != NULL) return s; 1.263 + } 1.264 + 1.265 + // Otherwise, add to symbol to table. Copy to a C string first. 1.266 + char stack_buf[128]; 1.267 + ResourceMark rm(THREAD); 1.268 + if (len <= 128) { 1.269 + buffer = stack_buf; 1.270 + } else { 1.271 + buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len); 1.272 + } 1.273 + for (int i=0; i<len; i++) { 1.274 + buffer[i] = name[i]; 1.275 + } 1.276 + // Make sure there is no safepoint in the code above since name can't move. 1.277 + // We can't include the code in No_Safepoint_Verifier because of the 1.278 + // ResourceMark. 1.279 + 1.280 + // Grab SymbolTable_lock first. 1.281 + MutexLocker ml(SymbolTable_lock, THREAD); 1.282 + 1.283 + return the_table()->basic_add(index, (u1*)buffer, len, hashValue, true, CHECK_NULL); 1.284 +} 1.285 + 1.286 +Symbol* SymbolTable::lookup_only(const char* name, int len, 1.287 + unsigned int& hash) { 1.288 + hash = hash_symbol(name, len); 1.289 + int index = the_table()->hash_to_index(hash); 1.290 + 1.291 + Symbol* s = the_table()->lookup(index, name, len, hash); 1.292 + return s; 1.293 +} 1.294 + 1.295 +// Look up the address of the literal in the SymbolTable for this Symbol* 1.296 +// Do not create any new symbols 1.297 +// Do not increment the reference count to keep this alive 1.298 +Symbol** SymbolTable::lookup_symbol_addr(Symbol* sym){ 1.299 + unsigned int hash = hash_symbol((char*)sym->bytes(), sym->utf8_length()); 1.300 + int index = the_table()->hash_to_index(hash); 1.301 + 1.302 + for (HashtableEntry<Symbol*, mtSymbol>* e = the_table()->bucket(index); e != NULL; e = e->next()) { 1.303 + if (e->hash() == hash) { 1.304 + Symbol* literal_sym = e->literal(); 1.305 + if (sym == literal_sym) { 1.306 + return e->literal_addr(); 1.307 + } 1.308 + } 1.309 + } 1.310 + return NULL; 1.311 +} 1.312 + 1.313 +// Suggestion: Push unicode-based lookup all the way into the hashing 1.314 +// and probing logic, so there is no need for convert_to_utf8 until 1.315 +// an actual new Symbol* is created. 1.316 +Symbol* SymbolTable::lookup_unicode(const jchar* name, int utf16_length, TRAPS) { 1.317 + int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); 1.318 + char stack_buf[128]; 1.319 + if (utf8_length < (int) sizeof(stack_buf)) { 1.320 + char* chars = stack_buf; 1.321 + UNICODE::convert_to_utf8(name, utf16_length, chars); 1.322 + return lookup(chars, utf8_length, THREAD); 1.323 + } else { 1.324 + ResourceMark rm(THREAD); 1.325 + char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; 1.326 + UNICODE::convert_to_utf8(name, utf16_length, chars); 1.327 + return lookup(chars, utf8_length, THREAD); 1.328 + } 1.329 +} 1.330 + 1.331 +Symbol* SymbolTable::lookup_only_unicode(const jchar* name, int utf16_length, 1.332 + unsigned int& hash) { 1.333 + int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); 1.334 + char stack_buf[128]; 1.335 + if (utf8_length < (int) sizeof(stack_buf)) { 1.336 + char* chars = stack_buf; 1.337 + UNICODE::convert_to_utf8(name, utf16_length, chars); 1.338 + return lookup_only(chars, utf8_length, hash); 1.339 + } else { 1.340 + ResourceMark rm; 1.341 + char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; 1.342 + UNICODE::convert_to_utf8(name, utf16_length, chars); 1.343 + return lookup_only(chars, utf8_length, hash); 1.344 + } 1.345 +} 1.346 + 1.347 +void SymbolTable::add(ClassLoaderData* loader_data, constantPoolHandle cp, 1.348 + int names_count, 1.349 + const char** names, int* lengths, int* cp_indices, 1.350 + unsigned int* hashValues, TRAPS) { 1.351 + // Grab SymbolTable_lock first. 1.352 + MutexLocker ml(SymbolTable_lock, THREAD); 1.353 + 1.354 + SymbolTable* table = the_table(); 1.355 + bool added = table->basic_add(loader_data, cp, names_count, names, lengths, 1.356 + cp_indices, hashValues, CHECK); 1.357 + if (!added) { 1.358 + // do it the hard way 1.359 + for (int i=0; i<names_count; i++) { 1.360 + int index = table->hash_to_index(hashValues[i]); 1.361 + bool c_heap = !loader_data->is_the_null_class_loader_data(); 1.362 + Symbol* sym = table->basic_add(index, (u1*)names[i], lengths[i], hashValues[i], c_heap, CHECK); 1.363 + cp->symbol_at_put(cp_indices[i], sym); 1.364 + } 1.365 + } 1.366 +} 1.367 + 1.368 +Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) { 1.369 + unsigned int hash; 1.370 + Symbol* result = SymbolTable::lookup_only((char*)name, (int)strlen(name), hash); 1.371 + if (result != NULL) { 1.372 + return result; 1.373 + } 1.374 + // Grab SymbolTable_lock first. 1.375 + MutexLocker ml(SymbolTable_lock, THREAD); 1.376 + 1.377 + SymbolTable* table = the_table(); 1.378 + int index = table->hash_to_index(hash); 1.379 + return table->basic_add(index, (u1*)name, (int)strlen(name), hash, false, THREAD); 1.380 +} 1.381 + 1.382 +Symbol* SymbolTable::basic_add(int index_arg, u1 *name, int len, 1.383 + unsigned int hashValue_arg, bool c_heap, TRAPS) { 1.384 + assert(!Universe::heap()->is_in_reserved(name), 1.385 + "proposed name of symbol must be stable"); 1.386 + 1.387 + // Don't allow symbols to be created which cannot fit in a Symbol*. 1.388 + if (len > Symbol::max_length()) { 1.389 + THROW_MSG_0(vmSymbols::java_lang_InternalError(), 1.390 + "name is too long to represent"); 1.391 + } 1.392 + 1.393 + // Cannot hit a safepoint in this function because the "this" pointer can move. 1.394 + No_Safepoint_Verifier nsv; 1.395 + 1.396 + // Check if the symbol table has been rehashed, if so, need to recalculate 1.397 + // the hash value and index. 1.398 + unsigned int hashValue; 1.399 + int index; 1.400 + if (use_alternate_hashcode()) { 1.401 + hashValue = hash_symbol((const char*)name, len); 1.402 + index = hash_to_index(hashValue); 1.403 + } else { 1.404 + hashValue = hashValue_arg; 1.405 + index = index_arg; 1.406 + } 1.407 + 1.408 + // Since look-up was done lock-free, we need to check if another 1.409 + // thread beat us in the race to insert the symbol. 1.410 + Symbol* test = lookup(index, (char*)name, len, hashValue); 1.411 + if (test != NULL) { 1.412 + // A race occurred and another thread introduced the symbol. 1.413 + assert(test->refcount() != 0, "lookup should have incremented the count"); 1.414 + return test; 1.415 + } 1.416 + 1.417 + // Create a new symbol. 1.418 + Symbol* sym = allocate_symbol(name, len, c_heap, CHECK_NULL); 1.419 + assert(sym->equals((char*)name, len), "symbol must be properly initialized"); 1.420 + 1.421 + HashtableEntry<Symbol*, mtSymbol>* entry = new_entry(hashValue, sym); 1.422 + add_entry(index, entry); 1.423 + return sym; 1.424 +} 1.425 + 1.426 +// This version of basic_add adds symbols in batch from the constant pool 1.427 +// parsing. 1.428 +bool SymbolTable::basic_add(ClassLoaderData* loader_data, constantPoolHandle cp, 1.429 + int names_count, 1.430 + const char** names, int* lengths, 1.431 + int* cp_indices, unsigned int* hashValues, 1.432 + TRAPS) { 1.433 + 1.434 + // Check symbol names are not too long. If any are too long, don't add any. 1.435 + for (int i = 0; i< names_count; i++) { 1.436 + if (lengths[i] > Symbol::max_length()) { 1.437 + THROW_MSG_0(vmSymbols::java_lang_InternalError(), 1.438 + "name is too long to represent"); 1.439 + } 1.440 + } 1.441 + 1.442 + // Cannot hit a safepoint in this function because the "this" pointer can move. 1.443 + No_Safepoint_Verifier nsv; 1.444 + 1.445 + for (int i=0; i<names_count; i++) { 1.446 + // Check if the symbol table has been rehashed, if so, need to recalculate 1.447 + // the hash value. 1.448 + unsigned int hashValue; 1.449 + if (use_alternate_hashcode()) { 1.450 + hashValue = hash_symbol(names[i], lengths[i]); 1.451 + } else { 1.452 + hashValue = hashValues[i]; 1.453 + } 1.454 + // Since look-up was done lock-free, we need to check if another 1.455 + // thread beat us in the race to insert the symbol. 1.456 + int index = hash_to_index(hashValue); 1.457 + Symbol* test = lookup(index, names[i], lengths[i], hashValue); 1.458 + if (test != NULL) { 1.459 + // A race occurred and another thread introduced the symbol, this one 1.460 + // will be dropped and collected. Use test instead. 1.461 + cp->symbol_at_put(cp_indices[i], test); 1.462 + assert(test->refcount() != 0, "lookup should have incremented the count"); 1.463 + } else { 1.464 + // Create a new symbol. The null class loader is never unloaded so these 1.465 + // are allocated specially in a permanent arena. 1.466 + bool c_heap = !loader_data->is_the_null_class_loader_data(); 1.467 + Symbol* sym = allocate_symbol((const u1*)names[i], lengths[i], c_heap, CHECK_(false)); 1.468 + assert(sym->equals(names[i], lengths[i]), "symbol must be properly initialized"); // why wouldn't it be??? 1.469 + HashtableEntry<Symbol*, mtSymbol>* entry = new_entry(hashValue, sym); 1.470 + add_entry(index, entry); 1.471 + cp->symbol_at_put(cp_indices[i], sym); 1.472 + } 1.473 + } 1.474 + return true; 1.475 +} 1.476 + 1.477 + 1.478 +void SymbolTable::verify() { 1.479 + for (int i = 0; i < the_table()->table_size(); ++i) { 1.480 + HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 1.481 + for ( ; p != NULL; p = p->next()) { 1.482 + Symbol* s = (Symbol*)(p->literal()); 1.483 + guarantee(s != NULL, "symbol is NULL"); 1.484 + unsigned int h = hash_symbol((char*)s->bytes(), s->utf8_length()); 1.485 + guarantee(p->hash() == h, "broken hash in symbol table entry"); 1.486 + guarantee(the_table()->hash_to_index(h) == i, 1.487 + "wrong index in symbol table"); 1.488 + } 1.489 + } 1.490 +} 1.491 + 1.492 +void SymbolTable::dump(outputStream* st) { 1.493 + the_table()->dump_table(st, "SymbolTable"); 1.494 +} 1.495 + 1.496 + 1.497 +//--------------------------------------------------------------------------- 1.498 +// Non-product code 1.499 + 1.500 +#ifndef PRODUCT 1.501 + 1.502 +void SymbolTable::print_histogram() { 1.503 + MutexLocker ml(SymbolTable_lock); 1.504 + const int results_length = 100; 1.505 + int results[results_length]; 1.506 + int i,j; 1.507 + 1.508 + // initialize results to zero 1.509 + for (j = 0; j < results_length; j++) { 1.510 + results[j] = 0; 1.511 + } 1.512 + 1.513 + int total = 0; 1.514 + int max_symbols = 0; 1.515 + int out_of_range = 0; 1.516 + int memory_total = 0; 1.517 + int count = 0; 1.518 + for (i = 0; i < the_table()->table_size(); i++) { 1.519 + HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 1.520 + for ( ; p != NULL; p = p->next()) { 1.521 + memory_total += p->literal()->size(); 1.522 + count++; 1.523 + int counter = p->literal()->utf8_length(); 1.524 + total += counter; 1.525 + if (counter < results_length) { 1.526 + results[counter]++; 1.527 + } else { 1.528 + out_of_range++; 1.529 + } 1.530 + max_symbols = MAX2(max_symbols, counter); 1.531 + } 1.532 + } 1.533 + tty->print_cr("Symbol Table:"); 1.534 + tty->print_cr("Total number of symbols %5d", count); 1.535 + tty->print_cr("Total size in memory %5dK", 1.536 + (memory_total*HeapWordSize)/1024); 1.537 + tty->print_cr("Total counted %5d", _symbols_counted); 1.538 + tty->print_cr("Total removed %5d", _symbols_removed); 1.539 + if (_symbols_counted > 0) { 1.540 + tty->print_cr("Percent removed %3.2f", 1.541 + ((float)_symbols_removed/(float)_symbols_counted)* 100); 1.542 + } 1.543 + tty->print_cr("Reference counts %5d", Symbol::_total_count); 1.544 + tty->print_cr("Symbol arena size %5d used %5d", 1.545 + arena()->size_in_bytes(), arena()->used()); 1.546 + tty->print_cr("Histogram of symbol length:"); 1.547 + tty->print_cr("%8s %5d", "Total ", total); 1.548 + tty->print_cr("%8s %5d", "Maximum", max_symbols); 1.549 + tty->print_cr("%8s %3.2f", "Average", 1.550 + ((float) total / (float) the_table()->table_size())); 1.551 + tty->print_cr("%s", "Histogram:"); 1.552 + tty->print_cr(" %s %29s", "Length", "Number chains that length"); 1.553 + for (i = 0; i < results_length; i++) { 1.554 + if (results[i] > 0) { 1.555 + tty->print_cr("%6d %10d", i, results[i]); 1.556 + } 1.557 + } 1.558 + if (Verbose) { 1.559 + int line_length = 70; 1.560 + tty->print_cr("%s %30s", " Length", "Number chains that length"); 1.561 + for (i = 0; i < results_length; i++) { 1.562 + if (results[i] > 0) { 1.563 + tty->print("%4d", i); 1.564 + for (j = 0; (j < results[i]) && (j < line_length); j++) { 1.565 + tty->print("%1s", "*"); 1.566 + } 1.567 + if (j == line_length) { 1.568 + tty->print("%1s", "+"); 1.569 + } 1.570 + tty->cr(); 1.571 + } 1.572 + } 1.573 + } 1.574 + tty->print_cr(" %s %d: %d\n", "Number chains longer than", 1.575 + results_length, out_of_range); 1.576 +} 1.577 + 1.578 +void SymbolTable::print() { 1.579 + for (int i = 0; i < the_table()->table_size(); ++i) { 1.580 + HashtableEntry<Symbol*, mtSymbol>** p = the_table()->bucket_addr(i); 1.581 + HashtableEntry<Symbol*, mtSymbol>* entry = the_table()->bucket(i); 1.582 + if (entry != NULL) { 1.583 + while (entry != NULL) { 1.584 + tty->print(PTR_FORMAT " ", entry->literal()); 1.585 + entry->literal()->print(); 1.586 + tty->print(" %d", entry->literal()->refcount()); 1.587 + p = entry->next_addr(); 1.588 + entry = (HashtableEntry<Symbol*, mtSymbol>*)HashtableEntry<Symbol*, mtSymbol>::make_ptr(*p); 1.589 + } 1.590 + tty->cr(); 1.591 + } 1.592 + } 1.593 +} 1.594 +#endif // PRODUCT 1.595 + 1.596 +// -------------------------------------------------------------------------- 1.597 + 1.598 +#ifdef ASSERT 1.599 +class StableMemoryChecker : public StackObj { 1.600 + enum { _bufsize = wordSize*4 }; 1.601 + 1.602 + address _region; 1.603 + jint _size; 1.604 + u1 _save_buf[_bufsize]; 1.605 + 1.606 + int sample(u1* save_buf) { 1.607 + if (_size <= _bufsize) { 1.608 + memcpy(save_buf, _region, _size); 1.609 + return _size; 1.610 + } else { 1.611 + // copy head and tail 1.612 + memcpy(&save_buf[0], _region, _bufsize/2); 1.613 + memcpy(&save_buf[_bufsize/2], _region + _size - _bufsize/2, _bufsize/2); 1.614 + return (_bufsize/2)*2; 1.615 + } 1.616 + } 1.617 + 1.618 + public: 1.619 + StableMemoryChecker(const void* region, jint size) { 1.620 + _region = (address) region; 1.621 + _size = size; 1.622 + sample(_save_buf); 1.623 + } 1.624 + 1.625 + bool verify() { 1.626 + u1 check_buf[sizeof(_save_buf)]; 1.627 + int check_size = sample(check_buf); 1.628 + return (0 == memcmp(_save_buf, check_buf, check_size)); 1.629 + } 1.630 + 1.631 + void set_region(const void* region) { _region = (address) region; } 1.632 +}; 1.633 +#endif 1.634 + 1.635 + 1.636 +// -------------------------------------------------------------------------- 1.637 +StringTable* StringTable::_the_table = NULL; 1.638 + 1.639 +bool StringTable::_needs_rehashing = false; 1.640 + 1.641 +volatile int StringTable::_parallel_claimed_idx = 0; 1.642 + 1.643 +// Pick hashing algorithm 1.644 +unsigned int StringTable::hash_string(const jchar* s, int len) { 1.645 + return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) : 1.646 + java_lang_String::hash_code(s, len); 1.647 +} 1.648 + 1.649 +oop StringTable::lookup(int index, jchar* name, 1.650 + int len, unsigned int hash) { 1.651 + int count = 0; 1.652 + for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) { 1.653 + count++; 1.654 + if (l->hash() == hash) { 1.655 + if (java_lang_String::equals(l->literal(), name, len)) { 1.656 + return l->literal(); 1.657 + } 1.658 + } 1.659 + } 1.660 + // If the bucket size is too deep check if this hash code is insufficient. 1.661 + if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) { 1.662 + _needs_rehashing = check_rehash_table(count); 1.663 + } 1.664 + return NULL; 1.665 +} 1.666 + 1.667 + 1.668 +oop StringTable::basic_add(int index_arg, Handle string, jchar* name, 1.669 + int len, unsigned int hashValue_arg, TRAPS) { 1.670 + 1.671 + assert(java_lang_String::equals(string(), name, len), 1.672 + "string must be properly initialized"); 1.673 + // Cannot hit a safepoint in this function because the "this" pointer can move. 1.674 + No_Safepoint_Verifier nsv; 1.675 + 1.676 + // Check if the symbol table has been rehashed, if so, need to recalculate 1.677 + // the hash value and index before second lookup. 1.678 + unsigned int hashValue; 1.679 + int index; 1.680 + if (use_alternate_hashcode()) { 1.681 + hashValue = hash_string(name, len); 1.682 + index = hash_to_index(hashValue); 1.683 + } else { 1.684 + hashValue = hashValue_arg; 1.685 + index = index_arg; 1.686 + } 1.687 + 1.688 + // Since look-up was done lock-free, we need to check if another 1.689 + // thread beat us in the race to insert the symbol. 1.690 + 1.691 + oop test = lookup(index, name, len, hashValue); // calls lookup(u1*, int) 1.692 + if (test != NULL) { 1.693 + // Entry already added 1.694 + return test; 1.695 + } 1.696 + 1.697 + HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string()); 1.698 + add_entry(index, entry); 1.699 + return string(); 1.700 +} 1.701 + 1.702 + 1.703 +oop StringTable::lookup(Symbol* symbol) { 1.704 + ResourceMark rm; 1.705 + int length; 1.706 + jchar* chars = symbol->as_unicode(length); 1.707 + return lookup(chars, length); 1.708 +} 1.709 + 1.710 + 1.711 +oop StringTable::lookup(jchar* name, int len) { 1.712 + unsigned int hash = hash_string(name, len); 1.713 + int index = the_table()->hash_to_index(hash); 1.714 + return the_table()->lookup(index, name, len, hash); 1.715 +} 1.716 + 1.717 + 1.718 +oop StringTable::intern(Handle string_or_null, jchar* name, 1.719 + int len, TRAPS) { 1.720 + unsigned int hashValue = hash_string(name, len); 1.721 + int index = the_table()->hash_to_index(hashValue); 1.722 + oop found_string = the_table()->lookup(index, name, len, hashValue); 1.723 + 1.724 + // Found 1.725 + if (found_string != NULL) return found_string; 1.726 + 1.727 + debug_only(StableMemoryChecker smc(name, len * sizeof(name[0]))); 1.728 + assert(!Universe::heap()->is_in_reserved(name), 1.729 + "proposed name of symbol must be stable"); 1.730 + 1.731 + Handle string; 1.732 + // try to reuse the string if possible 1.733 + if (!string_or_null.is_null()) { 1.734 + string = string_or_null; 1.735 + } else { 1.736 + string = java_lang_String::create_from_unicode(name, len, CHECK_NULL); 1.737 + } 1.738 + 1.739 +#if INCLUDE_ALL_GCS 1.740 + if (G1StringDedup::is_enabled()) { 1.741 + // Deduplicate the string before it is interned. Note that we should never 1.742 + // deduplicate a string after it has been interned. Doing so will counteract 1.743 + // compiler optimizations done on e.g. interned string literals. 1.744 + G1StringDedup::deduplicate(string()); 1.745 + } 1.746 +#endif 1.747 + 1.748 + // Grab the StringTable_lock before getting the_table() because it could 1.749 + // change at safepoint. 1.750 + MutexLocker ml(StringTable_lock, THREAD); 1.751 + 1.752 + // Otherwise, add to symbol to table 1.753 + return the_table()->basic_add(index, string, name, len, 1.754 + hashValue, CHECK_NULL); 1.755 +} 1.756 + 1.757 +oop StringTable::intern(Symbol* symbol, TRAPS) { 1.758 + if (symbol == NULL) return NULL; 1.759 + ResourceMark rm(THREAD); 1.760 + int length; 1.761 + jchar* chars = symbol->as_unicode(length); 1.762 + Handle string; 1.763 + oop result = intern(string, chars, length, CHECK_NULL); 1.764 + return result; 1.765 +} 1.766 + 1.767 + 1.768 +oop StringTable::intern(oop string, TRAPS) 1.769 +{ 1.770 + if (string == NULL) return NULL; 1.771 + ResourceMark rm(THREAD); 1.772 + int length; 1.773 + Handle h_string (THREAD, string); 1.774 + jchar* chars = java_lang_String::as_unicode_string(string, length, CHECK_NULL); 1.775 + oop result = intern(h_string, chars, length, CHECK_NULL); 1.776 + return result; 1.777 +} 1.778 + 1.779 + 1.780 +oop StringTable::intern(const char* utf8_string, TRAPS) { 1.781 + if (utf8_string == NULL) return NULL; 1.782 + ResourceMark rm(THREAD); 1.783 + int length = UTF8::unicode_length(utf8_string); 1.784 + jchar* chars = NEW_RESOURCE_ARRAY(jchar, length); 1.785 + UTF8::convert_to_unicode(utf8_string, chars, length); 1.786 + Handle string; 1.787 + oop result = intern(string, chars, length, CHECK_NULL); 1.788 + return result; 1.789 +} 1.790 + 1.791 +void StringTable::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) { 1.792 + buckets_unlink_or_oops_do(is_alive, f, 0, the_table()->table_size(), processed, removed); 1.793 +} 1.794 + 1.795 +void StringTable::possibly_parallel_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) { 1.796 + // Readers of the table are unlocked, so we should only be removing 1.797 + // entries at a safepoint. 1.798 + assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1.799 + const int limit = the_table()->table_size(); 1.800 + 1.801 + for (;;) { 1.802 + // Grab next set of buckets to scan 1.803 + int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; 1.804 + if (start_idx >= limit) { 1.805 + // End of table 1.806 + break; 1.807 + } 1.808 + 1.809 + int end_idx = MIN2(limit, start_idx + ClaimChunkSize); 1.810 + buckets_unlink_or_oops_do(is_alive, f, start_idx, end_idx, processed, removed); 1.811 + } 1.812 +} 1.813 + 1.814 +void StringTable::buckets_oops_do(OopClosure* f, int start_idx, int end_idx) { 1.815 + const int limit = the_table()->table_size(); 1.816 + 1.817 + assert(0 <= start_idx && start_idx <= limit, 1.818 + err_msg("start_idx (" INT32_FORMAT ") is out of bounds", start_idx)); 1.819 + assert(0 <= end_idx && end_idx <= limit, 1.820 + err_msg("end_idx (" INT32_FORMAT ") is out of bounds", end_idx)); 1.821 + assert(start_idx <= end_idx, 1.822 + err_msg("Index ordering: start_idx=" INT32_FORMAT", end_idx=" INT32_FORMAT, 1.823 + start_idx, end_idx)); 1.824 + 1.825 + for (int i = start_idx; i < end_idx; i += 1) { 1.826 + HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i); 1.827 + while (entry != NULL) { 1.828 + assert(!entry->is_shared(), "CDS not used for the StringTable"); 1.829 + 1.830 + f->do_oop((oop*)entry->literal_addr()); 1.831 + 1.832 + entry = entry->next(); 1.833 + } 1.834 + } 1.835 +} 1.836 + 1.837 +void StringTable::buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed) { 1.838 + const int limit = the_table()->table_size(); 1.839 + 1.840 + assert(0 <= start_idx && start_idx <= limit, 1.841 + err_msg("start_idx (" INT32_FORMAT ") is out of bounds", start_idx)); 1.842 + assert(0 <= end_idx && end_idx <= limit, 1.843 + err_msg("end_idx (" INT32_FORMAT ") is out of bounds", end_idx)); 1.844 + assert(start_idx <= end_idx, 1.845 + err_msg("Index ordering: start_idx=" INT32_FORMAT", end_idx=" INT32_FORMAT, 1.846 + start_idx, end_idx)); 1.847 + 1.848 + for (int i = start_idx; i < end_idx; ++i) { 1.849 + HashtableEntry<oop, mtSymbol>** p = the_table()->bucket_addr(i); 1.850 + HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i); 1.851 + while (entry != NULL) { 1.852 + assert(!entry->is_shared(), "CDS not used for the StringTable"); 1.853 + 1.854 + if (is_alive->do_object_b(entry->literal())) { 1.855 + if (f != NULL) { 1.856 + f->do_oop((oop*)entry->literal_addr()); 1.857 + } 1.858 + p = entry->next_addr(); 1.859 + } else { 1.860 + *p = entry->next(); 1.861 + the_table()->free_entry(entry); 1.862 + (*removed)++; 1.863 + } 1.864 + (*processed)++; 1.865 + entry = *p; 1.866 + } 1.867 + } 1.868 +} 1.869 + 1.870 +void StringTable::oops_do(OopClosure* f) { 1.871 + buckets_oops_do(f, 0, the_table()->table_size()); 1.872 +} 1.873 + 1.874 +void StringTable::possibly_parallel_oops_do(OopClosure* f) { 1.875 + const int limit = the_table()->table_size(); 1.876 + 1.877 + for (;;) { 1.878 + // Grab next set of buckets to scan 1.879 + int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; 1.880 + if (start_idx >= limit) { 1.881 + // End of table 1.882 + break; 1.883 + } 1.884 + 1.885 + int end_idx = MIN2(limit, start_idx + ClaimChunkSize); 1.886 + buckets_oops_do(f, start_idx, end_idx); 1.887 + } 1.888 +} 1.889 + 1.890 +// This verification is part of Universe::verify() and needs to be quick. 1.891 +// See StringTable::verify_and_compare() below for exhaustive verification. 1.892 +void StringTable::verify() { 1.893 + for (int i = 0; i < the_table()->table_size(); ++i) { 1.894 + HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i); 1.895 + for ( ; p != NULL; p = p->next()) { 1.896 + oop s = p->literal(); 1.897 + guarantee(s != NULL, "interned string is NULL"); 1.898 + unsigned int h = java_lang_String::hash_string(s); 1.899 + guarantee(p->hash() == h, "broken hash in string table entry"); 1.900 + guarantee(the_table()->hash_to_index(h) == i, 1.901 + "wrong index in string table"); 1.902 + } 1.903 + } 1.904 +} 1.905 + 1.906 +void StringTable::dump(outputStream* st) { 1.907 + the_table()->dump_table(st, "StringTable"); 1.908 +} 1.909 + 1.910 +StringTable::VerifyRetTypes StringTable::compare_entries( 1.911 + int bkt1, int e_cnt1, 1.912 + HashtableEntry<oop, mtSymbol>* e_ptr1, 1.913 + int bkt2, int e_cnt2, 1.914 + HashtableEntry<oop, mtSymbol>* e_ptr2) { 1.915 + // These entries are sanity checked by verify_and_compare_entries() 1.916 + // before this function is called. 1.917 + oop str1 = e_ptr1->literal(); 1.918 + oop str2 = e_ptr2->literal(); 1.919 + 1.920 + if (str1 == str2) { 1.921 + tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") " 1.922 + "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]", 1.923 + (void *)str1, bkt1, e_cnt1, bkt2, e_cnt2); 1.924 + return _verify_fail_continue; 1.925 + } 1.926 + 1.927 + if (java_lang_String::equals(str1, str2)) { 1.928 + tty->print_cr("ERROR: identical String values in entry @ " 1.929 + "bucket[%d][%d] and entry @ bucket[%d][%d]", 1.930 + bkt1, e_cnt1, bkt2, e_cnt2); 1.931 + return _verify_fail_continue; 1.932 + } 1.933 + 1.934 + return _verify_pass; 1.935 +} 1.936 + 1.937 +StringTable::VerifyRetTypes StringTable::verify_entry(int bkt, int e_cnt, 1.938 + HashtableEntry<oop, mtSymbol>* e_ptr, 1.939 + StringTable::VerifyMesgModes mesg_mode) { 1.940 + 1.941 + VerifyRetTypes ret = _verify_pass; // be optimistic 1.942 + 1.943 + oop str = e_ptr->literal(); 1.944 + if (str == NULL) { 1.945 + if (mesg_mode == _verify_with_mesgs) { 1.946 + tty->print_cr("ERROR: NULL oop value in entry @ bucket[%d][%d]", bkt, 1.947 + e_cnt); 1.948 + } 1.949 + // NULL oop means no more verifications are possible 1.950 + return _verify_fail_done; 1.951 + } 1.952 + 1.953 + if (str->klass() != SystemDictionary::String_klass()) { 1.954 + if (mesg_mode == _verify_with_mesgs) { 1.955 + tty->print_cr("ERROR: oop is not a String in entry @ bucket[%d][%d]", 1.956 + bkt, e_cnt); 1.957 + } 1.958 + // not a String means no more verifications are possible 1.959 + return _verify_fail_done; 1.960 + } 1.961 + 1.962 + unsigned int h = java_lang_String::hash_string(str); 1.963 + if (e_ptr->hash() != h) { 1.964 + if (mesg_mode == _verify_with_mesgs) { 1.965 + tty->print_cr("ERROR: broken hash value in entry @ bucket[%d][%d], " 1.966 + "bkt_hash=%d, str_hash=%d", bkt, e_cnt, e_ptr->hash(), h); 1.967 + } 1.968 + ret = _verify_fail_continue; 1.969 + } 1.970 + 1.971 + if (the_table()->hash_to_index(h) != bkt) { 1.972 + if (mesg_mode == _verify_with_mesgs) { 1.973 + tty->print_cr("ERROR: wrong index value for entry @ bucket[%d][%d], " 1.974 + "str_hash=%d, hash_to_index=%d", bkt, e_cnt, h, 1.975 + the_table()->hash_to_index(h)); 1.976 + } 1.977 + ret = _verify_fail_continue; 1.978 + } 1.979 + 1.980 + return ret; 1.981 +} 1.982 + 1.983 +// See StringTable::verify() above for the quick verification that is 1.984 +// part of Universe::verify(). This verification is exhaustive and 1.985 +// reports on every issue that is found. StringTable::verify() only 1.986 +// reports on the first issue that is found. 1.987 +// 1.988 +// StringTable::verify_entry() checks: 1.989 +// - oop value != NULL (same as verify()) 1.990 +// - oop value is a String 1.991 +// - hash(String) == hash in entry (same as verify()) 1.992 +// - index for hash == index of entry (same as verify()) 1.993 +// 1.994 +// StringTable::compare_entries() checks: 1.995 +// - oops are unique across all entries 1.996 +// - String values are unique across all entries 1.997 +// 1.998 +int StringTable::verify_and_compare_entries() { 1.999 + assert(StringTable_lock->is_locked(), "sanity check"); 1.1000 + 1.1001 + int fail_cnt = 0; 1.1002 + 1.1003 + // first, verify all the entries individually: 1.1004 + for (int bkt = 0; bkt < the_table()->table_size(); bkt++) { 1.1005 + HashtableEntry<oop, mtSymbol>* e_ptr = the_table()->bucket(bkt); 1.1006 + for (int e_cnt = 0; e_ptr != NULL; e_ptr = e_ptr->next(), e_cnt++) { 1.1007 + VerifyRetTypes ret = verify_entry(bkt, e_cnt, e_ptr, _verify_with_mesgs); 1.1008 + if (ret != _verify_pass) { 1.1009 + fail_cnt++; 1.1010 + } 1.1011 + } 1.1012 + } 1.1013 + 1.1014 + // Optimization: if the above check did not find any failures, then 1.1015 + // the comparison loop below does not need to call verify_entry() 1.1016 + // before calling compare_entries(). If there were failures, then we 1.1017 + // have to call verify_entry() to see if the entry can be passed to 1.1018 + // compare_entries() safely. When we call verify_entry() in the loop 1.1019 + // below, we do so quietly to void duplicate messages and we don't 1.1020 + // increment fail_cnt because the failures have already been counted. 1.1021 + bool need_entry_verify = (fail_cnt != 0); 1.1022 + 1.1023 + // second, verify all entries relative to each other: 1.1024 + for (int bkt1 = 0; bkt1 < the_table()->table_size(); bkt1++) { 1.1025 + HashtableEntry<oop, mtSymbol>* e_ptr1 = the_table()->bucket(bkt1); 1.1026 + for (int e_cnt1 = 0; e_ptr1 != NULL; e_ptr1 = e_ptr1->next(), e_cnt1++) { 1.1027 + if (need_entry_verify) { 1.1028 + VerifyRetTypes ret = verify_entry(bkt1, e_cnt1, e_ptr1, 1.1029 + _verify_quietly); 1.1030 + if (ret == _verify_fail_done) { 1.1031 + // cannot use the current entry to compare against other entries 1.1032 + continue; 1.1033 + } 1.1034 + } 1.1035 + 1.1036 + for (int bkt2 = bkt1; bkt2 < the_table()->table_size(); bkt2++) { 1.1037 + HashtableEntry<oop, mtSymbol>* e_ptr2 = the_table()->bucket(bkt2); 1.1038 + int e_cnt2; 1.1039 + for (e_cnt2 = 0; e_ptr2 != NULL; e_ptr2 = e_ptr2->next(), e_cnt2++) { 1.1040 + if (bkt1 == bkt2 && e_cnt2 <= e_cnt1) { 1.1041 + // skip the entries up to and including the one that 1.1042 + // we're comparing against 1.1043 + continue; 1.1044 + } 1.1045 + 1.1046 + if (need_entry_verify) { 1.1047 + VerifyRetTypes ret = verify_entry(bkt2, e_cnt2, e_ptr2, 1.1048 + _verify_quietly); 1.1049 + if (ret == _verify_fail_done) { 1.1050 + // cannot compare against this entry 1.1051 + continue; 1.1052 + } 1.1053 + } 1.1054 + 1.1055 + // compare two entries, report and count any failures: 1.1056 + if (compare_entries(bkt1, e_cnt1, e_ptr1, bkt2, e_cnt2, e_ptr2) 1.1057 + != _verify_pass) { 1.1058 + fail_cnt++; 1.1059 + } 1.1060 + } 1.1061 + } 1.1062 + } 1.1063 + } 1.1064 + return fail_cnt; 1.1065 +} 1.1066 + 1.1067 +// Create a new table and using alternate hash code, populate the new table 1.1068 +// with the existing strings. Set flag to use the alternate hash code afterwards. 1.1069 +void StringTable::rehash_table() { 1.1070 + assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1.1071 + // This should never happen with -Xshare:dump but it might in testing mode. 1.1072 + if (DumpSharedSpaces) return; 1.1073 + StringTable* new_table = new StringTable(); 1.1074 + 1.1075 + // Rehash the table 1.1076 + the_table()->move_to(new_table); 1.1077 + 1.1078 + // Delete the table and buckets (entries are reused in new table). 1.1079 + delete _the_table; 1.1080 + // Don't check if we need rehashing until the table gets unbalanced again. 1.1081 + // Then rehash with a new global seed. 1.1082 + _needs_rehashing = false; 1.1083 + _the_table = new_table; 1.1084 +}