Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cec2bf5

Browse files
committedSep 17, 2024·
Support restore with -XX:CRaCRestoreFrom=PATH
Signed-off-by: Jason Feng <fengj@ca.ibm.com>
1 parent 2abf31a commit cec2bf5

File tree

3 files changed

+30
-69
lines changed

3 files changed

+30
-69
lines changed
 

‎closed/src/java.base/share/native/libjli/criuhelpers.c

+27-28
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@
2222
* ===========================================================================
2323
*/
2424

25-
#include "criuhelpers.h"
25+
#include "j9cfg.h"
2626

2727
#if defined(J9VM_OPT_CRAC_SUPPORT)
28+
29+
#include "java.h"
30+
#include <ctype.h>
31+
#include <sys/wait.h>
32+
33+
void handleCRaCRestore(int argc, char **argv);
34+
2835
/**
2936
* Get the value of a command line option in the array of command line arguments.
3037
* @param[in] optionName The name of the command line option to search for
@@ -37,7 +44,7 @@ static const char *
3744
getCommandLineOptionValue(const char *optionName, int argc, char **argv, int *error)
3845
{
3946
const char *value = NULL;
40-
int i = argc - 1;
47+
int i = 0;
4148
size_t optionNameLength = strlen(optionName);
4249
*error = -1;
4350
for (i = argc - 1; i >= 0; i--) {
@@ -94,8 +101,7 @@ static int
94101
getLogLevel(int argc, char **argv, int *error)
95102
{
96103
int logLevelValue = 2; /* default */
97-
const char *logLevelPropertyValue = NULL;
98-
logLevelPropertyValue = getCommandLineOptionValue("-Dopenj9.internal.criu.logLevel", argc, argv, error);
104+
const char *logLevelPropertyValue = getCommandLineOptionValue("-Dopenj9.internal.criu.logLevel", argc, argv, error);
99105
if (0 == *error) {
100106
const char *c = logLevelPropertyValue;
101107
if (NULL == c) {
@@ -116,7 +122,9 @@ getLogLevel(int argc, char **argv, int *error)
116122
goto done;
117123
}
118124
setLogLevelOptionValueNotValidError:
119-
JLI_ReportErrorMessage("The value of the command line option is not valid, option=-Dopenj9.internal.criu.logLevel, value=%s.", logLevelPropertyValue);
125+
JLI_ReportErrorMessage(
126+
"The option '-Dopenj9.internal.criu.logLevel=%s' is not valid.",
127+
logLevelPropertyValue);
120128
*error = -2;
121129
done:
122130
return logLevelValue;
@@ -138,7 +146,9 @@ isUnprivilegedModeOn(int argc, char **argv, int *error)
138146
if (NULL == unprivilegedModePropertyValue) {
139147
isUnprivilegedModeOn = JNI_TRUE;
140148
} else {
141-
JLI_ReportErrorMessage("The value of the command line option is not expected, option=-Dopenj9.internal.criu.unprivilegedMode, value=%s.", unprivilegedModePropertyValue);
149+
JLI_ReportErrorMessage(
150+
"The option '-Dopenj9.internal.criu.unprivilegedMode=%s' does not accept a value.",
151+
unprivilegedModePropertyValue);
142152
*error = -2;
143153
}
144154
}
@@ -161,7 +171,7 @@ getLogFile(int argc, char **argv, int *error)
161171
if (NULL != logFilePropertyValue) {
162172
logFile = logFilePropertyValue;
163173
} else {
164-
JLI_ReportErrorMessage("The value of the command line option -Dopenj9.internal.criu.logFile was not found.");
174+
JLI_ReportErrorMessage("The option -Dopenj9.internal.criu.logFile requires a value.");
165175
*error = -2;
166176
}
167177
}
@@ -179,7 +189,6 @@ getLogFile(int argc, char **argv, int *error)
179189
static int
180190
restoreFromCheckpoint(const char *checkpointDirectory, int logLevel, jboolean unprivilegedModeOn, const char *logFile)
181191
{
182-
int restoreStatus = 0;
183192
int length = -1;
184193
char logLevelOption[4] = { 0 };
185194
char *logFileOption = NULL;
@@ -192,45 +201,35 @@ restoreFromCheckpoint(const char *checkpointDirectory, int logLevel, jboolean un
192201
length = snprintf(NULL, 0, "-v%d", logLevel);
193202
if (length < 0) {
194203
JLI_ReportErrorMessage("Failed to calculate the length of option '-v%d'.", logLevel);
195-
restoreStatus = -1;
196-
goto done;
197-
}
198-
if (snprintf(logLevelOption, sizeof(logLevelOption), "-v%d", logLevel) < 0) {
199-
JLI_ReportErrorMessage("Failed to format the log level option '-v%d'.", logLevel);
200-
restoreStatus = -1;
201-
goto done;
204+
goto fail;
202205
}
206+
snprintf(logLevelOption, sizeof(logLevelOption), "-v%d", logLevel);
203207
argv[argc++] = logLevelOption;
204208
argv[argc++] = "--shell-job";
205209
if (unprivilegedModeOn) {
206210
argv[argc++] = "--unprivileged";
207211
}
208212
if (NULL != logFile) {
209213
length = strlen(logFile) + sizeof("--log-file=%s") - 1;
210-
logFileOption = (char *)JLI_MemAlloc(length - 1);
214+
logFileOption = (char *)JLI_MemAlloc(length + 1);
211215
if (NULL == logFileOption) {
212216
JLI_ReportErrorMessage("Failed to allocate memory for option '--log-file=%s'.", logFile);
213-
restoreStatus = -1;
214-
goto done;
217+
goto fail;
215218
}
216-
if (snprintf(logFileOption, length - 1, "--log-file=%s", logFile) < 0) {
219+
if (snprintf(logFileOption, length + 1, "--log-file=%s", logFile) < 0) {
217220
JLI_ReportErrorMessage("Failed to format option '--log-file=%s'.", logFile);
218-
restoreStatus = -1;
219-
goto done;
221+
goto fail;
220222
}
221223
argv[argc++] = logFileOption;
222224
}
223225
argv[argc] = NULL;
224226
execvp(argv[0], (char * const *)argv);
225227
/* If execvp returns, there was an error. */
226-
restoreStatus = -1;
227-
freeLogFileOption:
228228
if (NULL != logFileOption) {
229229
JLI_MemFree((void *)logFileOption);
230-
logFileOption = NULL;
231230
}
232-
done:
233-
return restoreStatus;
231+
fail:
232+
return -1;
234233
}
235234

236235
/**
@@ -252,12 +251,12 @@ handleCRaCRestore(int argc, char **argv)
252251
int childProcessPidStatus = 0;
253252
int childProcessPidExitStatus = 0;
254253
checkpointDirectory = getCheckpointDirectory(argc, argv, &error);
255-
/* We ignore restore if the restore option -XX:CRaCRestoreFrom is not specified. */
256254
if (-1 == error) {
255+
/* Option -XX:CRaCRestoreFrom not specified. */
257256
return;
258257
}
259258
if (-2 == error) {
260-
JLI_ReportErrorMessage("Failed to get the CRIU checkpoint directory, error=%d.", error);
259+
JLI_ReportErrorMessage("Failed to get the CRIU checkpoint directory, error=-2.");
261260
parentProcessExitStatus = EXIT_FAILURE;
262261
goto doneParentProcess;
263262
}

‎closed/src/java.base/share/native/libjli/criuhelpers.h

-38
This file was deleted.

‎src/java.base/share/native/libjli/java.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959

6060
#include <assert.h>
6161

62-
#include "criuhelpers.h"
6362
#include "java.h"
6463
#include "jni.h"
64+
#include "j9cfg.h"
6565

6666
/*
6767
* A NOTE TO DEVELOPERS: For performance reasons it is important that
@@ -567,12 +567,12 @@ JavaMain(void* _args)
567567
jfieldID noArgMainField;
568568
jboolean noArgMain;
569569

570-
RegisterThread();
571-
572570
#if defined(J9VM_OPT_CRAC_SUPPORT)
573571
handleCRaCRestore(argc, argv);
574572
#endif /* defined(J9VM_OPT_CRAC_SUPPORT) */
575573

574+
RegisterThread();
575+
576576
/* Initialize the virtual machine */
577577
start = CurrentTimeMicros();
578578
if (!InitializeJVM(&vm, &env, &ifn)) {

0 commit comments

Comments
 (0)
Please sign in to comment.