From 6497a926f3a2682ddb732d9400123d58752b0795 Mon Sep 17 00:00:00 2001 From: Aleksandar Micic Date: Tue, 5 Dec 2023 13:13:44 -0800 Subject: [PATCH] Set gcThreadCountSpecified and allow -Xgcmaxthreads for restore VM Set gcThreadCountSpecified if either -Xgcthreads or -Xgcmaxthreads is specified, and use gcThreadCountForced to distinguish between the 2 options. This is a part of the fix that will allow -Xgcmaxthreads to work as expected (another OMR change is needed to make use of now properly set gcThreadCountSpecified flag). Aslo, allow -Xgcmaxthreads to be specified on restore VM too, and make sure that whichever is the last one wins (in any combination of those 2 options being or not beign specified on snapshot or restore side). Parsing of -Xgcmaxthreads handles it, since it's the latter one that gets processed in the code. There is also a change in behavior for restore VM. Previosly, if -Xgcthreads was specified on snapshot side, it would be ignored on restore side and the thread count would be recalculated from scratch. Now, if that option (or gcmaxthreads variant) is specified on snapshot side it will obeyed on restore side. Of course if restore side specifies any of the 2 options that will override the snapshot value. That was true before and still true, except that the value will possible to override by either gcthreads or (once fully working) gcmaxthreads variant. Signed-off-by: Aleksandar Micic --- runtime/gc_modron_startup/mminit.cpp | 7 +++- runtime/gc_modron_startup/mmparse.cpp | 50 ++++++++++++++---------- runtime/gc_modron_startup/mmparseXgc.cpp | 2 + 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/runtime/gc_modron_startup/mminit.cpp b/runtime/gc_modron_startup/mminit.cpp index 3f6bacaaf9d..7a988b21677 100644 --- a/runtime/gc_modron_startup/mminit.cpp +++ b/runtime/gc_modron_startup/mminit.cpp @@ -3183,7 +3183,12 @@ gcReinitializeDefaultsForRestore(J9VMThread* vmThread) PORT_ACCESS_FROM_JAVAVM(vm); OMRPORT_ACCESS_FROM_J9PORT(PORTLIB); - extensions->gcThreadCountForced = false; + /* If Snapshot VM did not specify -Xgcthreads or -Xgcmaxthreads, the count will be determined from scratch, either as new restore default or through restore specified options. + * If Snapshot VM did specify, we want to continue using the count value unless (only) restore specific options override it */ + if (!extensions->gcThreadCountSpecified) { + extensions->gcThreadCount = 0; + extensions->gcThreadCountForced = false; + } extensions->parSweepChunkSize = 0; if (!gcParseReconfigurableCommandLine(vm, vm->checkpointState.restoreArgsList)) { diff --git a/runtime/gc_modron_startup/mmparse.cpp b/runtime/gc_modron_startup/mmparse.cpp index 26d84b47f3b..8a09b79ac48 100644 --- a/runtime/gc_modron_startup/mmparse.cpp +++ b/runtime/gc_modron_startup/mmparse.cpp @@ -981,26 +981,6 @@ gcParseSovereignArguments(J9JavaVM *vm) extensions->heapContractionGCRatioThreshold._wasSpecified = true; } - /* Handling VMOPT_XGCMAXTHREADS is equivalent to VMOPT_XGCTHREADS (above), except it sets gcThreadCountForced to false rather than true. */ - if (-1 != FIND_ARG_IN_VMARGS(EXACT_MEMORY_MATCH, VMOPT_XGCMAXTHREADS, NULL)) { - result = option_set_to_opt_integer(vm, VMOPT_XGCMAXTHREADS, &index, EXACT_MEMORY_MATCH, &extensions->gcThreadCount); - if (OPTION_OK != result) { - if (OPTION_MALFORMED == result) { - j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_MUST_BE_NUMBER, VMOPT_XGCMAXTHREADS); - } else { - j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_VALUE_OVERFLOWED, VMOPT_XGCMAXTHREADS); - } - goto _error; - } - - if (0 == extensions->gcThreadCount) { - j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_VALUE_MUST_BE_ABOVE, VMOPT_XGCMAXTHREADS, (UDATA)0); - goto _error; - } - - extensions->gcThreadCountForced = false; - } - if(-1 != FIND_ARG_IN_VMARGS(EXACT_MEMORY_MATCH, "-Xgcworkpackets", NULL)) { result = option_set_to_opt_integer(vm, "-Xgcworkpackets", &index, EXACT_MEMORY_MATCH, &extensions->workpacketCount); if (OPTION_OK != result) { @@ -1275,11 +1255,13 @@ gcParseReconfigurableSoverignArguments(J9JavaVM* vm, J9VMInitArgs* args) MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(vm); IDATA index = -1; IDATA result = 0; + IDATA gcthread_index = -1; PORT_ACCESS_FROM_JAVAVM(vm); if (-1 != FIND_ARG_IN_ARGS(args, EXACT_MEMORY_MATCH, VMOPT_XGCTHREADS, NULL)) { result = option_set_to_opt_integer_args(vm, VMOPT_XGCTHREADS, &index, EXACT_MEMORY_MATCH, &extensions->gcThreadCount, args); + gcthread_index = index; if (OPTION_OK != result) { if (OPTION_MALFORMED == result) { j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_MUST_BE_NUMBER, VMOPT_XGCTHREADS); @@ -1294,9 +1276,37 @@ gcParseReconfigurableSoverignArguments(J9JavaVM* vm, J9VMInitArgs* args) goto _error; } + extensions->gcThreadCountSpecified = true; extensions->gcThreadCountForced = true; } + /* Handling VMOPT_XGCMAXTHREADS is equivalent to VMOPT_XGCTHREADS (above), except it sets gcThreadCountForced to false rather than true. */ + if (-1 != FIND_ARG_IN_ARGS(args, EXACT_MEMORY_MATCH, VMOPT_XGCMAXTHREADS, NULL)) { + UDATA gcThreadCount = 0; + IDATA gcmaxthread_index = -1; + + result = option_set_to_opt_integer_args(vm, VMOPT_XGCMAXTHREADS, &gcmaxthread_index, EXACT_MEMORY_MATCH, &gcThreadCount, args); + if (OPTION_OK != result) { + if (OPTION_MALFORMED == result) { + j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_MUST_BE_NUMBER, VMOPT_XGCMAXTHREADS); + } else { + j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_VALUE_OVERFLOWED, VMOPT_XGCMAXTHREADS); + } + goto _error; + } + + if (0 == gcThreadCount) { + j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_GC_OPTIONS_VALUE_MUST_BE_ABOVE, VMOPT_XGCMAXTHREADS, (UDATA)0); + goto _error; + } + + if (gcmaxthread_index > gcthread_index) { + extensions->gcThreadCount = gcThreadCount; + extensions->gcThreadCountSpecified = true; + extensions->gcThreadCountForced = false; + } + } + return true; _error: diff --git a/runtime/gc_modron_startup/mmparseXgc.cpp b/runtime/gc_modron_startup/mmparseXgc.cpp index ada8e198e9c..f2c23c20765 100644 --- a/runtime/gc_modron_startup/mmparseXgc.cpp +++ b/runtime/gc_modron_startup/mmparseXgc.cpp @@ -153,6 +153,7 @@ j9gc_initialize_parse_gc_colon(J9JavaVM *javaVM, char **scan_start) goto _error; } + extensions->gcThreadCountSpecified = true; extensions->gcThreadCountForced = true; goto _exit; } @@ -233,6 +234,7 @@ j9gc_initialize_parse_gc_colon(J9JavaVM *javaVM, char **scan_start) goto _error; } + extensions->gcThreadCountSpecified = true; extensions->gcThreadCountForced = true; goto _exit; }