RFR: 8333796: Add missing serialization functionality to sun.reflect.ReflectionFactory
David M. Lloyd
duke at openjdk.org
Fri Jul 5 14:46:44 UTC 2024
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
-------------
Commit messages:
- More tests
- Restrict field set to those defined by serialPersistentFields
- More tests and fixes
- Add tests for static accessors
- Missed one
- Apply review feedback
- Fix security manager permissions for test
- Neaten if statement
- Unused field
- Move bytecode gen back to `jdk.internal.reflect`, use unprivileged lookup for class definition
- ... and 18 more: https://git.openjdk.org/jdk/compare/d744059b...e7334655
Changes: https://git.openjdk.org/jdk/pull/19702/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19702&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8333796
Stats: 1111 lines in 5 files changed: 1106 ins; 1 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/19702.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/19702/head:pull/19702
PR: https://git.openjdk.org/jdk/pull/19702
More information about the core-libs-dev
mailing list