On Wed, 24 Jan 2024 15:42:05 GMT, Oli Gillespie <ogilles...@openjdk.org> wrote:

> A typical call to `new SecureRandom()` is slowed down by looking for a 
> constructor in NativePRNG which takes `java.security.SecureRandomParameters`. 
> NativePRNG does not have such a constructor, so the search fails 
> [here](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/security/Provider.java#L1951-L1957),
>  incurring all the cost of the lookup and creating a subsequent exception.
> 
> Creating a dummy constructor which takes and ignores this parameter will 
> speed up `new SecureRandom()` calls significantly. 
> 
> The benchmark from https://github.com/openjdk/jdk/pull/17559 shows around 80% 
> reduction in time taken to create a new SecureRandom with NativePRNG (default 
> on my machine).
> 
> 
> Before
> SecureRandomBench.newSecureRandom  avgt  2930 ± 50 ns/op
> 
> After
> SecureRandomBench.newSecureRandom  avgt  510 ± 16 ns/op

This pull request has now been integrated.

Changeset: 69b2674c
Author:    Oli Gillespie <ogilles...@openjdk.org>
Committer: Weijun Wang <wei...@openjdk.org>
URL:       
https://git.openjdk.org/jdk/commit/69b2674c6861fdb7d9f9cb39e07d50515c73e33a
Stats:     16 lines in 1 file changed: 9 ins; 3 del; 4 mod

8324648: Avoid NoSuchMethodError when instantiating NativePRNG

Reviewed-by: shade, weijun, liach, valeriep

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

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

Reply via email to