final fields in record
forax at univ-mlv.fr
Wed Nov 13 15:52:20 UTC 2019
It occurs to me that given that record is a new construct, we can fix an error from the past , final field not really be final.
Obviouly, it means that refactoring a class to a record or vice-versa will not be 100% compatible, but given that we have already introduced Class.isRecord(), it's not 100% compatible anyway. Compared to , which aim to solve the problem by adding more metadata, disabling mutation of the record synthetic fields once for all has the advantages that it requires less memory (and less possible deopt).
Given that records are immutable and that there is a special mechanism to deserialize them,
it think we should disallow records synthetic fields to be changed at runtime using reflection, JNI, Unsafe etc.
I believe the JLS has to be updated a bit to explicitly says that you can not change the synthetic fields of a record even by reflection during deserialization,
the reflection Field.set() has to be amended, etc.
And in the VM, the function `trust_final_non_static_fields` should add a case to trust record fields.
More information about the amber-spec-experts