On Sat, 20 Apr 2024 00:00:54 GMT, ExE Boss <d...@openjdk.org> wrote:

>> We can reduce overhead of first use of a switch bootstrap by moving 
>> `typePairToName` into `TypePairs` and by explicitly overriding `hashCode` 
>> and `equals`. The first change avoids loading and initializing the 
>> `TypePairs` class in actual cases, the second remove some excess code 
>> generation from happening on first use.
>
> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 685:
> 
>> 683:     record TypePairs(Class<?> from, Class<?> to) {
>> 684: 
>> 685:         private static final Map<TypePairs, String> typePairToName = 
>> initialize();
> 
> If `TypePairs.typePairToName` is never modified after initialisation, then it 
> should probably be made immutable:
> Suggestion:
> 
>         private static final Map<TypePairs, String> typePairToName = 
> Map.copyOf(initialize());

If you really think about it, the `initialize` method itself is somewhat 
problematic, as it's initializing with byte/short/char on the left, all of 
which are already converted to int in the of() factory. This should be done in 
a separate issue.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18865#discussion_r1573195851

Reply via email to