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