RFR: 8296507: GCM using more memory than necessary with in-place operations [v2]

Anthony Scarpino ascarpino at openjdk.org
Thu Dec 1 04:14:24 UTC 2022


On Thu, 1 Dec 2022 02:10:01 GMT, Valerie Peng <valeriep at openjdk.org> wrote:

>> Anthony Scarpino has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   comment cleanup & finesse ByteBuffer implGCMCrypt better
>
> src/java.base/share/classes/com/sun/crypto/provider/GaloisCounterMode.java line 778:
> 
>> 776:                             gctr, ghash);
>> 777:                     } else {
>> 778:                         int ofs = src.arrayOffset() + src.position();
> 
> Isn't this also used on line 774? Why not move this up and directly refer to it for both places?

The line 774 case only uses the calculated value once.  I'm avoiding the unnecessary store & load operations when it is set the value to a variable. I see it when I run  javap -c to view the bytecode.  It's purely an optimization for performance.   I do set it to the variable in the line 778 case because calculating the value twice is probably more expensive than once with the store & load operations.

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

PR: https://git.openjdk.org/jdk/pull/11121



More information about the security-dev mailing list