Skip to content

Commit

Permalink
8330681: Explicit hashCode and equals for java.lang.runtime.SwitchBoo…
Browse files Browse the repository at this point in the history
…tstraps$TypePairs

Reviewed-by: jlahoda, mchung
  • Loading branch information
cl4es committed Apr 22, 2024
1 parent 5313dcc commit 3d62bbf
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ private 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<TypePairs, String> typePairToName;

static {
try {
NULL_CHECK = LOOKUP.findStatic(Objects.class, "isNull",
Expand All @@ -99,7 +97,6 @@ private SwitchBootstraps() {}
catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
typePairToName = TypePairs.initialize();
}

/**
Expand Down Expand Up @@ -507,7 +504,7 @@ record Element(Label target, Label next, Object caseLabel) { }
}

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()));
Expand Down Expand Up @@ -684,13 +681,27 @@ else if (selectorType.equals(targetType) ||

// TypePairs should be in sync with the corresponding record in Lower
record TypePairs(Class<?> from, Class<?> to) {

private static final Map<TypePairs, String> typePairToName = initialize();

public static TypePairs of(Class<?> from, Class<?> to) {
if (from == byte.class || from == short.class || from == char.class) {
from = int.class;
}
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<TypePairs, String> initialize() {
Map<TypePairs, String> typePairToName = new HashMap<>();
typePairToName.put(new TypePairs(byte.class, char.class), "isIntToCharExact"); // redirected
Expand Down

1 comment on commit 3d62bbf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.