RFR: 8353835: Implement JEP 500: Prepare to Make Final Mean Final

Alan Bateman alanb at openjdk.org
Tue Sep 23 15:53:40 UTC 2025


On Mon, 22 Sep 2025 18:56:26 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:

>> Implementation changes for [JEP 500: Prepare to Make Final Mean Final](https://openjdk.org/jeps/500).
>> 
>> Field.set (and Lookup.unreflectSetter) are changed to allow/warn/debug/deny when mutating a final instance field. JFR event recorded if final field mutated. Spec updates to Field.set, Field.setAccessible and Module.addOpens to align with the proposal in the JEP.
>> 
>> HotSpot is updated to add support for the new command line options. To aid diagnosability, -Xcheck:jni reports a fatal error when a mutating a final field with JNI, and -Xlog:jni=debug can help identity when JNI code mutates finals. For now, JNI code is allowed to set the "write-protected" fields System.in/out/err, we can re-visit once we change the System.setIn/setOut/setErr methods to not use JNI (I prefer to keep this separate to this PR because there is a small startup regression to address when changing System.setXXX).
>> 
>> There are many new tests. A small number of existing tests are changed to run /othervm as reflectively opening a package isn't sufficient. Changing the tests to /othervm means that jtreg will launch the agent with the command line options to open the package.
>> 
>> Testing: tier1-6
>
> src/hotspot/share/runtime/fieldDescriptor.cpp line 49:
> 
>> 47: }
>> 48: 
>> 49: bool fieldDescriptor::is_mutable_static_final() const {
> 
> Please, migrate `ciField::initialize_from()` from ad-hoc checks to `fieldDescriptor::is_mutable_static_final()`.
> 
> 
> diff --git a/src/hotspot/share/ci/ciField.cpp b/src/hotspot/share/ci/ciField.cpp
> index cbe0cadbc93..dffc387612d 100644
> --- a/src/hotspot/share/ci/ciField.cpp
> +++ b/src/hotspot/share/ci/ciField.cpp
> @@ -267,17 +267,7 @@ void ciField::initialize_from(fieldDescriptor* fd) {
>        // not be constant is when the field is a *special* static & final field
>        // whose value may change.  The three examples are java.lang.System.in,
>        // java.lang.System.out, and java.lang.System.err.
> -      assert(vmClasses::System_klass() != nullptr, "Check once per vm");
> -      if (k == vmClasses::System_klass()) {
> -        // Check offsets for case 2: System.in, System.out, or System.err
> -        if (_offset == java_lang_System::in_offset()  ||
> -            _offset == java_lang_System::out_offset() ||
> -            _offset == java_lang_System::err_offset()) {
> -          _is_constant = false;
> -          return;
> -        }
> -      }
> -      _is_constant = true;
> +      _is_constant = !fd->is_mutable_static_final();
>      } else {
>        // An instance field can be constant if it's a final static field or if
>        // it's a final non-static field of a trusted class (classes in

Thanks, that does improve ciField::initialize_from.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25115#discussion_r2372777742


More information about the core-libs-dev mailing list