RFR: 8336240: Test com/sun/crypto/provider/Cipher/DES/PerformanceTest.java fails with java.lang.ArithmeticException [v2]
Fernando Guallini
fguallini at openjdk.org
Wed Jul 17 15:15:53 UTC 2024
On Mon, 15 Jul 2024 09:36:28 GMT, Fernando Guallini <fguallini at openjdk.org> wrote:
>> test/jdk/com/sun/crypto/provider/Cipher/DES/PerformanceTest.java line 186:
>>
>>> 184: end = System.currentTimeMillis();
>>> 185:
>>> 186: // To avoid diving by zero if end is equal to start
>>
>> Test is performing 100 and 1000 rounds of `update`. I don't think we are seeing same start and end. Please test further to determine root cause. Could be the case of overflow if `update` is taking long time.
>
> The root cause is that start and end are equal, leading to the exception ArithmeticException: / by zero. These rounds can execute very quickly; on a macOS platform, they can take as little as 1 millisecond.
>
> This issue is easily reproducible on platforms where System.currentTimeMillis() has low precision, such as many versions of Windows, end and start can be equal when obtaining System.currentTimeMillis() if the rounds run very quickly. (just updated the PR description including this information)
We can use System.nanoTime() instead, which is designed to measure elapsed time with very high precision. This overcomes the issue on platforms with low granularity, and we should no longer see end - start = 0.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20135#discussion_r1681237982
More information about the security-dev
mailing list