[code-reflection] RFR: Support conversions of primitives in testing context [v2]

Paul Sandoz psandoz at openjdk.org
Fri Oct 25 20:20:17 UTC 2024


On Fri, 25 Oct 2024 18:29:35 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

>> Support conversions of primitives in testing context.
>
> Mourad Abbay has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Support testing context 's conversions for reference values

src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 3162:

> 3160:                 TypeElement s = target.type();
> 3161:                 TypeElement t = targetType;
> 3162:                 if (isNarrowingPrimitiveConv(s, t)) {

I think it would be first simpler to reason about if we characterize whether we are a primitive pattern or not and then further specialize. It should simplify the checking and reduce duplication e.g.,:

if (t instanceof PrimitiveType pt) {
  // Primitive type pattern

  if (s instanceof ClassType cs) {
    // Unboxing conversions
  } else {
    // primitive to primitive conversion
      PrimitiveType ps = (PrimitiveType) s;
  }

} else {
  // Reference type pattern
}

You can still identify specific cases with comments, some i expect should collapse to the same code.

Also we don't need to branch if the predicate would otherwise be a true constant we can just inline.

src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 3255:

> 3253:                     return false;
> 3254:                 }
> 3255:                 List<PrimitiveType> l = List.of(BYTE, SHORT, CHAR, INT, LONG, FLOAT, DOUBLE);

We should avoid the allocation here on each call. Also i think you really need a map of bit sizes, then the special behaviour for short and char becomes clearer.

src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 3261:

> 3259:             }
> 3260: 
> 3261:             private static boolean isNarrower(PrimitiveType s, PrimitiveType t) {

Not used?

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/265#discussion_r1817287980
PR Review Comment: https://git.openjdk.org/babylon/pull/265#discussion_r1817293223
PR Review Comment: https://git.openjdk.org/babylon/pull/265#discussion_r1817288527


More information about the babylon-dev mailing list