Skip to content

Commit

Permalink
JEP471 sets system property according to the command line option value
Browse files Browse the repository at this point in the history
--sun-misc-unsafe-memory-access=value which is expected to be "allow",
"warn", "debug" or "deny";
Set a system property sun.misc.unsafe.memory.access with the value
specified via --sun-misc-unsafe-memory-access=value.

Signed-off-by: Jason Feng <fengj@ca.ibm.com>
  • Loading branch information
JasonFengJ9 committed Jun 6, 2024
1 parent c9f90d0 commit 9d3070f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions runtime/nls/j9vm/j9vm.nls
Original file line number Diff line number Diff line change
Expand Up @@ -2401,3 +2401,11 @@ J9NLS_VM_CRIU_CHECK_TRANSITION_TO_DEBUG_INTERPRETER_FAILED.explanation=checkTran
J9NLS_VM_CRIU_CHECK_TRANSITION_TO_DEBUG_INTERPRETER_FAILED.system_action=The JVM will throw a JVMRestoreException.
J9NLS_VM_CRIU_CHECK_TRANSITION_TO_DEBUG_INTERPRETER_FAILED.user_response=View CRIU documentation to determine how to resolve the error.
# END NON-TRANSLATABLE

J9NLS_VM_UNRECOGNISED_SUN_MISC_UNSAFE_MEMORY_ACCESS_VALUE=Value specified to --sun-misc-unsafe-memory-access not recognized: '%s'
# START NON-TRANSLATABLE
J9NLS_VM_UNRECOGNISED_CMD_LINE_OPT.sample_input_1=allow
J9NLS_VM_UNRECOGNISED_CMD_LINE_OPT.explanation=The value specified is not known.
J9NLS_VM_UNRECOGNISED_CMD_LINE_OPT.system_action=The JVM will fail to start.
J9NLS_VM_UNRECOGNISED_CMD_LINE_OPT.user_response=Change the value to one of "allow", "warn", "debug" or "deny".
# END NON-TRANSLATABLE
1 change: 1 addition & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ typedef struct J9VMCustomSpinOptions {
#define J9SYSPROP_ERROR_INVALID_JCL 4
#define J9SYSPROP_ERROR_UNSUPPORTED_PROP 5
#define J9SYSPROP_ERROR_ARG_MISSING 6
#define J9SYSPROP_ERROR_INVALID_VALUE 7

typedef struct J9VMDllLoadInfo {
char dllName[32];
Expand Down
6 changes: 6 additions & 0 deletions runtime/oti/jvminit.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ enum INIT_STAGE {
/* JEP 421: Deprecate Finalization for Removal */
#define VMOPT_DISABLE_FINALIZATION "--finalization="

/* JEP 471: Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal */
#define VMOPT_DISABLE_SUN_MISC_UNSAFE_MEMORY_ACCESS "--sun-misc-unsafe-memory-access="

#define ENVVAR_IBM_MIXED_MODE_THRESHOLD "IBM_MIXED_MODE_THRESHOLD"
#define ENVVAR_JAVA_COMPILER "JAVA_COMPILER"
#define ENVVAR_JAVA_OPTIONS "_JAVA_OPTIONS"
Expand Down Expand Up @@ -713,6 +716,9 @@ enum INIT_STAGE {
#define SYSPROP_JDK_MODULE_PATCH "jdk.module.patch."
#define SYSPROP_JDK_MODULE_ILLEGALACCESS "jdk.module.illegalAccess"
#define SYSPROP_JDK_MODULE_ENABLENATIVEACCESS "jdk.module.enable.native.access."
#if JAVA_SPEC_VERSION >= 23
#define SYSPROP_SUN_MISC_UNSAFE_MEMORY_ACCESS "sun.misc.unsafe.memory.access"
#endif /* JAVA_SPEC_VERSION >= 23 */
#define JAVA_BASE_MODULE "java.base"

#define SYSPROP_COM_SUN_MANAGEMENT "-Dcom.sun.management."
Expand Down
36 changes: 36 additions & 0 deletions runtime/vm/vmprops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,42 @@ initializeSystemProperties(J9JavaVM * vm)
}
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */

#if JAVA_SPEC_VERSION >= 23
{
/* JEP 471: Deprecate the Memory-Access Methods in sun.misc.Unsafe for Removal
* --sun-misc-unsafe-memory-access=value which is expected to be "allow", "warn", "debug" or "deny".
*/
IDATA argIndex = FIND_AND_CONSUME_VMARG(STARTSWITH_MATCH, VMOPT_DISABLE_SUN_MISC_UNSAFE_MEMORY_ACCESS, NULL);
if (argIndex >= 0) {
PORT_ACCESS_FROM_JAVAVM(vm);
UDATA optionNameLen = LITERAL_STRLEN(VMOPT_DISABLE_SUN_MISC_UNSAFE_MEMORY_ACCESS);
/* option name includes the '=' so go back one to get the option arg */
char *optionArg = getOptionArg(vm, argIndex, optionNameLen - 1);

if (NULL != optionArg) {
if ((0 == strcmp(optionArg, "allow"))
|| (0 == strcmp(optionArg, "warn"))
|| (0 == strcmp(optionArg, "debug"))
|| (0 == strcmp(optionArg, "deny"))
) {
rc = addSystemProperty(vm, SYSPROP_SUN_MISC_UNSAFE_MEMORY_ACCESS, optionArg, J9SYSPROP_FLAG_VALUE_ALLOCATED);
if (J9SYSPROP_ERROR_NONE != rc) {
goto fail;
}
} else {
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_VM_UNRECOGNISED_SUN_MISC_UNSAFE_MEMORY_ACCESS_VALUE, optionArg);
rc = J9SYSPROP_ERROR_INVALID_VALUE;
goto fail;
}
} else {
j9nls_printf(PORTLIB, J9NLS_ERROR, J9NLS_VM_UNRECOGNISED_SUN_MISC_UNSAFE_MEMORY_ACCESS_VALUE, "");
rc = J9SYSPROP_ERROR_ARG_MISSING;
goto fail;
}
}
}
#endif /* JAVA_SPEC_VERSION >= 23 */

/* If we get here all is good */
rc = J9SYSPROP_ERROR_NONE;

Expand Down

0 comments on commit 9d3070f

Please sign in to comment.