On Mon, 26 Jun 2023 12:57:34 GMT, Glavo <d...@openjdk.org> wrote: >> Chen Liang has updated the pull request with a new target base due to a >> merge or a rebase. The incremental webrev excludes the unrelated changes >> brought in by the merge/rebase. The pull request contains two additional >> commits since the last revision: >> >> - Merge branch 'master' into cleanup/invoke-instanceof >> - 8310849: Pattern matching for instanceof and arrayType cleanup in >> j.l.invoke and j.l.reflect > > src/java.base/share/classes/sun/invoke/util/ValueConversions.java line 239: > >> 237: return ZERO_INT; >> 238: } >> 239: if (x instanceof Number n) { > > Number res = switch (x) { > case Number n -> n; > case Boolean b -> b ? ONE_INT : ZERO_INT; > case Character c -> (int) c; > // this will fail with the required ClassCastException: > default -> (Number) x; > };
Unfortunately, this is used by MethodHandleImpl, so can't use indy switches. > src/java.base/share/classes/sun/invoke/util/ValueConversions.java line 262: > >> 260: */ >> 261: public static int widenSubword(Object x) { >> 262: if (x instanceof Integer i) > > return switch (x) { > case Integer i -> i; > case Boolean b -> fromBoolean(b); > case Character c -> c; > case Short s -> s; > case Byte b -> b; > // Fail with a ClassCastException. > case null, default -> (int) x; > }; Also used by MethodHandles.insertArgumentPrimitive, likely not safe. > src/java.base/share/classes/sun/invoke/util/Wrapper.java line 583: > >> 581: >> 582: private static Number numberValue(Object x) { >> 583: if (x instanceof Number n) return n; > > return switch (x) { > case Number n -> n; > case Character c -> (int) c; > case Boolean b -> b ? 1 : 0; > // Remaining allowed case of void: Must be a null reference. > case null, default -> (Number) x; > }; This is used by Wrapper.convert and MethodHandles.insertArgumentPrimitive, which I don't think is a safe candidate either. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14642#discussion_r1242192173 PR Review Comment: https://git.openjdk.org/jdk/pull/14642#discussion_r1242196620 PR Review Comment: https://git.openjdk.org/jdk/pull/14642#discussion_r1242195548