25
#include "precompiled.hpp"
26
#include "cds/archiveBuilder.hpp"
27
#include "cds/cdsConfig.hpp"
28
#include "cds/dynamicArchive.hpp"
29
#include "classfile/altHashing.hpp"
30
#include "classfile/classLoaderData.hpp"
31
#include "classfile/compactHashtable.hpp"
32
#include "classfile/javaClasses.hpp"
33
#include "classfile/symbolTable.hpp"
34
#include "memory/allocation.inline.hpp"
35
#include "memory/metaspaceClosure.hpp"
36
#include "memory/resourceArea.hpp"
37
#include "oops/oop.inline.hpp"
38
#include "runtime/atomic.hpp"
39
#include "runtime/interfaceSupport.inline.hpp"
40
#include "runtime/timerTrace.hpp"
41
#include "runtime/trimNativeHeap.hpp"
42
#include "services/diagnosticCommand.hpp"
43
#include "utilities/concurrentHashTable.inline.hpp"
44
#include "utilities/concurrentHashTableTasks.inline.hpp"
45
#include "utilities/utf8.hpp"
50
const double PREF_AVG_LIST_LEN = 8.0;
52
const size_t END_SIZE = 24;
54
const size_t REHASH_LEN = 100;
56
const size_t ON_STACK_BUFFER_LENGTH = 128;
60
inline bool symbol_equals_compact_hashtable_entry(Symbol* value, const char* key, int len) {
61
if (value->equals(key, len)) {
68
static OffsetCompactHashtable<
70
symbol_equals_compact_hashtable_entry
73
static OffsetCompactHashtable<
75
symbol_equals_compact_hashtable_entry
76
> _dynamic_shared_table;
80
typedef ConcurrentHashTable<SymbolTableConfig, mtSymbol> SymbolTableHash;
81
static SymbolTableHash* _local_table = nullptr;
83
volatile bool SymbolTable::_has_work = 0;
84
volatile bool SymbolTable::_needs_rehashing = false;
87
static size_t _symbols_removed = 0;
88
static size_t _symbols_counted = 0;
89
static size_t _current_size = 0;
91
static volatile size_t _items_count = 0;
92
static volatile bool _has_items_to_clean = false;
95
static volatile bool _alt_hash = false;
97
#ifdef USE_LIBRARY_BASED_TLS_ONLY
98
static volatile bool _lookup_shared_first = false;
102
static THREAD_LOCAL bool _lookup_shared_first = false;
106
Arena* SymbolTable::_arena = nullptr;
108
static bool _rehashed = false;
109
static uint64_t _alt_hash_seed = 0;
111
static inline void log_trace_symboltable_helper(Symbol* sym, const char* msg) {
114
log_trace(symboltable)("%s [%s]", msg, sym->as_quoted_ascii());
119
static unsigned int hash_symbol(const char* s, int len, bool useAlt) {
121
AltHashing::halfsiphash_32(_alt_hash_seed, (const uint8_t*)s, len) :
122
java_lang_String::hash_code((const jbyte*)s, len);
126
static unsigned int hash_shared_symbol(const char* s, int len) {
127
return java_lang_String::hash_code((const jbyte*)s, len);
131
class SymbolTableConfig : public AllStatic {
134
typedef Symbol Value;
136
static uintx get_hash(Value const& value, bool* is_dead) {
137
*is_dead = (value.refcount() == 0);
141
return hash_symbol((const char*)value.bytes(), value.utf8_length(), _alt_hash);
145
static void* allocate_node(void* context, size_t size, Value const& value) {
146
SymbolTable::item_added();
147
return allocate_node_impl(size, value);
149
static void free_node(void* context, void* memory, Value & value) {
155
assert(value.is_permanent() || (value.refcount() == 1) || (value.refcount() == 0),
156
"refcount %d", value.refcount());
158
if (CDSConfig::is_dumping_static_archive()) {
164
if (value.refcount() == 1) {
165
value.decrement_refcount();
166
assert(value.refcount() == 0, "expected dead symbol");
168
if (value.refcount() != PERM_REFCOUNT) {
171
MutexLocker ml(SymbolArena_lock, Mutex::_no_safepoint_check_flag);
174
log_trace_symboltable_helper(&value, "Freeing permanent symbol");
175
size_t alloc_size = SymbolTableHash::get_dynamic_node_size(value.byte_size());
176
if (!SymbolTable::arena()->Afree(memory, alloc_size)) {
177
log_trace_symboltable_helper(&value, "Leaked permanent symbol");
180
SymbolTable::item_removed();
184
static void* allocate_node_impl(size_t size, Value const& value) {
185
size_t alloc_size = SymbolTableHash::get_dynamic_node_size(value.byte_size());
187
if (CDSConfig::is_dumping_static_archive()) {
188
MutexLocker ml(DumpRegion_lock, Mutex::_no_safepoint_check_flag);
196
DEBUG_ONLY(static void* last = nullptr);
197
void* p = (void*)MetaspaceShared::symbol_space_alloc(alloc_size);
198
assert(p > last, "must increase monotonically");
199
DEBUG_ONLY(last = p);
203
if (value.refcount() != PERM_REFCOUNT) {
204
return AllocateHeap(alloc_size, mtSymbol);
207
MutexLocker ml(SymbolArena_lock, Mutex::_no_safepoint_check_flag);
208
return SymbolTable::arena()->Amalloc(alloc_size);
213
void SymbolTable::create_table () {
214
size_t start_size_log_2 = ceil_log2(SymbolTableSize);
215
_current_size = ((size_t)1) << start_size_log_2;
216
log_trace(symboltable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
217
_current_size, start_size_log_2);
218
_local_table = new SymbolTableHash(start_size_log_2, END_SIZE, REHASH_LEN, true);
221
if (symbol_alloc_arena_size == 0) {
222
_arena = new (mtSymbol) Arena(mtSymbol);
224
_arena = new (mtSymbol) Arena(mtSymbol, Arena::Tag::tag_other, symbol_alloc_arena_size);
228
void SymbolTable::reset_has_items_to_clean() { Atomic::store(&_has_items_to_clean, false); }
229
void SymbolTable::mark_has_items_to_clean() { Atomic::store(&_has_items_to_clean, true); }
230
bool SymbolTable::has_items_to_clean() { return Atomic::load(&_has_items_to_clean); }
232
void SymbolTable::item_added() {
233
Atomic::inc(&_items_count);
236
void SymbolTable::item_removed() {
237
Atomic::inc(&(_symbols_removed));
238
Atomic::dec(&_items_count);
241
double SymbolTable::get_load_factor() {
242
return (double)_items_count/(double)_current_size;
245
size_t SymbolTable::table_size() {
246
return ((size_t)1) << _local_table->get_size_log2(Thread::current());
249
bool SymbolTable::has_work() { return Atomic::load_acquire(&_has_work); }
251
void SymbolTable::trigger_cleanup() {
254
MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
256
Service_lock->notify_all();
260
class SymbolsDo : StackObj {
263
SymbolsDo(SymbolClosure *cl) : _cl(cl) {}
264
bool operator()(Symbol* value) {
265
assert(value != nullptr, "expected valid value");
266
_cl->do_symbol(&value);
271
class SharedSymbolIterator {
272
SymbolClosure* _symbol_closure;
274
SharedSymbolIterator(SymbolClosure* f) : _symbol_closure(f) {}
275
void do_value(Symbol* symbol) {
276
_symbol_closure->do_symbol(&symbol);
281
void SymbolTable::symbols_do(SymbolClosure *cl) {
282
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint");
284
SharedSymbolIterator iter(cl);
285
_shared_table.iterate(&iter);
286
_dynamic_shared_table.iterate(&iter);
290
_local_table->do_safepoint_scan(sd);
294
void SymbolTable::shared_symbols_do(SymbolClosure *cl) {
295
SharedSymbolIterator iter(cl);
296
_shared_table.iterate(&iter);
297
_dynamic_shared_table.iterate(&iter);
300
Symbol* SymbolTable::lookup_dynamic(const char* name,
301
int len, unsigned int hash) {
302
Symbol* sym = do_lookup(name, len, hash);
303
assert((sym == nullptr) || sym->refcount() != 0, "refcount must not be zero");
308
Symbol* SymbolTable::lookup_shared(const char* name,
309
int len, unsigned int hash) {
310
Symbol* sym = nullptr;
311
if (!_shared_table.empty()) {
315
hash = hash_shared_symbol(name, len);
317
sym = _shared_table.lookup(name, hash, len);
318
if (sym == nullptr && DynamicArchive::is_mapped()) {
319
sym = _dynamic_shared_table.lookup(name, hash, len);
326
Symbol* SymbolTable::lookup_common(const char* name,
327
int len, unsigned int hash) {
329
if (_lookup_shared_first) {
330
sym = lookup_shared(name, len, hash);
331
if (sym == nullptr) {
332
_lookup_shared_first = false;
333
sym = lookup_dynamic(name, len, hash);
336
sym = lookup_dynamic(name, len, hash);
337
if (sym == nullptr) {
338
sym = lookup_shared(name, len, hash);
339
if (sym != nullptr) {
340
_lookup_shared_first = true;
351
static int check_length(const char* name, int len) {
352
assert(len <= Symbol::max_length(),
353
"String length %d exceeds the maximum Symbol length of %d", len, Symbol::max_length());
354
if (len > Symbol::max_length()) {
355
warning("A string \"%.80s ... %.80s\" exceeds the maximum Symbol "
356
"length of %d and has been truncated", name, (name + len - 80), Symbol::max_length());
357
len = Symbol::max_length();
362
Symbol* SymbolTable::new_symbol(const char* name, int len) {
363
len = check_length(name, len);
364
unsigned int hash = hash_symbol(name, len, _alt_hash);
365
Symbol* sym = lookup_common(name, len, hash);
366
if (sym == nullptr) {
367
sym = do_add_if_needed(name, len, hash, false);
369
assert(sym->refcount() != 0, "lookup should have incremented the count");
370
assert(sym->equals(name, len), "symbol must be properly initialized");
374
Symbol* SymbolTable::new_symbol(const Symbol* sym, int begin, int end) {
375
assert(begin <= end && end <= sym->utf8_length(), "just checking");
376
assert(sym->refcount() != 0, "require a valid symbol");
377
const char* name = (const char*)sym->base() + begin;
378
int len = end - begin;
379
assert(len <= Symbol::max_length(), "sanity");
380
unsigned int hash = hash_symbol(name, len, _alt_hash);
381
Symbol* found = lookup_common(name, len, hash);
382
if (found == nullptr) {
383
found = do_add_if_needed(name, len, hash, false);
388
class SymbolTableLookup : StackObj {
394
SymbolTableLookup(const char* key, int len, uintx hash)
395
: _hash(hash), _len(len), _str(key) {}
396
uintx get_hash() const {
403
bool equals(Symbol* value) {
404
assert(value != nullptr, "expected valid value");
406
if (sym->equals(_str, _len)) {
407
if (sym->try_increment_refcount()) {
411
assert(sym->refcount() == 0, "expected dead symbol");
418
bool is_dead(Symbol* value) {
419
return value->refcount() == 0;
423
class SymbolTableGet : public StackObj {
426
SymbolTableGet() : _return(nullptr) {}
427
void operator()(Symbol* value) {
428
assert(value != nullptr, "expected valid value");
431
Symbol* get_res_sym() const {
436
void SymbolTable::update_needs_rehash(bool rehash) {
438
_needs_rehashing = true;
443
Symbol* SymbolTable::do_lookup(const char* name, int len, uintx hash) {
444
Thread* thread = Thread::current();
445
SymbolTableLookup lookup(name, len, hash);
447
bool rehash_warning = false;
448
_local_table->get(thread, lookup, stg, &rehash_warning);
449
update_needs_rehash(rehash_warning);
450
Symbol* sym = stg.get_res_sym();
451
assert((sym == nullptr) || sym->refcount() != 0, "found dead symbol");
455
Symbol* SymbolTable::lookup_only(const char* name, int len, unsigned int& hash) {
456
hash = hash_symbol(name, len, _alt_hash);
457
return lookup_common(name, len, hash);
463
Symbol* SymbolTable::new_symbol(const jchar* name, int utf16_length) {
464
int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length);
465
char stack_buf[ON_STACK_BUFFER_LENGTH];
466
if (utf8_length < (int) sizeof(stack_buf)) {
467
char* chars = stack_buf;
468
UNICODE::convert_to_utf8(name, utf16_length, chars);
469
return new_symbol(chars, utf8_length);
472
char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);
473
UNICODE::convert_to_utf8(name, utf16_length, chars);
474
return new_symbol(chars, utf8_length);
478
Symbol* SymbolTable::lookup_only_unicode(const jchar* name, int utf16_length,
479
unsigned int& hash) {
480
int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length);
481
char stack_buf[ON_STACK_BUFFER_LENGTH];
482
if (utf8_length < (int) sizeof(stack_buf)) {
483
char* chars = stack_buf;
484
UNICODE::convert_to_utf8(name, utf16_length, chars);
485
return lookup_only(chars, utf8_length, hash);
488
char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);
489
UNICODE::convert_to_utf8(name, utf16_length, chars);
490
return lookup_only(chars, utf8_length, hash);
494
void SymbolTable::new_symbols(ClassLoaderData* loader_data, const constantPoolHandle& cp,
495
int names_count, const char** names, int* lengths,
496
int* cp_indices, unsigned int* hashValues) {
499
bool is_permanent = loader_data->is_the_null_class_loader_data();
500
for (int i = 0; i < names_count; i++) {
501
const char *name = names[i];
502
int len = lengths[i];
503
assert(len <= Symbol::max_length(), "must be - these come from the constant pool");
504
unsigned int hash = hashValues[i];
505
assert(lookup_shared(name, len, hash) == nullptr, "must have checked already");
506
Symbol* sym = do_add_if_needed(name, len, hash, is_permanent);
507
assert(sym->refcount() != 0, "lookup should have incremented the count");
508
cp->symbol_at_put(cp_indices[i], sym);
512
Symbol* SymbolTable::do_add_if_needed(const char* name, int len, uintx hash, bool is_permanent) {
513
assert(len <= Symbol::max_length(), "caller should have ensured this");
514
SymbolTableLookup lookup(name, len, hash);
516
bool clean_hint = false;
517
bool rehash_warning = false;
518
Thread* current = Thread::current();
521
ResourceMark rm(current);
522
const int alloc_size = Symbol::byte_size(len);
523
u1* u1_buf = NEW_RESOURCE_ARRAY_IN_THREAD(current, u1, alloc_size);
524
Symbol* tmp = ::new ((void*)u1_buf) Symbol((const u1*)name, len,
525
(is_permanent || CDSConfig::is_dumping_static_archive()) ? PERM_REFCOUNT : 1);
528
if (_local_table->insert(current, lookup, *tmp, &rehash_warning, &clean_hint)) {
529
if (_local_table->get(current, lookup, stg, &rehash_warning)) {
530
sym = stg.get_res_sym();
533
if (sym->refcount() != PERM_REFCOUNT) {
534
sym->decrement_refcount();
542
if (_local_table->get(current, lookup, stg, &rehash_warning)) {
544
sym = stg.get_res_sym();
549
update_needs_rehash(rehash_warning);
552
mark_has_items_to_clean();
553
check_concurrent_work();
556
assert((sym == nullptr) || sym->refcount() != 0, "found dead symbol");
560
Symbol* SymbolTable::new_permanent_symbol(const char* name) {
561
unsigned int hash = 0;
562
int len = check_length(name, (int)strlen(name));
563
Symbol* sym = SymbolTable::lookup_only(name, len, hash);
564
if (sym == nullptr) {
565
sym = do_add_if_needed(name, len, hash, true);
567
if (!sym->is_permanent()) {
568
sym->make_permanent();
569
log_trace_symboltable_helper(sym, "Asked for a permanent symbol, but got a regular one");
574
struct SizeFunc : StackObj {
575
size_t operator()(Symbol* value) {
576
assert(value != nullptr, "expected valid value");
577
return (value)->size() * HeapWordSize;
581
TableStatistics SymbolTable::get_table_statistics() {
582
static TableStatistics ts;
584
ts = _local_table->statistics_get(Thread::current(), sz, ts);
588
void SymbolTable::print_table_statistics(outputStream* st) {
590
_local_table->statistics_to(Thread::current(), sz, st, "SymbolTable");
592
if (!_shared_table.empty()) {
593
_shared_table.print_table_statistics(st, "Shared Symbol Table");
596
if (!_dynamic_shared_table.empty()) {
597
_dynamic_shared_table.print_table_statistics(st, "Dynamic Shared Symbol Table");
602
class VerifySymbols : StackObj {
604
bool operator()(Symbol* value) {
605
guarantee(value != nullptr, "expected valid value");
607
guarantee(sym->equals((const char*)sym->bytes(), sym->utf8_length()),
608
"symbol must be internally consistent");
613
void SymbolTable::verify() {
614
Thread* thr = Thread::current();
616
if (!_local_table->try_scan(thr, vs)) {
617
log_info(symboltable)("verify unavailable at this moment");
621
static void print_symbol(outputStream* st, Symbol* sym) {
622
const char* utf8_string = (const char*)sym->bytes();
623
int utf8_length = sym->utf8_length();
624
st->print("%d %d: ", utf8_length, sym->refcount());
625
HashtableTextDump::put_utf8(st, utf8_string, utf8_length);
630
class DumpSymbol : StackObj {
634
DumpSymbol(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
635
bool operator()(Symbol* value) {
636
assert(value != nullptr, "expected valid value");
637
print_symbol(_st, value);
642
class DumpSharedSymbol : StackObj {
645
DumpSharedSymbol(outputStream* st) : _st(st) {}
646
void do_value(Symbol* value) {
647
assert(value != nullptr, "value should point to a symbol");
648
print_symbol(_st, value);
652
void SymbolTable::dump(outputStream* st, bool verbose) {
654
print_table_statistics(st);
656
Thread* thr = Thread::current();
657
ResourceMark rm(thr);
658
st->print_cr("VERSION: 1.1");
659
DumpSymbol ds(thr, st);
660
if (!_local_table->try_scan(thr, ds)) {
661
log_info(symboltable)("dump unavailable at this moment");
663
if (!_shared_table.empty()) {
664
st->print_cr("#----------------");
665
st->print_cr("# Shared symbols:");
666
st->print_cr("#----------------");
667
DumpSharedSymbol dss(st);
668
_shared_table.iterate(&dss);
670
if (!_dynamic_shared_table.empty()) {
671
st->print_cr("#------------------------");
672
st->print_cr("# Dynamic shared symbols:");
673
st->print_cr("#------------------------");
674
DumpSharedSymbol dss(st);
675
_dynamic_shared_table.iterate(&dss);
681
void SymbolTable::copy_shared_symbol_table(GrowableArray<Symbol*>* symbols,
682
CompactHashtableWriter* writer) {
683
ArchiveBuilder* builder = ArchiveBuilder::current();
684
int len = symbols->length();
685
for (int i = 0; i < len; i++) {
686
Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
687
unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
688
assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
689
"must not rehash during dumping");
690
sym->set_permanent();
691
writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
695
size_t SymbolTable::estimate_size_for_archive() {
696
if (_items_count > (size_t)max_jint) {
697
fatal("Too many symbols to be archived: %zu", _items_count);
699
return CompactHashtableWriter::estimate_size(int(_items_count));
702
void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
703
CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
704
copy_shared_symbol_table(symbols, &writer);
705
if (CDSConfig::is_dumping_static_archive()) {
706
_shared_table.reset();
707
writer.dump(&_shared_table, "symbol");
709
assert(CDSConfig::is_dumping_dynamic_archive(), "must be");
710
_dynamic_shared_table.reset();
711
writer.dump(&_dynamic_shared_table, "symbol");
715
void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
716
bool is_static_archive) {
717
OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
718
if (is_static_archive) {
719
table = &_shared_table;
721
table = &_dynamic_shared_table;
723
table->serialize_header(soc);
724
if (soc->writing()) {
732
void SymbolTable::grow(JavaThread* jt) {
733
SymbolTableHash::GrowTask gt(_local_table);
734
if (!gt.prepare(jt)) {
737
log_trace(symboltable)("Started to grow");
739
TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
740
while (gt.do_task(jt)) {
743
ThreadBlockInVM tbivm(jt);
749
_current_size = table_size();
750
log_debug(symboltable)("Grown to size:" SIZE_FORMAT, _current_size);
753
struct SymbolTableDoDelete : StackObj {
755
SymbolTableDoDelete() : _deleted(0) {}
756
void operator()(Symbol* value) {
757
assert(value != nullptr, "expected valid value");
759
assert(sym->refcount() == 0, "refcount");
764
struct SymbolTableDeleteCheck : StackObj {
766
SymbolTableDeleteCheck() : _processed(0) {}
767
bool operator()(Symbol* value) {
768
assert(value != nullptr, "expected valid value");
771
return (sym->refcount() == 0);
775
void SymbolTable::clean_dead_entries(JavaThread* jt) {
776
SymbolTableHash::BulkDeleteTask bdt(_local_table);
777
if (!bdt.prepare(jt)) {
781
SymbolTableDeleteCheck stdc;
782
SymbolTableDoDelete stdd;
783
NativeHeapTrimmer::SuspendMark sm("symboltable");
785
TraceTime timer("Clean", TRACETIME_LOG(Debug, symboltable, perf));
786
while (bdt.do_task(jt, stdc, stdd)) {
789
ThreadBlockInVM tbivm(jt);
793
reset_has_items_to_clean();
797
Atomic::add(&_symbols_counted, stdc._processed);
799
log_debug(symboltable)("Cleaned " SIZE_FORMAT " of " SIZE_FORMAT,
800
stdd._deleted, stdc._processed);
803
void SymbolTable::check_concurrent_work() {
810
if (has_items_to_clean() || (get_load_factor() > PREF_AVG_LIST_LEN)) {
811
log_debug(symboltable)("Concurrent work triggered, load factor: %f, items to clean: %s",
812
get_load_factor(), has_items_to_clean() ? "true" : "false");
817
bool SymbolTable::should_grow() {
818
return get_load_factor() > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached();
821
void SymbolTable::do_concurrent_work(JavaThread* jt) {
824
if (needs_rehashing() && maybe_rehash_table()) {
825
Atomic::release_store(&_has_work, false);
828
log_debug(symboltable, perf)("Concurrent work, live factor: %g", get_load_factor());
833
clean_dead_entries(jt);
835
Atomic::release_store(&_has_work, false);
839
void SymbolTable::rehash_table() {
840
assert(SafepointSynchronize::is_at_safepoint(), "must be called at safepoint");
842
assert (_local_table->is_safepoint_safe(), "Should not be resizing now");
844
_alt_hash_seed = AltHashing::compute_seed();
847
size_t new_size = _local_table->get_size_log2(Thread::current());
848
SymbolTableHash* new_table = new SymbolTableHash(new_size, END_SIZE, REHASH_LEN, true);
851
_local_table->rehash_nodes_to(Thread::current(), new_table);
855
_local_table = new_table;
858
_needs_rehashing = false;
861
bool SymbolTable::maybe_rehash_table() {
862
log_debug(symboltable)("Table imbalanced, rehashing called.");
866
log_debug(symboltable)("Choosing growing over rehashing.");
867
_needs_rehashing = false;
873
log_warning(symboltable)("Rehashing already done, still long lists.");
874
_needs_rehashing = false;
878
VM_RehashSymbolTable op;
879
VMThread::execute(&op);
888
class HistogramIterator : StackObj {
890
static const size_t results_length = 100;
891
size_t counts[results_length];
892
size_t sizes[results_length];
897
size_t out_of_range_count;
898
size_t out_of_range_size;
899
HistogramIterator() : total_size(0), total_count(0), total_length(0),
900
max_length(0), out_of_range_count(0), out_of_range_size(0) {
902
for (size_t i = 0; i < results_length; i++) {
907
bool operator()(Symbol* value) {
908
assert(value != nullptr, "expected valid value");
910
size_t size = sym->size();
911
size_t len = sym->utf8_length();
912
if (len < results_length) {
916
out_of_range_count++;
917
out_of_range_size += size;
922
max_length = MAX2(max_length, len);
928
void SymbolTable::print_histogram() {
929
HistogramIterator hi;
930
_local_table->do_scan(Thread::current(), hi);
931
tty->print_cr("Symbol Table Histogram:");
932
tty->print_cr(" Total number of symbols " SIZE_FORMAT_W(7), hi.total_count);
933
tty->print_cr(" Total size in memory " SIZE_FORMAT_W(7) "K", (hi.total_size * wordSize) / K);
934
tty->print_cr(" Total counted " SIZE_FORMAT_W(7), _symbols_counted);
935
tty->print_cr(" Total removed " SIZE_FORMAT_W(7), _symbols_removed);
936
if (_symbols_counted > 0) {
937
tty->print_cr(" Percent removed %3.2f",
938
((double)_symbols_removed / (double)_symbols_counted) * 100);
940
tty->print_cr(" Reference counts " SIZE_FORMAT_W(7), Symbol::_total_count);
941
tty->print_cr(" Symbol arena used " SIZE_FORMAT_W(7) "K", arena()->used() / K);
942
tty->print_cr(" Symbol arena size " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes() / K);
943
tty->print_cr(" Total symbol length " SIZE_FORMAT_W(7), hi.total_length);
944
tty->print_cr(" Maximum symbol length " SIZE_FORMAT_W(7), hi.max_length);
945
tty->print_cr(" Average symbol length %7.2f", ((double)hi.total_length / (double)hi.total_count));
946
tty->print_cr(" Symbol length histogram:");
947
tty->print_cr(" %6s %10s %10s", "Length", "#Symbols", "Size");
948
for (size_t i = 0; i < hi.results_length; i++) {
949
if (hi.counts[i] > 0) {
950
tty->print_cr(" " SIZE_FORMAT_W(6) " " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) "K",
951
i, hi.counts[i], (hi.sizes[i] * wordSize) / K);
954
tty->print_cr(" >=" SIZE_FORMAT_W(6) " " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) "K\n",
955
hi.results_length, hi.out_of_range_count, (hi.out_of_range_size*wordSize) / K);
960
SymboltableDCmd::SymboltableDCmd(outputStream* output, bool heap) :
961
DCmdWithParser(output, heap),
962
_verbose("-verbose", "Dump the content of each symbol in the table",
963
"BOOLEAN", false, "false") {
964
_dcmdparser.add_dcmd_option(&_verbose);
967
void SymboltableDCmd::execute(DCmdSource source, TRAPS) {
968
VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpSymbols,
970
VMThread::execute(&dumper);