2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2016-01-14 15:45:31 -05:00
|
|
|
* Copyright (c) 1997, 2016, 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"
|
2015-12-02 18:14:54 -08:00
|
|
|
#include "classfile/compactHashtable.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/javaClasses.hpp"
|
|
|
|
#include "classfile/symbolTable.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/shared/collectedHeap.inline.hpp"
|
|
|
|
#include "gc/shared/gcLocker.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"
|
2016-04-04 12:57:48 -04:00
|
|
|
#include "memory/resourceArea.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/oop.inline.hpp"
|
2014-06-04 11:56:44 +02:00
|
|
|
#include "runtime/atomic.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#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;
|
2014-12-17 23:34:52 -05:00
|
|
|
bool SymbolTable::_lookup_shared_first = false;
|
|
|
|
|
|
|
|
CompactHashtable<Symbol*, char> SymbolTable::_shared_table;
|
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
|
2015-07-15 12:24:41 -07:00
|
|
|
sym = new (len, ClassLoaderData::the_null_class_loader_data(), THREAD) Symbol(name, len, PERM_REFCOUNT);
|
2013-03-13 15:15:56 -04:00
|
|
|
} 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
|
2015-07-15 12:24:41 -07:00
|
|
|
sym = new (len, arena(), THREAD) Symbol(name, len, PERM_REFCOUNT);
|
2012-03-23 11:16:05 -04:00
|
|
|
}
|
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) {
|
2014-08-07 12:18:58 -07:00
|
|
|
_arena = new (mtSymbol) Arena(mtSymbol);
|
2012-03-23 11:16:05 -04:00
|
|
|
} else {
|
2014-08-07 12:18:58 -07:00
|
|
|
_arena = new (mtSymbol) Arena(mtSymbol, 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) {
|
2015-01-14 16:35:00 -05:00
|
|
|
// all symbols from shared table
|
|
|
|
_shared_table.symbols_do(cl);
|
|
|
|
|
|
|
|
// all symbols from the dynamic table
|
2011-01-27 16:11:27 -08:00
|
|
|
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
|
|
|
|
2015-11-19 16:14:45 +01:00
|
|
|
void SymbolTable::buckets_unlink(int start_idx, int end_idx, int* processed, int* removed) {
|
2014-01-20 11:47:07 +01:00
|
|
|
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
|
|
|
(*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;
|
2015-11-19 16:14:45 +01:00
|
|
|
buckets_unlink(0, the_table()->table_size(), processed, removed);
|
2014-01-20 11:47:07 +01:00
|
|
|
_symbols_removed += *removed;
|
|
|
|
_symbols_counted += *processed;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-11-19 16:14:45 +01:00
|
|
|
buckets_unlink(start_idx, end_idx, processed, removed);
|
2014-01-20 11:47:07 +01:00
|
|
|
}
|
|
|
|
Atomic::add(*processed, &_symbols_counted);
|
|
|
|
Atomic::add(*removed, &_symbols_removed);
|
2011-01-27 16:11:27 -08:00
|
|
|
}
|
|
|
|
|
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() {
|
2016-03-23 09:00:22 -07:00
|
|
|
if (DumpSharedSpaces) {
|
|
|
|
tty->print_cr("Warning: rehash_table should not be called while dumping archive");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-13 19:52:59 -04:00
|
|
|
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.
|
|
|
|
|
2014-12-17 23:34:52 -05:00
|
|
|
Symbol* SymbolTable::lookup_dynamic(int index, const char* 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<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.
|
2014-08-29 13:08:01 +02:00
|
|
|
if (count >= 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;
|
|
|
|
}
|
|
|
|
|
2014-12-17 23:34:52 -05:00
|
|
|
Symbol* SymbolTable::lookup_shared(const char* name,
|
|
|
|
int len, unsigned int hash) {
|
2016-03-23 09:00:22 -07:00
|
|
|
if (use_alternate_hashcode()) {
|
|
|
|
// hash_code parameter may use alternate hashing algorithm but the shared table
|
|
|
|
// always uses the same original hash code.
|
|
|
|
hash = hash_shared_symbol(name, len);
|
|
|
|
}
|
2014-12-17 23:34:52 -05:00
|
|
|
return _shared_table.lookup(name, hash, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol* SymbolTable::lookup(int index, const char* name,
|
|
|
|
int len, unsigned int hash) {
|
|
|
|
Symbol* sym;
|
|
|
|
if (_lookup_shared_first) {
|
|
|
|
sym = lookup_shared(name, len, hash);
|
|
|
|
if (sym != NULL) {
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
_lookup_shared_first = false;
|
|
|
|
return lookup_dynamic(index, name, len, hash);
|
|
|
|
} else {
|
|
|
|
sym = lookup_dynamic(index, name, len, hash);
|
|
|
|
if (sym != NULL) {
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
sym = lookup_shared(name, len, hash);
|
|
|
|
if (sym != NULL) {
|
|
|
|
_lookup_shared_first = true;
|
|
|
|
}
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 21:53:44 -07:00
|
|
|
u4 SymbolTable::encode_shared(Symbol* sym) {
|
|
|
|
assert(DumpSharedSpaces, "called only during dump time");
|
|
|
|
uintx base_address = uintx(MetaspaceShared::shared_rs()->base());
|
|
|
|
uintx offset = uintx(sym) - base_address;
|
|
|
|
assert(offset < 0x7fffffff, "sanity");
|
|
|
|
return u4(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol* SymbolTable::decode_shared(u4 offset) {
|
|
|
|
assert(!DumpSharedSpaces, "called only during runtime");
|
|
|
|
uintx base_address = _shared_table.base_address();
|
|
|
|
Symbol* sym = (Symbol*)(base_address + offset);
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
const char* s = (const char*)sym->bytes();
|
|
|
|
int len = sym->utf8_length();
|
|
|
|
unsigned int hash = hash_symbol(s, len);
|
|
|
|
assert(sym == lookup_shared(s, len, hash), "must be shared symbol");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
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) :
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
java_lang_String::hash_code((const jbyte*)s, len);
|
2012-06-13 19:52:59 -04:00
|
|
|
}
|
|
|
|
|
2016-03-23 09:00:22 -07:00
|
|
|
unsigned int SymbolTable::hash_shared_symbol(const char* s, int len) {
|
|
|
|
return java_lang_String::hash_code((const jbyte*)s, len);
|
|
|
|
}
|
|
|
|
|
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
|
2014-11-12 13:55:59 +01:00
|
|
|
return the_table()->basic_add(index, (u1*)name, len, hashValue, true, THREAD);
|
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;
|
|
|
|
{
|
2016-01-14 13:26:19 +01:00
|
|
|
debug_only(NoSafepointVerifier nsv;)
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
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.
|
2016-01-14 13:26:19 +01:00
|
|
|
// We can't include the code in NoSafepointVerifier because of the
|
2007-12-01 00:00:00 +00:00
|
|
|
// ResourceMark.
|
|
|
|
|
2012-06-25 21:33:35 -04:00
|
|
|
// Grab SymbolTable_lock first.
|
|
|
|
MutexLocker ml(SymbolTable_lock, THREAD);
|
|
|
|
|
2014-11-12 13:55:59 +01:00
|
|
|
return the_table()->basic_add(index, (u1*)buffer, len, hashValue, true, THREAD);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
void SymbolTable::add(ClassLoaderData* loader_data, const 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.
|
2016-01-14 13:26:19 +01:00
|
|
|
NoSafepointVerifier 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.
|
2015-10-23 16:48:38 -04:00
|
|
|
bool SymbolTable::basic_add(ClassLoaderData* loader_data, const 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.
|
2016-01-14 13:26:19 +01:00
|
|
|
NoSafepointVerifier 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-17 23:34:52 -05:00
|
|
|
void SymbolTable::dump(outputStream* st, bool verbose) {
|
|
|
|
if (!verbose) {
|
|
|
|
the_table()->dump_table(st, "SymbolTable");
|
|
|
|
} else {
|
|
|
|
st->print_cr("VERSION: 1.0");
|
|
|
|
for (int i = 0; i < the_table()->table_size(); ++i) {
|
|
|
|
HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i);
|
|
|
|
for ( ; p != NULL; p = p->next()) {
|
|
|
|
Symbol* s = (Symbol*)(p->literal());
|
|
|
|
const char* utf8_string = (const char*)s->bytes();
|
|
|
|
int utf8_length = s->utf8_length();
|
|
|
|
st->print("%d %d: ", utf8_length, s->refcount());
|
|
|
|
HashtableTextDump::put_utf8(st, utf8_string, utf8_length);
|
|
|
|
st->cr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 19:15:52 -07:00
|
|
|
void SymbolTable::serialize(SerializeClosure* soc) {
|
2014-12-17 23:34:52 -05:00
|
|
|
#if INCLUDE_CDS
|
2016-04-17 19:15:52 -07:00
|
|
|
_shared_table.reset();
|
|
|
|
if (soc->writing()) {
|
|
|
|
int num_buckets = the_table()->number_of_entries() /
|
|
|
|
SharedSymbolTableBucketSize;
|
|
|
|
CompactSymbolTableWriter writer(num_buckets,
|
|
|
|
&MetaspaceShared::stats()->symbol);
|
|
|
|
for (int i = 0; i < the_table()->table_size(); ++i) {
|
|
|
|
HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i);
|
|
|
|
for ( ; p != NULL; p = p->next()) {
|
|
|
|
Symbol* s = (Symbol*)(p->literal());
|
2016-03-23 09:00:22 -07:00
|
|
|
unsigned int fixed_hash = hash_shared_symbol((char*)s->bytes(), s->utf8_length());
|
2016-04-17 19:15:52 -07:00
|
|
|
assert(fixed_hash == p->hash(), "must not rehash during dumping");
|
|
|
|
writer.add(fixed_hash, s);
|
|
|
|
}
|
2014-12-17 23:34:52 -05:00
|
|
|
}
|
2016-04-17 19:15:52 -07:00
|
|
|
|
|
|
|
writer.dump(&_shared_table);
|
2014-12-17 23:34:52 -05:00
|
|
|
}
|
|
|
|
|
2016-04-17 19:15:52 -07:00
|
|
|
_shared_table.set_type(CompactHashtable<Symbol*, char>::_symbol_table);
|
|
|
|
_shared_table.serialize(soc);
|
2014-12-17 23:34:52 -05:00
|
|
|
|
2016-04-17 19:15:52 -07:00
|
|
|
if (soc->writing()) {
|
|
|
|
// Verify table is correct
|
|
|
|
Symbol* sym = vmSymbols::java_lang_Object();
|
|
|
|
const char* name = (const char*)sym->bytes();
|
|
|
|
int len = sym->utf8_length();
|
|
|
|
unsigned int hash = hash_symbol(name, len);
|
|
|
|
assert(sym == _shared_table.lookup(name, hash, len), "sanity");
|
2012-06-13 19:52:59 -04:00
|
|
|
|
2016-04-17 19:15:52 -07:00
|
|
|
// Sanity. Make sure we don't use the shared table at dump time
|
|
|
|
_shared_table.reset();
|
|
|
|
}
|
|
|
|
#endif
|
2014-12-17 23:34:52 -05: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;
|
2014-09-22 18:34:35 +04:00
|
|
|
int counts[results_length];
|
|
|
|
int sizes[results_length];
|
2007-12-01 00:00:00 +00:00
|
|
|
int i,j;
|
|
|
|
|
|
|
|
// initialize results to zero
|
|
|
|
for (j = 0; j < results_length; j++) {
|
2014-09-22 18:34:35 +04:00
|
|
|
counts[j] = 0;
|
|
|
|
sizes[j] = 0;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 18:34:35 +04:00
|
|
|
int total_size = 0;
|
|
|
|
int total_count = 0;
|
|
|
|
int total_length = 0;
|
|
|
|
int max_length = 0;
|
|
|
|
int out_of_range_count = 0;
|
|
|
|
int out_of_range_size = 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()) {
|
2014-09-22 18:34:35 +04:00
|
|
|
int size = p->literal()->size();
|
|
|
|
int len = p->literal()->utf8_length();
|
|
|
|
if (len < results_length) {
|
|
|
|
counts[len]++;
|
|
|
|
sizes[len] += size;
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
2014-09-22 18:34:35 +04:00
|
|
|
out_of_range_count++;
|
|
|
|
out_of_range_size += size;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2014-09-22 18:34:35 +04:00
|
|
|
total_count++;
|
|
|
|
total_size += size;
|
|
|
|
total_length += len;
|
|
|
|
max_length = MAX2(max_length, len);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-22 18:34:35 +04:00
|
|
|
tty->print_cr("Symbol Table Histogram:");
|
|
|
|
tty->print_cr(" Total number of symbols %7d", total_count);
|
|
|
|
tty->print_cr(" Total size in memory %7dK",
|
2016-01-30 11:02:29 -05:00
|
|
|
(total_size*wordSize)/1024);
|
2014-09-22 18:34:35 +04:00
|
|
|
tty->print_cr(" Total counted %7d", _symbols_counted);
|
|
|
|
tty->print_cr(" Total removed %7d", _symbols_removed);
|
2014-01-20 11:47:07 +01:00
|
|
|
if (_symbols_counted > 0) {
|
2014-09-22 18:34:35 +04: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
|
|
|
}
|
2014-09-22 18:34:35 +04:00
|
|
|
tty->print_cr(" Reference counts %7d", Symbol::_total_count);
|
2015-10-09 09:42:33 +02:00
|
|
|
tty->print_cr(" Symbol arena used " SIZE_FORMAT_W(7) "K", arena()->used()/1024);
|
|
|
|
tty->print_cr(" Symbol arena size " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes()/1024);
|
2014-09-22 18:34:35 +04:00
|
|
|
tty->print_cr(" Total symbol length %7d", total_length);
|
|
|
|
tty->print_cr(" Maximum symbol length %7d", max_length);
|
|
|
|
tty->print_cr(" Average symbol length %7.2f", ((float) total_length / (float) total_count));
|
|
|
|
tty->print_cr(" Symbol length histogram:");
|
|
|
|
tty->print_cr(" %6s %10s %10s", "Length", "#Symbols", "Size");
|
2007-12-01 00:00:00 +00:00
|
|
|
for (i = 0; i < results_length; i++) {
|
2014-09-22 18:34:35 +04:00
|
|
|
if (counts[i] > 0) {
|
2016-01-30 11:02:29 -05:00
|
|
|
tty->print_cr(" %6d %10d %10dK", i, counts[i], (sizes[i]*wordSize)/1024);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-22 18:34:35 +04:00
|
|
|
tty->print_cr(" >=%6d %10d %10dK\n", results_length,
|
2016-01-30 11:02:29 -05:00
|
|
|
out_of_range_count, (out_of_range_size*wordSize)/1024);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2015-10-09 09:42:33 +02:00
|
|
|
tty->print(PTR_FORMAT " ", p2i(entry->literal()));
|
2011-01-27 16:11:27 -08:00
|
|
|
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
|
2014-12-17 23:34:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
// Utility for dumping symbols
|
|
|
|
SymboltableDCmd::SymboltableDCmd(outputStream* output, bool heap) :
|
|
|
|
DCmdWithParser(output, heap),
|
|
|
|
_verbose("-verbose", "Dump the content of each symbol in the table",
|
|
|
|
"BOOLEAN", false, "false") {
|
|
|
|
_dcmdparser.add_dcmd_option(&_verbose);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SymboltableDCmd::execute(DCmdSource source, TRAPS) {
|
|
|
|
VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpSymbols,
|
|
|
|
_verbose.value());
|
|
|
|
VMThread::execute(&dumper);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SymboltableDCmd::num_arguments() {
|
|
|
|
ResourceMark rm;
|
|
|
|
SymboltableDCmd* dcmd = new SymboltableDCmd(NULL, false);
|
|
|
|
if (dcmd != NULL) {
|
|
|
|
DCmdMark mark(dcmd);
|
|
|
|
return dcmd->_dcmdparser.num_arguments();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-01-14 15:45:31 -05:00
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
// Internal test of TempNewSymbol
|
|
|
|
void Test_TempNewSymbol() {
|
|
|
|
// Assert messages assume these symbols are unique, and the refcounts start at
|
|
|
|
// one, but code does not rely on this.
|
|
|
|
Thread* THREAD = Thread::current();
|
|
|
|
Symbol* abc = SymbolTable::new_symbol("abc", CATCH);
|
|
|
|
int abccount = abc->refcount();
|
|
|
|
TempNewSymbol ss = abc;
|
|
|
|
assert(ss->refcount() == abccount, "only one abc");
|
|
|
|
assert(ss->refcount() == abc->refcount(), "should match TempNewSymbol");
|
|
|
|
|
|
|
|
Symbol* efg = SymbolTable::new_symbol("efg", CATCH);
|
|
|
|
Symbol* hij = SymbolTable::new_symbol("hij", CATCH);
|
|
|
|
int efgcount = efg->refcount();
|
|
|
|
int hijcount = hij->refcount();
|
|
|
|
|
|
|
|
TempNewSymbol s1 = efg;
|
|
|
|
TempNewSymbol s2 = hij;
|
|
|
|
assert(s1->refcount() == efgcount, "one efg");
|
|
|
|
assert(s2->refcount() == hijcount, "one hij");
|
|
|
|
|
|
|
|
// Assignment operator
|
|
|
|
s1 = s2;
|
|
|
|
assert(hij->refcount() == hijcount + 1, "should be two hij");
|
|
|
|
assert(efg->refcount() == efgcount - 1, "should be no efg");
|
|
|
|
|
|
|
|
s1 = ss; // s1 is abc
|
|
|
|
assert(s1->refcount() == abccount + 1, "should be two abc (s1 and ss)");
|
|
|
|
assert(hij->refcount() == hijcount, "should only have one hij now (s2)");
|
|
|
|
|
|
|
|
s1 = s1; // self assignment
|
|
|
|
assert(s1->refcount() == abccount + 1, "should still be two abc (s1 and ss)");
|
|
|
|
|
|
|
|
TempNewSymbol s3;
|
|
|
|
Symbol* klm = SymbolTable::new_symbol("klm", CATCH);
|
|
|
|
int klmcount = klm->refcount();
|
|
|
|
s3 = klm; // assignment
|
|
|
|
assert(s3->refcount() == klmcount, "only one klm now");
|
|
|
|
|
|
|
|
Symbol* xyz = SymbolTable::new_symbol("xyz", CATCH);
|
|
|
|
int xyzcount = xyz->refcount();
|
|
|
|
{ // inner scope
|
|
|
|
TempNewSymbol s_inner = xyz;
|
|
|
|
}
|
|
|
|
assert(xyz->refcount() == (xyzcount - 1),
|
|
|
|
"Should have been decremented by dtor in inner scope");
|
|
|
|
}
|
|
|
|
#endif // PRODUCT
|