Skip to content

Use ThreadLocal caching for ExtendedRandom PRNG contexts - #1509

Open
taoliult wants to merge 2 commits into
IBM:java21from
taoliult:java21_securerandom_native_2
Open

Use ThreadLocal caching for ExtendedRandom PRNG contexts#1509
taoliult wants to merge 2 commits into
IBM:java21from
taoliult:java21_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 16, 2026 13:33
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>

@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

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