198 if (_is_static) {
199 assert(_current_info == this, "must be singleton"); // not thread safe
200 _current_info = NULL;
201 } else {
202 assert(_dynamic_archive_info == this, "must be singleton"); // not thread safe
203 _dynamic_archive_info = NULL;
204 }
205 }
206
207 void FileMapInfo::populate_header(size_t alignment) {
208 _header->populate(this, alignment);
209 }
210
211 void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
212 if (DynamicDumpSharedSpaces) {
213 _magic = CDS_DYNAMIC_ARCHIVE_MAGIC;
214 } else {
215 _magic = CDS_ARCHIVE_MAGIC;
216 }
217 _version = CURRENT_CDS_ARCHIVE_VERSION;
218 _alignment = alignment;
219 _obj_alignment = ObjectAlignmentInBytes;
220 _compact_strings = CompactStrings;
221 _narrow_oop_mode = CompressedOops::mode();
222 _narrow_oop_base = CompressedOops::base();
223 _narrow_oop_shift = CompressedOops::shift();
224 _max_heap_size = MaxHeapSize;
225 _narrow_klass_base = CompressedKlassPointers::base();
226 _narrow_klass_shift = CompressedKlassPointers::shift();
227 _shared_path_table = mapinfo->_shared_path_table;
228 if (HeapShared::is_heap_object_archiving_allowed()) {
229 _heap_reserved = Universe::heap()->reserved_region();
230 }
231
232 // The following fields are for sanity checks for whether this archive
233 // will function correctly with this JVM and the bootclasspath it's
234 // invoked with.
235
236 // JVM version string ... changes on each build.
237 get_header_version(_jvm_ident);
874 }
875
876 os::free(dynamic_header);
877 os::close(fd);
878 return true;
879 }
880
881 void FileMapInfo::restore_shared_path_table() {
882 _shared_path_table = _current_info->_header->_shared_path_table;
883 }
884
885 // Read the FileMapInfo information from the file.
886
887 bool FileMapInfo::init_from_file(int fd, bool is_static) {
888 size_t sz = is_static ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader);
889 size_t n = os::read(fd, _header, (unsigned int)sz);
890 if (n != sz) {
891 fail_continue("Unable to read the file header.");
892 return false;
893 }
894 if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) {
895 fail_continue("The shared archive file has the wrong version.");
896 return false;
897 }
898 _file_offset = n;
899
900 size_t info_size = _header->_paths_misc_info_size;
901 _paths_misc_info = NEW_C_HEAP_ARRAY(char, info_size, mtClass);
902 n = os::read(fd, _paths_misc_info, (unsigned int)info_size);
903 if (n != info_size) {
904 fail_continue("Unable to read the shared path info header.");
905 FREE_C_HEAP_ARRAY(char, _paths_misc_info);
906 _paths_misc_info = NULL;
907 return false;
908 }
909 _file_offset += n + _header->_base_archive_name_size; // accounts for the size of _base_archive_name
910
911 if (is_static) {
912 if (_header->_magic != CDS_ARCHIVE_MAGIC) {
913 fail_continue("Incorrect static archive magic number");
914 return false;
915 }
916 // just checking the last region is sufficient since the archive is written
917 // in sequential order
1733 if (HeapShared::is_heap_region(idx)) {
1734 assert(DumpSharedSpaces, "The following doesn't work at runtime");
1735 return si->_used > 0 ?
1736 (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL;
1737 } else {
1738 return si->_addr._base;
1739 }
1740 }
1741
1742 int FileMapHeader::compute_crc() {
1743 char* start = (char*)this;
1744 // start computing from the field after _crc
1745 char* buf = (char*)&_crc + sizeof(_crc);
1746 size_t sz = _header_size - (buf - start);
1747 int crc = ClassLoader::crc32(0, buf, (jint)sz);
1748 return crc;
1749 }
1750
1751 // This function should only be called during run time with UseSharedSpaces enabled.
1752 bool FileMapHeader::validate() {
1753 if (VerifySharedSpaces && compute_crc() != _crc) {
1754 FileMapInfo::fail_continue("Header checksum verification failed.");
1755 return false;
1756 }
1757
1758 if (!Arguments::has_jimage()) {
1759 FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
1760 return false;
1761 }
1762
1763 if (_version != CURRENT_CDS_ARCHIVE_VERSION) {
1764 FileMapInfo::fail_continue("The shared archive file is the wrong version.");
1765 return false;
1766 }
1767 if (_magic != CDS_ARCHIVE_MAGIC && _magic != CDS_DYNAMIC_ARCHIVE_MAGIC) {
1768 FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
1769 return false;
1770 }
1771 char header_version[JVM_IDENT_MAX];
1772 get_header_version(header_version);
1773 if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
1774 log_info(class, path)("expected: %s", header_version);
1775 log_info(class, path)("actual: %s", _jvm_ident);
1776 FileMapInfo::fail_continue("The shared archive file was created by a different"
1777 " version or build of HotSpot");
1778 return false;
1779 }
1780 if (_obj_alignment != ObjectAlignmentInBytes) {
1781 FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
1782 " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".",
1783 _obj_alignment, ObjectAlignmentInBytes);
1784 return false;
1785 }
1786 if (_compact_strings != CompactStrings) {
1787 FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)"
1788 " does not equal the current CompactStrings setting (%s).",
1789 _compact_strings ? "enabled" : "disabled",
1790 CompactStrings ? "enabled" : "disabled");
1791 return false;
1792 }
1793
1794 // This must be done after header validation because it might change the
1795 // header data
1796 const char* prop = Arguments::get_property("java.system.class.loader");
1797 if (prop != NULL) {
1798 warning("Archived non-system classes are disabled because the "
1799 "java.system.class.loader property is specified (value = \"%s\"). "
|
198 if (_is_static) {
199 assert(_current_info == this, "must be singleton"); // not thread safe
200 _current_info = NULL;
201 } else {
202 assert(_dynamic_archive_info == this, "must be singleton"); // not thread safe
203 _dynamic_archive_info = NULL;
204 }
205 }
206
207 void FileMapInfo::populate_header(size_t alignment) {
208 _header->populate(this, alignment);
209 }
210
211 void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
212 if (DynamicDumpSharedSpaces) {
213 _magic = CDS_DYNAMIC_ARCHIVE_MAGIC;
214 } else {
215 _magic = CDS_ARCHIVE_MAGIC;
216 }
217 _version = CURRENT_CDS_ARCHIVE_VERSION;
218 _end_magic = CDS_END_MAGIC;
219 _alignment = alignment;
220 _obj_alignment = ObjectAlignmentInBytes;
221 _compact_strings = CompactStrings;
222 _narrow_oop_mode = CompressedOops::mode();
223 _narrow_oop_base = CompressedOops::base();
224 _narrow_oop_shift = CompressedOops::shift();
225 _max_heap_size = MaxHeapSize;
226 _narrow_klass_base = CompressedKlassPointers::base();
227 _narrow_klass_shift = CompressedKlassPointers::shift();
228 _shared_path_table = mapinfo->_shared_path_table;
229 if (HeapShared::is_heap_object_archiving_allowed()) {
230 _heap_reserved = Universe::heap()->reserved_region();
231 }
232
233 // The following fields are for sanity checks for whether this archive
234 // will function correctly with this JVM and the bootclasspath it's
235 // invoked with.
236
237 // JVM version string ... changes on each build.
238 get_header_version(_jvm_ident);
875 }
876
877 os::free(dynamic_header);
878 os::close(fd);
879 return true;
880 }
881
882 void FileMapInfo::restore_shared_path_table() {
883 _shared_path_table = _current_info->_header->_shared_path_table;
884 }
885
886 // Read the FileMapInfo information from the file.
887
888 bool FileMapInfo::init_from_file(int fd, bool is_static) {
889 size_t sz = is_static ? sizeof(FileMapHeader) : sizeof(DynamicArchiveHeader);
890 size_t n = os::read(fd, _header, (unsigned int)sz);
891 if (n != sz) {
892 fail_continue("Unable to read the file header.");
893 return false;
894 }
895
896 if (!Arguments::has_jimage()) {
897 FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build.");
898 return false;
899 }
900
901 if (_header->_magic != CDS_ARCHIVE_MAGIC && _header->_magic != CDS_DYNAMIC_ARCHIVE_MAGIC) {
902 unsigned int expected_magic = is_static ? CDS_ARCHIVE_MAGIC : CDS_DYNAMIC_ARCHIVE_MAGIC;
903 log_info(cds)("_magic expected: 0x%08x", expected_magic);
904 log_info(cds)(" actual: 0x%08x", _header->_magic);
905 FileMapInfo::fail_continue("The shared archive file has a bad magic number.");
906 return false;
907 }
908
909 if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) {
910 log_info(cds)("_version expected: %d", CURRENT_CDS_ARCHIVE_VERSION);
911 log_info(cds)(" actual: %d", _header->_version);
912 fail_continue("The shared archive file has the wrong version.");
913 return false;
914 }
915
916 if (_header->_end_magic != CDS_END_MAGIC) {
917 log_info(cds)("_end_magic expected: 0x%08x", CDS_END_MAGIC);
918 log_info(cds)(" actual: 0x%08x", _header->_end_magic);
919 FileMapInfo::fail_continue("The shared archive file has a bad end magic number.");
920 return false;
921 }
922
923 if (_header->_header_size != sz) {
924 log_info(cds)("_header_size expected: " SIZE_FORMAT, sz);
925 log_info(cds)(" actual: " SIZE_FORMAT, _header->_header_size);
926 FileMapInfo::fail_continue("The shared archive file has an incorrect header size.");
927 return false;
928 }
929
930 char header_version[JVM_IDENT_MAX];
931 get_header_version(header_version);
932 if (strncmp(_header->_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) {
933 log_info(class, path)("expected: %s", header_version);
934 _header->_end_magic = 0x0; // just in case _header->_jvm_ident is not 0-terminated
935 log_info(class, path)("actual: %s", _header->_jvm_ident);
936 FileMapInfo::fail_continue("The shared archive file was created by a different"
937 " version or build of HotSpot");
938 return false;
939 }
940
941 if (VerifySharedSpaces) {
942 int expected_crc = _header->compute_crc();
943 if (expected_crc != _header->_crc) {
944 log_info(cds)("_crc expected: %d", expected_crc);
945 log_info(cds)(" actual: %d", _header->_crc);
946 FileMapInfo::fail_continue("Header checksum verification failed.");
947 return false;
948 }
949 }
950
951 _file_offset = n;
952
953 size_t info_size = _header->_paths_misc_info_size;
954 _paths_misc_info = NEW_C_HEAP_ARRAY(char, info_size, mtClass);
955 n = os::read(fd, _paths_misc_info, (unsigned int)info_size);
956 if (n != info_size) {
957 fail_continue("Unable to read the shared path info header.");
958 FREE_C_HEAP_ARRAY(char, _paths_misc_info);
959 _paths_misc_info = NULL;
960 return false;
961 }
962 _file_offset += n + _header->_base_archive_name_size; // accounts for the size of _base_archive_name
963
964 if (is_static) {
965 if (_header->_magic != CDS_ARCHIVE_MAGIC) {
966 fail_continue("Incorrect static archive magic number");
967 return false;
968 }
969 // just checking the last region is sufficient since the archive is written
970 // in sequential order
1786 if (HeapShared::is_heap_region(idx)) {
1787 assert(DumpSharedSpaces, "The following doesn't work at runtime");
1788 return si->_used > 0 ?
1789 (char*)start_address_as_decoded_with_current_oop_encoding_mode(si) : NULL;
1790 } else {
1791 return si->_addr._base;
1792 }
1793 }
1794
1795 int FileMapHeader::compute_crc() {
1796 char* start = (char*)this;
1797 // start computing from the field after _crc
1798 char* buf = (char*)&_crc + sizeof(_crc);
1799 size_t sz = _header_size - (buf - start);
1800 int crc = ClassLoader::crc32(0, buf, (jint)sz);
1801 return crc;
1802 }
1803
1804 // This function should only be called during run time with UseSharedSpaces enabled.
1805 bool FileMapHeader::validate() {
1806
1807 if (_obj_alignment != ObjectAlignmentInBytes) {
1808 FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d"
1809 " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".",
1810 _obj_alignment, ObjectAlignmentInBytes);
1811 return false;
1812 }
1813 if (_compact_strings != CompactStrings) {
1814 FileMapInfo::fail_continue("The shared archive file's CompactStrings setting (%s)"
1815 " does not equal the current CompactStrings setting (%s).",
1816 _compact_strings ? "enabled" : "disabled",
1817 CompactStrings ? "enabled" : "disabled");
1818 return false;
1819 }
1820
1821 // This must be done after header validation because it might change the
1822 // header data
1823 const char* prop = Arguments::get_property("java.system.class.loader");
1824 if (prop != NULL) {
1825 warning("Archived non-system classes are disabled because the "
1826 "java.system.class.loader property is specified (value = \"%s\"). "
|