Skip to content

Commit b8c17e8

Browse files
committed
Get the start time of the criu restore process
Get the start time of the criu restore process, which is the parent process of the restored java process. Issue: eclipse-openj9#18598 Depends-on: eclipse-omr/omr#7214 Signed-off-by: Amarpreet Singh <[email protected]>
1 parent 0318ff9 commit b8c17e8

File tree

15 files changed

+150
-11
lines changed

15 files changed

+150
-11
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public final class InternalCRIUSupport {
6969
private static native boolean enableCRIUSecProviderImpl();
7070
private static native long getCheckpointRestoreNanoTimeDeltaImpl();
7171
private static native long getLastRestoreTimeImpl();
72+
private static native long getProcessRestoreStartTimeImpl();
7273
private static native boolean isCRIUSupportEnabledImpl();
7374
private static native boolean isCheckpointAllowedImpl();
7475
/*[IF CRAC_SUPPORT]*/
@@ -95,13 +96,24 @@ public static long getCheckpointRestoreNanoTimeDelta() {
9596
* Retrieve the time when the last restore occurred. In the case of multiple
9697
* restores the previous times are overwritten.
9798
*
98-
* @return the time in milliseconds since the start of the epoch, -1 if restore
99+
* @return the time in nanoseconds since the start of the epoch, -1 if restore
99100
* has not occurred.
100101
*/
101102
public static long getLastRestoreTime() {
102103
return getLastRestoreTimeImpl();
103104
}
104105

106+
/**
107+
* Get the start time of the CRIU process that restores the java process.
108+
* The time that is set by the restored java process when it resumes from
109+
* checkpoint can be retrieved with {@link #getLastRestoreTime()}.
110+
*
111+
* @return the time in nanoseconds since the epoch, -1 if restore has not occurred.
112+
*/
113+
public static long getProcessRestoreStartTime() {
114+
return getProcessRestoreStartTimeImpl();
115+
}
116+
105117
/**
106118
* Queries if CRaC or CRIU support is enabled.
107119
*

runtime/jcl/common/criu.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ Java_openj9_internal_criu_InternalCRIUSupport_getLastRestoreTimeImpl(JNIEnv *env
4343
{
4444
J9VMThread *currentThread = (J9VMThread *)env;
4545

46-
return currentThread->javaVM->checkpointState.lastRestoreTimeMillis;
46+
return currentThread->javaVM->checkpointState.lastRestoreTimeInNanoseconds;
47+
}
48+
49+
jlong JNICALL
50+
Java_openj9_internal_criu_InternalCRIUSupport_getProcessRestoreStartTimeImpl(JNIEnv *env, jclass unused)
51+
{
52+
J9VMThread *currentThread = (J9VMThread *)env;
53+
54+
return currentThread->javaVM->checkpointState.processRestoreStartTimeInNanoseconds;
4755
}
4856

4957
jboolean JNICALL

runtime/jcl/exports.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ if(J9VM_OPT_CRIU_SUPPORT)
675675
Java_openj9_internal_criu_InternalCRIUSupport_enableCRIUSecProviderImpl
676676
Java_openj9_internal_criu_InternalCRIUSupport_getCheckpointRestoreNanoTimeDeltaImpl
677677
Java_openj9_internal_criu_InternalCRIUSupport_getLastRestoreTimeImpl
678+
Java_openj9_internal_criu_InternalCRIUSupport_getProcessRestoreStartTimeImpl
678679
Java_openj9_internal_criu_InternalCRIUSupport_getRestoreSystemProperites
679680
Java_openj9_internal_criu_InternalCRIUSupport_isCheckpointAllowedImpl
680681
Java_openj9_internal_criu_InternalCRIUSupport_isCRIUSupportEnabledImpl

runtime/jcl/uma/criu_exports.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
2323
<export name="Java_openj9_internal_criu_InternalCRIUSupport_enableCRIUSecProviderImpl" />
2424
<export name="Java_openj9_internal_criu_InternalCRIUSupport_getCheckpointRestoreNanoTimeDeltaImpl" />
2525
<export name="Java_openj9_internal_criu_InternalCRIUSupport_getLastRestoreTimeImpl" />
26+
<export name="Java_openj9_internal_criu_InternalCRIUSupport_getProcessRestoreStartTimeImpl" />
2627
<export name="Java_openj9_internal_criu_InternalCRIUSupport_isCheckpointAllowedImpl" />
2728
<export name="Java_openj9_internal_criu_InternalCRIUSupport_isCRIUSupportEnabledImpl" />
2829
</exports>

runtime/nls/j9vm/j9vm.nls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,3 +2313,10 @@ J9NLS_VM_CRIU_CRAC_INCOMPATIBLE_SETTING.explanation=-XX:+EnableCRIUSupport and -
23132313
J9NLS_VM_CRIU_CRAC_INCOMPATIBLE_SETTING.system_action=The JVM will fail to start.
23142314
J9NLS_VM_CRIU_CRAC_INCOMPATIBLE_SETTING.user_response=Remove one of the options from the command line.
23152315
# END NON-TRANSLATABLE
2316+
2317+
J9NLS_VM_CRIU_J9_GET_PROCESS_START_TIME_FAILURE=j9sysinfo_get_process_start_time failed with errno=%zi
2318+
# START NON-TRANSLATABLE
2319+
J9NLS_VM_CRIU_J9_GET_PROCESS_START_TIME_FAILURE.explanation=j9sysinfo_get_process_start_time failed.
2320+
J9NLS_VM_CRIU_J9_GET_PROCESS_START_TIME_FAILURE.system_action=The JVM will throw a JVMRestoreException.
2321+
J9NLS_VM_CRIU_J9_GET_PROCESS_START_TIME_FAILURE.user_response=View CRIU documentation to determine how to resolve the error.
2322+
# END NON-TRANSLATABLE

runtime/oti/j9nonbuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4228,7 +4228,8 @@ typedef struct J9CRIUCheckpointState {
42284228
* Only supports one Checkpoint, could be restored multiple times.
42294229
*/
42304230
I_64 checkpointRestoreTimeDelta;
4231-
I_64 lastRestoreTimeMillis;
4231+
I_64 lastRestoreTimeInNanoseconds;
4232+
I_64 processRestoreStartTimeInNanoseconds;
42324233
UDATA maxRetryForNotCheckpointSafe;
42334234
UDATA sleepMillisecondsForNotCheckpointSafe;
42344235
jclass criuJVMCheckpointExceptionClass;

runtime/oti/j9port_generated.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ extern J9_CFUNC int32_t j9port_isCompatible(struct J9PortLibraryVersion *expecte
761761
#define j9sysinfo_get_open_file_count(param1) OMRPORT_FROM_J9PORT(privatePortLibrary)->sysinfo_get_open_file_count(OMRPORT_FROM_J9PORT(privatePortLibrary),param1)
762762
#define j9sysinfo_get_os_description(param1) OMRPORT_FROM_J9PORT(privatePortLibrary)->sysinfo_get_os_description(OMRPORT_FROM_J9PORT(privatePortLibrary),param1)
763763
#define j9sysinfo_os_has_feature(param1,param2) OMRPORT_FROM_J9PORT(privatePortLibrary)->sysinfo_os_has_feature(OMRPORT_FROM_J9PORT(privatePortLibrary),param1,param2)
764+
#if defined(J9VM_OPT_CRIU_SUPPORT)
765+
#define j9sysinfo_get_process_start_time(param1,param2) OMRPORT_FROM_J9PORT(privatePortLibrary)->sysinfo_get_process_start_time(OMRPORT_FROM_J9PORT(privatePortLibrary),param1,param2)
766+
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
764767
#define j9syslog_write(param1,param2) OMRPORT_FROM_J9PORT(privatePortLibrary)->syslog_write(OMRPORT_FROM_J9PORT(privatePortLibrary),param1,param2)
765768
#define j9hypervisor_startup() privatePortLibrary->hypervisor_startup(privatePortLibrary)
766769
#define j9hypervisor_shutdown() privatePortLibrary->hypervisor_shutdown(privatePortLibrary)

runtime/oti/jclprots.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,9 @@ Java_openj9_internal_criu_InternalCRIUSupport_getCheckpointRestoreNanoTimeDeltaI
13031303
jlong JNICALL
13041304
Java_openj9_internal_criu_InternalCRIUSupport_getLastRestoreTimeImpl(JNIEnv *env, jclass unused);
13051305

1306+
jlong JNICALL
1307+
Java_openj9_internal_criu_InternalCRIUSupport_getProcessRestoreStartTimeImpl(JNIEnv *env, jclass unused);
1308+
13061309
jboolean JNICALL
13071310
Java_openj9_internal_criu_InternalCRIUSupport_isCheckpointAllowedImpl(JNIEnv *env, jclass unused);
13081311

runtime/tests/port/si.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,27 @@ j9sysinfo_test_get_l1dcache_line_size(struct J9PortLibrary *portLibrary)
22802280
return reportTestExit(portLibrary, testName);
22812281
}
22822282

2283+
#if defined(J9VM_OPT_CRIU_SUPPORT)
2284+
I_32
2285+
j9sysinfo_test_get_process_start_time(struct J9PortLibrary *portLibrary)
2286+
{
2287+
PORT_ACCESS_FROM_PORT(portLibrary);
2288+
const char *testName = "j9sysinfo_test_get_process_start_time";
2289+
UDATA pid = j9sysinfo_get_pid();
2290+
U_64 processStartTimeInNanoseconds = 0;
2291+
I_32 rc = j9sysinfo_get_process_start_time(pid, &processStartTimeInNanoseconds);
2292+
if ((0 != rc) || (0 == processStartTimeInNanoseconds)) {
2293+
outputErrorMessage(
2294+
PORTTEST_ERROR_ARGS,
2295+
"j9sysinfo_get_process_start_time, pid=%zu, processStartTimeInNanoseconds=%llu, rc=%d.\n",
2296+
pid,
2297+
processStartTimeInNanoseconds,
2298+
rc);
2299+
}
2300+
return reportTestExit(portLibrary, testName);
2301+
}
2302+
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
2303+
22832304
/*
22842305
* pass in the port library to do sysinfo tests
22852306
*/
@@ -2350,6 +2371,9 @@ j9sysinfo_runTests(struct J9PortLibrary *portLibrary, char *argv0)
23502371
/* Not supported on Z & OSX (and Windows, of course). Enable, when available. */
23512372
rc |= j9sysinfo_test_get_open_file_count(portLibrary);
23522373
#endif /* defined(LINUX) || defined(AIXPPC) */
2374+
#if defined(J9VM_OPT_CRIU_SUPPORT)
2375+
rc |= j9sysinfo_test_get_process_start_time(portLibrary);
2376+
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
23532377

23542378
/* Output results */
23552379
j9tty_printf(PORTLIB, "\nSysinfo test done%s\n\n", rc == TEST_PASS ? "." : ", failures detected.");

runtime/vm/CRIUHelpers.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static BOOLEAN criuRestoreDisableSharedClassCache(J9VMThread *currentThread, voi
6060
static BOOLEAN criuRestoreInitializeDump(J9VMThread *currentThread, void *userData, const char **nlsMsgFormat);
6161
static jvmtiIterationControl objectIteratorCallback(J9JavaVM *vm, J9MM_IterateObjectDescriptor *objectDesc, void *userData);
6262

63-
#define J9TIME_NANOSECONDS_PER_MILLIS 1000000
6463
#define STRING_BUFFER_SIZE 256
6564
#define ENV_FILE_BUFFER 1024
6665

@@ -1510,6 +1509,7 @@ criuCheckpointJVMImpl(JNIEnv *env,
15101509
I_32 syslogBufferSize = 0;
15111510
UDATA oldVMState = VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_CHECKPOINT_PHASE_START);
15121511
UDATA notSafeToCheckpoint = 0;
1512+
UDATA criuRestorePid = 0;
15131513

15141514
vmFuncs->internalEnterVMFromJNI(currentThread);
15151515

@@ -1756,8 +1756,31 @@ criuCheckpointJVMImpl(JNIEnv *env,
17561756
VM_VMHelpers::setVMState(currentThread, J9VMSTATE_CRIU_SUPPORT_RESTORE_PHASE_START);
17571757
restoreNanoTimeMonotonic = j9time_nano_time();
17581758
restoreNanoUTCTime = j9time_current_time_nanos(&success);
1759-
vm->checkpointState.lastRestoreTimeMillis = (I_64)(restoreNanoUTCTime / J9TIME_NANOSECONDS_PER_MILLIS);
1760-
Trc_VM_criu_after_dump(currentThread, restoreNanoTimeMonotonic, restoreNanoUTCTime, vm->checkpointState.lastRestoreTimeMillis);
1759+
if (0 == success) {
1760+
systemReturnCode = errno;
1761+
currentExceptionClass = vm->checkpointState.criuSystemRestoreExceptionClass;
1762+
nlsMsgFormat = j9nls_lookup_message(
1763+
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
1764+
J9NLS_VM_CRIU_J9_CURRENT_TIME_NANOS_FAILURE,
1765+
NULL);
1766+
j9mem_free_memory(syslogOptions);
1767+
goto wakeJavaThreadsWithExclusiveVMAccess;
1768+
}
1769+
vm->checkpointState.lastRestoreTimeInNanoseconds = (I_64)restoreNanoUTCTime;
1770+
Trc_VM_criu_after_dump(currentThread, restoreNanoTimeMonotonic, vm->checkpointState.lastRestoreTimeInNanoseconds);
1771+
criuRestorePid = j9sysinfo_get_ppid();
1772+
systemReturnCode = j9sysinfo_get_process_start_time(criuRestorePid, &restoreNanoUTCTime);
1773+
if (0 != systemReturnCode) {
1774+
currentExceptionClass = vm->checkpointState.criuSystemRestoreExceptionClass;
1775+
nlsMsgFormat = j9nls_lookup_message(
1776+
J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
1777+
J9NLS_VM_CRIU_J9_GET_PROCESS_START_TIME_FAILURE,
1778+
NULL);
1779+
j9mem_free_memory(syslogOptions);
1780+
goto wakeJavaThreadsWithExclusiveVMAccess;
1781+
}
1782+
vm->checkpointState.processRestoreStartTimeInNanoseconds = (I_64)restoreNanoUTCTime;
1783+
Trc_VM_criu_process_restore_start_after_dump(currentThread, criuRestorePid, vm->checkpointState.processRestoreStartTimeInNanoseconds);
17611784
if (!syslogFlagNone) {
17621785
/* Re-open the system logger, and set options with saved string value. */
17631786
j9port_control(J9PORT_CTLDATA_SYSLOG_OPEN, 0);

0 commit comments

Comments
 (0)