On Tue, 23 Sep 2025 14:39:34 GMT, Vladimir Ivanov <[email protected]> wrote:
>> src/hotspot/share/runtime/fieldDescriptor.cpp line 53:
>>
>>> 51: // write protected fields (JLS 17.5.4)
>>> 52: if (is_final() && is_static() && ik == vmClasses::System_klass() &&
>>> 53: (offset() == java_lang_System::in_offset() || offset() ==
>>> java_lang_System::out_offset() || offset() ==
>>> java_lang_System::err_offset())) {
>>
>> I thought the ability to mutate these fields was restricted to the native
>> implementations of `setIn` et al. and was not allowed via regular
>> reflection? Otherwise how can these fields be considered as "trusted
>> finals"??
>
>> Otherwise how can these fields be considered as "trusted finals"??
>
> FTR `System.in` et al are not considered as trusted finals. There's a special
> logic in `ciField::initialize_from()` to disable corresponding optimizations,
> so the fields aren't treated as constants.
@iwanowww they are not special-cased here:
bool fieldDescriptor::is_trusted_final() const {
InstanceKlass* ik = field_holder();
return is_final() && (is_static() || ik->is_hidden() || ik->is_record());
}
and so would be reported as "trusted finals".
@AlanBateman my point is, if these can only be changed via JNI code through the
setX native methods, then why do we have to special case them in this code. ??
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25115#discussion_r2373552612