1 /* 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/altHashing.hpp" 27 #include "classfile/compactHashtable.hpp" 28 #include "classfile/javaClasses.hpp" 29 #include "classfile/symbolTable.hpp" 30 #include "classfile/systemDictionary.hpp" 31 #include "gc_interface/collectedHeap.inline.hpp" 32 #include "memory/allocation.inline.hpp" 33 #include "memory/filemap.hpp" 34 #include "memory/gcLocker.inline.hpp" 35 #include "oops/oop.inline.hpp" 36 #include "oops/oop.inline2.hpp" 37 #include "runtime/atomic.inline.hpp" 38 #include "runtime/mutexLocker.hpp" 39 #include "utilities/hashtable.inline.hpp" 40 41 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 42 43 // -------------------------------------------------------------------------- 44 // the number of buckets a thread claims 45 const int ClaimChunkSize = 32; 46 47 SymbolTable* SymbolTable::_the_table = NULL; 48 // Static arena for symbols that are not deallocated 49 Arena* SymbolTable::_arena = NULL; 50 bool SymbolTable::_needs_rehashing = false; 51 bool SymbolTable::_lookup_shared_first = false; 52 53 CompactHashtable<Symbol*, char> SymbolTable::_shared_table; 54 55 Symbol* SymbolTable::allocate_symbol(const u1* name, int len, bool c_heap, TRAPS) { 56 assert (len <= Symbol::max_length(), "should be checked by caller"); 57 58 Symbol* sym; 59 60 if (DumpSharedSpaces) { 61 // Allocate all symbols to CLD shared metaspace 62 sym = new (len, ClassLoaderData::the_null_class_loader_data(), THREAD) Symbol(name, len, -1); 63 } else if (c_heap) { 64 // refcount starts as 1 65 sym = new (len, THREAD) Symbol(name, len, 1); 66 assert(sym != NULL, "new should call vm_exit_out_of_memory if C_HEAP is exhausted"); 67 } else { 68 // Allocate to global arena 69 sym = new (len, arena(), THREAD) Symbol(name, len, -1); 70 } 71 return sym; 72 } 73 74 void SymbolTable::initialize_symbols(int arena_alloc_size) { 75 // Initialize the arena for global symbols, size passed in depends on CDS. 76 if (arena_alloc_size == 0) { 77 _arena = new (mtSymbol) Arena(mtSymbol); 78 } else { 79 _arena = new (mtSymbol) Arena(mtSymbol, arena_alloc_size); 80 } 81 } 82 83 // Call function for all symbols in the symbol table. 84 void SymbolTable::symbols_do(SymbolClosure *cl) { 85 const int n = the_table()->table_size(); 86 for (int i = 0; i < n; i++) { 87 for (HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 88 p != NULL; 89 p = p->next()) { 90 cl->do_symbol(p->literal_addr()); 91 } 92 } 93 } 94 95 int SymbolTable::_symbols_removed = 0; 96 int SymbolTable::_symbols_counted = 0; 97 volatile int SymbolTable::_parallel_claimed_idx = 0; 98 99 void SymbolTable::buckets_unlink(int start_idx, int end_idx, int* processed, int* removed, size_t* memory_total) { 100 for (int i = start_idx; i < end_idx; ++i) { 101 HashtableEntry<Symbol*, mtSymbol>** p = the_table()->bucket_addr(i); 102 HashtableEntry<Symbol*, mtSymbol>* entry = the_table()->bucket(i); 103 while (entry != NULL) { 104 // Shared entries are normally at the end of the bucket and if we run into 105 // a shared entry, then there is nothing more to remove. However, if we 106 // have rehashed the table, then the shared entries are no longer at the 107 // end of the bucket. 108 if (entry->is_shared() && !use_alternate_hashcode()) { 109 break; 110 } 111 Symbol* s = entry->literal(); 112 (*memory_total) += s->size(); 113 (*processed)++; 114 assert(s != NULL, "just checking"); 115 // If reference count is zero, remove. 116 if (s->refcount() == 0) { 117 assert(!entry->is_shared(), "shared entries should be kept live"); 118 delete s; 119 (*removed)++; 120 *p = entry->next(); 121 the_table()->free_entry(entry); 122 } else { 123 p = entry->next_addr(); 124 } 125 // get next entry 126 entry = (HashtableEntry<Symbol*, mtSymbol>*)HashtableEntry<Symbol*, mtSymbol>::make_ptr(*p); 127 } 128 } 129 } 130 131 // Remove unreferenced symbols from the symbol table 132 // This is done late during GC. 133 void SymbolTable::unlink(int* processed, int* removed) { 134 size_t memory_total = 0; 135 buckets_unlink(0, the_table()->table_size(), processed, removed, &memory_total); 136 _symbols_removed += *removed; 137 _symbols_counted += *processed; 138 // Exclude printing for normal PrintGCDetails because people parse 139 // this output. 140 if (PrintGCDetails && Verbose && WizardMode) { 141 gclog_or_tty->print(" [Symbols=%d size=" SIZE_FORMAT "K] ", *processed, 142 (memory_total*HeapWordSize)/1024); 143 } 144 } 145 146 void SymbolTable::possibly_parallel_unlink(int* processed, int* removed) { 147 const int limit = the_table()->table_size(); 148 149 size_t memory_total = 0; 150 151 for (;;) { 152 // Grab next set of buckets to scan 153 int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize; 154 if (start_idx >= limit) { 155 // End of table 156 break; 157 } 158 159 int end_idx = MIN2(limit, start_idx + ClaimChunkSize); 160 buckets_unlink(start_idx, end_idx, processed, removed, &memory_total); 161 } 162 Atomic::add(*processed, &_symbols_counted); 163 Atomic::add(*removed, &_symbols_removed); 164 // Exclude printing for normal PrintGCDetails because people parse 165 // this output. 166 if (PrintGCDetails && Verbose && WizardMode) { 167 gclog_or_tty->print(" [Symbols: scanned=%d removed=%d size=" SIZE_FORMAT "K] ", *processed, *removed, 168 (memory_total*HeapWordSize)/1024); 169 } 170 } 171 172 // Create a new table and using alternate hash code, populate the new table 173 // with the existing strings. Set flag to use the alternate hash code afterwards. 174 void SymbolTable::rehash_table() { 175 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 176 // This should never happen with -Xshare:dump but it might in testing mode. 177 if (DumpSharedSpaces) return; 178 // Create a new symbol table 179 SymbolTable* new_table = new SymbolTable(); 180 181 the_table()->move_to(new_table); 182 183 // Delete the table and buckets (entries are reused in new table). 184 delete _the_table; 185 // Don't check if we need rehashing until the table gets unbalanced again. 186 // Then rehash with a new global seed. 187 _needs_rehashing = false; 188 _the_table = new_table; 189 } 190 191 // Lookup a symbol in a bucket. 192 193 Symbol* SymbolTable::lookup_dynamic(int index, const char* name, 194 int len, unsigned int hash) { 195 int count = 0; 196 for (HashtableEntry<Symbol*, mtSymbol>* e = bucket(index); e != NULL; e = e->next()) { 197 count++; // count all entries in this bucket, not just ones with same hash 198 if (e->hash() == hash) { 199 Symbol* sym = e->literal(); 200 if (sym->equals(name, len)) { 201 // something is referencing this symbol now. 202 sym->increment_refcount(); 203 return sym; 204 } 205 } 206 } 207 // If the bucket size is too deep check if this hash code is insufficient. 208 if (count >= rehash_count && !needs_rehashing()) { 209 _needs_rehashing = check_rehash_table(count); 210 } 211 return NULL; 212 } 213 214 Symbol* SymbolTable::lookup_shared(const char* name, 215 int len, unsigned int hash) { 216 return _shared_table.lookup(name, hash, len); 217 } 218 219 Symbol* SymbolTable::lookup(int index, const char* name, 220 int len, unsigned int hash) { 221 Symbol* sym; 222 if (_lookup_shared_first) { 223 sym = lookup_shared(name, len, hash); 224 if (sym != NULL) { 225 return sym; 226 } 227 _lookup_shared_first = false; 228 return lookup_dynamic(index, name, len, hash); 229 } else { 230 sym = lookup_dynamic(index, name, len, hash); 231 if (sym != NULL) { 232 return sym; 233 } 234 sym = lookup_shared(name, len, hash); 235 if (sym != NULL) { 236 _lookup_shared_first = true; 237 } 238 return sym; 239 } 240 } 241 242 // Pick hashing algorithm. 243 unsigned int SymbolTable::hash_symbol(const char* s, int len) { 244 return use_alternate_hashcode() ? 245 AltHashing::murmur3_32(seed(), (const jbyte*)s, len) : 246 java_lang_String::hash_code(s, len); 247 } 248 249 250 // We take care not to be blocking while holding the 251 // SymbolTable_lock. Otherwise, the system might deadlock, since the 252 // symboltable is used during compilation (VM_thread) The lock free 253 // synchronization is simplified by the fact that we do not delete 254 // entries in the symbol table during normal execution (only during 255 // safepoints). 256 257 Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) { 258 unsigned int hashValue = hash_symbol(name, len); 259 int index = the_table()->hash_to_index(hashValue); 260 261 Symbol* s = the_table()->lookup(index, name, len, hashValue); 262 263 // Found 264 if (s != NULL) return s; 265 266 // Grab SymbolTable_lock first. 267 MutexLocker ml(SymbolTable_lock, THREAD); 268 269 // Otherwise, add to symbol to table 270 return the_table()->basic_add(index, (u1*)name, len, hashValue, true, CHECK_NULL); 271 } 272 273 Symbol* SymbolTable::lookup(const Symbol* sym, int begin, int end, TRAPS) { 274 char* buffer; 275 int index, len; 276 unsigned int hashValue; 277 char* name; 278 { 279 debug_only(No_Safepoint_Verifier nsv;) 280 281 name = (char*)sym->base() + begin; 282 len = end - begin; 283 hashValue = hash_symbol(name, len); 284 index = the_table()->hash_to_index(hashValue); 285 Symbol* s = the_table()->lookup(index, name, len, hashValue); 286 287 // Found 288 if (s != NULL) return s; 289 } 290 291 // Otherwise, add to symbol to table. Copy to a C string first. 292 char stack_buf[128]; 293 ResourceMark rm(THREAD); 294 if (len <= 128) { 295 buffer = stack_buf; 296 } else { 297 buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len); 298 } 299 for (int i=0; i<len; i++) { 300 buffer[i] = name[i]; 301 } 302 // Make sure there is no safepoint in the code above since name can't move. 303 // We can't include the code in No_Safepoint_Verifier because of the 304 // ResourceMark. 305 306 // Grab SymbolTable_lock first. 307 MutexLocker ml(SymbolTable_lock, THREAD); 308 309 return the_table()->basic_add(index, (u1*)buffer, len, hashValue, true, CHECK_NULL); 310 } 311 312 Symbol* SymbolTable::lookup_only(const char* name, int len, 313 unsigned int& hash) { 314 hash = hash_symbol(name, len); 315 int index = the_table()->hash_to_index(hash); 316 317 Symbol* s = the_table()->lookup(index, name, len, hash); 318 return s; 319 } 320 321 // Look up the address of the literal in the SymbolTable for this Symbol* 322 // Do not create any new symbols 323 // Do not increment the reference count to keep this alive 324 Symbol** SymbolTable::lookup_symbol_addr(Symbol* sym){ 325 unsigned int hash = hash_symbol((char*)sym->bytes(), sym->utf8_length()); 326 int index = the_table()->hash_to_index(hash); 327 328 for (HashtableEntry<Symbol*, mtSymbol>* e = the_table()->bucket(index); e != NULL; e = e->next()) { 329 if (e->hash() == hash) { 330 Symbol* literal_sym = e->literal(); 331 if (sym == literal_sym) { 332 return e->literal_addr(); 333 } 334 } 335 } 336 return NULL; 337 } 338 339 // Suggestion: Push unicode-based lookup all the way into the hashing 340 // and probing logic, so there is no need for convert_to_utf8 until 341 // an actual new Symbol* is created. 342 Symbol* SymbolTable::lookup_unicode(const jchar* name, int utf16_length, TRAPS) { 343 int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); 344 char stack_buf[128]; 345 if (utf8_length < (int) sizeof(stack_buf)) { 346 char* chars = stack_buf; 347 UNICODE::convert_to_utf8(name, utf16_length, chars); 348 return lookup(chars, utf8_length, THREAD); 349 } else { 350 ResourceMark rm(THREAD); 351 char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; 352 UNICODE::convert_to_utf8(name, utf16_length, chars); 353 return lookup(chars, utf8_length, THREAD); 354 } 355 } 356 357 Symbol* SymbolTable::lookup_only_unicode(const jchar* name, int utf16_length, 358 unsigned int& hash) { 359 int utf8_length = UNICODE::utf8_length((jchar*) name, utf16_length); 360 char stack_buf[128]; 361 if (utf8_length < (int) sizeof(stack_buf)) { 362 char* chars = stack_buf; 363 UNICODE::convert_to_utf8(name, utf16_length, chars); 364 return lookup_only(chars, utf8_length, hash); 365 } else { 366 ResourceMark rm; 367 char* chars = NEW_RESOURCE_ARRAY(char, utf8_length + 1);; 368 UNICODE::convert_to_utf8(name, utf16_length, chars); 369 return lookup_only(chars, utf8_length, hash); 370 } 371 } 372 373 void SymbolTable::add(ClassLoaderData* loader_data, constantPoolHandle cp, 374 int names_count, 375 const char** names, int* lengths, int* cp_indices, 376 unsigned int* hashValues, TRAPS) { 377 // Grab SymbolTable_lock first. 378 MutexLocker ml(SymbolTable_lock, THREAD); 379 380 SymbolTable* table = the_table(); 381 bool added = table->basic_add(loader_data, cp, names_count, names, lengths, 382 cp_indices, hashValues, CHECK); 383 if (!added) { 384 // do it the hard way 385 for (int i=0; i<names_count; i++) { 386 int index = table->hash_to_index(hashValues[i]); 387 bool c_heap = !loader_data->is_the_null_class_loader_data(); 388 Symbol* sym = table->basic_add(index, (u1*)names[i], lengths[i], hashValues[i], c_heap, CHECK); 389 cp->symbol_at_put(cp_indices[i], sym); 390 } 391 } 392 } 393 394 Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) { 395 unsigned int hash; 396 Symbol* result = SymbolTable::lookup_only((char*)name, (int)strlen(name), hash); 397 if (result != NULL) { 398 return result; 399 } 400 // Grab SymbolTable_lock first. 401 MutexLocker ml(SymbolTable_lock, THREAD); 402 403 SymbolTable* table = the_table(); 404 int index = table->hash_to_index(hash); 405 return table->basic_add(index, (u1*)name, (int)strlen(name), hash, false, THREAD); 406 } 407 408 Symbol* SymbolTable::basic_add(int index_arg, u1 *name, int len, 409 unsigned int hashValue_arg, bool c_heap, TRAPS) { 410 assert(!Universe::heap()->is_in_reserved(name), 411 "proposed name of symbol must be stable"); 412 413 // Don't allow symbols to be created which cannot fit in a Symbol*. 414 if (len > Symbol::max_length()) { 415 THROW_MSG_0(vmSymbols::java_lang_InternalError(), 416 "name is too long to represent"); 417 } 418 419 // Cannot hit a safepoint in this function because the "this" pointer can move. 420 No_Safepoint_Verifier nsv; 421 422 // Check if the symbol table has been rehashed, if so, need to recalculate 423 // the hash value and index. 424 unsigned int hashValue; 425 int index; 426 if (use_alternate_hashcode()) { 427 hashValue = hash_symbol((const char*)name, len); 428 index = hash_to_index(hashValue); 429 } else { 430 hashValue = hashValue_arg; 431 index = index_arg; 432 } 433 434 // Since look-up was done lock-free, we need to check if another 435 // thread beat us in the race to insert the symbol. 436 Symbol* test = lookup(index, (char*)name, len, hashValue); 437 if (test != NULL) { 438 // A race occurred and another thread introduced the symbol. 439 assert(test->refcount() != 0, "lookup should have incremented the count"); 440 return test; 441 } 442 443 // Create a new symbol. 444 Symbol* sym = allocate_symbol(name, len, c_heap, CHECK_NULL); 445 assert(sym->equals((char*)name, len), "symbol must be properly initialized"); 446 447 HashtableEntry<Symbol*, mtSymbol>* entry = new_entry(hashValue, sym); 448 add_entry(index, entry); 449 return sym; 450 } 451 452 // This version of basic_add adds symbols in batch from the constant pool 453 // parsing. 454 bool SymbolTable::basic_add(ClassLoaderData* loader_data, constantPoolHandle cp, 455 int names_count, 456 const char** names, int* lengths, 457 int* cp_indices, unsigned int* hashValues, 458 TRAPS) { 459 460 // Check symbol names are not too long. If any are too long, don't add any. 461 for (int i = 0; i< names_count; i++) { 462 if (lengths[i] > Symbol::max_length()) { 463 THROW_MSG_0(vmSymbols::java_lang_InternalError(), 464 "name is too long to represent"); 465 } 466 } 467 468 // Cannot hit a safepoint in this function because the "this" pointer can move. 469 No_Safepoint_Verifier nsv; 470 471 for (int i=0; i<names_count; i++) { 472 // Check if the symbol table has been rehashed, if so, need to recalculate 473 // the hash value. 474 unsigned int hashValue; 475 if (use_alternate_hashcode()) { 476 hashValue = hash_symbol(names[i], lengths[i]); 477 } else { 478 hashValue = hashValues[i]; 479 } 480 // Since look-up was done lock-free, we need to check if another 481 // thread beat us in the race to insert the symbol. 482 int index = hash_to_index(hashValue); 483 Symbol* test = lookup(index, names[i], lengths[i], hashValue); 484 if (test != NULL) { 485 // A race occurred and another thread introduced the symbol, this one 486 // will be dropped and collected. Use test instead. 487 cp->symbol_at_put(cp_indices[i], test); 488 assert(test->refcount() != 0, "lookup should have incremented the count"); 489 } else { 490 // Create a new symbol. The null class loader is never unloaded so these 491 // are allocated specially in a permanent arena. 492 bool c_heap = !loader_data->is_the_null_class_loader_data(); 493 Symbol* sym = allocate_symbol((const u1*)names[i], lengths[i], c_heap, CHECK_(false)); 494 assert(sym->equals(names[i], lengths[i]), "symbol must be properly initialized"); // why wouldn't it be??? 495 HashtableEntry<Symbol*, mtSymbol>* entry = new_entry(hashValue, sym); 496 add_entry(index, entry); 497 cp->symbol_at_put(cp_indices[i], sym); 498 } 499 } 500 return true; 501 } 502 503 504 void SymbolTable::verify() { 505 for (int i = 0; i < the_table()->table_size(); ++i) { 506 HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 507 for ( ; p != NULL; p = p->next()) { 508 Symbol* s = (Symbol*)(p->literal()); 509 guarantee(s != NULL, "symbol is NULL"); 510 unsigned int h = hash_symbol((char*)s->bytes(), s->utf8_length()); 511 guarantee(p->hash() == h, "broken hash in symbol table entry"); 512 guarantee(the_table()->hash_to_index(h) == i, 513 "wrong index in symbol table"); 514 } 515 } 516 } 517 518 void SymbolTable::dump(outputStream* st, bool verbose) { 519 if (!verbose) { 520 the_table()->dump_table(st, "SymbolTable"); 521 } else { 522 st->print_cr("VERSION: 1.0"); 523 for (int i = 0; i < the_table()->table_size(); ++i) { 524 HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 525 for ( ; p != NULL; p = p->next()) { 526 Symbol* s = (Symbol*)(p->literal()); 527 const char* utf8_string = (const char*)s->bytes(); 528 int utf8_length = s->utf8_length(); 529 st->print("%d %d: ", utf8_length, s->refcount()); 530 HashtableTextDump::put_utf8(st, utf8_string, utf8_length); 531 st->cr(); 532 } 533 } 534 } 535 } 536 537 bool SymbolTable::copy_compact_table(char** top, char*end) { 538 #if INCLUDE_CDS 539 CompactHashtableWriter ch_table("symbol", the_table()->number_of_entries(), 540 &MetaspaceShared::stats()->symbol); 541 if (*top + ch_table.get_required_bytes() > end) { 542 // not enough space left 543 return false; 544 } 545 546 for (int i = 0; i < the_table()->table_size(); ++i) { 547 HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 548 for ( ; p != NULL; p = p->next()) { 549 Symbol* s = (Symbol*)(p->literal()); 550 unsigned int fixed_hash = hash_symbol((char*)s->bytes(), s->utf8_length()); 551 assert(fixed_hash == p->hash(), "must not rehash during dumping"); 552 ch_table.add(fixed_hash, s); 553 } 554 } 555 556 char* old_top = *top; 557 ch_table.dump(top, end); 558 559 *top = (char*)align_pointer_up(*top, sizeof(void*)); 560 #endif 561 return true; 562 } 563 564 const char* SymbolTable::init_shared_table(const char* buffer) { 565 const char* end = _shared_table.init(buffer); 566 return (const char*)align_pointer_up(end, sizeof(void*)); 567 } 568 569 //--------------------------------------------------------------------------- 570 // Non-product code 571 572 #ifndef PRODUCT 573 574 void SymbolTable::print_histogram() { 575 MutexLocker ml(SymbolTable_lock); 576 const int results_length = 100; 577 int counts[results_length]; 578 int sizes[results_length]; 579 int i,j; 580 581 // initialize results to zero 582 for (j = 0; j < results_length; j++) { 583 counts[j] = 0; 584 sizes[j] = 0; 585 } 586 587 int total_size = 0; 588 int total_count = 0; 589 int total_length = 0; 590 int max_length = 0; 591 int out_of_range_count = 0; 592 int out_of_range_size = 0; 593 for (i = 0; i < the_table()->table_size(); i++) { 594 HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i); 595 for ( ; p != NULL; p = p->next()) { 596 int size = p->literal()->size(); 597 int len = p->literal()->utf8_length(); 598 if (len < results_length) { 599 counts[len]++; 600 sizes[len] += size; 601 } else { 602 out_of_range_count++; 603 out_of_range_size += size; 604 } 605 total_count++; 606 total_size += size; 607 total_length += len; 608 max_length = MAX2(max_length, len); 609 } 610 } 611 tty->print_cr("Symbol Table Histogram:"); 612 tty->print_cr(" Total number of symbols %7d", total_count); 613 tty->print_cr(" Total size in memory %7dK", 614 (total_size*HeapWordSize)/1024); 615 tty->print_cr(" Total counted %7d", _symbols_counted); 616 tty->print_cr(" Total removed %7d", _symbols_removed); 617 if (_symbols_counted > 0) { 618 tty->print_cr(" Percent removed %3.2f", 619 ((float)_symbols_removed/(float)_symbols_counted)* 100); 620 } 621 tty->print_cr(" Reference counts %7d", Symbol::_total_count); 622 tty->print_cr(" Symbol arena used %7dK", arena()->used()/1024); 623 tty->print_cr(" Symbol arena size %7dK", arena()->size_in_bytes()/1024); 624 tty->print_cr(" Total symbol length %7d", total_length); 625 tty->print_cr(" Maximum symbol length %7d", max_length); 626 tty->print_cr(" Average symbol length %7.2f", ((float) total_length / (float) total_count)); 627 tty->print_cr(" Symbol length histogram:"); 628 tty->print_cr(" %6s %10s %10s", "Length", "#Symbols", "Size"); 629 for (i = 0; i < results_length; i++) { 630 if (counts[i] > 0) { 631 tty->print_cr(" %6d %10d %10dK", i, counts[i], (sizes[i]*HeapWordSize)/1024); 632 } 633 } 634 tty->print_cr(" >=%6d %10d %10dK\n", results_length, 635 out_of_range_count, (out_of_range_size*HeapWordSize)/1024); 636 } 637 638 void SymbolTable::print() { 639 for (int i = 0; i < the_table()->table_size(); ++i) { 640 HashtableEntry<Symbol*, mtSymbol>** p = the_table()->bucket_addr(i); 641 HashtableEntry<Symbol*, mtSymbol>* entry = the_table()->bucket(i); 642 if (entry != NULL) { 643 while (entry != NULL) { 644 tty->print(PTR_FORMAT " ", entry->literal()); 645 entry->literal()->print(); 646 tty->print(" %d", entry->literal()->refcount()); 647 p = entry->next_addr(); 648 entry = (HashtableEntry<Symbol*, mtSymbol>*)HashtableEntry<Symbol*, mtSymbol>::make_ptr(*p); 649 } 650 tty->cr(); 651 } 652 } 653 } 654 #endif // PRODUCT 655 656 657 // Utility for dumping symbols 658 SymboltableDCmd::SymboltableDCmd(outputStream* output, bool heap) : 659 DCmdWithParser(output, heap), 660 _verbose("-verbose", "Dump the content of each symbol in the table", 661 "BOOLEAN", false, "false") { 662 _dcmdparser.add_dcmd_option(&_verbose); 663 } 664 665 void SymboltableDCmd::execute(DCmdSource source, TRAPS) { 666 VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpSymbols, 667 _verbose.value()); 668 VMThread::execute(&dumper); 669 } 670 671 int SymboltableDCmd::num_arguments() { 672 ResourceMark rm; 673 SymboltableDCmd* dcmd = new SymboltableDCmd(NULL, false); 674 if (dcmd != NULL) { 675 DCmdMark mark(dcmd); 676 return dcmd->_dcmdparser.num_arguments(); 677 } else { 678 return 0; 679 } 680 }