Skip to content

Use ThreadLocal caching for ExtendedRandom PRNG contexts#1508

Open
taoliult wants to merge 2 commits into
IBM:java25from
taoliult:java25_securerandom_native_2
Open

Use ThreadLocal caching for ExtendedRandom PRNG contexts#1508
taoliult wants to merge 2 commits into
IBM:java25from
taoliult:java25_securerandom_native_2

Conversation

@taoliult

@taoliult taoliult commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Add ThreadLocal caching for native PRNG contexts used by ExtendedRandom. Each thread creates and reuses a PRNG context for supported DRBG algorithms.

This avoids repeated EXTRAND_create calls when instances are created frequently.

Benefits:

  • Reduce native allocation overhead
  • Reuse PRNG contexts per thread
  • Improve performance in RNG-heavy workloads

This PR is back-ported from PR #1255

taoliult added 2 commits June 11, 2026 13:28
Add ThreadLocal caching for native PRNG contexts used by
ExtendedRandom. Each thread creates and reuses a PRNG
context for supported DRBG algorithms.

This avoids repeated EXTRAND_create calls when instances
are created frequently.

Benefits:
- Reduce native allocation overhead
- Reuse PRNG contexts per thread
- Improve performance in RNG-heavy workloads

Signed-off-by: Tao Liu <tao.liu@ibm.com>
ThreadLocal can cause native TCB context issues on z/OS. This
change bypasses ThreadLocal on z/OS by creating instance-specific
PRNG contexts, while other platforms continue using ThreadLocal
for performance.

Signed-off-by: Tao Liu <tao.liu@ibm.com>
@taoliult taoliult force-pushed the java25_securerandom_native_2 branch from f13ded4 to 235c7da Compare June 11, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant