Skip to content

Commit 6c50c07

Browse files
committed
Cache security algorithms for CRIU startup
When making use of the CRIU feature for a fast startup it has been found that fetching algorithms is quite slow from the providers installed. This update saves all algorithms available in all providers prior to a checkpoint being taken. This cache then becomes available for callers after a restore has taken place. Any updates to the security providers order made via the Security classes triggers the invalidation of this cache. This update is dependent upon: eclipse-openj9/openj9#16888 Signed-off-by: Jason Katonica [email protected]
1 parent 2fa3123 commit 6c50c07

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/java.base/share/classes/java/security/Security.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public final class Security {
7373
/* Are we debugging? -- for developers */
7474
private static final Debug sdebug =
7575
Debug.getInstance("properties");
76+
/*[IF CRIU_SUPPORT]*/
77+
private static final boolean criuDebug = Boolean.getBoolean("enable.j9internal.checkpoint.security.api.debug");
78+
/*[ENDIF] CRIU_SUPPORT */
7679

7780
/* The java.security properties */
7881
private static Properties props;
@@ -138,12 +141,12 @@ private static void initialize() {
138141
}
139142
}
140143

141-
/*[IF CRIU_SUPPORT]*/
144+
/*[IF CRIU_SUPPORT]*/
142145
// Check if CRIU checkpoint mode is enabled, if it is then reconfigure the security providers.
143146
if (InternalCRIUSupport.isCheckpointAllowed()) {
144147
CRIUConfigurator.setCRIUSecMode(props);
145148
}
146-
/*[ENDIF] CRIU_SUPPORT*/
149+
/*[ENDIF] CRIU_SUPPORT */
147150

148151
// Load FIPS properties
149152
boolean fipsEnabled = FIPSConfigurator.configureFIPS(props);
@@ -365,6 +368,11 @@ public static String getAlgorithmProperty(String algName,
365368
*/
366369
public static synchronized int insertProviderAt(Provider provider,
367370
int position) {
371+
372+
/*[IF CRIU_SUPPORT]*/
373+
CRIUConfigurator.invalidateAlgorithmCache();
374+
/*[ENDIF] CRIU_SUPPORT */
375+
368376
String providerName = provider.getName();
369377
checkInsertProvider(providerName);
370378
ProviderList list = Providers.getFullProviderList();
@@ -446,6 +454,10 @@ public static int addProvider(Provider provider) {
446454
* @see #addProvider
447455
*/
448456
public static synchronized void removeProvider(String name) {
457+
/*[IF CRIU_SUPPORT]*/
458+
CRIUConfigurator.invalidateAlgorithmCache();
459+
/*[ENDIF] CRIU_SUPPORT */
460+
449461
check("removeProvider." + name);
450462
ProviderList list = Providers.getFullProviderList();
451463
ProviderList newList = ProviderList.remove(list, name);
@@ -1078,6 +1090,20 @@ static String[] getFilterComponents(String filterKey, String filterValue) {
10781090
*/
10791091
public static Set<String> getAlgorithms(String serviceName) {
10801092

1093+
/*[IF CRIU_SUPPORT]*/
1094+
// Check if the CRIU algorithm cache is ready/valid and contains data. If true use that cached data.
1095+
if (CRIUConfigurator.isCachedAlgorithmsPresentAndReady()) {
1096+
if (criuDebug) {
1097+
System.out.println("Use CRIU cache for getAlgorithms()");
1098+
}
1099+
return CRIUConfigurator.getAlgorithms(serviceName);
1100+
} else {
1101+
if (criuDebug) {
1102+
System.out.println("Do not use CRIU cache for getAlgorithms()");
1103+
}
1104+
}
1105+
/*[ENDIF] CRIU_SUPPORT */
1106+
10811107
if ((serviceName == null) || (serviceName.isEmpty()) ||
10821108
(serviceName.endsWith("."))) {
10831109
return Collections.emptySet();

0 commit comments

Comments
 (0)