<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Tony,<div class=""><br class=""></div><div class="">while running regression tests, I noticed that my assumption only holds true for unpadded ciphers. For padded ciphers, we still need the temporary buffer, as only the unpadded cleartext shall be written to the output buffer.</div><div class=""><br class=""></div><div class="">That said, here is my PR. I'd be happy if you could review it (and act as a sponsor for the commit): <a href="https://github.com/openjdk/jdk/pull/7230" class="">https://github.com/openjdk/jdk/pull/7230</a></div><div class=""><br class=""></div><div class="">Cheers!</div><div class="">Sebastian<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 25. Jan 2022, at 22:43, Anthony Scarpino <<a href="mailto:anthony.scarpino@oracle.com" class="">anthony.scarpino@oracle.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi,<br class=""><br class="">I think it's a mistake. Looking at the old code I believe the if() for cipher.save() above that was suppose to include the new byte allocation and offset, but got missed.<br class=""><br class="">Feel free to fix it if you like.  Let me know if you need something.<br class=""><br class="">Tony<br class=""><br class="">On 1/25/22 12:06 PM, Sebastian Stenzel wrote:<br class=""><blockquote type="cite" class="">Hi all,<br class="">while playing around with JFR today, I stumbled upon a piece of code that causes a thousands of byte[] allocations. In fact it is responsible for 90% of the memory allocations in my application and causes GC to run without pause during decryption of large files.<br class="">The line in question can be found here [1]. The behaviour can be triggered with a simple AES-CTR cipher as in this minimal example [2].<br class="">As you can see, the comments in [1] even say that this byte[] _should_ only be allocated if there is insufficient space in the provided output buffer. However some kind of conditional statement is missing.<br class="">There used to be a `if (getMode() != GCM_MODE || outputCapacity < estOutSize)`, before GCM has been decoupled from CipherCore. But this line seems wrong to me either.<br class="">I guess this should be fixed, as I'm probably not the only one affected by those allocations. I'd be volunteering, unless the behaviour is intended.<br class="">Cheers!<br class="">Sebastian<br class="">[1] <a href="https://github.com/openjdk/jdk/blob/76fe03fe01a7c824e2e9263de95b8bcbb4b9d752/src/java.base/share/classes/com/sun/crypto/provider/CipherCore.java#L815-L818" class="">https://github.com/openjdk/jdk/blob/76fe03fe01a7c824e2e9263de95b8bcbb4b9d752/src/java.base/share/classes/com/sun/crypto/provider/CipherCore.java#L815-L818</a> <<a href="https://github.com/openjdk/jdk/blob/76fe03fe01a7c824e2e9263de95b8bcbb4b9d752/src/java.base/share/classes/com/sun/crypto/provider/CipherCore.java#L815-L818" class="">https://github.com/openjdk/jdk/blob/76fe03fe01a7c824e2e9263de95b8bcbb4b9d752/src/java.base/share/classes/com/sun/crypto/provider/CipherCore.java#L815-L818</a>><br class="">[2] <a href="https://gist.github.com/overheadhunter/f3969950c0fdbaecaa77c857b2246cc5" class="">https://gist.github.com/overheadhunter/f3969950c0fdbaecaa77c857b2246cc5</a> <<a href="https://gist.github.com/overheadhunter/f3969950c0fdbaecaa77c857b2246cc5" class="">https://gist.github.com/overheadhunter/f3969950c0fdbaecaa77c857b2246cc5</a>><br class=""></blockquote></div></div></blockquote></div><br class=""></div></body></html>