Skip to content

Commit 3d62bbf

Browse files
committed
8330681: Explicit hashCode and equals for java.lang.runtime.SwitchBootstraps$TypePairs
Reviewed-by: jlahoda, mchung
1 parent 5313dcc commit 3d62bbf

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ private SwitchBootstraps() {}
8282
private static final MethodTypeDesc TYPES_SWITCH_DESCRIPTOR =
8383
MethodTypeDesc.ofDescriptor("(Ljava/lang/Object;ILjava/util/function/BiPredicate;Ljava/util/List;)I");
8484

85-
private static final Map<TypePairs, String> typePairToName;
86-
8785
static {
8886
try {
8987
NULL_CHECK = LOOKUP.findStatic(Objects.class, "isNull",
@@ -99,7 +97,6 @@ private SwitchBootstraps() {}
9997
catch (ReflectiveOperationException e) {
10098
throw new ExceptionInInitializerError(e);
10199
}
102-
typePairToName = TypePairs.initialize();
103100
}
104101

105102
/**
@@ -507,7 +504,7 @@ record Element(Label target, Label next, Object caseLabel) { }
507504
}
508505

509506
TypePairs typePair = TypePairs.of(Wrapper.asPrimitiveType(selectorType), classLabel);
510-
String methodName = typePairToName.get(typePair);
507+
String methodName = TypePairs.typePairToName.get(typePair);
511508
cb.invokestatic(ExactConversionsSupport.class.describeConstable().orElseThrow(),
512509
methodName,
513510
MethodTypeDesc.of(ConstantDescs.CD_boolean, typePair.from.describeConstable().orElseThrow()));
@@ -684,13 +681,27 @@ else if (selectorType.equals(targetType) ||
684681

685682
// TypePairs should be in sync with the corresponding record in Lower
686683
record TypePairs(Class<?> from, Class<?> to) {
684+
685+
private static final Map<TypePairs, String> typePairToName = initialize();
686+
687687
public static TypePairs of(Class<?> from, Class<?> to) {
688688
if (from == byte.class || from == short.class || from == char.class) {
689689
from = int.class;
690690
}
691691
return new TypePairs(from, to);
692692
}
693693

694+
public int hashCode() {
695+
return 31 * from.hashCode() + to.hashCode();
696+
}
697+
698+
public boolean equals(Object other) {
699+
if (other instanceof TypePairs otherPair) {
700+
return otherPair.from == from && otherPair.to == to;
701+
}
702+
return false;
703+
}
704+
694705
public static Map<TypePairs, String> initialize() {
695706
Map<TypePairs, String> typePairToName = new HashMap<>();
696707
typePairToName.put(new TypePairs(byte.class, char.class), "isIntToCharExact"); // redirected

0 commit comments

Comments
 (0)