RFR: 8286978: SIGBUS in libz during CDS initialization [v2]
Ioi Lam
iklam at openjdk.java.net
Fri May 20 14:51:59 UTC 2022
On Fri, 20 May 2022 06:23:57 GMT, Ioi Lam <iklam at openjdk.org> wrote:
>> Calvin Cheung has updated the pull request incrementally with one additional commit since the last revision:
>>
>> corrected the condition of the while loop, removed an unneeded line of code
>
> test/lib/jdk/test/lib/cds/CDSArchiveUtils.java line 440:
>
>> 438: transferFrom(inputChannel, outputChannel, 0, offset);
>> 439: outputChannel.position(offset);
>> 440: outputChannel.write(ByteBuffer.wrap(bytes));
>
> The changes for transferFrom looks good, but we still have a problem with outputChannel.write(), which can also return fewer bytes than requested (or even zero).
>
> For simplicity, I think it's best to ditch FileChannel and use FileOutputStream.write() instead.
Another option is to avoid using outputChannel.write(). Instead, duplicate some bytes from the end of the header.
public static File insertBytesRandomlyAfterHeader(File orgFile, String newFileName) throws Exception {
long headerSize = fileHeaderSize(orgFile);
long dupSize = getRandomBetween(0L, headerSize);
File dstFile = new File(newFileName);
try (FileChannel inputChannel = new FileInputStream(orgFile).getChannel();
FileChannel outputChannel = new FileOutputStream(dstFile).getChannel()) {
long orgSize = inputChannel.size();
// Copy the header
transferFrom(inputChannel, outputChannel, 0, headerSize);
// Copy dupSize bytes from the end of the header. Then, copy the rest
// of the input such that the new file will have the same size as
// the old file.
inputChannel.position(headerSize - dupSize);
transferFrom(inputChannel, outputChannel, headerSize, orgSize - headerSize);
}
return dstFile;
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/8799
More information about the hotspot-runtime-dev
mailing list