On Thu, 12 Sep 2024 17:38:44 GMT, Per Minborg <pminb...@openjdk.org> wrote:
> This PR suggests introducing an internal class in `java.base` to simplify the > use of some `MethodHandles.Lookup` operations. > > While the utility of the methods might appear to be limited in classes with > many static `VarHandle`/`MethodHandle` variables, it should be noted that the > class files become smaller and simpler. Here are some examples: > > | Class File | Base [Bytes] | Patch > [Byte] | > | --------------------------------| ------------- | ------------ | > | FutureTask.class | 10255 | > 10154 | > | AtomicBoolean.class | 5364 | > 5161 | > |AtomicMarkableReference.class | 3890 | 3687 | > >  > > The new `MethodHandlesInternal.class` file is of size 2012 bytes. > > In total for `java.base` we have: > > | Build map "jdk" | Size [Bytes] | > | ---------------| ------------- | > | Base | 5963657 | > | Patch | 5962751 | > | Delta | 906| > > For 60 billion instances, this represents 54 TB. src/java.base/share/classes/jdk/internal/reflect/MethodHandlesInternal.java line 47: > 45: private MethodHandlesInternal() {} > 46: > 47: public static VarHandle findVarHandleOrThrow(MethodHandles.Lookup > lookup, Class<?> recv, String name, Class<?> type) { The method naming might benefit from being clear that failure is fatal; never call it with arguments that might fail. Perhaps even throw java.lang.InternalError. ExceptionInInitializerError might be misconstrued as a some kind of race or being called too early. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20972#discussion_r1757467476