From 4956a766213c3d76e13b98ac5d5efe5d4f553895 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Thu, 21 Nov 2024 17:54:45 +0000 Subject: [PATCH] 8317538: Potential bottleneck in Provider::getService: specjvm2008::crypto.rsa have scalability issue for high vCPU numbers Reviewed-by: ascarpino --- src/java.base/share/classes/java/security/Provider.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/java.base/share/classes/java/security/Provider.java b/src/java.base/share/classes/java/security/Provider.java index 385247d4c8f..7012bcc9eeb 100644 --- a/src/java.base/share/classes/java/security/Provider.java +++ b/src/java.base/share/classes/java/security/Provider.java @@ -1157,10 +1157,10 @@ public abstract class Provider extends Properties { public Service getService(String type, String algorithm) { checkInitialized(); // avoid allocating a new ServiceKey object if possible - ServiceKey key = previousKey; + ServiceKey key = previousKey.get(); if (!key.matches(type, algorithm)) { key = new ServiceKey(type, algorithm, false); - previousKey = key; + previousKey.set(key); } Service s = serviceMap.get(key); @@ -1188,8 +1188,8 @@ public abstract class Provider extends Properties { // re-use will occur e.g. as the framework traverses the provider // list and queries each provider with the same values until it finds // a matching service - private static volatile ServiceKey previousKey = - new ServiceKey("", "", false); + private static final ThreadLocal previousKey = + ThreadLocal.withInitial(() -> new ServiceKey("","", false)); /** * Get an unmodifiable Set of all services supported by