On Thu, 25 Jan 2024 12:52:21 GMT, Maurizio Cimadamore <mcimadam...@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?
>>> 
>>> Yes, I think so.
>> 
>> But then whatever is in the fast path and `fooHasCertainStaticProperties` 
>> are never profiled because never executed by the interpreter or c1. So 
>> `fooHasCertainStaticProperties` will likely not be inlined and c2 will do a 
>> poor (or rather not as good as you'd like) job of compiling whatever is in 
>> the fast path.
>
>> > > 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?
>> > 
>> > 
>> > Yes, I think so.
>> 
>> But then whatever is in the fast path and `fooHasCertainStaticProperties` 
>> are never profiled because never executed by the interpreter or c1. So 
>> `fooHasCertainStaticProperties` will likely not be inlined and c2 will do a 
>> poor (or rather not as good as you'd like) job of compiling whatever is in 
>> the fast path.
> 
> I suppose perhaps it is implied that `fooHasCertainStaticProperties` should 
> have `@ForceInline` ? But yes, there seems to be several assumptions in how 
> this logic is supposed to be used, and at the moment, it seems to me more of 
> a footgun than something actually useful (but I admit my ignorance on the 
> subject).

> @mcimadamore Yes this is hard to use apart from the simple cases. Considering 
> we have already used this technique in the `MethodHandle` implementation, I 
> think there are valid use cases.

I don't 100% buy the `MethodHandleImpl` analogy. In that case the check is not 
simply used to save a branch, but to spare spinning of a completely new lambda 
form. That is a very heavy operation. What I'm trying to say is that I'm not 
too sure how robust of a mechanism this is in the context of 
micro(nano?)-optimizations (such as the one you are considering).

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

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

Reply via email to