On Fri, 28 Jun 2024 22:03:36 GMT, ExE Boss <d...@openjdk.org> wrote: >> Issue [JDK-8164908](https://bugs.openjdk.org/browse/JDK-8164908) added >> support for functionality required to continue to support IIOP and custom >> serializers in light of additional module-based restrictions on reflection. >> It was expected that these libraries would use `sun.misc.Unsafe` in order to >> access fields of serializable classes. However, with JEP 471, the methods >> necessary to do this are being removed. >> >> To allow these libraries to continue to function, it is proposed to add two >> methods to `sun.reflect.ReflectionFactory` which will allow serialization >> libraries to acquire a method handle to generated `readObject`/`writeObject` >> methods which set or get the fields of the serializable class using the >> serialization `GetField`/`PutField` mechanism. These generated methods >> should be used by serialization libraries to serialize and deserialize >> classes which do not have a `readObject`/`writeObject` method or which use >> `ObjectInputStream.defaultReadObject`/`ObjectOutputStream.defaultWriteObject` >> to supplement default serialization. >> >> It is also proposed to add methods which allow for the reading of >> serialization-specific private static final fields from classes which have >> them. >> >> With the addition of these methods, serialization libraries no longer need >> to rely on `Unsafe` for serialization/deserialization activities. >> cc: @AlanBateman > > src/java.base/share/classes/jdk/internal/reflect/SerializationBytecodeGenerator.java > line 239: > >> 237: >> 238: private static final ClassDesc CD_Generated_writeObject = >> ClassDesc.of("jdk.internal.reflect", "Generated$$writeObject"); >> 239: private static final ClassDesc CD_Genearted_readObject = >> ClassDesc.of("jdk.internal.reflect", "Generated$$readObject"); > > It might be better to use `ReferenceClassDescImpl.ofValidated(String)` > here, or at least `ClassDesc.ofDescriptor(String)` to avoid binary to > internal name conversion: > > Suggestion: > > private static final ClassDesc CD_ObjectInputStream = > ReferenceClassDescImpl.ofValidated("Ljava/io/ObjectInputStream;"); > private static final ClassDesc CD_ObjectInputStream_GetField = > ReferenceClassDescImpl.ofValidated("Ljava/io/ObjectInputStream$GetField;"); > > private static final ClassDesc CD_ObjectOutputStream = > ReferenceClassDescImpl.ofValidated("Ljava/io/ObjectOutputStream;"); > private static final ClassDesc CD_ObjectOutputStream_PutField = > ReferenceClassDescImpl.ofValidated("Ljava/io/ObjectOutputStream$PutField;"); > > private static final ClassDesc CD_Generated_writeObject = > ReferenceClassDescImpl.ofValidated("Ljdk/internal/reflect/Generated$$writeObject;"); > private static final ClassDesc CD_Generated_readObject = > ReferenceClassDescImpl.ofValidated("Ljdk/internal/reflect/Generated$$readObject;");
Good idea. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/19702#discussion_r1660974461