RFR: 8324433: Introduce a way to determine if an expression is evaluated as a constant by the Jit compiler [v6]
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Jan 24 18:54:28 UTC 2024
On Wed, 24 Jan 2024 18:48:03 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> Naive question: the right way to use this would be almost invariably be like this:
>
> ```
> if (isCompileConstant(foo) && fooHasCertainStaticProperties(foo)) {
> // fast-path
> }
> // slow path
> ```
>
> Right? Then the expectation is that during interpreter and C1, `isCompileConstant` always returns false, so we just never take the fast path (but we probably still pay for the branch, right?). And, when we get to C2 and this method is inlined, at this point we know that either `foo` is constant or not. If it is constant we can check other conditions on foo (which presumably is cheap because `foo` is constant) and maybe take the fast-path. In both cases, there's no branch in the generated code because we know "statically" when inlining if `foo` has the right shape or not. Correct?
P.S. if this is correct, please consider adding something along those lines in the javadoc of `isCompileConstant`; as it stands it is a bit obscure to understand how this thing might be used, and what are the common pitfalls to avoid when using it.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17527#issuecomment-1908729766
More information about the core-libs-dev
mailing list