RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted [v17]

Vladimir Sitnikov vsitnikov at openjdk.org
Thu Dec 28 15:09:09 UTC 2023


On Sat, 23 Dec 2023 13:01:09 GMT, Markus KARG <duke at openjdk.org> wrote:

>Typically it was sufficient to document the JMH results before and after a PR just once (not dynamically in the form of a test).

The problem with "results before and after a PR just once" is those benchmarks will not automatically fail the build if somebody else breaks the optimization unintentionally. In other words, benchmarks do not serve as a safety net.

At the same time, if the test code were to ensure "less than 20 bytes allocated" in a common case of transferring data from `BufferedInputStream` to `ByteArrayOutputStream`, then it would be a nice safety net so the optimization will not be broken unintentionally.

>The latter should be rather easy to check: Invoke transferTo(out) two times in a row and compare the identity of the two byte arrays passed to out.write(). If they stay the same, then apparently no temporary copy was created. Two achieve this, the BIS must be wrapper around an extendable input stream (like FileInputStream) so between calls the stream could get extended (e. g. by writing into the file)

Markus, I am afraid you missed that anything that "extends FileOutputStream" (I assume you mean `FileOutputStream`, not `FileInputStream`) would **not** qualify as a trusted stream, and `transferTo` will make a copy. The current check is `clazz == FileOutputStream.class`

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16879#discussion_r1435625914


More information about the core-libs-dev mailing list