RFR[12] JDK-8179098 "Crypto AES/ECB encryption/decryption performance regression (introduced in jdk9b73)"

Claes Redestad claes.redestad at oracle.com
Wed Jul 11 18:41:35 UTC 2018

FWIW, but as we're in java.base there's a way to use the 
jdk.internal.util.Preconditions API backing Objects.checkFrom* methods 
directly, which lets you control the type of exception thrown:

private static final BiFunction<String, List<Integer>, ArrayIndexOutOfBoundsException> AIOOBE_SUPPLIER
     = Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new);

public static void nullAndBoundsCheck(byte[] array, int offset, int len) {
     Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER); // implicit null check of array

Prior art is really only the java.lang.invoke.VarHandle.AIOOBE_SUPPLIER (which is used from generated code, e.g. j.l.i.VarHandleInts); maybe it could be refactored to some internal package for reuse.

(I'd remove the explicit null check and lower-case the N in NullAndBoundsCheck, regardless)



On 2018-07-10 02:42, Valerie Peng wrote:
> Hi Tony,
> The purpose of the if-block is to ensure that 
> ArrayIndexOutOfBoundsException is thrown instead of 
> IndexOutOfBoundsException.  Objects.checkFromIndexSize(...) API is 
> specified to throw IndexOutOfBoundsException which is more general and 
> can be thrown when an index of some sort (such as to an array, to a 
> string, or to a vector) is out of range. 
> ArrayIndexOutOfBoundsException is a subclass of 
> IndexOutOfBoundsException and is for array index out of bounds.
> Thanks,
> Valerie
> On 7/9/2018 3:14 PM, Anthony Scarpino wrote:
>> On 07/03/2018 02:03 PM, Valerie Peng wrote:
>>> Hi Tony,
>>> Would you have time to review this? Instead of doing the bounds 
>>> check per block, the changes move the bounds check up one level.
>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8179098
>>> Webrev: http://cr.openjdk.java.net/~valeriep/8179098/webrev.00/
>>> Thanks,
>>> Valerie
>> ArrayUtil.java: Line 48
>> - It seems like your not throwing any 
>> ArrayIndexOutOfBoundsExceptions, is that intentional? The method in 
>> the try-catch seems to only throw IndexOutOfBoundsException, whole 
>> if() seems confusing to me.
>> thanks
>> Tony

More information about the security-dev mailing list