On Thu, 6 Feb 2025 13:08:31 GMT, Coleen Phillimore <cole...@openjdk.org> wrote:
>> Does `static final` help here? > > Yes. Yes it does. Cases when a class mirror is a compile-time constant are already well-optimized. Non constant cases are the ones where missing optimization opportunities arise. In this particular case, C2 doesn't benefit from the observation that `Clazz[]` is a leaf type at runtime (no subclasses). Hence, a value loaded from a field typed as `Clazz[]` has exactly the same type and `clazzArray.getClass()` can be constant folded to `Clazz[].class`. Rather than a common case, it feels more like a corner case. So, worth addressing as a follow-up enhancement. Another scenario is a meet of 2 primitive array types (ends up as `bottom[]` in C2 type system), but I believe it hasn't been optimized before. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/22652#discussion_r1945451909