From 3d62bbf4f2ea1b37d59c8307225239a88d9e66c0 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Mon, 22 Apr 2024 08:54:29 +0000 Subject: [PATCH] 8330681: Explicit hashCode and equals for java.lang.runtime.SwitchBootstraps$TypePairs Reviewed-by: jlahoda, mchung --- .../java/lang/runtime/SwitchBootstraps.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java index b7c9cb48812..f91a9ad4de3 100644 --- a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java +++ b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java @@ -82,8 +82,6 @@ public class SwitchBootstraps { private static final MethodTypeDesc TYPES_SWITCH_DESCRIPTOR = MethodTypeDesc.ofDescriptor("(Ljava/lang/Object;ILjava/util/function/BiPredicate;Ljava/util/List;)I"); - private static final Map typePairToName; - static { try { NULL_CHECK = LOOKUP.findStatic(Objects.class, "isNull", @@ -99,7 +97,6 @@ public class SwitchBootstraps { catch (ReflectiveOperationException e) { throw new ExceptionInInitializerError(e); } - typePairToName = TypePairs.initialize(); } /** @@ -507,7 +504,7 @@ public class SwitchBootstraps { } TypePairs typePair = TypePairs.of(Wrapper.asPrimitiveType(selectorType), classLabel); - String methodName = typePairToName.get(typePair); + String methodName = TypePairs.typePairToName.get(typePair); cb.invokestatic(ExactConversionsSupport.class.describeConstable().orElseThrow(), methodName, MethodTypeDesc.of(ConstantDescs.CD_boolean, typePair.from.describeConstable().orElseThrow())); @@ -684,6 +681,9 @@ public class SwitchBootstraps { // TypePairs should be in sync with the corresponding record in Lower record TypePairs(Class from, Class to) { + + private static final Map typePairToName = initialize(); + public static TypePairs of(Class from, Class to) { if (from == byte.class || from == short.class || from == char.class) { from = int.class; @@ -691,6 +691,17 @@ public class SwitchBootstraps { return new TypePairs(from, to); } + public int hashCode() { + return 31 * from.hashCode() + to.hashCode(); + } + + public boolean equals(Object other) { + if (other instanceof TypePairs otherPair) { + return otherPair.from == from && otherPair.to == to; + } + return false; + } + public static Map initialize() { Map typePairToName = new HashMap<>(); typePairToName.put(new TypePairs(byte.class, char.class), "isIntToCharExact"); // redirected