On Mon, 26 Jun 2023 12:53:32 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/java/lang/invoke/MethodHandleNatives.java line > 359: > >> 357: if (staticArguments == null) >> 358: return "BSA0=null"; >> 359: return "BSA1="+staticArguments; > > Suggestion: > > return switch (staticArguments) { > case Object[] array -> "BSA="+java.util.Arrays.asList(array); > case int[] array -> "BSA@"+java.util.Arrays.toString(array); > case null -> "BSA0=null"; > default -> "BSA1="+staticArguments; > };
Nice observation and suggestions that I've totally missed, but unfortunately these code is used to set up boostrap methods, so pattern matching switches, which are implemented with bootstrap method [`SwitchBootstraps::typeSwitch`](https://github.com/openjdk/jdk/blob/4f5829e3433270d21f75ee949fbc056ae309a494/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java#L144), cannot be used or it will lead to infinite loops like using lambdas in early startup code. Meanwhile, even though Supplier, Consumer etc. are loaded as collections are loaded very early in startup, lambdas in their implementation methods are not called until j.l.invoke is ready, so they are safe. It's just some early startup shenanigans. Same story for early-startup records: https://github.com/openjdk/jdk/blob/4f5829e3433270d21f75ee949fbc056ae309a494/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java#L574-L578 ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14642#discussion_r1242181811