RFR: 8279018: CRC calculation in CDS should not include _version and _head_size

Ioi Lam iklam at openjdk.java.net
Mon Dec 20 22:34:31 UTC 2021


On Mon, 20 Dec 2021 20:30:15 GMT, Yumin Qi <minqi at openjdk.org> wrote:

> Please review the simple change for not including _version and _header_size in crc computation. These two fields are checked separately and they should not affect crc.
> 
> tests: tier1,tier4
> 
> Thanks
> Yumin

Also, I think the _crc field should not be moved. That's because all previous version of CDS (since JDK 8) have the following 3 fields at the beginning of the CDS archive file:


    int    _magic;                    // identify file type.
    int    _crc;                      // header crc checksum.
    int    _version;                  // (from enum, above.)


If we move the `_crc` field,  the VM will not be correctly reading the `_version` of a CDS file generated by an older version of the JDK. This will make it difficult to implement [JDK-8261455](https://bugs.openjdk.java.net/browse/JDK-8261455) - Automatically generate the CDS archive if necessary.

I think the correct fix of this bug is to change the following:


int FileMapHeader::compute_crc() {
  char* start = (char*)this;
  // start computing from the field after _crc to end of base archive name.
-  char* buf = (char*)&(_generic_header._crc) + sizeof(_generic_header._crc);
+  char* buf = (char*)&(_generic_header._header_size) + sizeof(_generic_header._header_size);


Also, CURRENT_CDS_ARCHIVE_VERSION and CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION 
need to be updated to 13 because the meaning of the `_crc` field has changed.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6899


More information about the hotspot-runtime-dev mailing list