aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/altHashing.hpp" aoqi@0: #include "classfile/javaClasses.hpp" aoqi@0: #include "classfile/symbolTable.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "gc_interface/collectedHeap.inline.hpp" aoqi@0: #include "memory/allocation.inline.hpp" aoqi@0: #include "memory/filemap.hpp" aoqi@0: #include "memory/gcLocker.inline.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "oops/oop.inline2.hpp" aoqi@0: #include "runtime/mutexLocker.hpp" aoqi@0: #include "utilities/hashtable.inline.hpp" aoqi@0: #if INCLUDE_ALL_GCS stefank@6992: #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" aoqi@0: #include "gc_implementation/g1/g1StringDedup.hpp" aoqi@0: #endif aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: // -------------------------------------------------------------------------- aoqi@0: aoqi@0: // the number of buckets a thread claims aoqi@0: const int ClaimChunkSize = 32; aoqi@0: aoqi@0: SymbolTable* SymbolTable::_the_table = NULL; aoqi@0: // Static arena for symbols that are not deallocated aoqi@0: Arena* SymbolTable::_arena = NULL; aoqi@0: bool SymbolTable::_needs_rehashing = false; aoqi@0: aoqi@0: Symbol* SymbolTable::allocate_symbol(const u1* name, int len, bool c_heap, TRAPS) { aoqi@0: assert (len <= Symbol::max_length(), "should be checked by caller"); aoqi@0: aoqi@0: Symbol* sym; aoqi@0: aoqi@0: if (DumpSharedSpaces) { aoqi@0: // Allocate all symbols to CLD shared metaspace aoqi@0: sym = new (len, ClassLoaderData::the_null_class_loader_data(), THREAD) Symbol(name, len, -1); aoqi@0: } else if (c_heap) { aoqi@0: // refcount starts as 1 aoqi@0: sym = new (len, THREAD) Symbol(name, len, 1); aoqi@0: assert(sym != NULL, "new should call vm_exit_out_of_memory if C_HEAP is exhausted"); aoqi@0: } else { aoqi@0: // Allocate to global arena aoqi@0: sym = new (len, arena(), THREAD) Symbol(name, len, -1); aoqi@0: } aoqi@0: return sym; aoqi@0: } aoqi@0: aoqi@0: void SymbolTable::initialize_symbols(int arena_alloc_size) { aoqi@0: // Initialize the arena for global symbols, size passed in depends on CDS. aoqi@0: if (arena_alloc_size == 0) { zgu@7074: _arena = new (mtSymbol) Arena(mtSymbol); aoqi@0: } else { zgu@7074: _arena = new (mtSymbol) Arena(mtSymbol, arena_alloc_size); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Call function for all symbols in the symbol table. aoqi@0: void SymbolTable::symbols_do(SymbolClosure *cl) { aoqi@0: const int n = the_table()->table_size(); aoqi@0: for (int i = 0; i < n; i++) { aoqi@0: for (HashtableEntry* p = the_table()->bucket(i); aoqi@0: p != NULL; aoqi@0: p = p->next()) { aoqi@0: cl->do_symbol(p->literal_addr()); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: int SymbolTable::_symbols_removed = 0; aoqi@0: int SymbolTable::_symbols_counted = 0; aoqi@0: volatile int SymbolTable::_parallel_claimed_idx = 0; aoqi@0: aoqi@0: void SymbolTable::buckets_unlink(int start_idx, int end_idx, int* processed, int* removed, size_t* memory_total) { aoqi@0: for (int i = start_idx; i < end_idx; ++i) { aoqi@0: HashtableEntry** p = the_table()->bucket_addr(i); aoqi@0: HashtableEntry* entry = the_table()->bucket(i); aoqi@0: while (entry != NULL) { aoqi@0: // Shared entries are normally at the end of the bucket and if we run into aoqi@0: // a shared entry, then there is nothing more to remove. However, if we aoqi@0: // have rehashed the table, then the shared entries are no longer at the aoqi@0: // end of the bucket. aoqi@0: if (entry->is_shared() && !use_alternate_hashcode()) { aoqi@0: break; aoqi@0: } aoqi@0: Symbol* s = entry->literal(); aoqi@0: (*memory_total) += s->size(); aoqi@0: (*processed)++; aoqi@0: assert(s != NULL, "just checking"); aoqi@0: // If reference count is zero, remove. aoqi@0: if (s->refcount() == 0) { aoqi@0: assert(!entry->is_shared(), "shared entries should be kept live"); aoqi@0: delete s; aoqi@0: (*removed)++; aoqi@0: *p = entry->next(); aoqi@0: the_table()->free_entry(entry); aoqi@0: } else { aoqi@0: p = entry->next_addr(); aoqi@0: } aoqi@0: // get next entry aoqi@0: entry = (HashtableEntry*)HashtableEntry::make_ptr(*p); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Remove unreferenced symbols from the symbol table aoqi@0: // This is done late during GC. aoqi@0: void SymbolTable::unlink(int* processed, int* removed) { aoqi@0: size_t memory_total = 0; aoqi@0: buckets_unlink(0, the_table()->table_size(), processed, removed, &memory_total); aoqi@0: _symbols_removed += *removed; aoqi@0: _symbols_counted += *processed; aoqi@0: // Exclude printing for normal PrintGCDetails because people parse aoqi@0: // this output. aoqi@0: if (PrintGCDetails && Verbose && WizardMode) { aoqi@0: gclog_or_tty->print(" [Symbols=%d size=" SIZE_FORMAT "K] ", *processed, aoqi@0: (memory_total*HeapWordSize)/1024); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void SymbolTable::possibly_parallel_unlink(int* processed, int* removed) { aoqi@0: const int limit = the_table()->table_size(); aoqi@0: aoqi@0: size_t memory_total = 0; aoqi@0: aoqi@0: for (;;) { aoqi@0: // Grab next set of buckets to scan aoqi@0: int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; aoqi@0: if (start_idx >= limit) { aoqi@0: // End of table aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: int end_idx = MIN2(limit, start_idx + ClaimChunkSize); aoqi@0: buckets_unlink(start_idx, end_idx, processed, removed, &memory_total); aoqi@0: } aoqi@0: Atomic::add(*processed, &_symbols_counted); aoqi@0: Atomic::add(*removed, &_symbols_removed); aoqi@0: // Exclude printing for normal PrintGCDetails because people parse aoqi@0: // this output. aoqi@0: if (PrintGCDetails && Verbose && WizardMode) { aoqi@0: gclog_or_tty->print(" [Symbols: scanned=%d removed=%d size=" SIZE_FORMAT "K] ", *processed, *removed, aoqi@0: (memory_total*HeapWordSize)/1024); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Create a new table and using alternate hash code, populate the new table aoqi@0: // with the existing strings. Set flag to use the alternate hash code afterwards. aoqi@0: void SymbolTable::rehash_table() { aoqi@0: assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); aoqi@0: // This should never happen with -Xshare:dump but it might in testing mode. aoqi@0: if (DumpSharedSpaces) return; aoqi@0: // Create a new symbol table aoqi@0: SymbolTable* new_table = new SymbolTable(); aoqi@0: aoqi@0: the_table()->move_to(new_table); aoqi@0: aoqi@0: // Delete the table and buckets (entries are reused in new table). aoqi@0: delete _the_table; aoqi@0: // Don't check if we need rehashing until the table gets unbalanced again. aoqi@0: // Then rehash with a new global seed. aoqi@0: _needs_rehashing = false; aoqi@0: _the_table = new_table; aoqi@0: } aoqi@0: aoqi@0: // Lookup a symbol in a bucket. aoqi@0: aoqi@0: Symbol* SymbolTable::lookup(int index, const char* name, aoqi@0: int len, unsigned int hash) { aoqi@0: int count = 0; aoqi@0: for (HashtableEntry* e = bucket(index); e != NULL; e = e->next()) { aoqi@0: count++; // count all entries in this bucket, not just ones with same hash aoqi@0: if (e->hash() == hash) { aoqi@0: Symbol* sym = e->literal(); aoqi@0: if (sym->equals(name, len)) { aoqi@0: // something is referencing this symbol now. aoqi@0: sym->increment_refcount(); aoqi@0: return sym; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: // If the bucket size is too deep check if this hash code is insufficient. mgerdin@7207: if (count >= rehash_count && !needs_rehashing()) { aoqi@0: _needs_rehashing = check_rehash_table(count); aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: // Pick hashing algorithm. aoqi@0: unsigned int SymbolTable::hash_symbol(const char* s, int len) { aoqi@0: return use_alternate_hashcode() ? aoqi@0: AltHashing::murmur3_32(seed(), (const jbyte*)s, len) : aoqi@0: java_lang_String::hash_code(s, len); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // We take care not to be blocking while holding the aoqi@0: // SymbolTable_lock. Otherwise, the system might deadlock, since the aoqi@0: // symboltable is used during compilation (VM_thread) The lock free aoqi@0: // synchronization is simplified by the fact that we do not delete aoqi@0: // entries in the symbol table during normal execution (only during aoqi@0: // safepoints). aoqi@0: aoqi@0: Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) { aoqi@0: unsigned int hashValue = hash_symbol(name, len); aoqi@0: int index = the_table()->hash_to_index(hashValue); aoqi@0: aoqi@0: Symbol* s = the_table()->lookup(index, name, len, hashValue); aoqi@0: aoqi@0: // Found aoqi@0: if (s != NULL) return s; aoqi@0: aoqi@0: // Grab SymbolTable_lock first. aoqi@0: MutexLocker ml(SymbolTable_lock, THREAD); aoqi@0: aoqi@0: // Otherwise, add to symbol to table aoqi@0: return the_table()->basic_add(index, (u1*)name, len, hashValue, true, CHECK_NULL); aoqi@0: } aoqi@0: aoqi@0: Symbol* SymbolTable::lookup(const Symbol* sym, int begin, int end, TRAPS) { aoqi@0: char* buffer; aoqi@0: int index, len; aoqi@0: unsigned int hashValue; aoqi@0: char* name; aoqi@0: { aoqi@0: debug_only(No_Safepoint_Verifier nsv;) aoqi@0: aoqi@0: name = (char*)sym->base() + begin; aoqi@0: len = end - begin; aoqi@0: hashValue = hash_symbol(name, len); aoqi@0: index = the_table()->hash_to_index(hashValue); aoqi@0: Symbol* s = the_table()->lookup(index, name, len, hashValue); aoqi@0: aoqi@0: // Found aoqi@0: if (s != NULL) return s; aoqi@0: } aoqi@0: aoqi@0: // Otherwise, add to symbol to table. Copy to a C string first. aoqi@0: char stack_buf[128]; aoqi@0: ResourceMark rm(THREAD); aoqi@0: if (len <= 128) { aoqi@0: buffer = stack_buf; aoqi@0: } else { aoqi@0: buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len); aoqi@0: } aoqi@0: for (int i=0; ibasic_add(index, (u1*)buffer, len, hashValue, true, CHECK_NULL); aoqi@0: } aoqi@0: aoqi@0: Symbol* SymbolTable::lookup_only(const char* name, int len, aoqi@0: unsigned int& hash) { aoqi@0: hash = hash_symbol(name, len); aoqi@0: int index = the_table()->hash_to_index(hash); aoqi@0: aoqi@0: Symbol* s = the_table()->lookup(index, name, len, hash); aoqi@0: return s; aoqi@0: } aoqi@0: aoqi@0: // Look up the address of the literal in the SymbolTable for this Symbol* aoqi@0: // Do not create any new symbols aoqi@0: // Do not increment the reference count to keep this alive aoqi@0: Symbol** SymbolTable::lookup_symbol_addr(Symbol* sym){ aoqi@0: unsigned int hash = hash_symbol((char*)sym->bytes(), sym->utf8_length()); aoqi@0: int index = the_table()->hash_to_index(hash); aoqi@0: aoqi@0: for (HashtableEntry* e = the_table()->bucket(index); e != NULL; e = e->next()) { aoqi@0: if (e->hash() == hash) { aoqi@0: Symbol* literal_sym = e->literal(); aoqi@0: if (sym == literal_sym) { aoqi@0: return e->literal_addr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: // Suggestion: Push unicode-based lookup all the way into the hashing aoqi@0: // and probing logic, so there is no need for convert_to_utf8 until aoqi@0: // an actual new Symbol* is created. aoqi@0: Symbol* SymbolTable::lookup_unicode(const jchar* name, int utf16_length, TRAPS) { aoqi@0: int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); aoqi@0: char stack_buf[128]; aoqi@0: if (utf8_length < (int) sizeof(stack_buf)) { aoqi@0: char* chars = stack_buf; aoqi@0: UNICODE::convert_to_utf8(name, utf16_length, chars); aoqi@0: return lookup(chars, utf8_length, THREAD); aoqi@0: } else { aoqi@0: ResourceMark rm(THREAD); aoqi@0: char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; aoqi@0: UNICODE::convert_to_utf8(name, utf16_length, chars); aoqi@0: return lookup(chars, utf8_length, THREAD); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: Symbol* SymbolTable::lookup_only_unicode(const jchar* name, int utf16_length, aoqi@0: unsigned int& hash) { aoqi@0: int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); aoqi@0: char stack_buf[128]; aoqi@0: if (utf8_length < (int) sizeof(stack_buf)) { aoqi@0: char* chars = stack_buf; aoqi@0: UNICODE::convert_to_utf8(name, utf16_length, chars); aoqi@0: return lookup_only(chars, utf8_length, hash); aoqi@0: } else { aoqi@0: ResourceMark rm; aoqi@0: char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; aoqi@0: UNICODE::convert_to_utf8(name, utf16_length, chars); aoqi@0: return lookup_only(chars, utf8_length, hash); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void SymbolTable::add(ClassLoaderData* loader_data, constantPoolHandle cp, aoqi@0: int names_count, aoqi@0: const char** names, int* lengths, int* cp_indices, aoqi@0: unsigned int* hashValues, TRAPS) { aoqi@0: // Grab SymbolTable_lock first. aoqi@0: MutexLocker ml(SymbolTable_lock, THREAD); aoqi@0: aoqi@0: SymbolTable* table = the_table(); aoqi@0: bool added = table->basic_add(loader_data, cp, names_count, names, lengths, aoqi@0: cp_indices, hashValues, CHECK); aoqi@0: if (!added) { aoqi@0: // do it the hard way aoqi@0: for (int i=0; ihash_to_index(hashValues[i]); aoqi@0: bool c_heap = !loader_data->is_the_null_class_loader_data(); aoqi@0: Symbol* sym = table->basic_add(index, (u1*)names[i], lengths[i], hashValues[i], c_heap, CHECK); aoqi@0: cp->symbol_at_put(cp_indices[i], sym); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) { aoqi@0: unsigned int hash; aoqi@0: Symbol* result = SymbolTable::lookup_only((char*)name, (int)strlen(name), hash); aoqi@0: if (result != NULL) { aoqi@0: return result; aoqi@0: } aoqi@0: // Grab SymbolTable_lock first. aoqi@0: MutexLocker ml(SymbolTable_lock, THREAD); aoqi@0: aoqi@0: SymbolTable* table = the_table(); aoqi@0: int index = table->hash_to_index(hash); aoqi@0: return table->basic_add(index, (u1*)name, (int)strlen(name), hash, false, THREAD); aoqi@0: } aoqi@0: aoqi@0: Symbol* SymbolTable::basic_add(int index_arg, u1 *name, int len, aoqi@0: unsigned int hashValue_arg, bool c_heap, TRAPS) { aoqi@0: assert(!Universe::heap()->is_in_reserved(name), aoqi@0: "proposed name of symbol must be stable"); aoqi@0: aoqi@0: // Don't allow symbols to be created which cannot fit in a Symbol*. aoqi@0: if (len > Symbol::max_length()) { aoqi@0: THROW_MSG_0(vmSymbols::java_lang_InternalError(), aoqi@0: "name is too long to represent"); aoqi@0: } aoqi@0: aoqi@0: // Cannot hit a safepoint in this function because the "this" pointer can move. aoqi@0: No_Safepoint_Verifier nsv; aoqi@0: aoqi@0: // Check if the symbol table has been rehashed, if so, need to recalculate aoqi@0: // the hash value and index. aoqi@0: unsigned int hashValue; aoqi@0: int index; aoqi@0: if (use_alternate_hashcode()) { aoqi@0: hashValue = hash_symbol((const char*)name, len); aoqi@0: index = hash_to_index(hashValue); aoqi@0: } else { aoqi@0: hashValue = hashValue_arg; aoqi@0: index = index_arg; aoqi@0: } aoqi@0: aoqi@0: // Since look-up was done lock-free, we need to check if another aoqi@0: // thread beat us in the race to insert the symbol. aoqi@0: Symbol* test = lookup(index, (char*)name, len, hashValue); aoqi@0: if (test != NULL) { aoqi@0: // A race occurred and another thread introduced the symbol. aoqi@0: assert(test->refcount() != 0, "lookup should have incremented the count"); aoqi@0: return test; aoqi@0: } aoqi@0: aoqi@0: // Create a new symbol. aoqi@0: Symbol* sym = allocate_symbol(name, len, c_heap, CHECK_NULL); aoqi@0: assert(sym->equals((char*)name, len), "symbol must be properly initialized"); aoqi@0: aoqi@0: HashtableEntry* entry = new_entry(hashValue, sym); aoqi@0: add_entry(index, entry); aoqi@0: return sym; aoqi@0: } aoqi@0: aoqi@0: // This version of basic_add adds symbols in batch from the constant pool aoqi@0: // parsing. aoqi@0: bool SymbolTable::basic_add(ClassLoaderData* loader_data, constantPoolHandle cp, aoqi@0: int names_count, aoqi@0: const char** names, int* lengths, aoqi@0: int* cp_indices, unsigned int* hashValues, aoqi@0: TRAPS) { aoqi@0: aoqi@0: // Check symbol names are not too long. If any are too long, don't add any. aoqi@0: for (int i = 0; i< names_count; i++) { aoqi@0: if (lengths[i] > Symbol::max_length()) { aoqi@0: THROW_MSG_0(vmSymbols::java_lang_InternalError(), aoqi@0: "name is too long to represent"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Cannot hit a safepoint in this function because the "this" pointer can move. aoqi@0: No_Safepoint_Verifier nsv; aoqi@0: aoqi@0: for (int i=0; isymbol_at_put(cp_indices[i], test); aoqi@0: assert(test->refcount() != 0, "lookup should have incremented the count"); aoqi@0: } else { aoqi@0: // Create a new symbol. The null class loader is never unloaded so these aoqi@0: // are allocated specially in a permanent arena. aoqi@0: bool c_heap = !loader_data->is_the_null_class_loader_data(); aoqi@0: Symbol* sym = allocate_symbol((const u1*)names[i], lengths[i], c_heap, CHECK_(false)); aoqi@0: assert(sym->equals(names[i], lengths[i]), "symbol must be properly initialized"); // why wouldn't it be??? aoqi@0: HashtableEntry* entry = new_entry(hashValue, sym); aoqi@0: add_entry(index, entry); aoqi@0: cp->symbol_at_put(cp_indices[i], sym); aoqi@0: } aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void SymbolTable::verify() { aoqi@0: for (int i = 0; i < the_table()->table_size(); ++i) { aoqi@0: HashtableEntry* p = the_table()->bucket(i); aoqi@0: for ( ; p != NULL; p = p->next()) { aoqi@0: Symbol* s = (Symbol*)(p->literal()); aoqi@0: guarantee(s != NULL, "symbol is NULL"); aoqi@0: unsigned int h = hash_symbol((char*)s->bytes(), s->utf8_length()); aoqi@0: guarantee(p->hash() == h, "broken hash in symbol table entry"); aoqi@0: guarantee(the_table()->hash_to_index(h) == i, aoqi@0: "wrong index in symbol table"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void SymbolTable::dump(outputStream* st) { aoqi@0: the_table()->dump_table(st, "SymbolTable"); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: //--------------------------------------------------------------------------- aoqi@0: // Non-product code aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: void SymbolTable::print_histogram() { aoqi@0: MutexLocker ml(SymbolTable_lock); aoqi@0: const int results_length = 100; aoqi@0: int results[results_length]; aoqi@0: int i,j; aoqi@0: aoqi@0: // initialize results to zero aoqi@0: for (j = 0; j < results_length; j++) { aoqi@0: results[j] = 0; aoqi@0: } aoqi@0: aoqi@0: int total = 0; aoqi@0: int max_symbols = 0; aoqi@0: int out_of_range = 0; aoqi@0: int memory_total = 0; aoqi@0: int count = 0; aoqi@0: for (i = 0; i < the_table()->table_size(); i++) { aoqi@0: HashtableEntry* p = the_table()->bucket(i); aoqi@0: for ( ; p != NULL; p = p->next()) { aoqi@0: memory_total += p->literal()->size(); aoqi@0: count++; aoqi@0: int counter = p->literal()->utf8_length(); aoqi@0: total += counter; aoqi@0: if (counter < results_length) { aoqi@0: results[counter]++; aoqi@0: } else { aoqi@0: out_of_range++; aoqi@0: } aoqi@0: max_symbols = MAX2(max_symbols, counter); aoqi@0: } aoqi@0: } aoqi@0: tty->print_cr("Symbol Table:"); aoqi@0: tty->print_cr("Total number of symbols %5d", count); aoqi@0: tty->print_cr("Total size in memory %5dK", aoqi@0: (memory_total*HeapWordSize)/1024); aoqi@0: tty->print_cr("Total counted %5d", _symbols_counted); aoqi@0: tty->print_cr("Total removed %5d", _symbols_removed); aoqi@0: if (_symbols_counted > 0) { aoqi@0: tty->print_cr("Percent removed %3.2f", aoqi@0: ((float)_symbols_removed/(float)_symbols_counted)* 100); aoqi@0: } aoqi@0: tty->print_cr("Reference counts %5d", Symbol::_total_count); aoqi@0: tty->print_cr("Symbol arena size %5d used %5d", aoqi@0: arena()->size_in_bytes(), arena()->used()); aoqi@0: tty->print_cr("Histogram of symbol length:"); aoqi@0: tty->print_cr("%8s %5d", "Total ", total); aoqi@0: tty->print_cr("%8s %5d", "Maximum", max_symbols); aoqi@0: tty->print_cr("%8s %3.2f", "Average", aoqi@0: ((float) total / (float) the_table()->table_size())); aoqi@0: tty->print_cr("%s", "Histogram:"); aoqi@0: tty->print_cr(" %s %29s", "Length", "Number chains that length"); aoqi@0: for (i = 0; i < results_length; i++) { aoqi@0: if (results[i] > 0) { aoqi@0: tty->print_cr("%6d %10d", i, results[i]); aoqi@0: } aoqi@0: } aoqi@0: if (Verbose) { aoqi@0: int line_length = 70; aoqi@0: tty->print_cr("%s %30s", " Length", "Number chains that length"); aoqi@0: for (i = 0; i < results_length; i++) { aoqi@0: if (results[i] > 0) { aoqi@0: tty->print("%4d", i); aoqi@0: for (j = 0; (j < results[i]) && (j < line_length); j++) { aoqi@0: tty->print("%1s", "*"); aoqi@0: } aoqi@0: if (j == line_length) { aoqi@0: tty->print("%1s", "+"); aoqi@0: } aoqi@0: tty->cr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: tty->print_cr(" %s %d: %d\n", "Number chains longer than", aoqi@0: results_length, out_of_range); aoqi@0: } aoqi@0: aoqi@0: void SymbolTable::print() { aoqi@0: for (int i = 0; i < the_table()->table_size(); ++i) { aoqi@0: HashtableEntry** p = the_table()->bucket_addr(i); aoqi@0: HashtableEntry* entry = the_table()->bucket(i); aoqi@0: if (entry != NULL) { aoqi@0: while (entry != NULL) { aoqi@0: tty->print(PTR_FORMAT " ", entry->literal()); aoqi@0: entry->literal()->print(); aoqi@0: tty->print(" %d", entry->literal()->refcount()); aoqi@0: p = entry->next_addr(); aoqi@0: entry = (HashtableEntry*)HashtableEntry::make_ptr(*p); aoqi@0: } aoqi@0: tty->cr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: #endif // PRODUCT aoqi@0: aoqi@0: // -------------------------------------------------------------------------- aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: class StableMemoryChecker : public StackObj { aoqi@0: enum { _bufsize = wordSize*4 }; aoqi@0: aoqi@0: address _region; aoqi@0: jint _size; aoqi@0: u1 _save_buf[_bufsize]; aoqi@0: aoqi@0: int sample(u1* save_buf) { aoqi@0: if (_size <= _bufsize) { aoqi@0: memcpy(save_buf, _region, _size); aoqi@0: return _size; aoqi@0: } else { aoqi@0: // copy head and tail aoqi@0: memcpy(&save_buf[0], _region, _bufsize/2); aoqi@0: memcpy(&save_buf[_bufsize/2], _region + _size - _bufsize/2, _bufsize/2); aoqi@0: return (_bufsize/2)*2; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: StableMemoryChecker(const void* region, jint size) { aoqi@0: _region = (address) region; aoqi@0: _size = size; aoqi@0: sample(_save_buf); aoqi@0: } aoqi@0: aoqi@0: bool verify() { aoqi@0: u1 check_buf[sizeof(_save_buf)]; aoqi@0: int check_size = sample(check_buf); aoqi@0: return (0 == memcmp(_save_buf, check_buf, check_size)); aoqi@0: } aoqi@0: aoqi@0: void set_region(const void* region) { _region = (address) region; } aoqi@0: }; aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: // -------------------------------------------------------------------------- aoqi@0: StringTable* StringTable::_the_table = NULL; aoqi@0: aoqi@0: bool StringTable::_needs_rehashing = false; aoqi@0: aoqi@0: volatile int StringTable::_parallel_claimed_idx = 0; aoqi@0: aoqi@0: // Pick hashing algorithm aoqi@0: unsigned int StringTable::hash_string(const jchar* s, int len) { aoqi@0: return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) : aoqi@0: java_lang_String::hash_code(s, len); aoqi@0: } aoqi@0: aoqi@0: oop StringTable::lookup(int index, jchar* name, aoqi@0: int len, unsigned int hash) { aoqi@0: int count = 0; aoqi@0: for (HashtableEntry* l = bucket(index); l != NULL; l = l->next()) { aoqi@0: count++; aoqi@0: if (l->hash() == hash) { aoqi@0: if (java_lang_String::equals(l->literal(), name, len)) { aoqi@0: return l->literal(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: // If the bucket size is too deep check if this hash code is insufficient. mgerdin@7207: if (count >= rehash_count && !needs_rehashing()) { aoqi@0: _needs_rehashing = check_rehash_table(count); aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: oop StringTable::basic_add(int index_arg, Handle string, jchar* name, aoqi@0: int len, unsigned int hashValue_arg, TRAPS) { aoqi@0: aoqi@0: assert(java_lang_String::equals(string(), name, len), aoqi@0: "string must be properly initialized"); aoqi@0: // Cannot hit a safepoint in this function because the "this" pointer can move. aoqi@0: No_Safepoint_Verifier nsv; aoqi@0: aoqi@0: // Check if the symbol table has been rehashed, if so, need to recalculate aoqi@0: // the hash value and index before second lookup. aoqi@0: unsigned int hashValue; aoqi@0: int index; aoqi@0: if (use_alternate_hashcode()) { aoqi@0: hashValue = hash_string(name, len); aoqi@0: index = hash_to_index(hashValue); aoqi@0: } else { aoqi@0: hashValue = hashValue_arg; aoqi@0: index = index_arg; aoqi@0: } aoqi@0: aoqi@0: // Since look-up was done lock-free, we need to check if another aoqi@0: // thread beat us in the race to insert the symbol. aoqi@0: aoqi@0: oop test = lookup(index, name, len, hashValue); // calls lookup(u1*, int) aoqi@0: if (test != NULL) { aoqi@0: // Entry already added aoqi@0: return test; aoqi@0: } aoqi@0: aoqi@0: HashtableEntry* entry = new_entry(hashValue, string()); aoqi@0: add_entry(index, entry); aoqi@0: return string(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: oop StringTable::lookup(Symbol* symbol) { aoqi@0: ResourceMark rm; aoqi@0: int length; aoqi@0: jchar* chars = symbol->as_unicode(length); aoqi@0: return lookup(chars, length); aoqi@0: } aoqi@0: stefank@6992: // Tell the GC that this string was looked up in the StringTable. stefank@6992: static void ensure_string_alive(oop string) { stefank@6992: // A lookup in the StringTable could return an object that was previously stefank@6992: // considered dead. The SATB part of G1 needs to get notified about this stefank@6992: // potential resurrection, otherwise the marking might not find the object. stefank@6992: #if INCLUDE_ALL_GCS stefank@6992: if (UseG1GC && string != NULL) { stefank@6992: G1SATBCardTableModRefBS::enqueue(string); stefank@6992: } stefank@6992: #endif stefank@6992: } aoqi@0: aoqi@0: oop StringTable::lookup(jchar* name, int len) { aoqi@0: unsigned int hash = hash_string(name, len); aoqi@0: int index = the_table()->hash_to_index(hash); stefank@6992: oop string = the_table()->lookup(index, name, len, hash); stefank@6992: stefank@6992: ensure_string_alive(string); stefank@6992: stefank@6992: return string; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: oop StringTable::intern(Handle string_or_null, jchar* name, aoqi@0: int len, TRAPS) { aoqi@0: unsigned int hashValue = hash_string(name, len); aoqi@0: int index = the_table()->hash_to_index(hashValue); aoqi@0: oop found_string = the_table()->lookup(index, name, len, hashValue); aoqi@0: aoqi@0: // Found stefank@6992: if (found_string != NULL) { stefank@6992: ensure_string_alive(found_string); stefank@6992: return found_string; stefank@6992: } aoqi@0: aoqi@0: debug_only(StableMemoryChecker smc(name, len * sizeof(name[0]))); aoqi@0: assert(!Universe::heap()->is_in_reserved(name), aoqi@0: "proposed name of symbol must be stable"); aoqi@0: aoqi@0: Handle string; aoqi@0: // try to reuse the string if possible aoqi@0: if (!string_or_null.is_null()) { aoqi@0: string = string_or_null; aoqi@0: } else { aoqi@0: string = java_lang_String::create_from_unicode(name, len, CHECK_NULL); aoqi@0: } aoqi@0: aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: if (G1StringDedup::is_enabled()) { aoqi@0: // Deduplicate the string before it is interned. Note that we should never aoqi@0: // deduplicate a string after it has been interned. Doing so will counteract aoqi@0: // compiler optimizations done on e.g. interned string literals. aoqi@0: G1StringDedup::deduplicate(string()); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Grab the StringTable_lock before getting the_table() because it could aoqi@0: // change at safepoint. stefank@6992: oop added_or_found; stefank@6992: { stefank@6992: MutexLocker ml(StringTable_lock, THREAD); stefank@6992: // Otherwise, add to symbol to table stefank@6992: added_or_found = the_table()->basic_add(index, string, name, len, stefank@6992: hashValue, CHECK_NULL); stefank@6992: } aoqi@0: stefank@6992: ensure_string_alive(added_or_found); stefank@6992: stefank@6992: return added_or_found; aoqi@0: } aoqi@0: aoqi@0: oop StringTable::intern(Symbol* symbol, TRAPS) { aoqi@0: if (symbol == NULL) return NULL; aoqi@0: ResourceMark rm(THREAD); aoqi@0: int length; aoqi@0: jchar* chars = symbol->as_unicode(length); aoqi@0: Handle string; aoqi@0: oop result = intern(string, chars, length, CHECK_NULL); aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: oop StringTable::intern(oop string, TRAPS) aoqi@0: { aoqi@0: if (string == NULL) return NULL; aoqi@0: ResourceMark rm(THREAD); aoqi@0: int length; aoqi@0: Handle h_string (THREAD, string); aoqi@0: jchar* chars = java_lang_String::as_unicode_string(string, length, CHECK_NULL); aoqi@0: oop result = intern(h_string, chars, length, CHECK_NULL); aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: oop StringTable::intern(const char* utf8_string, TRAPS) { aoqi@0: if (utf8_string == NULL) return NULL; aoqi@0: ResourceMark rm(THREAD); aoqi@0: int length = UTF8::unicode_length(utf8_string); aoqi@0: jchar* chars = NEW_RESOURCE_ARRAY(jchar, length); aoqi@0: UTF8::convert_to_unicode(utf8_string, chars, length); aoqi@0: Handle string; aoqi@0: oop result = intern(string, chars, length, CHECK_NULL); aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: void StringTable::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) { aoqi@0: buckets_unlink_or_oops_do(is_alive, f, 0, the_table()->table_size(), processed, removed); aoqi@0: } aoqi@0: aoqi@0: void StringTable::possibly_parallel_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) { aoqi@0: // Readers of the table are unlocked, so we should only be removing aoqi@0: // entries at a safepoint. aoqi@0: assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); aoqi@0: const int limit = the_table()->table_size(); aoqi@0: aoqi@0: for (;;) { aoqi@0: // Grab next set of buckets to scan aoqi@0: int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; aoqi@0: if (start_idx >= limit) { aoqi@0: // End of table aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: int end_idx = MIN2(limit, start_idx + ClaimChunkSize); aoqi@0: buckets_unlink_or_oops_do(is_alive, f, start_idx, end_idx, processed, removed); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void StringTable::buckets_oops_do(OopClosure* f, int start_idx, int end_idx) { aoqi@0: const int limit = the_table()->table_size(); aoqi@0: aoqi@0: assert(0 <= start_idx && start_idx <= limit, aoqi@0: err_msg("start_idx (" INT32_FORMAT ") is out of bounds", start_idx)); aoqi@0: assert(0 <= end_idx && end_idx <= limit, aoqi@0: err_msg("end_idx (" INT32_FORMAT ") is out of bounds", end_idx)); aoqi@0: assert(start_idx <= end_idx, aoqi@0: err_msg("Index ordering: start_idx=" INT32_FORMAT", end_idx=" INT32_FORMAT, aoqi@0: start_idx, end_idx)); aoqi@0: aoqi@0: for (int i = start_idx; i < end_idx; i += 1) { aoqi@0: HashtableEntry* entry = the_table()->bucket(i); aoqi@0: while (entry != NULL) { aoqi@0: assert(!entry->is_shared(), "CDS not used for the StringTable"); aoqi@0: aoqi@0: f->do_oop((oop*)entry->literal_addr()); aoqi@0: aoqi@0: entry = entry->next(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void StringTable::buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed) { aoqi@0: const int limit = the_table()->table_size(); aoqi@0: aoqi@0: assert(0 <= start_idx && start_idx <= limit, aoqi@0: err_msg("start_idx (" INT32_FORMAT ") is out of bounds", start_idx)); aoqi@0: assert(0 <= end_idx && end_idx <= limit, aoqi@0: err_msg("end_idx (" INT32_FORMAT ") is out of bounds", end_idx)); aoqi@0: assert(start_idx <= end_idx, aoqi@0: err_msg("Index ordering: start_idx=" INT32_FORMAT", end_idx=" INT32_FORMAT, aoqi@0: start_idx, end_idx)); aoqi@0: aoqi@0: for (int i = start_idx; i < end_idx; ++i) { aoqi@0: HashtableEntry** p = the_table()->bucket_addr(i); aoqi@0: HashtableEntry* entry = the_table()->bucket(i); aoqi@0: while (entry != NULL) { aoqi@0: assert(!entry->is_shared(), "CDS not used for the StringTable"); aoqi@0: aoqi@0: if (is_alive->do_object_b(entry->literal())) { aoqi@0: if (f != NULL) { aoqi@0: f->do_oop((oop*)entry->literal_addr()); aoqi@0: } aoqi@0: p = entry->next_addr(); aoqi@0: } else { aoqi@0: *p = entry->next(); aoqi@0: the_table()->free_entry(entry); aoqi@0: (*removed)++; aoqi@0: } aoqi@0: (*processed)++; aoqi@0: entry = *p; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void StringTable::oops_do(OopClosure* f) { aoqi@0: buckets_oops_do(f, 0, the_table()->table_size()); aoqi@0: } aoqi@0: aoqi@0: void StringTable::possibly_parallel_oops_do(OopClosure* f) { aoqi@0: const int limit = the_table()->table_size(); aoqi@0: aoqi@0: for (;;) { aoqi@0: // Grab next set of buckets to scan aoqi@0: int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; aoqi@0: if (start_idx >= limit) { aoqi@0: // End of table aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: int end_idx = MIN2(limit, start_idx + ClaimChunkSize); aoqi@0: buckets_oops_do(f, start_idx, end_idx); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // This verification is part of Universe::verify() and needs to be quick. aoqi@0: // See StringTable::verify_and_compare() below for exhaustive verification. aoqi@0: void StringTable::verify() { aoqi@0: for (int i = 0; i < the_table()->table_size(); ++i) { aoqi@0: HashtableEntry* p = the_table()->bucket(i); aoqi@0: for ( ; p != NULL; p = p->next()) { aoqi@0: oop s = p->literal(); aoqi@0: guarantee(s != NULL, "interned string is NULL"); aoqi@0: unsigned int h = java_lang_String::hash_string(s); aoqi@0: guarantee(p->hash() == h, "broken hash in string table entry"); aoqi@0: guarantee(the_table()->hash_to_index(h) == i, aoqi@0: "wrong index in string table"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void StringTable::dump(outputStream* st) { aoqi@0: the_table()->dump_table(st, "StringTable"); aoqi@0: } aoqi@0: aoqi@0: StringTable::VerifyRetTypes StringTable::compare_entries( aoqi@0: int bkt1, int e_cnt1, aoqi@0: HashtableEntry* e_ptr1, aoqi@0: int bkt2, int e_cnt2, aoqi@0: HashtableEntry* e_ptr2) { aoqi@0: // These entries are sanity checked by verify_and_compare_entries() aoqi@0: // before this function is called. aoqi@0: oop str1 = e_ptr1->literal(); aoqi@0: oop str2 = e_ptr2->literal(); aoqi@0: aoqi@0: if (str1 == str2) { aoqi@0: tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") " aoqi@0: "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]", aoqi@0: (void *)str1, bkt1, e_cnt1, bkt2, e_cnt2); aoqi@0: return _verify_fail_continue; aoqi@0: } aoqi@0: aoqi@0: if (java_lang_String::equals(str1, str2)) { aoqi@0: tty->print_cr("ERROR: identical String values in entry @ " aoqi@0: "bucket[%d][%d] and entry @ bucket[%d][%d]", aoqi@0: bkt1, e_cnt1, bkt2, e_cnt2); aoqi@0: return _verify_fail_continue; aoqi@0: } aoqi@0: aoqi@0: return _verify_pass; aoqi@0: } aoqi@0: aoqi@0: StringTable::VerifyRetTypes StringTable::verify_entry(int bkt, int e_cnt, aoqi@0: HashtableEntry* e_ptr, aoqi@0: StringTable::VerifyMesgModes mesg_mode) { aoqi@0: aoqi@0: VerifyRetTypes ret = _verify_pass; // be optimistic aoqi@0: aoqi@0: oop str = e_ptr->literal(); aoqi@0: if (str == NULL) { aoqi@0: if (mesg_mode == _verify_with_mesgs) { aoqi@0: tty->print_cr("ERROR: NULL oop value in entry @ bucket[%d][%d]", bkt, aoqi@0: e_cnt); aoqi@0: } aoqi@0: // NULL oop means no more verifications are possible aoqi@0: return _verify_fail_done; aoqi@0: } aoqi@0: aoqi@0: if (str->klass() != SystemDictionary::String_klass()) { aoqi@0: if (mesg_mode == _verify_with_mesgs) { aoqi@0: tty->print_cr("ERROR: oop is not a String in entry @ bucket[%d][%d]", aoqi@0: bkt, e_cnt); aoqi@0: } aoqi@0: // not a String means no more verifications are possible aoqi@0: return _verify_fail_done; aoqi@0: } aoqi@0: aoqi@0: unsigned int h = java_lang_String::hash_string(str); aoqi@0: if (e_ptr->hash() != h) { aoqi@0: if (mesg_mode == _verify_with_mesgs) { aoqi@0: tty->print_cr("ERROR: broken hash value in entry @ bucket[%d][%d], " aoqi@0: "bkt_hash=%d, str_hash=%d", bkt, e_cnt, e_ptr->hash(), h); aoqi@0: } aoqi@0: ret = _verify_fail_continue; aoqi@0: } aoqi@0: aoqi@0: if (the_table()->hash_to_index(h) != bkt) { aoqi@0: if (mesg_mode == _verify_with_mesgs) { aoqi@0: tty->print_cr("ERROR: wrong index value for entry @ bucket[%d][%d], " aoqi@0: "str_hash=%d, hash_to_index=%d", bkt, e_cnt, h, aoqi@0: the_table()->hash_to_index(h)); aoqi@0: } aoqi@0: ret = _verify_fail_continue; aoqi@0: } aoqi@0: aoqi@0: return ret; aoqi@0: } aoqi@0: aoqi@0: // See StringTable::verify() above for the quick verification that is aoqi@0: // part of Universe::verify(). This verification is exhaustive and aoqi@0: // reports on every issue that is found. StringTable::verify() only aoqi@0: // reports on the first issue that is found. aoqi@0: // aoqi@0: // StringTable::verify_entry() checks: aoqi@0: // - oop value != NULL (same as verify()) aoqi@0: // - oop value is a String aoqi@0: // - hash(String) == hash in entry (same as verify()) aoqi@0: // - index for hash == index of entry (same as verify()) aoqi@0: // aoqi@0: // StringTable::compare_entries() checks: aoqi@0: // - oops are unique across all entries aoqi@0: // - String values are unique across all entries aoqi@0: // aoqi@0: int StringTable::verify_and_compare_entries() { aoqi@0: assert(StringTable_lock->is_locked(), "sanity check"); aoqi@0: aoqi@0: int fail_cnt = 0; aoqi@0: aoqi@0: // first, verify all the entries individually: aoqi@0: for (int bkt = 0; bkt < the_table()->table_size(); bkt++) { aoqi@0: HashtableEntry* e_ptr = the_table()->bucket(bkt); aoqi@0: for (int e_cnt = 0; e_ptr != NULL; e_ptr = e_ptr->next(), e_cnt++) { aoqi@0: VerifyRetTypes ret = verify_entry(bkt, e_cnt, e_ptr, _verify_with_mesgs); aoqi@0: if (ret != _verify_pass) { aoqi@0: fail_cnt++; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Optimization: if the above check did not find any failures, then aoqi@0: // the comparison loop below does not need to call verify_entry() aoqi@0: // before calling compare_entries(). If there were failures, then we aoqi@0: // have to call verify_entry() to see if the entry can be passed to aoqi@0: // compare_entries() safely. When we call verify_entry() in the loop aoqi@0: // below, we do so quietly to void duplicate messages and we don't aoqi@0: // increment fail_cnt because the failures have already been counted. aoqi@0: bool need_entry_verify = (fail_cnt != 0); aoqi@0: aoqi@0: // second, verify all entries relative to each other: aoqi@0: for (int bkt1 = 0; bkt1 < the_table()->table_size(); bkt1++) { aoqi@0: HashtableEntry* e_ptr1 = the_table()->bucket(bkt1); aoqi@0: for (int e_cnt1 = 0; e_ptr1 != NULL; e_ptr1 = e_ptr1->next(), e_cnt1++) { aoqi@0: if (need_entry_verify) { aoqi@0: VerifyRetTypes ret = verify_entry(bkt1, e_cnt1, e_ptr1, aoqi@0: _verify_quietly); aoqi@0: if (ret == _verify_fail_done) { aoqi@0: // cannot use the current entry to compare against other entries aoqi@0: continue; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: for (int bkt2 = bkt1; bkt2 < the_table()->table_size(); bkt2++) { aoqi@0: HashtableEntry* e_ptr2 = the_table()->bucket(bkt2); aoqi@0: int e_cnt2; aoqi@0: for (e_cnt2 = 0; e_ptr2 != NULL; e_ptr2 = e_ptr2->next(), e_cnt2++) { aoqi@0: if (bkt1 == bkt2 && e_cnt2 <= e_cnt1) { aoqi@0: // skip the entries up to and including the one that aoqi@0: // we're comparing against aoqi@0: continue; aoqi@0: } aoqi@0: aoqi@0: if (need_entry_verify) { aoqi@0: VerifyRetTypes ret = verify_entry(bkt2, e_cnt2, e_ptr2, aoqi@0: _verify_quietly); aoqi@0: if (ret == _verify_fail_done) { aoqi@0: // cannot compare against this entry aoqi@0: continue; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // compare two entries, report and count any failures: aoqi@0: if (compare_entries(bkt1, e_cnt1, e_ptr1, bkt2, e_cnt2, e_ptr2) aoqi@0: != _verify_pass) { aoqi@0: fail_cnt++; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return fail_cnt; aoqi@0: } aoqi@0: aoqi@0: // Create a new table and using alternate hash code, populate the new table aoqi@0: // with the existing strings. Set flag to use the alternate hash code afterwards. aoqi@0: void StringTable::rehash_table() { aoqi@0: assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); aoqi@0: // This should never happen with -Xshare:dump but it might in testing mode. aoqi@0: if (DumpSharedSpaces) return; aoqi@0: StringTable* new_table = new StringTable(); aoqi@0: aoqi@0: // Rehash the table aoqi@0: the_table()->move_to(new_table); aoqi@0: aoqi@0: // Delete the table and buckets (entries are reused in new table). aoqi@0: delete _the_table; aoqi@0: // Don't check if we need rehashing until the table gets unbalanced again. aoqi@0: // Then rehash with a new global seed. aoqi@0: _needs_rehashing = false; aoqi@0: _the_table = new_table; aoqi@0: }