JDK-8342381 : Implement JEP Warn about use of Memory-Access Methods in `sun.misc.Unsafe`
  • Type: CSR
  • Component: core-libs
  • Priority: P4
  • Status: Provisional
  • Resolution: Unresolved
  • Fix Versions: 24
  • Submitted: 2024-10-16
  • Updated: 2024-10-22
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Change the default value of the command line option `--sun-misc-unsafe-memory-access` from `allow` to `warn`. A warning is printed to standard error on the first occasion that any memory-access method in `sun.misc.Unsafe` is used.


Problem
-------

JEP 471 introduced `--sun-misc-unsafe-memory-access={allow|warn|debug|deny}`, which controls the runtime behavior of `sun.misc.Unsafe`'s memory-access methods, with the default value of `allow`.

The next step in the roadmap is to change the default value of the option from `allow` to `warn`. A future JEP and CSR will propose to change the default value to `deny`.


Solution
--------

Change the default value of the command line option `--sun-misc-unsafe-memory-access` to `warn`. This is the equivalent of running with `--sun-misc-unsafe-memory-access=warn`. A  warning is printed to standard error on the first occasion that any memory-access method is used.

The warning can be suppressed in this release by running with `--sun-misc-unsafe-memory-access=allow`. 

Developers can prepare for the future by testing with `--sun-misc-unsafe-memory-access=deny`.


Specification
-------------

There are no specification changes.

The output from `java -X` for the command line option changes to:

```
    --sun-misc-unsafe-memory-access=<value>
                      allow or deny usage of unsupported API sun.misc.Unsafe
                      <value> is one of "allow", "warn", "debug", or "deny".
                      The default value is "warn".
```
Comments
Moving to Provisional.
22-10-2024