RFR: 8324648: Avoid NoSuchMethodError when instantiating NativePRNG [v2]

Oli Gillespie ogillespie at openjdk.org
Tue Feb 6 10:41:55 UTC 2024


> 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

Oli Gillespie has updated the pull request incrementally with one additional commit since the last revision:

  Throw exception if params non-null, remove original constructors

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/17560/files
  - new: https://git.openjdk.org/jdk/pull/17560/files/d537b80c..de4d83ac

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=17560&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=17560&range=00-01

  Stats: 27 lines in 1 file changed: 9 ins; 15 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/17560.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17560/head:pull/17560

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



More information about the security-dev mailing list