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
687 for (int i = 0; i < len; i++) {
688 Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
689 unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
690 assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
691 "must not rehash during dumping");
692 sym->set_permanent();
693 writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
694 }
695 }
696
697 size_t SymbolTable::estimate_size_for_archive() {
698 if (_items_count > (size_t)max_jint) {
699 fatal("Too many symbols to be archived: %zu", _items_count);
700 }
701 return CompactHashtableWriter::estimate_size(int(_items_count));
702 }
703
704 void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
705 CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
706 copy_shared_symbol_table(symbols, &writer);
707 if (CDSConfig::is_dumping_static_archive()) {
708 _shared_table.reset();
709 writer.dump(&_shared_table, "symbol");
710 } else {
711 assert(CDSConfig::is_dumping_dynamic_archive(), "must be");
712 _dynamic_shared_table.reset();
713 writer.dump(&_dynamic_shared_table, "symbol");
714 }
715 }
716
717 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
718 bool is_static_archive) {
719 OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
720 if (is_static_archive) {
721 table = &_shared_table;
722 } else {
723 table = &_dynamic_shared_table;
724 }
725 table->serialize_header(soc);
726 if (soc->writing()) {
727 // Sanity. Make sure we don't use the shared table at dump time
728 table->reset();
729 }
730 }
731 #endif //INCLUDE_CDS
732
733 // Concurrent work
734 void SymbolTable::grow(JavaThread* jt) {
735 SymbolTableHash::GrowTask gt(_local_table);
736 if (!gt.prepare(jt)) {
737 return;
738 }
739 log_trace(symboltable)("Started to grow");
740 {
741 TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
742 while (gt.do_task(jt)) {
743 gt.pause(jt);
744 {
745 ThreadBlockInVM tbivm(jt);
746 }
747 gt.cont(jt);
748 }
749 }
|
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
682 for (int i = 0; i < len; i++) {
683 Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
684 unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
685 assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
686 "must not rehash during dumping");
687 sym->set_permanent();
688 writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
689 }
690 }
691
692 size_t SymbolTable::estimate_size_for_archive() {
693 if (_items_count > (size_t)max_jint) {
694 fatal("Too many symbols to be archived: %zu", _items_count);
695 }
696 return CompactHashtableWriter::estimate_size(int(_items_count));
697 }
698
699 void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
700 CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
701 copy_shared_symbol_table(symbols, &writer);
702 _shared_table_for_dumping.reset();
703 writer.dump(&_shared_table_for_dumping, "symbol");
704 }
705
706 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
707 bool is_static_archive) {
708 OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
709 if (soc->reading()) {
710 if (is_static_archive) {
711 table = &_shared_table;
712 } else {
713 table = &_dynamic_shared_table;
714 }
715 } else {
716 table = &_shared_table_for_dumping;
717 }
718
719 table->serialize_header(soc);
720 }
721 #endif //INCLUDE_CDS
722
723 // Concurrent work
724 void SymbolTable::grow(JavaThread* jt) {
725 SymbolTableHash::GrowTask gt(_local_table);
726 if (!gt.prepare(jt)) {
727 return;
728 }
729 log_trace(symboltable)("Started to grow");
730 {
731 TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
732 while (gt.do_task(jt)) {
733 gt.pause(jt);
734 {
735 ThreadBlockInVM tbivm(jt);
736 }
737 gt.cont(jt);
738 }
739 }
|