From d51767b43febcb3783db59eba0e347ac5153c5f3 Mon Sep 17 00:00:00 2001 From: Peter Shipton Date: Thu, 7 Dec 2023 22:55:48 -0500 Subject: [PATCH] The java.compiler system property is obsolete in jdk21+ Issue https://github.com/eclipse-openj9/openj9/issues/18430 Signed-off-by: Peter Shipton --- .../internal/CompilationMXBeanImpl.java | 7 ++++- runtime/include/vmi.h | 2 +- runtime/jcl/common/system.c | 12 ++++++++ runtime/nls/j9cl/j9jcl.nls | 18 +++++++++++ runtime/util/vmargs.c | 2 ++ runtime/vm/jvminit.c | 30 +++++++++++++++---- runtime/vm/vmifunc.c | 2 +- runtime/vm/vmprops.c | 2 ++ .../test/vmArguments/VmArgumentTests.java | 9 ++++-- 9 files changed, 73 insertions(+), 11 deletions(-) diff --git a/jcl/src/java.management/share/classes/com/ibm/java/lang/management/internal/CompilationMXBeanImpl.java b/jcl/src/java.management/share/classes/com/ibm/java/lang/management/internal/CompilationMXBeanImpl.java index 480e8fca6a0..bae3318d3d0 100644 --- a/jcl/src/java.management/share/classes/com/ibm/java/lang/management/internal/CompilationMXBeanImpl.java +++ b/jcl/src/java.management/share/classes/com/ibm/java/lang/management/internal/CompilationMXBeanImpl.java @@ -72,7 +72,12 @@ public static CompilationMXBeanImpl getInstance() { */ @Override public String getName() { - return com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties().getProperty("java.compiler"); //$NON-NLS-1$ + return com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties(). +/*[IF JAVA_SPEC_VERSION < 21]*/ + getProperty("java.compiler"); //$NON-NLS-1$ +/*[ELSE] JAVA_SPEC_VERSION < 21 */ + getProperty("openj9.compiler"); //$NON-NLS-1$ +/*[ENDIF] JAVA_SPEC_VERSION < 21*/ } /** diff --git a/runtime/include/vmi.h b/runtime/include/vmi.h index 7c16c58e2fb..f5846ce7c1d 100644 --- a/runtime/include/vmi.h +++ b/runtime/include/vmi.h @@ -276,7 +276,7 @@ GetInitArgs(VMInterface* vmi);
OpenJ9 - 1ca0ab98
OMR - 05d2b8a2
JCL - c2aa0348 based on jdk8u172-b11" - * java.compiler "j9jit29" + * java.compiler "j9jit29" - not supported from jdk21 * java.class.version "52.0" * java.home the absolute path of the parent directory of the directory containing the vm
i.e. for a vm /clear/bin/vm.exe, java.home is /clear diff --git a/runtime/jcl/common/system.c b/runtime/jcl/common/system.c index fde6411f43e..9a46a056012 100644 --- a/runtime/jcl/common/system.c +++ b/runtime/jcl/common/system.c @@ -36,6 +36,7 @@ #include "jclprots.h" #include "ut_j9jcl.h" +#include "j9jclnls.h" #if defined(J9ZOS390) #include "atoe.h" @@ -551,6 +552,17 @@ systemPropertyIterator(char* key, char* value, void* userData) return; } +#if JAVA_SPEC_VERSION >= 21 + if (0 == strcmp("java.compiler", key)) { + PORT_ACCESS_FROM_ENV(env); + if ((0 == strcmp("jitc", value)) || (0 == strcmp(J9_JIT_DLL_NAME, value))) { + j9nls_printf(PORTLIB, J9NLS_WARNING, J9NLS_JCL_JAVA_COMPILER_WARNING_XJIT); + } else { + j9nls_printf(PORTLIB, J9NLS_WARNING, J9NLS_JCL_JAVA_COMPILER_WARNING_XINT); + } + return; + } +#endif /* JAVA_SPEC_VERSION >= 21 */ /* check for overridden system properties, use linear scan for now */ for (i=0; i < defaultCount; i+=2) { diff --git a/runtime/nls/j9cl/j9jcl.nls b/runtime/nls/j9cl/j9jcl.nls index 0a0c30cfdaf..cb1067bc754 100644 --- a/runtime/nls/j9cl/j9jcl.nls +++ b/runtime/nls/j9cl/j9jcl.nls @@ -588,3 +588,21 @@ J9NLS_JCL_CRIU_FAILED_TO_ENABLE_ALL_RESTORE_OPTIONS.explanation=CRIUSupport::che J9NLS_JCL_CRIU_FAILED_TO_ENABLE_ALL_RESTORE_OPTIONS.system_action=The JVM will throw a JVMRestoreException. J9NLS_JCL_CRIU_FAILED_TO_ENABLE_ALL_RESTORE_OPTIONS.user_response=Check documentation to see which options are allowed on restore. # END NON-TRANSLATABLE + +# Note: "java.compiler" is a system property name and should not be translated. +# Note: "-Xjit" is a command line parameter and should not be translated. +J9NLS_JCL_JAVA_COMPILER_WARNING_XJIT=Setting the java.compiler system property is obsolete in version 21 and later, use -Xjit instead. +# START NON-TRANSLATABLE +J9NLS_JCL_JAVA_COMPILER_WARNING_XJIT.explanation=The java.compiler system property can no longer be used to enable or disable the JIT. +J9NLS_JCL_JAVA_COMPILER_WARNING_XJIT.system_action=Setting the java.compiler system property is ignored. +J9NLS_JCL_JAVA_COMPILER_WARNING_XJIT.user_response=Use the -Xjit option to enable the JIT. +# END NON-TRANSLATABLE + +# Note: "java.compiler" is a system property name and should not be translated. +# Note: "-Xint" is a command line parameter and should not be translated. +J9NLS_JCL_JAVA_COMPILER_WARNING_XINT=Setting the java.compiler system property is obsolete in version 21 and later, use -Xint instead. +# START NON-TRANSLATABLE +J9NLS_JCL_JAVA_COMPILER_WARNING_XINT.explanation=The java.compiler system property can no longer be used to enable or disable the JIT. +J9NLS_JCL_JAVA_COMPILER_WARNING_XINT.system_action=Setting the java.compiler system property is ignored. +J9NLS_JCL_JAVA_COMPILER_WARNING_XINT.user_response=Use the -Xint option to disable the JIT. +# END NON-TRANSLATABLE diff --git a/runtime/util/vmargs.c b/runtime/util/vmargs.c index ec2e2dbc89a..416916a4fc2 100644 --- a/runtime/util/vmargs.c +++ b/runtime/util/vmargs.c @@ -1388,7 +1388,9 @@ addEnvironmentVariables(J9PortLibrary *portLib, JavaVMInitArgs *launcherArgs, J9 IDATA status = 0; if ( (0 != mapEnvVarToArgument(portLib, ENVVAR_IBM_MIXED_MODE_THRESHOLD, MAPOPT_XJIT_COUNT_EQUALS, vmArgumentsList, EXACT_MAP_WITH_OPTIONS, verboseFlags)) +#if JAVA_SPEC_VERSION < 21 || (0 != mapEnvVarToArgument(portLib, ENVVAR_JAVA_COMPILER, SYSPROP_DJAVA_COMPILER_EQUALS, vmArgumentsList, EXACT_MAP_WITH_OPTIONS, verboseFlags)) +#endif /* JAVA_SPEC_VERSION < 21 */ || (0 != mapEnvVarToArgument(portLib, ENVVAR_IBM_NOSIGHANDLER, VMOPT_XRS, vmArgumentsList, EXACT_MAP_NO_OPTIONS, verboseFlags)) #if defined(J9ZOS390) || (0 != mapEnvVarToArgument(portLib, ENVVAR_JAVA_THREAD_MODEL, MAPOPT_XTHR_TW_EQUALS, vmArgumentsList, EXACT_MAP_WITH_OPTIONS, verboseFlags)) diff --git a/runtime/vm/jvminit.c b/runtime/vm/jvminit.c index ce08e211ce3..10560341820 100644 --- a/runtime/vm/jvminit.c +++ b/runtime/vm/jvminit.c @@ -266,9 +266,9 @@ static void loadDLL (void* dllLoadInfo, void* userDataTemp); static void registerIgnoredOptions (J9PortLibrary *portLibrary, J9VMInitArgs* j9vm_args); static UDATA protectedInitializeJavaVM (J9PortLibrary* portLibrary, void * userData); static J9Pool *initializeDllLoadTable (J9PortLibrary *portLibrary, J9VMInitArgs* j9vm_args, UDATA verboseFlags, J9JavaVM *vm); -#if (defined(J9VM_OPT_SIDECAR)) +#if defined(J9VM_OPT_SIDECAR) && (JAVA_SPEC_VERSION < 21) static IDATA checkDjavacompiler (J9PortLibrary *portLibrary, J9VMInitArgs* j9vm_args); -#endif /* J9VM_OPT_SIDECAR */ +#endif /* defined(J9VM_OPT_SIDECAR) && (JAVA_SPEC_VERSION < 21) */ static void* getOptionExtraInfo (J9PortLibrary *portLibrary, J9VMInitArgs* j9vm_args, IDATA match, char* optionName); static void closeAllDLLs (J9JavaVM* vm); @@ -4865,6 +4865,7 @@ registerCmdLineMapping(J9JavaVM* vm, char* sov_option, char* j9_option, UDATA ma static IDATA registerVMCmdLineMappings(J9JavaVM* vm) { +#if JAVA_SPEC_VERSION < 21 char jitOpt[SMALL_STRING_BUF_SIZE]; /* Plenty big enough */ char* changeCursor; IDATA bufLeft = 0; @@ -4873,6 +4874,7 @@ registerVMCmdLineMappings(J9JavaVM* vm) strcpy(jitOpt, SYSPROP_DJAVA_COMPILER_EQUALS); bufLeft = SMALL_STRING_BUF_SIZE - strlen(jitOpt) - 1; changeCursor = &jitOpt[strlen(jitOpt)]; +#endif /* JAVA_SPEC_VERSION < 21 */ #ifdef J9VM_OPT_JVMTI if (registerCmdLineMapping(vm, MAPOPT_JAVAAGENT_COLON, MAPOPT_AGENTLIB_INSTRUMENT_EQUALS, MAP_WITH_INCLUSIVE_OPTIONS) == RC_FAILED) { @@ -4883,6 +4885,7 @@ registerVMCmdLineMappings(J9JavaVM* vm) if (registerCmdLineMapping(vm, MAPOPT_XCOMP, MAPOPT_XJIT_COUNT0, EXACT_MAP_NO_OPTIONS) == RC_FAILED) { return RC_FAILED; } +#if JAVA_SPEC_VERSION < 21 strncpy(changeCursor, DJCOPT_JITC, bufLeft); if (registerCmdLineMapping(vm, jitOpt, VMOPT_XJIT, EXACT_MAP_NO_OPTIONS) == RC_FAILED) { return RC_FAILED; @@ -4894,6 +4897,7 @@ registerVMCmdLineMappings(J9JavaVM* vm) if (registerCmdLineMapping(vm, SYSPROP_DJAVA_COMPILER_EQUALS, VMOPT_XINT, STARTSWITH_MAP_NO_OPTIONS) == RC_FAILED) { /* any other -Djava.compiler= found is mapped to -Xint */ return RC_FAILED; } +#endif /* JAVA_SPEC_VERSION < 21 */ if (registerCmdLineMapping(vm, MAPOPT_XDISABLEJAVADUMP, MAPOPT_XDUMP_JAVA_NONE, EXACT_MAP_NO_OPTIONS) == RC_FAILED) { return RC_FAILED; } @@ -6238,7 +6242,7 @@ testOptionValueOps(J9JavaVM* vm) #endif -#if (defined(J9VM_OPT_SIDECAR)) +#if defined(J9VM_OPT_SIDECAR) && (JAVA_SPEC_VERSION < 21) /* Whine about -Djava.compiler if the option is not used correctly */ static IDATA @@ -6263,7 +6267,7 @@ checkDjavacompiler(J9PortLibrary *portLibrary, J9VMInitArgs* j9vm_args) } return 0; } -#endif /* J9VM_OPT_SIDECAR */ +#endif /* defined(J9VM_OPT_SIDECAR) && (JAVA_SPEC_VERSION < 21) */ static IDATA @@ -7208,10 +7212,12 @@ protectedInitializeJavaVM(J9PortLibrary* portLibrary, void * userData) #endif #ifdef J9VM_OPT_SIDECAR +#if JAVA_SPEC_VERSION < 21 /* Whine about -Djava.compiler after extra VM options are added, but before mappings are set */ if (RC_FAILED == checkDjavacompiler(portLibrary, vm->vmArgsArray)) { goto error; } +#endif /* JAVA_SPEC_VERSION < 21 */ if (doParseXlogForCompatibility) { if (JNI_OK != parseXlogForCompatibility(vm)) { @@ -7367,17 +7373,23 @@ protectedInitializeJavaVM(J9PortLibrary* portLibrary, void * userData) goto error; } - /* If the JIT started, set the java.compiler system property and allocate the global OSR buffer */ + /* If the JIT started, set the java.compiler/openj9.compiler system property and allocate the global OSR buffer */ if (NULL != vm->jitConfig) { - J9VMSystemProperty * property = NULL; #ifndef DELETEME UDATA osrGlobalBufferSize = sizeof(J9JITDecompilationInfo); #endif +#if JAVA_SPEC_VERSION < 21 + J9VMSystemProperty * property = NULL; if (J9SYSPROP_ERROR_NONE == getSystemProperty(vm, "java.compiler", &property)) { setSystemProperty(vm, property, J9_JIT_DLL_NAME); property->flags &= ~J9SYSPROP_FLAG_WRITEABLE; } +#else /* JAVA_SPEC_VERSION < 21 */ + if (J9SYSPROP_ERROR_NONE != addSystemProperty(vm, "openj9.compiler", J9_JIT_DLL_NAME, 0)) { + goto error; + } +#endif /* JAVA_SPEC_VERSION < 21 */ #ifndef DELETEME osrGlobalBufferSize += ROUND_TO(sizeof(UDATA), vm->jitConfig->osrFramesMaximumSize); osrGlobalBufferSize += ROUND_TO(sizeof(UDATA), vm->jitConfig->osrScratchBufferMaximumSize); @@ -7422,6 +7434,12 @@ protectedInitializeJavaVM(J9PortLibrary* portLibrary, void * userData) } } else { +#if JAVA_SPEC_VERSION >= 21 + if (J9SYSPROP_ERROR_NONE != addSystemProperty(vm, "openj9.compiler", "", 0)) { + goto error; + } +#endif /* JAVA_SPEC_VERSION >= 21 */ + /* If there is no JIT, change the vm phase so RAS will enable level 2 tracepoints */ jvmPhaseChange(vm, J9VM_PHASE_NOT_STARTUP); } diff --git a/runtime/vm/vmifunc.c b/runtime/vm/vmifunc.c index 1772ae7f811..e60f0bf8ccd 100644 --- a/runtime/vm/vmifunc.c +++ b/runtime/vm/vmifunc.c @@ -204,7 +204,7 @@ vmi_getPortLibrary(VMInterface* vmi)
OpenJ9 - 1ca0ab98
OMR - 05d2b8a2
JCL - c2aa0348 based on jdk8u172-b11" - * java.compiler "j9jit29" + * java.compiler "j9jit29" - not supported from jdk21 * java.class.version "52.0" * java.home the absolute path of the parent directory of the directory containing the vm
i.e. for a vm /clear/bin/vm.exe, java.home is /clear diff --git a/runtime/vm/vmprops.c b/runtime/vm/vmprops.c index 7c4610f982d..4f9800183cc 100644 --- a/runtime/vm/vmprops.c +++ b/runtime/vm/vmprops.c @@ -744,11 +744,13 @@ initializeSystemProperties(J9JavaVM * vm) } #endif +#if JAVA_SPEC_VERSION < 21 /* Don't know the JIT yet, put in a placeholder and make it writeable for now */ rc = addSystemProperty(vm, "java.compiler", "", J9SYSPROP_FLAG_WRITEABLE); if (J9SYSPROP_ERROR_NONE != rc) { goto fail; } +#endif /* JAVA_SPEC_VERSION < 21 */ /* We don't have enough information yet. Put in placeholders. */ #if defined(J9VM_OPT_SIDECAR) && !defined(WIN32) diff --git a/test/functional/Java8andUp/src/org/openj9/test/vmArguments/VmArgumentTests.java b/test/functional/Java8andUp/src/org/openj9/test/vmArguments/VmArgumentTests.java index 497d4a0d814..c6dd43aff2c 100644 --- a/test/functional/Java8andUp/src/org/openj9/test/vmArguments/VmArgumentTests.java +++ b/test/functional/Java8andUp/src/org/openj9/test/vmArguments/VmArgumentTests.java @@ -115,7 +115,7 @@ public class VmArgumentTests { private static final String MAPOPT_XJIT_COUNT_EQUALS = "-Xjit:count="+MIXED_MODE_THRESHOLD_VALUE; private static final String JAVA_COMPILER = "JAVA_COMPILER"; - private static final String JAVA_COMPILER_VALUE=System.getProperty("java.compiler"); + private static final String JAVA_COMPILER_VALUE = System.getProperty(VersionCheck.major() < 21 ? "java.compiler" : "openj9.compiler"); private static final String SYSPROP_DJAVA_COMPILER_EQUALS = "-Djava.compiler="+JAVA_COMPILER_VALUE; private static final boolean isIBM; @@ -499,7 +499,12 @@ public void testMappedOptions() { env.put(IBM_JAVA_OPTIONS, ibmJavaOptionsArg); actualArguments = runAndGetArgumentList(pb); - final String[] expectedArguments = new String[] {MAPOPT_XJIT_COUNT_EQUALS, SYSPROP_DJAVA_COMPILER_EQUALS, VMOPT_XRS, ibmJavaOptionsArg}; + final String[] expectedArguments; + if (VersionCheck.major() < 21) { + expectedArguments = new String[] {MAPOPT_XJIT_COUNT_EQUALS, SYSPROP_DJAVA_COMPILER_EQUALS, VMOPT_XRS, ibmJavaOptionsArg}; + } else { + expectedArguments = new String[] {MAPOPT_XJIT_COUNT_EQUALS, VMOPT_XRS, ibmJavaOptionsArg}; + } HashMap argumentPositions = checkArguments(actualArguments, expectedArguments); checkArgumentSequence(expectedArguments, argumentPositions, true); /* mapped options in environment variables should come before other non-implicit arguments */