< prev index next >

src/hotspot/share/classfile/symbolTable.cpp

Print this page




 250 
 251 class SharedSymbolIterator {
 252   SymbolClosure* _symbol_closure;
 253 public:
 254   SharedSymbolIterator(SymbolClosure* f) : _symbol_closure(f) {}
 255   void do_value(Symbol* symbol) {
 256     _symbol_closure->do_symbol(&symbol);
 257   }
 258 };
 259 
 260 // Call function for all symbols in the symbol table.
 261 void SymbolTable::symbols_do(SymbolClosure *cl) {
 262   // all symbols from shared table
 263   SharedSymbolIterator iter(cl);
 264   _shared_table.iterate(&iter);
 265   _dynamic_shared_table.iterate(&iter);
 266 
 267   // all symbols from the dynamic table
 268   SymbolsDo sd(cl);
 269   if (!_local_table->try_scan(Thread::current(), sd)) {
 270     log_info(symboltable)("symbols_do unavailable at this moment");
 271   }
 272 }
 273 
 274 class MetaspacePointersDo : StackObj {
 275   MetaspaceClosure *_it;
 276 public:
 277   MetaspacePointersDo(MetaspaceClosure *it) : _it(it) {}
 278   bool operator()(Symbol** value) {
 279     assert(value != NULL, "expected valid value");
 280     assert(*value != NULL, "value should point to a symbol");
 281     _it->push(value);
 282     return true;
 283   };
 284 };
 285 
 286 void SymbolTable::metaspace_pointers_do(MetaspaceClosure* it) {
 287   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "called only during dump time");
 288   MetaspacePointersDo mpd(it);
 289   _local_table->do_safepoint_scan(mpd);
 290 }


 540   _local_table->statistics_to(Thread::current(), sz, st, table_name);
 541 }
 542 
 543 // Verification
 544 class VerifySymbols : StackObj {
 545 public:
 546   bool operator()(Symbol** value) {
 547     guarantee(value != NULL, "expected valid value");
 548     guarantee(*value != NULL, "value should point to a symbol");
 549     Symbol* sym = *value;
 550     guarantee(sym->equals((const char*)sym->bytes(), sym->utf8_length()),
 551               "symbol must be internally consistent");
 552     return true;
 553   };
 554 };
 555 
 556 void SymbolTable::verify() {
 557   Thread* thr = Thread::current();
 558   VerifySymbols vs;
 559   if (!_local_table->try_scan(thr, vs)) {
 560     log_info(symboltable)("verify unavailable at this moment");
 561   }
 562 }
 563 
 564 // Dumping
 565 class DumpSymbol : StackObj {
 566   Thread* _thr;
 567   outputStream* _st;
 568 public:
 569   DumpSymbol(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
 570   bool operator()(Symbol** value) {
 571     assert(value != NULL, "expected valid value");
 572     assert(*value != NULL, "value should point to a symbol");
 573     Symbol* sym = *value;
 574     const char* utf8_string = (const char*)sym->bytes();
 575     int utf8_length = sym->utf8_length();
 576     _st->print("%d %d: ", utf8_length, sym->refcount());
 577     HashtableTextDump::put_utf8(_st, utf8_string, utf8_length);
 578     _st->cr();
 579     return true;
 580   };


 606     assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
 607            "must not rehash during dumping");
 608     if (DynamicDumpSharedSpaces) {
 609       sym = DynamicArchive::original_to_target(sym);
 610     }
 611     _writer->add(fixed_hash, MetaspaceShared::object_delta_u4(sym));
 612     return true;
 613   }
 614 };
 615 
 616 void SymbolTable::copy_shared_symbol_table(CompactHashtableWriter* writer) {
 617   CopyToArchive copy(writer);
 618   _local_table->do_safepoint_scan(copy);
 619 }
 620 
 621 size_t SymbolTable::estimate_size_for_archive() {
 622   return CompactHashtableWriter::estimate_size(int(_items_count));
 623 }
 624 
 625 void SymbolTable::write_to_archive(bool is_static_archive) {



 626   CompactHashtableWriter writer(int(_items_count),
 627                                 &MetaspaceShared::stats()->symbol);
 628   copy_shared_symbol_table(&writer);
 629   if (is_static_archive) {
 630     _shared_table.reset();
 631     writer.dump(&_shared_table, "symbol");
 632 
 633     // Verify table is correct
 634     Symbol* sym = vmSymbols::java_lang_Object();
 635     const char* name = (const char*)sym->bytes();
 636     int len = sym->utf8_length();
 637     unsigned int hash = hash_symbol(name, len, _alt_hash);
 638     assert(sym == _shared_table.lookup(name, hash, len), "sanity");
 639   } else {
 640     _dynamic_shared_table.reset();
 641     writer.dump(&_dynamic_shared_table, "symbol");
 642   }
 643 }
 644 
 645 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
 646                                                 bool is_static_archive) {
 647   OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
 648   if (is_static_archive) {
 649     table = &_shared_table;
 650   } else {
 651     table = &_dynamic_shared_table;
 652   }
 653   table->serialize_header(soc);
 654   if (soc->writing()) {
 655     // Sanity. Make sure we don't use the shared table at dump time
 656     table->reset();
 657   }
 658 }
 659 #endif //INCLUDE_CDS
 660 


 746 }
 747 
 748 void SymbolTable::do_concurrent_work(JavaThread* jt) {
 749   double load_factor = get_load_factor();
 750   log_debug(symboltable, perf)("Concurrent work, live factor: %g", load_factor);
 751   // We prefer growing, since that also removes dead items
 752   if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
 753     grow(jt);
 754   } else {
 755     clean_dead_entries(jt);
 756   }
 757   _has_work = false;
 758 }
 759 
 760 // Rehash
 761 bool SymbolTable::do_rehash() {
 762   if (!_local_table->is_safepoint_safe()) {
 763     return false;
 764   }
 765 
 766   // We use current size
 767   size_t new_size = _local_table->get_size_log2(Thread::current());
 768   SymbolTableHash* new_table = new SymbolTableHash(new_size, END_SIZE, REHASH_LEN);
 769   // Use alt hash from now on
 770   _alt_hash = true;
 771   if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) {
 772     _alt_hash = false;
 773     delete new_table;
 774     return false;
 775   }
 776 
 777   // free old table
 778   delete _local_table;
 779   _local_table = new_table;
 780 
 781   return true;
 782 }
 783 
 784 void SymbolTable::rehash_table() {
 785   static bool rehashed = false;
 786   log_debug(symboltable)("Table imbalanced, rehashing called.");
 787 
 788   // Grow instead of rehash.




 250 
 251 class SharedSymbolIterator {
 252   SymbolClosure* _symbol_closure;
 253 public:
 254   SharedSymbolIterator(SymbolClosure* f) : _symbol_closure(f) {}
 255   void do_value(Symbol* symbol) {
 256     _symbol_closure->do_symbol(&symbol);
 257   }
 258 };
 259 
 260 // Call function for all symbols in the symbol table.
 261 void SymbolTable::symbols_do(SymbolClosure *cl) {
 262   // all symbols from shared table
 263   SharedSymbolIterator iter(cl);
 264   _shared_table.iterate(&iter);
 265   _dynamic_shared_table.iterate(&iter);
 266 
 267   // all symbols from the dynamic table
 268   SymbolsDo sd(cl);
 269   if (!_local_table->try_scan(Thread::current(), sd)) {
 270     log_info(stringtable)("symbols_do unavailable at this moment");
 271   }
 272 }
 273 
 274 class MetaspacePointersDo : StackObj {
 275   MetaspaceClosure *_it;
 276 public:
 277   MetaspacePointersDo(MetaspaceClosure *it) : _it(it) {}
 278   bool operator()(Symbol** value) {
 279     assert(value != NULL, "expected valid value");
 280     assert(*value != NULL, "value should point to a symbol");
 281     _it->push(value);
 282     return true;
 283   };
 284 };
 285 
 286 void SymbolTable::metaspace_pointers_do(MetaspaceClosure* it) {
 287   assert(DumpSharedSpaces || DynamicDumpSharedSpaces, "called only during dump time");
 288   MetaspacePointersDo mpd(it);
 289   _local_table->do_safepoint_scan(mpd);
 290 }


 540   _local_table->statistics_to(Thread::current(), sz, st, table_name);
 541 }
 542 
 543 // Verification
 544 class VerifySymbols : StackObj {
 545 public:
 546   bool operator()(Symbol** value) {
 547     guarantee(value != NULL, "expected valid value");
 548     guarantee(*value != NULL, "value should point to a symbol");
 549     Symbol* sym = *value;
 550     guarantee(sym->equals((const char*)sym->bytes(), sym->utf8_length()),
 551               "symbol must be internally consistent");
 552     return true;
 553   };
 554 };
 555 
 556 void SymbolTable::verify() {
 557   Thread* thr = Thread::current();
 558   VerifySymbols vs;
 559   if (!_local_table->try_scan(thr, vs)) {
 560     log_info(stringtable)("verify unavailable at this moment");
 561   }
 562 }
 563 
 564 // Dumping
 565 class DumpSymbol : StackObj {
 566   Thread* _thr;
 567   outputStream* _st;
 568 public:
 569   DumpSymbol(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
 570   bool operator()(Symbol** value) {
 571     assert(value != NULL, "expected valid value");
 572     assert(*value != NULL, "value should point to a symbol");
 573     Symbol* sym = *value;
 574     const char* utf8_string = (const char*)sym->bytes();
 575     int utf8_length = sym->utf8_length();
 576     _st->print("%d %d: ", utf8_length, sym->refcount());
 577     HashtableTextDump::put_utf8(_st, utf8_string, utf8_length);
 578     _st->cr();
 579     return true;
 580   };


 606     assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
 607            "must not rehash during dumping");
 608     if (DynamicDumpSharedSpaces) {
 609       sym = DynamicArchive::original_to_target(sym);
 610     }
 611     _writer->add(fixed_hash, MetaspaceShared::object_delta_u4(sym));
 612     return true;
 613   }
 614 };
 615 
 616 void SymbolTable::copy_shared_symbol_table(CompactHashtableWriter* writer) {
 617   CopyToArchive copy(writer);
 618   _local_table->do_safepoint_scan(copy);
 619 }
 620 
 621 size_t SymbolTable::estimate_size_for_archive() {
 622   return CompactHashtableWriter::estimate_size(int(_items_count));
 623 }
 624 
 625 void SymbolTable::write_to_archive(bool is_static_archive) {
 626   _shared_table.reset();
 627   _dynamic_shared_table.reset();
 628 
 629   CompactHashtableWriter writer(int(_items_count),
 630                                 &MetaspaceShared::stats()->symbol);
 631   copy_shared_symbol_table(&writer);
 632   if (is_static_archive) {

 633     writer.dump(&_shared_table, "symbol");
 634 
 635     // Verify table is correct
 636     Symbol* sym = vmSymbols::java_lang_Object();
 637     const char* name = (const char*)sym->bytes();
 638     int len = sym->utf8_length();
 639     unsigned int hash = hash_symbol(name, len, _alt_hash);
 640     assert(sym == _shared_table.lookup(name, hash, len), "sanity");
 641   } else {

 642     writer.dump(&_dynamic_shared_table, "symbol");
 643   }
 644 }
 645 
 646 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
 647                                                 bool is_static_archive) {
 648   OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
 649   if (is_static_archive) {
 650     table = &_shared_table;
 651   } else {
 652     table = &_dynamic_shared_table;
 653   }
 654   table->serialize_header(soc);
 655   if (soc->writing()) {
 656     // Sanity. Make sure we don't use the shared table at dump time
 657     table->reset();
 658   }
 659 }
 660 #endif //INCLUDE_CDS
 661 


 747 }
 748 
 749 void SymbolTable::do_concurrent_work(JavaThread* jt) {
 750   double load_factor = get_load_factor();
 751   log_debug(symboltable, perf)("Concurrent work, live factor: %g", load_factor);
 752   // We prefer growing, since that also removes dead items
 753   if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
 754     grow(jt);
 755   } else {
 756     clean_dead_entries(jt);
 757   }
 758   _has_work = false;
 759 }
 760 
 761 // Rehash
 762 bool SymbolTable::do_rehash() {
 763   if (!_local_table->is_safepoint_safe()) {
 764     return false;
 765   }
 766 
 767   // We use max size
 768   SymbolTableHash* new_table = new SymbolTableHash(END_SIZE, END_SIZE, REHASH_LEN);

 769   // Use alt hash from now on
 770   _alt_hash = true;
 771   if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) {
 772     _alt_hash = false;
 773     delete new_table;
 774     return false;
 775   }
 776 
 777   // free old table
 778   delete _local_table;
 779   _local_table = new_table;
 780 
 781   return true;
 782 }
 783 
 784 void SymbolTable::rehash_table() {
 785   static bool rehashed = false;
 786   log_debug(symboltable)("Table imbalanced, rehashing called.");
 787 
 788   // Grow instead of rehash.


< prev index next >