On Thu, 25 Jan 2024 14:01:59 GMT, Quan Anh Mai <qa...@openjdk.org> wrote:

>> Hi,
>> 
>> This patch introduces `JitCompiler::isConstantExpression` which can be used 
>> to statically determine whether an expression has been constant-folded by 
>> the Jit compiler, leading to more constant-folding opportunities. For 
>> example, it can be used in `MemorySessionImpl::checkValidStateRaw` to 
>> eliminate the lifetime check on global sessions without imposing additional 
>> branches on other non-global sessions. This is similar to 
>> `__builtin_constant_p` in GCC and clang.
>> 
>> Please kindly give your opinion as well as your reviews, thanks very much.
>
> Quan Anh Mai has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   change expr to val, add examples

I share Roland's concerns w.r.t. profiling. If there's any code guarded by 
`isCompileConstant(value) == true`, the only way to trigger its profiling is by 
deoptimizing from C2-generated code.

I added `MHI.isCompileConstant` intrinsic as part of a point fix for a 
performance problem caused by Java-level code profiling/specialization 
happening in `java.lang.invoke`. It guards profiling logic which is pruned 
completely once C2 kicks in. So, absence of profiling is not a problem there. 

Also, there's a constraint on implementation side: the current implementation 
supports only parse-time folding. If a value turns into a constant later 
(either during parsing after the call is encountered or during post-parsing 
phase), it won't have any effect.

So, as it is now (both on API and implementation sides) it's hard to correctly 
use `isCompileConstant` for more general cases.

It would be helpful to see more examples illustrating possible usage scenarios.

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

PR Comment: https://git.openjdk.org/jdk/pull/17527#issuecomment-1914052884

Reply via email to