RFR: 8286978: SIGBUS in libz during CDS initialization [v2]
Calvin Cheung
ccheung at openjdk.java.net
Fri May 20 17:23:42 UTC 2022
On Fri, 20 May 2022 14:48:36 GMT, Ioi Lam <iklam at openjdk.org> wrote:
>> 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;
> }
Thanks for the suggestions. I've pushed another commit with the above changes. I also changed the callsite in SharedArchiveConsistency.java since there's no need to pass in a byte array.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8799
More information about the hotspot-runtime-dev
mailing list