< prev index next >

src/hotspot/share/classfile/symbolTable.cpp

Print this page

 51 // 2^24 is max size, like StringTable.
 52 const size_t END_SIZE = 24;
 53 // If a chain gets to 100 something might be wrong
 54 const size_t REHASH_LEN = 100;
 55 
 56 const size_t ON_STACK_BUFFER_LENGTH = 128;
 57 
 58 // --------------------------------------------------------------------------
 59 
 60 inline bool symbol_equals_compact_hashtable_entry(Symbol* value, const char* key, int len) {
 61   if (value->equals(key, len)) {
 62     return true;
 63   } else {
 64     return false;
 65   }
 66 }
 67 
 68 static OffsetCompactHashtable<
 69   const char*, Symbol*,
 70   symbol_equals_compact_hashtable_entry
 71 > _shared_table;
 72 
 73 static OffsetCompactHashtable<
 74   const char*, Symbol*,
 75   symbol_equals_compact_hashtable_entry
 76 > _dynamic_shared_table;
 77 
 78 // --------------------------------------------------------------------------
 79 
 80 typedef ConcurrentHashTable<SymbolTableConfig, mtSymbol> SymbolTableHash;
 81 static SymbolTableHash* _local_table = nullptr;
 82 
 83 volatile bool SymbolTable::_has_work = 0;
 84 volatile bool SymbolTable::_needs_rehashing = false;
 85 
 86 // For statistics
 87 static size_t _symbols_removed = 0;
 88 static size_t _symbols_counted = 0;
 89 static size_t _current_size = 0;
 90 
 91 static volatile size_t _items_count = 0;
 92 static volatile bool   _has_items_to_clean = false;
 93 
 94 
 95 static volatile bool _alt_hash = false;
 96 

668   for (int i = 0; i < len; i++) {
669     Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
670     unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
671     assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
672            "must not rehash during dumping");
673     sym->set_permanent();
674     writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
675   }
676 }
677 
678 size_t SymbolTable::estimate_size_for_archive() {
679   if (_items_count > (size_t)max_jint) {
680     fatal("Too many symbols to be archived: %zu", _items_count);
681   }
682   return CompactHashtableWriter::estimate_size(int(_items_count));
683 }
684 
685 void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
686   CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
687   copy_shared_symbol_table(symbols, &writer);
688   if (CDSConfig::is_dumping_static_archive()) {
689     _shared_table.reset();
690     writer.dump(&_shared_table, "symbol");
691   } else {
692     assert(CDSConfig::is_dumping_dynamic_archive(), "must be");
693     _dynamic_shared_table.reset();
694     writer.dump(&_dynamic_shared_table, "symbol");
695   }
696 }
697 
698 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
699                                                 bool is_static_archive) {
700   OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
701   if (is_static_archive) {
702     table = &_shared_table;




703   } else {
704     table = &_dynamic_shared_table;
705   }

706   table->serialize_header(soc);
707   if (soc->writing()) {
708     // Sanity. Make sure we don't use the shared table at dump time
709     table->reset();
710   }
711 }
712 #endif //INCLUDE_CDS
713 
714 // Concurrent work
715 void SymbolTable::grow(JavaThread* jt) {
716   SymbolTableHash::GrowTask gt(_local_table);
717   if (!gt.prepare(jt)) {
718     return;
719   }
720   log_trace(symboltable)("Started to grow");
721   {
722     TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
723     while (gt.do_task(jt)) {
724       gt.pause(jt);
725       {
726         ThreadBlockInVM tbivm(jt);
727       }
728       gt.cont(jt);
729     }
730   }

 51 // 2^24 is max size, like StringTable.
 52 const size_t END_SIZE = 24;
 53 // If a chain gets to 100 something might be wrong
 54 const size_t REHASH_LEN = 100;
 55 
 56 const size_t ON_STACK_BUFFER_LENGTH = 128;
 57 
 58 // --------------------------------------------------------------------------
 59 
 60 inline bool symbol_equals_compact_hashtable_entry(Symbol* value, const char* key, int len) {
 61   if (value->equals(key, len)) {
 62     return true;
 63   } else {
 64     return false;
 65   }
 66 }
 67 
 68 static OffsetCompactHashtable<
 69   const char*, Symbol*,
 70   symbol_equals_compact_hashtable_entry
 71 > _shared_table, _dynamic_shared_table, _shared_table_for_dumping;





 72 
 73 // --------------------------------------------------------------------------
 74 
 75 typedef ConcurrentHashTable<SymbolTableConfig, mtSymbol> SymbolTableHash;
 76 static SymbolTableHash* _local_table = nullptr;
 77 
 78 volatile bool SymbolTable::_has_work = 0;
 79 volatile bool SymbolTable::_needs_rehashing = false;
 80 
 81 // For statistics
 82 static size_t _symbols_removed = 0;
 83 static size_t _symbols_counted = 0;
 84 static size_t _current_size = 0;
 85 
 86 static volatile size_t _items_count = 0;
 87 static volatile bool   _has_items_to_clean = false;
 88 
 89 
 90 static volatile bool _alt_hash = false;
 91 

663   for (int i = 0; i < len; i++) {
664     Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
665     unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
666     assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
667            "must not rehash during dumping");
668     sym->set_permanent();
669     writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
670   }
671 }
672 
673 size_t SymbolTable::estimate_size_for_archive() {
674   if (_items_count > (size_t)max_jint) {
675     fatal("Too many symbols to be archived: %zu", _items_count);
676   }
677   return CompactHashtableWriter::estimate_size(int(_items_count));
678 }
679 
680 void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
681   CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
682   copy_shared_symbol_table(symbols, &writer);
683   _shared_table_for_dumping.reset();
684   writer.dump(&_shared_table_for_dumping, "symbol");






685 }
686 
687 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
688                                                 bool is_static_archive) {
689   OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
690   if (soc->reading()) {
691     if (is_static_archive) {
692       table = &_shared_table;
693     } else {
694       table = &_dynamic_shared_table;
695     }
696   } else {
697     table = &_shared_table_for_dumping;
698   }
699 
700   table->serialize_header(soc);




701 }
702 #endif //INCLUDE_CDS
703 
704 // Concurrent work
705 void SymbolTable::grow(JavaThread* jt) {
706   SymbolTableHash::GrowTask gt(_local_table);
707   if (!gt.prepare(jt)) {
708     return;
709   }
710   log_trace(symboltable)("Started to grow");
711   {
712     TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
713     while (gt.do_task(jt)) {
714       gt.pause(jt);
715       {
716         ThreadBlockInVM tbivm(jt);
717       }
718       gt.cont(jt);
719     }
720   }
< prev index next >