On Tue, 23 Jan 2024 08:16:07 GMT, Aleksey Shipilev <sh...@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 inspired by 
>> `std::is_constant_evaluated` in C++.
>> 
>> Please kindly give your opinion as well as your reviews, thanks very much.
>
> Nice. I had a similar thing stashed in my todo queue. Note that there is 
> already `isCompileConstant` that does similar thing: 
> https://github.com/openjdk/jdk/blob/5a74c2a67ebcb47e51732f03c4be694bdf920469/src/hotspot/share/opto/library_call.cpp#L8189-L8193
>  -- maybe we should just expose that more widely. I would suggest we just do 
> the private `java.lang.{Integer,...}.isCompileConstant` methods and bind them 
> to that intrinsic.

> @shipilev Thanks a lot for your suggestions. Yes I can just use 
> `inline_isCompileConstant` instead.
> 
> Regarding the place of the method, I'm not really sure as putting in 
> `java.lang.Long` seems out-of-place for an internal mechanism that is 
> obviously not only used in `java.lang`, which will force a new entry in 
> `JavaLangAccess`. 

Ah yes, if you need to use it across module boundaries, putting the 
private/protected method would require `JavaLangAccess`, which is burdensome. I 
am just icky about introducing a whole new internal class for this. Is there 
anything in current `jdk.internal.vm.*` that fits it? Maybe `misc.Unsafe` or 
`misc.VM`?

> Finally, I think accepting a `long` would be enough (maybe `double`, too?) 
> since `int`, `boolean` etc can be converted losslessly to `long`.

Right, that would work for primitives, since we could probably rely on 
conversion for constants to be folded. But I also see the value for asking 
`isCompileConstant(Object)`, which is not easily convertible. So I would just 
do the overloads for all primitives and `Object`. The C2 intrinsic would not 
care about the `arg(0)` type, it would reply `isCon` on those constants just 
the same.

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

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

Reply via email to