RFR: 8325949: Create an internal utility method for creating VarHandle instances [v4]
Roger Riggs
rriggs at openjdk.org
Tue Sep 17 14:07:05 UTC 2024
On Tue, 17 Sep 2024 13:05:24 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 | 10,255 | 10,123 |
>> | AtomicBoolean.class | 5,364 | 5,134 |
>> |AtomicMarkableReference.class | 3,890 | 3,660 |
>>
>> 
>>
>> The new `MethodHandlesInternal.class` file is of size 1,952 bytes.
>>
>> In total for `java.base` we have:
>>
>> | Build map "jdk" | Size [Bytes] |
>> | ---------------| ------------- |
>> | Base | 5,906,457 |
>> | Patch | 5,905,487 |
>> | Delta | 940|
>>
>> For 60 billion instances, this represents > 50 TB.
>>
>> Tried and passed tier1-3
>
> Per Minborg has updated the pull request incrementally with two additional commits since the last revision:
>
> - Update javadoc
> - Rename utility class
Overall looks good. Having a concise source construct representing these factories will enable jlink or similar pre-processing steps to optimize.
The new class will be lonesome in its own package.
I'd shorten the classname to "MHUtil" making the source lines more readable.
src/java.base/share/classes/jdk/internal/invoke/MethodHandlesUtil.java line 35:
> 33: /**
> 34: * This class contains a number of static factories for certain
> 35: * VarHandle/MethodHandle variants.
I'd write this as a more concise 1st line comment. "This class contains a number of" is noise.
"Utility static factories of method handles for fields and methods."
or similar.
-------------
PR Review: https://git.openjdk.org/jdk/pull/20972#pullrequestreview-2309856171
PR Review Comment: https://git.openjdk.org/jdk/pull/20972#discussion_r1763305393
More information about the core-libs-dev
mailing list