Skip to content

Commit d5e17dd

Browse files
authored
Merge pull request #18354 from WilburZjh/simpleenablefullproviderincriu
Enable the -XX:[+|-]CRIUSecProvider jvm option
2 parents ac47064 + df6acd4 commit d5e17dd

File tree

12 files changed

+84
-5
lines changed

12 files changed

+84
-5
lines changed

jcl/src/java.base/share/classes/openj9/internal/criu/InternalCRIUSupport.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@
2525
/**
2626
* Internal CRIU Support API
2727
*/
28-
/*[IF JAVA_SPEC_VERSION >= 17]*/
29-
@SuppressWarnings({ "deprecation", "removal" })
30-
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
3128
public final class InternalCRIUSupport {
3229
private static final boolean criuSupportEnabled = isCRIUSupportEnabledImpl();
3330
private static long checkpointRestoreNanoTimeDelta;
3431

35-
private static native boolean isCRIUSupportEnabledImpl();
36-
private static native boolean isCheckpointAllowedImpl();
32+
private static native boolean enableCRIUSecProviderImpl();
3733
private static native long getCheckpointRestoreNanoTimeDeltaImpl();
3834
private static native long getLastRestoreTimeImpl();
35+
private static native boolean isCRIUSupportEnabledImpl();
36+
private static native boolean isCheckpointAllowedImpl();
3937

4038
/**
4139
* Retrieve the elapsed time between Checkpoint and Restore.
@@ -70,6 +68,20 @@ public synchronized static boolean isCRIUSupportEnabled() {
7068
return criuSupportEnabled;
7169
}
7270

71+
/**
72+
* Checks if CRIU Security provider is enabled
73+
* when CRIU support is enabled.
74+
*
75+
* @return true if enabled, otherwise false
76+
*/
77+
public static boolean enableCRIUSecProvider() {
78+
boolean isCRIUSecProviderEnabled = false;
79+
if (criuSupportEnabled) {
80+
isCRIUSecProviderEnabled = enableCRIUSecProviderImpl();
81+
}
82+
return isCRIUSecProviderEnabled;
83+
}
84+
7385
/**
7486
* Queries if CRIU Checkpoint is allowed.
7587
* isCRIUSupportEnabled() is invoked first to check if CRIU support is enabled,

jcl/src/openj9.criu/share/classes/org/eclipse/openj9/criu/CRIUSupport.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ public static boolean isCRIUSupportEnabled() {
203203
return (nativeLoaded && InternalCRIUSupport.isCRIUSupportEnabled());
204204
}
205205

206+
/**
207+
* Checks if the CRIUSecProvider is enabled when CRIU
208+
* checkpoints are allowed (checks whether -XX:-CRIUSecProvider
209+
* has been specified).
210+
*
211+
* @return true if CRIUSecProvider is enabled, otherwise false
212+
*/
213+
public static boolean enableCRIUSecProvider() {
214+
return InternalCRIUSupport.enableCRIUSecProvider();
215+
}
216+
206217
/**
207218
* Queries if CRIU Checkpoint is allowed. With -XX:+CRIURestoreNonPortableMode enabled
208219
* (default policy) only a single checkpoint is allowed.

runtime/jcl/common/criu.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,18 @@ Java_openj9_internal_criu_InternalCRIUSupport_isCRIUSupportEnabledImpl(JNIEnv *e
7171

7272
return res;
7373
}
74+
75+
jboolean JNICALL
76+
Java_openj9_internal_criu_InternalCRIUSupport_enableCRIUSecProviderImpl(JNIEnv *env, jclass unused)
77+
{
78+
J9VMThread *currentThread = (J9VMThread *)env;
79+
jboolean res = JNI_FALSE;
80+
81+
if (currentThread->javaVM->internalVMFunctions->enableCRIUSecProvider(currentThread)) {
82+
res = JNI_TRUE;
83+
}
84+
85+
return res;
86+
}
7487
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
7588
}

runtime/jcl/exports.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ endif()
670670
# J9VM_OPT_CRIU_SUPPORT
671671
if(J9VM_OPT_CRIU_SUPPORT)
672672
omr_add_exports(jclse
673+
Java_openj9_internal_criu_InternalCRIUSupport_enableCRIUSecProviderImpl
673674
Java_openj9_internal_criu_InternalCRIUSupport_getCheckpointRestoreNanoTimeDeltaImpl
674675
Java_openj9_internal_criu_InternalCRIUSupport_getLastRestoreTimeImpl
675676
Java_openj9_internal_criu_InternalCRIUSupport_isCheckpointAllowedImpl

runtime/jcl/uma/criu_exports.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ OpenJDK Assembly Exception [2].
2020
SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
2121
-->
2222
<exports group="criu">
23+
<export name="Java_openj9_internal_criu_InternalCRIUSupport_enableCRIUSecProviderImpl" />
2324
<export name="Java_openj9_internal_criu_InternalCRIUSupport_getCheckpointRestoreNanoTimeDeltaImpl" />
2425
<export name="Java_openj9_internal_criu_InternalCRIUSupport_getLastRestoreTimeImpl" />
2526
<export name="Java_openj9_internal_criu_InternalCRIUSupport_isCheckpointAllowedImpl" />

runtime/oti/j9nonbuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4205,6 +4205,7 @@ typedef struct J9DelayedLockingOpertionsRecord {
42054205
#define J9VM_CRIU_IS_JDWP_ENABLED 0x8
42064206
#define J9VM_CRIU_IS_THROW_ON_DELAYED_CHECKPOINT_ENABLED 0x10
42074207
#define J9VM_CRIU_IS_PORTABLE_JVM_RESTORE_MODE 0x20
4208+
#define J9VM_CRIU_ENABLE_CRIU_SEC_PROVIDER 0x40
42084209

42094210
typedef struct J9CRIUCheckpointState {
42104211
U_32 flags;
@@ -5025,6 +5026,7 @@ typedef struct J9InternalVMFunctions {
50255026
BOOLEAN (*jvmRestoreHooks)(struct J9VMThread *currentThread);
50265027
BOOLEAN (*isCRIUSupportEnabled)(struct J9VMThread *currentThread);
50275028
BOOLEAN (*isCRIUSupportEnabled_VM)(struct J9JavaVM *vm);
5029+
BOOLEAN (*enableCRIUSecProvider)(struct J9VMThread *currentThread);
50285030
BOOLEAN (*isCheckpointAllowed)(struct J9VMThread *currentThread);
50295031
BOOLEAN (*isNonPortableRestoreMode)(struct J9VMThread *currentThread);
50305032
BOOLEAN (*isJVMInPortableRestoreMode)(struct J9VMThread *currentThread);

runtime/oti/jclprots.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,9 @@ Java_jdk_internal_misc_ScopedMemoryAccess_closeScope0(JNIEnv *env, jobject insta
12921292

12931293
#if defined(J9VM_OPT_CRIU_SUPPORT)
12941294
/* criu.cpp */
1295+
jboolean JNICALL
1296+
Java_openj9_internal_criu_InternalCRIUSupport_enableCRIUSecProviderImpl(JNIEnv *env, jclass unused);
1297+
12951298
jlong JNICALL
12961299
Java_openj9_internal_criu_InternalCRIUSupport_getCheckpointRestoreNanoTimeDeltaImpl(JNIEnv *env, jclass unused);
12971300

runtime/oti/jvminit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ enum INIT_STAGE {
424424
#if defined(J9VM_OPT_CRIU_SUPPORT)
425425
#define VMOPT_XXENABLECRIU "-XX:+EnableCRIUSupport"
426426
#define VMOPT_XXDISABLECRIU "-XX:-EnableCRIUSupport"
427+
#define VMOPT_XXENABLECRIUSECPROVIDER "-XX:+CRIUSecProvider"
428+
#define VMOPT_XXDISABLECRIUSECPROVIDER "-XX:-CRIUSecProvider"
427429
#define VMOPT_XXENABLECRIUNONPORTABLEMODE "-XX:+CRIURestoreNonPortableMode"
428430
#define VMOPT_XXDISABLECRIUNONPORTABLEMODE "-XX:-CRIURestoreNonPortableMode"
429431
#define VMOPT_XXENABLEJVMRESTOREPORTABLEMODE "-XX:+JVMPortableRestoreMode"

runtime/oti/vm_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,17 @@ isCRIUSupportEnabled(J9VMThread *currentThread);
517517
BOOLEAN
518518
isCRIUSupportEnabled_VM(J9JavaVM *vm);
519519

520+
/**
521+
* @brief Checks if the CRIU security provider is enabled when CRIU
522+
* checkpoints are allowed. By default it is enabled, it can be disabled with
523+
* -XX:-CRIUSecProvider.
524+
*
525+
* @param currentThread vmthread token
526+
* @return TRUE if enabled, FALSE otherwise
527+
*/
528+
BOOLEAN
529+
enableCRIUSecProvider(J9VMThread *currentThread);
530+
520531
/**
521532
* @brief Queries if checkpointing is permitted. Note, when
522533
* -XX:+CRIURestoreNonPortableMode option is specified checkpointing

runtime/vm/CRIUHelpers.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ isCheckpointAllowed(J9VMThread *currentThread)
128128
return result;
129129
}
130130

131+
BOOLEAN
132+
enableCRIUSecProvider(J9VMThread *currentThread)
133+
{
134+
BOOLEAN result = FALSE;
135+
136+
if (isCRIUSupportEnabled(currentThread)) {
137+
result = J9_ARE_ANY_BITS_SET(currentThread->javaVM->checkpointState.flags, J9VM_CRIU_ENABLE_CRIU_SEC_PROVIDER);
138+
}
139+
140+
return result;
141+
}
142+
131143
BOOLEAN
132144
isNonPortableRestoreMode(J9VMThread *currentThread)
133145
{

runtime/vm/intfunc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ J9InternalVMFunctions J9InternalFunctions = {
409409
jvmRestoreHooks,
410410
isCRIUSupportEnabled,
411411
isCRIUSupportEnabled_VM,
412+
enableCRIUSecProvider,
412413
isCheckpointAllowed,
413414
isNonPortableRestoreMode,
414415
isJVMInPortableRestoreMode,

runtime/vm/jvminit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,6 +3885,16 @@ processVMArgsFromFirstToLast(J9JavaVM * vm)
38853885
}
38863886
}
38873887

3888+
{
3889+
IDATA enableCRIUSecProvider = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXENABLECRIUSECPROVIDER, NULL);
3890+
IDATA disableCRIUSecProvider = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXDISABLECRIUSECPROVIDER, NULL);
3891+
if (enableCRIUSecProvider >= disableCRIUSecProvider) {
3892+
if (J9_ARE_ANY_BITS_SET(vm->checkpointState.flags, J9VM_CRIU_IS_CHECKPOINT_ENABLED)) {
3893+
vm->checkpointState.flags |= J9VM_CRIU_ENABLE_CRIU_SEC_PROVIDER;
3894+
}
3895+
}
3896+
}
3897+
38883898
{
38893899
IDATA enableCRIUNonPortableMode = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXENABLECRIUNONPORTABLEMODE, NULL);
38903900
IDATA disableCRIUNonPortableMode = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXDISABLECRIUNONPORTABLEMODE, NULL);

0 commit comments

Comments
 (0)