@@ -754,32 +754,7 @@ oop StringTable::lookup_shared(const jchar* name, int len) {
754754 return _shared_table.lookup (name, java_lang_String::hash_code (name, len), len);
755755}
756756
757- oop StringTable::create_archived_string (oop s) {
758- assert (DumpSharedSpaces, " this function is only used with -Xshare:dump" );
759- assert (java_lang_String::is_instance (s), " sanity" );
760- assert (!HeapShared::is_archived_object_during_dumptime (s), " sanity" );
761-
762- oop new_s = nullptr ;
763- typeArrayOop v = java_lang_String::value_no_keepalive (s);
764- typeArrayOop new_v = (typeArrayOop)HeapShared::archive_object (v);
765- if (new_v == nullptr ) {
766- return nullptr ;
767- }
768- new_s = HeapShared::archive_object (s);
769- if (new_s == nullptr ) {
770- return nullptr ;
771- }
772-
773- // adjust the pointer to the 'value' field in the new String oop
774- java_lang_String::set_value_raw (new_s, new_v);
775- // Prevent string deduplication from changing the 'value' field to
776- // something not in the archive before building the archive. Also marks
777- // the shared string when loaded.
778- java_lang_String::set_deduplication_forbidden (new_s);
779- return new_s;
780- }
781-
782- class CopyToArchive : StackObj {
757+ class EncodeSharedStringsAsOffsets : StackObj {
783758 CompactHashtableWriter* _writer;
784759private:
785760 u4 compute_delta (oop s) {
@@ -792,34 +767,35 @@ class CopyToArchive : StackObj {
792767 return (u4)offset;
793768 }
794769public:
795- CopyToArchive (CompactHashtableWriter* writer) : _writer(writer) {}
770+ EncodeSharedStringsAsOffsets (CompactHashtableWriter* writer) : _writer(writer) {}
796771 bool do_entry (oop s, bool value_ignored) {
797772 assert (s != nullptr , " sanity" );
798- unsigned int hash = java_lang_String::hash_code (s);
799- oop new_s = StringTable::create_archived_string (s);
800- if (new_s == nullptr ) {
801- return true ;
802- }
803-
804- // add to the compact table
805- if (UseCompressedOops) {
806- _writer->add (hash, CompressedOops::narrow_oop_value (new_s));
807- } else {
808- _writer->add (hash, compute_delta (new_s));
773+ oop new_s = HeapShared::find_archived_heap_object (s);
774+ if (new_s != nullptr ) { // could be null if the string is too big
775+ unsigned int hash = java_lang_String::hash_code (s);
776+ if (UseCompressedOops) {
777+ _writer->add (hash, CompressedOops::narrow_oop_value (new_s));
778+ } else {
779+ _writer->add (hash, compute_delta (new_s));
780+ }
809781 }
810- return true ;
782+ return true ; // keep iterating
811783 }
812784};
813785
814- void StringTable::write_to_archive (const DumpedInternedStrings* dumped_interned_strings) {
786+ // Write the _shared_table (a CompactHashtable) into the CDS archive file.
787+ void StringTable::write_shared_table (const DumpedInternedStrings* dumped_interned_strings) {
815788 assert (HeapShared::can_write (), " must be" );
816789
817790 _shared_table.reset ();
818791 CompactHashtableWriter writer (_items_count, ArchiveBuilder::string_stats ());
819792
820- // Copy the interned strings into the "string space" within the java heap
821- CopyToArchive copier (&writer);
822- dumped_interned_strings->iterate(&copier);
793+ // Encode the strings in the CompactHashtable using offsets -- we know that the
794+ // strings will not move during runtime because they are inside the G1 closed
795+ // archive region.
796+ EncodeSharedStringsAsOffsets offset_finder (&writer);
797+ dumped_interned_strings->iterate(&offset_finder);
798+
823799 writer.dump (&_shared_table, " string" );
824800}
825801
0 commit comments