Skip to content

Use ThreadLocal caching for ExtendedRandom PRNG contexts - #1507

Open
taoliult wants to merge 2 commits into
IBM:java26from
taoliult:java26_securerandom_native_2
Open

Use ThreadLocal caching for ExtendedRandom PRNG contexts#1507
taoliult wants to merge 2 commits into
IBM:java26from
taoliult:java26_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

@KostasTsiounis KostasTsiounis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jasonkatonica jasonkatonica left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

taoliult added 2 commits June 19, 2026 18:16
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 java26_securerandom_native_2 branch from a24155f to 323849a Compare June 19, 2026 22:16
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.

4 participants