50 // 2^24 is max size, like StringTable.
51 const size_t END_SIZE = 24;
52 // If a chain gets to 100 something might be wrong
53 const size_t REHASH_LEN = 100;
54
55 const size_t ON_STACK_BUFFER_LENGTH = 128;
56
57 // --------------------------------------------------------------------------
58
59 inline bool symbol_equals_compact_hashtable_entry(Symbol* value, const char* key, int len) {
60 if (value->equals(key, len)) {
61 return true;
62 } else {
63 return false;
64 }
65 }
66
67 static OffsetCompactHashtable<
68 const char*, Symbol*,
69 symbol_equals_compact_hashtable_entry
70 > _shared_table;
71
72 static OffsetCompactHashtable<
73 const char*, Symbol*,
74 symbol_equals_compact_hashtable_entry
75 > _dynamic_shared_table;
76
77 // --------------------------------------------------------------------------
78
79 typedef ConcurrentHashTable<SymbolTableConfig, mtSymbol> SymbolTableHash;
80 static SymbolTableHash* _local_table = nullptr;
81
82 volatile bool SymbolTable::_has_work = 0;
83 volatile bool SymbolTable::_needs_rehashing = false;
84
85 // For statistics
86 static size_t _symbols_removed = 0;
87 static size_t _symbols_counted = 0;
88 static size_t _current_size = 0;
89
90 static volatile size_t _items_count = 0;
91 static volatile bool _has_items_to_clean = false;
92
93
94 static volatile bool _alt_hash = false;
95
686 for (int i = 0; i < len; i++) {
687 Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
688 unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
689 assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
690 "must not rehash during dumping");
691 sym->set_permanent();
692 writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
693 }
694 }
695
696 size_t SymbolTable::estimate_size_for_archive() {
697 if (_items_count > (size_t)max_jint) {
698 fatal("Too many symbols to be archived: %zu", _items_count);
699 }
700 return CompactHashtableWriter::estimate_size(int(_items_count));
701 }
702
703 void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
704 CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
705 copy_shared_symbol_table(symbols, &writer);
706 if (CDSConfig::is_dumping_static_archive()) {
707 _shared_table.reset();
708 writer.dump(&_shared_table, "symbol");
709 } else {
710 assert(CDSConfig::is_dumping_dynamic_archive(), "must be");
711 _dynamic_shared_table.reset();
712 writer.dump(&_dynamic_shared_table, "symbol");
713 }
714 }
715
716 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
717 bool is_static_archive) {
718 OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
719 if (is_static_archive) {
720 table = &_shared_table;
721 } else {
722 table = &_dynamic_shared_table;
723 }
724 table->serialize_header(soc);
725 if (soc->writing()) {
726 // Sanity. Make sure we don't use the shared table at dump time
727 table->reset();
728 }
729 }
730 #endif //INCLUDE_CDS
731
732 // Concurrent work
733 void SymbolTable::grow(JavaThread* jt) {
734 SymbolTableHash::GrowTask gt(_local_table);
735 if (!gt.prepare(jt)) {
736 return;
737 }
738 log_trace(symboltable)("Started to grow");
739 {
740 TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
741 while (gt.do_task(jt)) {
742 gt.pause(jt);
743 {
744 ThreadBlockInVM tbivm(jt);
745 }
746 gt.cont(jt);
747 }
748 }
|
50 // 2^24 is max size, like StringTable.
51 const size_t END_SIZE = 24;
52 // If a chain gets to 100 something might be wrong
53 const size_t REHASH_LEN = 100;
54
55 const size_t ON_STACK_BUFFER_LENGTH = 128;
56
57 // --------------------------------------------------------------------------
58
59 inline bool symbol_equals_compact_hashtable_entry(Symbol* value, const char* key, int len) {
60 if (value->equals(key, len)) {
61 return true;
62 } else {
63 return false;
64 }
65 }
66
67 static OffsetCompactHashtable<
68 const char*, Symbol*,
69 symbol_equals_compact_hashtable_entry
70 > _shared_table, _dynamic_shared_table, _shared_table_for_dumping;
71
72 // --------------------------------------------------------------------------
73
74 typedef ConcurrentHashTable<SymbolTableConfig, mtSymbol> SymbolTableHash;
75 static SymbolTableHash* _local_table = nullptr;
76
77 volatile bool SymbolTable::_has_work = 0;
78 volatile bool SymbolTable::_needs_rehashing = false;
79
80 // For statistics
81 static size_t _symbols_removed = 0;
82 static size_t _symbols_counted = 0;
83 static size_t _current_size = 0;
84
85 static volatile size_t _items_count = 0;
86 static volatile bool _has_items_to_clean = false;
87
88
89 static volatile bool _alt_hash = false;
90
681 for (int i = 0; i < len; i++) {
682 Symbol* sym = ArchiveBuilder::get_buffered_symbol(symbols->at(i));
683 unsigned int fixed_hash = hash_shared_symbol((const char*)sym->bytes(), sym->utf8_length());
684 assert(fixed_hash == hash_symbol((const char*)sym->bytes(), sym->utf8_length(), false),
685 "must not rehash during dumping");
686 sym->set_permanent();
687 writer->add(fixed_hash, builder->buffer_to_offset_u4((address)sym));
688 }
689 }
690
691 size_t SymbolTable::estimate_size_for_archive() {
692 if (_items_count > (size_t)max_jint) {
693 fatal("Too many symbols to be archived: %zu", _items_count);
694 }
695 return CompactHashtableWriter::estimate_size(int(_items_count));
696 }
697
698 void SymbolTable::write_to_archive(GrowableArray<Symbol*>* symbols) {
699 CompactHashtableWriter writer(int(_items_count), ArchiveBuilder::symbol_stats());
700 copy_shared_symbol_table(symbols, &writer);
701 _shared_table_for_dumping.reset();
702 writer.dump(&_shared_table_for_dumping, "symbol");
703 }
704
705 void SymbolTable::serialize_shared_table_header(SerializeClosure* soc,
706 bool is_static_archive) {
707 OffsetCompactHashtable<const char*, Symbol*, symbol_equals_compact_hashtable_entry> * table;
708 if (soc->reading()) {
709 if (is_static_archive) {
710 table = &_shared_table;
711 } else {
712 table = &_dynamic_shared_table;
713 }
714 } else {
715 table = &_shared_table_for_dumping;
716 }
717
718 table->serialize_header(soc);
719 }
720 #endif //INCLUDE_CDS
721
722 // Concurrent work
723 void SymbolTable::grow(JavaThread* jt) {
724 SymbolTableHash::GrowTask gt(_local_table);
725 if (!gt.prepare(jt)) {
726 return;
727 }
728 log_trace(symboltable)("Started to grow");
729 {
730 TraceTime timer("Grow", TRACETIME_LOG(Debug, symboltable, perf));
731 while (gt.do_task(jt)) {
732 gt.pause(jt);
733 {
734 ThreadBlockInVM tbivm(jt);
735 }
736 gt.cont(jt);
737 }
738 }
|