Skip to content

Commit

Permalink
Merge pull request #704 from pshipton/ibm
Browse files Browse the repository at this point in the history
Parse -Xmso from more locations
  • Loading branch information
keithc-ca authored Sep 12, 2023
2 parents 27c0f0f + 02870a7 commit 5e99d55
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 28 deletions.
49 changes: 44 additions & 5 deletions src/java.base/share/native/libjli/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,12 @@ static JLI_List expandArgFile(const char *arg) {

/* failed to access the file */
if (stat(arg, &st) != 0) {
JLI_ReportMessage(CFG_ERROR6, arg);
exit(1);
if (parsingOpenJ9Args) {
return NULL;
} else {
JLI_ReportMessage(CFG_ERROR6, arg);
exit(1);
}
}

if (st.st_size > MAX_ARGF_SIZE) {
Expand All @@ -383,15 +387,19 @@ static JLI_List expandArgFile(const char *arg) {
fptr = fopen(arg, "r");
/* arg file cannot be openned */
if (fptr == NULL) {
JLI_ReportMessage(CFG_ERROR6, arg);
exit(1);
if (parsingOpenJ9Args) {
return NULL;
} else {
JLI_ReportMessage(CFG_ERROR6, arg);
exit(1);
}
}

rv = readArgFile(fptr);
fclose(fptr);

/* error occurred reading the file */
if (rv == NULL) {
if (rv == NULL && !parsingOpenJ9Args) {
JLI_ReportMessage(DLL_ERROR4, arg);
exit(1);
}
Expand Down Expand Up @@ -535,6 +543,37 @@ JLI_ParseOpenJ9ArgsFromEnvVar(JLI_List args, const char *var_name) {
return result;
}

JNIEXPORT JLI_List JNICALL
JLI_ParseOpenJ9ArgsFile(const char *filename) {
JLI_List result = NULL;

/* Save the state. */
int savedFirstAppArgIndex = firstAppArgIndex;
jboolean savedExpectingNoDashArg = expectingNoDashArg;
size_t savedArgsCount = argsCount;
jboolean savedStopExpansion = stopExpansion;
jboolean savedRelaunch = relaunch;

parsingOpenJ9Args = JNI_TRUE;
firstAppArgIndex = NOT_FOUND;
expectingNoDashArg = JNI_FALSE;
argsCount = 1;
stopExpansion = JNI_FALSE;
relaunch = JNI_FALSE;

result = expandArgFile(filename);

/* Restore the state. */
parsingOpenJ9Args = JNI_FALSE;
firstAppArgIndex = savedFirstAppArgIndex;
expectingNoDashArg = savedExpectingNoDashArg;
argsCount = savedArgsCount;
stopExpansion = savedStopExpansion;
relaunch = savedRelaunch;

return result;
}

/*
* Expand a string into a list of args.
* If the string is the result of looking up an environment variable,
Expand Down
77 changes: 54 additions & 23 deletions src/java.base/share/native/libjli/java.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,44 @@ static jlong initialHeapSize = 0; /* inital heap size */
#define STACK_SIZE_MINIMUM (64 * KB)
#endif

static void
parseXmso(JLI_List openj9Args)
{
size_t i = openj9Args->size;
while (i > 0) {
i -= 1;
if (JLI_StrCCmp(openj9Args->elements[i], "-Xmso") == 0) {
jlong tmp = 0;
if (parse_size(openj9Args->elements[i] + 5, &tmp)) {
threadStackSize = tmp;
if (threadStackSize > 0 && threadStackSize < (jlong)STACK_SIZE_MINIMUM) {
threadStackSize = STACK_SIZE_MINIMUM;
}
}
break;
}
}
JLI_List_free(openj9Args);
}

static void
parseXmsoInFile(const char *filename)
{
JLI_List openj9Args = JLI_ParseOpenJ9ArgsFile(filename);
if (openj9Args != NULL) {
parseXmso(openj9Args);
}
}

static void
parseXmsoInEnv(const char *envVar)
{
JLI_List openj9Args = JLI_List_new(8); /* 8 is arbitrary */
if (JLI_ParseOpenJ9ArgsFromEnvVar(openj9Args, envVar)) {
parseXmso(openj9Args);
}
}

/*
* Entry point.
*/
Expand Down Expand Up @@ -325,29 +363,17 @@ JLI_Launch(int argc, char ** argv, /* main argc, argv */
}
}

/* Process -Xmso to set the main thread stack size. May be overridden by
* a later command line option.
*/
{
/* Process -Xmso in the OPENJ9_JAVA_OPTIONS environment variable to
* set the main thread stack size. May be overridden by a later command
* line option.
*/
JLI_List openj9Args = JLI_List_new(8); /* 8 is arbitrary */
if (JLI_ParseOpenJ9ArgsFromEnvVar(openj9Args, "OPENJ9_JAVA_OPTIONS")) {
size_t i = openj9Args->size;
while (i > 0) {
i -= 1;
if (JLI_StrCCmp(openj9Args->elements[i], "-Xmso") == 0) {
jlong tmp = 0;
if (parse_size(openj9Args->elements[i] + 5, &tmp)) {
threadStackSize = tmp;
if (threadStackSize > 0 && threadStackSize < (jlong)STACK_SIZE_MINIMUM) {
threadStackSize = STACK_SIZE_MINIMUM;
}
}
break;
}
}
JLI_List_free(openj9Args);
}
#define OPTIONS_DEFAULT_PATH "/lib/options.default"
char optionsfile[sizeof(jrepath) + sizeof(OPTIONS_DEFAULT_PATH) - 1];
JLI_Snprintf(optionsfile, sizeof(optionsfile), "%s" OPTIONS_DEFAULT_PATH, jrepath);
parseXmsoInFile(optionsfile);
parseXmsoInEnv("JAVA_TOOL_OPTIONS");
parseXmsoInEnv("OPENJ9_JAVA_OPTIONS");
parseXmsoInEnv("IBM_JAVA_OPTIONS");
}

/* Parse command line options; if the return value of
Expand Down Expand Up @@ -968,8 +994,13 @@ AddOption(char *str, void *info)
options[numOptions++].extraInfo = info;

/* In OpenJ9 -Xmso is used to set native stack size instead of -Xss. -Xss is used to
* set Java thread size only, which is handled in the JVM code.
* set Java thread size only, which is handled in the JVM code. Check for -Xmso in any
* -Xoptionsfile= and on the command line itself. The default.options file and relevent
* environment variables are checked earlier.
*/
if (JLI_StrCCmp(str, "-Xoptionsfile=") == 0) {
parseXmsoInFile(str + 14);
}
if (JLI_StrCCmp(str, "-Xmso") == 0) {
jlong tmp;
if (parse_size(str + 5, &tmp)) {
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/native/libjli/jli_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ JLI_AddArgsFromEnvVar(JLI_List args, const char *var_name);
JNIEXPORT jboolean JNICALL
JLI_ParseOpenJ9ArgsFromEnvVar(JLI_List args, const char *var_name);

JNIEXPORT JLI_List JNICALL
JLI_ParseOpenJ9ArgsFile(const char *filename);

#endif /* _JLI_UTIL_H */

0 comments on commit 5e99d55

Please sign in to comment.