RFR: 8325949: Create an internal utility method for creating VarHandle instances [v2]

Kasper Nielsen duke at openjdk.org
Mon Sep 16 10:22:05 UTC 2024


On Fri, 13 Sep 2024 07:50:49 GMT, Per Minborg <pminborg at 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 |
>> 
>> ![image](https://github.com/user-attachments/assets/fdcbbdfe-c906-4e50-a48c-4944c53c08cc)
>> 
>> 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.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Rename and reformat

This would actually be super useful in a public API. I use the same "trick" in some of my projects. Not because I care too much about the classfile size. But it is just a lot easier on the eye.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/20972#issuecomment-2352521927


More information about the core-libs-dev mailing list