null checks vs. class resolution, and translation strategy for casts
Brian Goetz
brian.goetz at oracle.com
Thu Apr 9 20:03:39 UTC 2020
> I have a proposal for a translation strategy:
Casts to inline classes from their reference projections will be
frequent. Because the reference projection is sealed to permit only the
value projection, a cast is morally equivalent to a null check. We want
to preserve this performance model, because otherwise we're reinventing
boxing.
Going through `ldc X.class / invokevirtual Class.cast` will surely be
slow in the interpreter, but also risks being slow elsewhere (as do many
of the other options.)
So let me add to your list: is it time for a `checknonnull` bytecode,
which throws NPE if null, or some other more flexible checking
bytecode? (Alternatively, if we're saving bytecodes: `invokevirtual
Object.<nullcheck>`), where <nullcheck> is a fake method that always
links to a no-op, but invokevirtual NPEs on a null receiver.)
More information about the valhalla-spec-observers
mailing list