couple questions on method handle combinators

Paul Sandoz paul.sandoz at oracle.com
Wed Jun 14 17:27:10 UTC 2017


> On 14 Jun 2017, at 10:04, Vladimir Ivanov <vladimir.x.ivanov at oracle.com> wrote:
> 
>>> The is due to the call to invoke, which performs an asType
>>> transformation and thus the receiver is not constant.
>> 
>> So it's effectively constant but the compiler can't see it? I had a
>> patch that added profiling of that receiver value. It didn't seem to
>> show any benefit at the time. I wonder it would make sense to experiment
>> with something similar again.
> 
> There's a simpler solution: since MH.asType() already uses 1-element cache [1], it should be enough to just mark MH.asTypeCache as @Stable.
> 

Would not invalidate the contract of @Stable where the value changes at most once? thereby causes issues for already compiled methods treating that as a constant when other code updates the value via an asType call.

i realize that we break similar rules for updating the LF, but that is a special case where we are in control where as we don’t control who calls MH.asType.

Paul.


> The problem with MH.asType() is more general: 1-element caching scheme doesn't scale for multiple MH.invoke() call sites with different signatures. Every cache miss requires a new method handle to be created.
> 
> Best regards,
> Vladimir Ivanov
> 
> [1] jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java:
> ...
> public abstract class MethodHandle {
> ...
>    /*private*/ MethodHandle asTypeCache;
> ...
>    public MethodHandle asType(MethodType newType) {
>        // Fast path alternative to a heavyweight {@code asType} call.
>        // Return 'this' if the conversion will be a no-op.
>        if (newType == type) {
>            return this;
>        }
>        // Return 'this.asTypeCache' if the conversion is already memoized.
>        MethodHandle atc = asTypeCached(newType);
>        if (atc != null) {
>            return atc;
>        }
>        return asTypeUncached(newType);
>    }
> 
>    private MethodHandle asTypeCached(MethodType newType) {
>        MethodHandle atc = asTypeCache;
>        if (atc != null && newType == atc.type) {
>            return atc;
>        }
>        return null;
>    }




More information about the valhalla-dev mailing list