< 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 

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




691   } else {
692     table = &_dynamic_shared_table;
693   }

694   table->serialize_header(soc);
695   if (soc->writing()) {
696     // Sanity. Make sure we don't use the shared table at dump time
697     table->reset();
698   }
699 }
700 #endif //INCLUDE_CDS
701 
702 // Concurrent work
703 void SymbolTable::grow(JavaThread* jt) {
704   SymbolTableHash::GrowTask gt(_local_table);
705   if (!gt.prepare(jt)) {
706     return;
707   }
708   log_trace(symboltable)("Started to grow");
709   {
710     TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
711     while (gt.do_task(jt)) {
712       gt.pause(jt);
713       {
714         ThreadBlockInVM tbivm(jt);
715       }
716       gt.cont(jt);
717     }
718   }

 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 

651   for (int i = 0; i < len; i++) {
652     Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
653     unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
654     assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
655            "must not rehash during dumping");
656     sym->set_permanent();
657     writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
658   }
659 }
660 
661 size_t SymbolTable::estimate_size_for_archive() {
662   if (_items_count > (size_t)max_jint) {
663     fatal("Too many symbols to be archived: %zu", _items_count);
664   }
665   return CompactHashtableWriter::estimate_size(int(_items_count));
666 }
667 
668 void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
669   CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
670   copy_shared_symbol_table(symbols, &writer);
671   _shared_table_for_dumping.reset();
672   writer.dump(&_shared_table_for_dumping, "symbol");






673 }
674 
675 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
676                                                 bool is_static_archive) {
677   OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
678   if (soc->reading()) {
679     if (is_static_archive) {
680       table = &_shared_table;
681     } else {
682       table = &_dynamic_shared_table;
683     }
684   } else {
685     table = &_shared_table_for_dumping;
686   }
687 
688   table->serialize_header(soc);




689 }
690 #endif //INCLUDE_CDS
691 
692 // Concurrent work
693 void SymbolTable::grow(JavaThread* jt) {
694   SymbolTableHash::GrowTask gt(_local_table);
695   if (!gt.prepare(jt)) {
696     return;
697   }
698   log_trace(symboltable)("Started to grow");
699   {
700     TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
701     while (gt.do_task(jt)) {
702       gt.pause(jt);
703       {
704         ThreadBlockInVM tbivm(jt);
705       }
706       gt.cont(jt);
707     }
708   }
< prev index next >