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