153 assert(N == JVM_IDENT_MAX, "Bad header_version size"); |
153 assert(N == JVM_IDENT_MAX, "Bad header_version size"); |
154 |
154 |
155 const char *vm_version = VM_Version::internal_vm_info_string(); |
155 const char *vm_version = VM_Version::internal_vm_info_string(); |
156 const int version_len = (int)strlen(vm_version); |
156 const int version_len = (int)strlen(vm_version); |
157 |
157 |
|
158 memset(header_version, 0, JVM_IDENT_MAX); |
|
159 |
158 if (version_len < (JVM_IDENT_MAX-1)) { |
160 if (version_len < (JVM_IDENT_MAX-1)) { |
159 strcpy(header_version, vm_version); |
161 strcpy(header_version, vm_version); |
160 |
162 |
161 } else { |
163 } else { |
162 // Get the hash value. Use a static seed because the hash needs to return the same |
164 // Get the hash value. Use a static seed because the hash needs to return the same |
168 |
170 |
169 // Append the hash code as eight hex digits. |
171 // Append the hash code as eight hex digits. |
170 sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash); |
172 sprintf(&header_version[JVM_IDENT_MAX-9], "%08x", hash); |
171 header_version[JVM_IDENT_MAX-1] = 0; // Null terminate. |
173 header_version[JVM_IDENT_MAX-1] = 0; // Null terminate. |
172 } |
174 } |
|
175 |
|
176 assert(header_version[JVM_IDENT_MAX-1] == 0, "must be"); |
173 } |
177 } |
174 |
178 |
175 FileMapInfo::FileMapInfo(bool is_static) { |
179 FileMapInfo::FileMapInfo(bool is_static) { |
176 memset((void*)this, 0, sizeof(FileMapInfo)); |
180 memset((void*)this, 0, sizeof(FileMapInfo)); |
177 _is_static = is_static; |
181 _is_static = is_static; |
728 size_t n = os::read(fd, _header, (unsigned int)sz); |
732 size_t n = os::read(fd, _header, (unsigned int)sz); |
729 if (n != sz) { |
733 if (n != sz) { |
730 fail_continue("Unable to read the file header."); |
734 fail_continue("Unable to read the file header."); |
731 return false; |
735 return false; |
732 } |
736 } |
|
737 |
|
738 if (!Arguments::has_jimage()) { |
|
739 FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build."); |
|
740 return false; |
|
741 } |
|
742 |
|
743 unsigned int expected_magic = is_static ? CDS_ARCHIVE_MAGIC : CDS_DYNAMIC_ARCHIVE_MAGIC; |
|
744 if (_header->_magic != expected_magic) { |
|
745 log_info(cds)("_magic expected: 0x%08x", expected_magic); |
|
746 log_info(cds)(" actual: 0x%08x", _header->_magic); |
|
747 FileMapInfo::fail_continue("The shared archive file has a bad magic number."); |
|
748 return false; |
|
749 } |
|
750 |
733 if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) { |
751 if (_header->_version != CURRENT_CDS_ARCHIVE_VERSION) { |
|
752 log_info(cds)("_version expected: %d", CURRENT_CDS_ARCHIVE_VERSION); |
|
753 log_info(cds)(" actual: %d", _header->_version); |
734 fail_continue("The shared archive file has the wrong version."); |
754 fail_continue("The shared archive file has the wrong version."); |
735 return false; |
755 return false; |
736 } |
756 } |
|
757 |
|
758 if (_header->_header_size != sz) { |
|
759 log_info(cds)("_header_size expected: " SIZE_FORMAT, sz); |
|
760 log_info(cds)(" actual: " SIZE_FORMAT, _header->_header_size); |
|
761 FileMapInfo::fail_continue("The shared archive file has an incorrect header size."); |
|
762 return false; |
|
763 } |
|
764 |
|
765 if (_header->_jvm_ident[JVM_IDENT_MAX-1] != 0) { |
|
766 FileMapInfo::fail_continue("JVM version identifier is corrupted."); |
|
767 return false; |
|
768 } |
|
769 |
|
770 char header_version[JVM_IDENT_MAX]; |
|
771 get_header_version(header_version); |
|
772 if (strncmp(_header->_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) { |
|
773 log_info(cds)("_jvm_ident expected: %s", header_version); |
|
774 log_info(cds)(" actual: %s", _header->_jvm_ident); |
|
775 FileMapInfo::fail_continue("The shared archive file was created by a different" |
|
776 " version or build of HotSpot"); |
|
777 return false; |
|
778 } |
|
779 |
|
780 if (VerifySharedSpaces) { |
|
781 int expected_crc = _header->compute_crc(); |
|
782 if (expected_crc != _header->_crc) { |
|
783 log_info(cds)("_crc expected: %d", expected_crc); |
|
784 log_info(cds)(" actual: %d", _header->_crc); |
|
785 FileMapInfo::fail_continue("Header checksum verification failed."); |
|
786 return false; |
|
787 } |
|
788 } |
|
789 |
737 _file_offset = n; |
790 _file_offset = n; |
738 |
791 |
739 size_t info_size = _header->_paths_misc_info_size; |
792 size_t info_size = _header->_paths_misc_info_size; |
740 _paths_misc_info = NEW_C_HEAP_ARRAY(char, info_size, mtClass); |
793 _paths_misc_info = NEW_C_HEAP_ARRAY(char, info_size, mtClass); |
741 n = os::read(fd, _paths_misc_info, (unsigned int)info_size); |
794 n = os::read(fd, _paths_misc_info, (unsigned int)info_size); |
746 return false; |
799 return false; |
747 } |
800 } |
748 _file_offset += n + _header->_base_archive_name_size; // accounts for the size of _base_archive_name |
801 _file_offset += n + _header->_base_archive_name_size; // accounts for the size of _base_archive_name |
749 |
802 |
750 if (is_static) { |
803 if (is_static) { |
751 if (_header->_magic != CDS_ARCHIVE_MAGIC) { |
|
752 fail_continue("Incorrect static archive magic number"); |
|
753 return false; |
|
754 } |
|
755 // just checking the last region is sufficient since the archive is written |
804 // just checking the last region is sufficient since the archive is written |
756 // in sequential order |
805 // in sequential order |
757 size_t len = lseek(fd, 0, SEEK_END); |
806 size_t len = lseek(fd, 0, SEEK_END); |
758 CDSFileMapRegion* si = space_at(MetaspaceShared::last_valid_region); |
807 CDSFileMapRegion* si = space_at(MetaspaceShared::last_valid_region); |
759 // The last space might be empty |
808 // The last space might be empty |
1587 return crc; |
1636 return crc; |
1588 } |
1637 } |
1589 |
1638 |
1590 // This function should only be called during run time with UseSharedSpaces enabled. |
1639 // This function should only be called during run time with UseSharedSpaces enabled. |
1591 bool FileMapHeader::validate() { |
1640 bool FileMapHeader::validate() { |
1592 if (VerifySharedSpaces && compute_crc() != _crc) { |
1641 |
1593 FileMapInfo::fail_continue("Header checksum verification failed."); |
|
1594 return false; |
|
1595 } |
|
1596 |
|
1597 if (!Arguments::has_jimage()) { |
|
1598 FileMapInfo::fail_continue("The shared archive file cannot be used with an exploded module build."); |
|
1599 return false; |
|
1600 } |
|
1601 |
|
1602 if (_version != CURRENT_CDS_ARCHIVE_VERSION) { |
|
1603 FileMapInfo::fail_continue("The shared archive file is the wrong version."); |
|
1604 return false; |
|
1605 } |
|
1606 if (_magic != CDS_ARCHIVE_MAGIC && _magic != CDS_DYNAMIC_ARCHIVE_MAGIC) { |
|
1607 FileMapInfo::fail_continue("The shared archive file has a bad magic number."); |
|
1608 return false; |
|
1609 } |
|
1610 char header_version[JVM_IDENT_MAX]; |
|
1611 get_header_version(header_version); |
|
1612 if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) { |
|
1613 log_info(class, path)("expected: %s", header_version); |
|
1614 log_info(class, path)("actual: %s", _jvm_ident); |
|
1615 FileMapInfo::fail_continue("The shared archive file was created by a different" |
|
1616 " version or build of HotSpot"); |
|
1617 return false; |
|
1618 } |
|
1619 if (_obj_alignment != ObjectAlignmentInBytes) { |
1642 if (_obj_alignment != ObjectAlignmentInBytes) { |
1620 FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d" |
1643 FileMapInfo::fail_continue("The shared archive file's ObjectAlignmentInBytes of %d" |
1621 " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".", |
1644 " does not equal the current ObjectAlignmentInBytes of " INTX_FORMAT ".", |
1622 _obj_alignment, ObjectAlignmentInBytes); |
1645 _obj_alignment, ObjectAlignmentInBytes); |
1623 return false; |
1646 return false; |