couple questions on method handle combinators

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Wed Jun 14 17:39:01 UTC 2017


>> (I'll happily leave your other inlining questions to people more
>> knowledgeable in that area).
>
> I could have phrased that question better. Let me try to give some
> context. For:
>
> MethodHandles.guardWithTest(test77_mh_test, test77_mh1, test77_mh2);
>
> AFAICT, the logic implemented by the lambda forms is:
>
> MethodHandle mh = selectAlternative(test77_mh_test, test77_mh1, test77_mh2);
> mh.invoke(...);
>
> So mh can't be a constant at the invoke if test77_mh_test returns either
> true and false.
>
> I suppose I expected something like:
>
> if (test77_mh_test.invoke()) {
>   test77_mh1.invoke();
> } else {
>   test77_mh2.invoke();
> }

Yes, that's how compiled LambdaForm for GWT should look like in 
bytecode. InvokerBytecodeGenerator.emitSelectAlternative() translates:

  t2:I=MethodHandle.invokeBasic(...);
  t5:L=MethodHandleImpl.selectAlternative(t2:I,...);
  ... =MethodHandle.invokeBasic(...)

into equivalent of

   if (testMH.invokeBasic(...)) {
      trueMH.invokeBasic(...);
   } else {
      falseMH.invokeBasic(...);
   }

(It's a bit more complicated to enable sharing of LambdaForm instances 
for GWTs and per-GWT branch frequencies profiling.)

Most likely, there's something missing for Q-typed shapes which disables 
SELECT_ALTERNATIVE intrinsic.

(I saw that Paul has already started looking into the problem.)

Best regards,
Vladimir Ivanov

>
> in which case, at the invoke sites the method handles could be known.
>
> The reason I'm experimenting with guardWithTest is that I'd like the
> lambda forms to follow a particular shape (to check if c2 can optimize
> the handling of the method handle call return properly):
>
> if ( ) {
>   value_type_result = m1.invoke();
> } else {
>   value_type_result = m2.invoke();
> }
> // value type result merged here
> return value_type_result;
>
> The merge of 2 return values is what I'm interested in. With a loop I
> expect I would get a similar pattern:
>
> value_type_result = init_mh.invoke();
> for(;;) {
>   value_type_result = body_mh.invoke(); // value type result merged here
> }
> return value_type_result;
>
> So I guess my question is: Is there no way to get guardWithTest to do
> what I want? Other than with loops and guardWithTest, is there another
> way to get a merge point with returned values from invokes?
>
> Roland.
>


More information about the valhalla-dev mailing list