31 #include "gc/shared/collectedHeap.inline.hpp" |
31 #include "gc/shared/collectedHeap.inline.hpp" |
32 #include "gc/shared/gcLocker.inline.hpp" |
32 #include "gc/shared/gcLocker.inline.hpp" |
33 #include "logging/log.hpp" |
33 #include "logging/log.hpp" |
34 #include "memory/allocation.inline.hpp" |
34 #include "memory/allocation.inline.hpp" |
35 #include "memory/filemap.hpp" |
35 #include "memory/filemap.hpp" |
|
36 #include "memory/metaspaceShared.hpp" |
36 #include "memory/resourceArea.hpp" |
37 #include "memory/resourceArea.hpp" |
37 #include "oops/oop.inline.hpp" |
38 #include "oops/oop.inline.hpp" |
38 #include "runtime/atomic.hpp" |
39 #include "runtime/atomic.hpp" |
39 #include "runtime/mutexLocker.hpp" |
40 #include "runtime/mutexLocker.hpp" |
40 #include "services/diagnosticCommand.hpp" |
41 #include "services/diagnosticCommand.hpp" |
729 java_lang_String::set_hash(new_s, hash); |
730 java_lang_String::set_hash(new_s, hash); |
730 } |
731 } |
731 |
732 |
732 // add to the compact table |
733 // add to the compact table |
733 writer->add(hash, new_s); |
734 writer->add(hash, new_s); |
|
735 |
|
736 MetaspaceShared::relocate_klass_ptr(new_s); |
|
737 MetaspaceShared::relocate_klass_ptr(new_v); |
734 } |
738 } |
735 } |
739 } |
736 |
740 |
737 G1CollectedHeap::heap()->end_archive_alloc_range(string_space, os::vm_allocation_granularity()); |
741 G1CollectedHeap::heap()->end_archive_alloc_range(string_space, os::vm_allocation_granularity()); |
738 assert(string_space->length() <= 2, "sanity"); |
742 assert(string_space->length() <= 2, "sanity"); |
739 #endif |
743 #endif |
740 return true; |
744 return true; |
741 } |
745 } |
742 |
746 |
743 void StringTable::serialize(SerializeClosure* soc, GrowableArray<MemRegion> *string_space, |
747 void StringTable::write_to_archive(GrowableArray<MemRegion> *string_space) { |
744 size_t* space_size) { |
748 #if INCLUDE_CDS |
|
749 _shared_table.reset(); |
|
750 if (!(UseG1GC && UseCompressedOops && UseCompressedClassPointers)) { |
|
751 log_info(cds)( |
|
752 "Shared strings are excluded from the archive as UseG1GC, " |
|
753 "UseCompressedOops and UseCompressedClassPointers are required." |
|
754 "Current settings: UseG1GC=%s, UseCompressedOops=%s, UseCompressedClassPointers=%s.", |
|
755 BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedOops), |
|
756 BOOL_TO_STR(UseCompressedClassPointers)); |
|
757 } else { |
|
758 int num_buckets = the_table()->number_of_entries() / |
|
759 SharedSymbolTableBucketSize; |
|
760 // calculation of num_buckets can result in zero buckets, we need at least one |
|
761 CompactStringTableWriter writer(num_buckets > 1 ? num_buckets : 1, |
|
762 &MetaspaceShared::stats()->string); |
|
763 |
|
764 // Copy the interned strings into the "string space" within the java heap |
|
765 if (copy_shared_string(string_space, &writer)) { |
|
766 writer.dump(&_shared_table); |
|
767 } |
|
768 } |
|
769 #endif |
|
770 } |
|
771 |
|
772 void StringTable::serialize(SerializeClosure* soc) { |
745 #if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS) |
773 #if INCLUDE_CDS && defined(_LP64) && !defined(_WINDOWS) |
746 _shared_table.reset(); |
|
747 if (soc->writing()) { |
|
748 if (!(UseG1GC && UseCompressedOops && UseCompressedClassPointers)) { |
|
749 log_info(cds)( |
|
750 "Shared strings are excluded from the archive as UseG1GC, " |
|
751 "UseCompressedOops and UseCompressedClassPointers are required." |
|
752 "Current settings: UseG1GC=%s, UseCompressedOops=%s, UseCompressedClassPointers=%s.", |
|
753 BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedOops), |
|
754 BOOL_TO_STR(UseCompressedClassPointers)); |
|
755 } else { |
|
756 int num_buckets = the_table()->number_of_entries() / |
|
757 SharedSymbolTableBucketSize; |
|
758 // calculation of num_buckets can result in zero buckets, we need at least one |
|
759 CompactStringTableWriter writer(num_buckets > 1 ? num_buckets : 1, |
|
760 &MetaspaceShared::stats()->string); |
|
761 |
|
762 // Copy the interned strings into the "string space" within the java heap |
|
763 if (copy_shared_string(string_space, &writer)) { |
|
764 for (int i = 0; i < string_space->length(); i++) { |
|
765 *space_size += string_space->at(i).byte_size(); |
|
766 } |
|
767 writer.dump(&_shared_table); |
|
768 } |
|
769 } |
|
770 } |
|
771 |
|
772 _shared_table.set_type(CompactHashtable<oop, char>::_string_table); |
774 _shared_table.set_type(CompactHashtable<oop, char>::_string_table); |
773 _shared_table.serialize(soc); |
775 _shared_table.serialize(soc); |
774 |
776 |
775 if (soc->writing()) { |
777 if (soc->writing()) { |
776 _shared_table.reset(); // Sanity. Make sure we don't use the shared table at dump time |
778 _shared_table.reset(); // Sanity. Make sure we don't use the shared table at dump time |