@@ -946,6 +946,8 @@ void StringTable::allocate_shared_strings_array(TRAPS) {
946946 if (!CDSConfig::is_dumping_heap ()) {
947947 return ;
948948 }
949+ assert (CDSConfig::allow_only_single_java_thread (), " No more interned strings can be added" );
950+
949951 if (_items_count > (size_t )max_jint) {
950952 fatal (" Too many strings to be archived: %zu" , _items_count);
951953 }
@@ -1026,48 +1028,61 @@ void StringTable::verify_secondary_array_index_bits() {
10261028// For each shared string:
10271029// [1] Store it into _shared_strings_array. Encode its position as a 32-bit index.
10281030// [2] Store the index and hashcode into _shared_table.
1029- oop StringTable::init_shared_strings_array (const DumpedInternedStrings* dumped_interned_strings ) {
1031+ oop StringTable::init_shared_strings_array () {
10301032 assert (CDSConfig::is_dumping_heap (), " must be" );
10311033 objArrayOop array = (objArrayOop)(_shared_strings_array.resolve ());
10321034
10331035 verify_secondary_array_index_bits ();
10341036
10351037 int index = 0 ;
1036- auto copy_into_array = [&] (oop string, bool value_ignored) {
1037- if (!_is_two_dimensional_shared_strings_array) {
1038- assert (index < array->length (), " no strings should have been added" );
1039- array->obj_at_put (index, string);
1040- } else {
1041- int primary_index = index >> _secondary_array_index_bits;
1042- int secondary_index = index & _secondary_array_index_mask;
1038+ auto copy_into_array = [&] (WeakHandle* val) {
1039+ oop string = val->peek ();
1040+ if (string != nullptr && !ArchiveHeapWriter::is_string_too_large_to_archive (string)) {
1041+ // If string is too large, don't put it into the string table.
1042+ // - If there are no other refernences to it, it won't be stored into the archive,
1043+ // so we are all good.
1044+ // - If there's a referece to it, we will report an error inside HeapShared.cpp and
1045+ // dumping will fail.
1046+ HeapShared::add_to_dumped_interned_strings (string);
1047+ if (!_is_two_dimensional_shared_strings_array) {
1048+ assert (index < array->length (), " no strings should have been added" );
1049+ array->obj_at_put (index, string);
1050+ } else {
1051+ int primary_index = index >> _secondary_array_index_bits;
1052+ int secondary_index = index & _secondary_array_index_mask;
10431053
1044- assert (primary_index < array->length (), " no strings should have been added" );
1045- objArrayOop secondary = (objArrayOop)array->obj_at (primary_index);
1054+ assert (primary_index < array->length (), " no strings should have been added" );
1055+ objArrayOop secondary = (objArrayOop)array->obj_at (primary_index);
10461056
1047- assert (secondary != nullptr && secondary->is_objArray (), " must be" );
1048- assert (secondary_index < secondary->length (), " no strings should have been added" );
1049- secondary->obj_at_put (secondary_index, string);
1057+ assert (secondary != nullptr && secondary->is_objArray (), " must be" );
1058+ assert (secondary_index < secondary->length (), " no strings should have been added" );
1059+ secondary->obj_at_put (secondary_index, string);
1060+ }
1061+ index ++;
10501062 }
1051-
1052- index ++;
1063+ return true ;
10531064 };
1054- dumped_interned_strings->iterate_all (copy_into_array);
10551065
1066+ _local_table->do_safepoint_scan (copy_into_array);
1067+ log_info (cds)(" Archived %d interned strings" , index);
10561068 return array;
1057- }
1069+ };
10581070
1059- void StringTable::write_shared_table (const DumpedInternedStrings* dumped_interned_strings ) {
1071+ void StringTable::write_shared_table () {
10601072 _shared_table.reset ();
10611073 CompactHashtableWriter writer ((int )_items_count, ArchiveBuilder::string_stats ());
10621074
10631075 int index = 0 ;
1064- auto copy_into_shared_table = [&] (oop string, bool value_ignored) {
1065- unsigned int hash = java_lang_String::hash_code (string);
1066- writer.add (hash, index);
1067- index ++;
1076+ auto copy_into_shared_table = [&] (WeakHandle* val) {
1077+ oop string = val->peek ();
1078+ if (string != nullptr && !ArchiveHeapWriter::is_string_too_large_to_archive (string)) {
1079+ unsigned int hash = java_lang_String::hash_code (string);
1080+ writer.add (hash, index);
1081+ index ++;
1082+ }
1083+ return true ;
10681084 };
1069- dumped_interned_strings->iterate_all (copy_into_shared_table);
1070-
1085+ _local_table->do_safepoint_scan (copy_into_shared_table);
10711086 writer.dump (&_shared_table, " string" );
10721087}
10731088
0 commit comments