On Fri, 22 Dec 2023 14:27:16 GMT, Markus KARG <d...@openjdk.org> wrote:
>> Can anybody give a hint how one can create assertions in OpenJDK test code >> that would check the amount of allocated heap for the tested method? >> >> Since the change here is "removal of an allocation", the assert in the code >> should probably allow only a very small allocation in `.transferTo`. >> >> Does `com.sun.management.ThreadMXBean#getCurrentThreadAllocatedBytes()` >> sound right for the test? > > I think there is a misundertanding. This PR is not intendend to reduce the > *amount* of allocated heap, it is about sparing time by not creating > *temporary copies*. 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, could you please double-check? A temporary allocation *is* an allocation, and it is the point of the change to avoid allocation and copying the temp data when the output stream is known to behave well. I am sure the allocation "before the change" would be non-trivial (more than several KiB), and after the change the allocation within .transferTo would be minimal (few bytes) assuming the output stream has already allocated its buffer ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/16879#discussion_r1435120325