couple questions on method handle combinators

Paul Sandoz paul.sandoz at oracle.com
Sat Jun 10 00:18:22 UTC 2017


Hi Roland,

I think the general problem here is two distinct value worlds are colliding, the shadowy MVT value world, and the "avoiding the syntax bike shed painting" __ByValue value world.

AFAICT the MVT API assumes that if the ACC_VALUE modifier is set on a class (Q type) then it should have a particular naming convention related to the value capable class from which the value type class was derived (the latter being named <C>$Value, where <C> is the name of the value capable class. This is why 6 characters are chopped of the end of the name of the class MyValue5.

(There is some “magic” in the VM that detects, when class file parsing, if a class is a value capable class and if so derives the value type class via an up call to Java, see valhalla.shady.MinimalValueTypes_1_0.createDerivedValueType)

That assumption is encoded in areas of the method handle implementation, such as here:

private static MethodHandle makeIdentity(Class<?> ptype) {
    if (!MinimalValueTypes_1_0.isValueType(ptype)) {
        MethodType mtype = MethodType.methodType(ptype, ptype);
        LambdaForm lform = LambdaForm.identityForm(BasicType.basicType(ptype));
        return MethodHandleImpl.makeIntrinsic(mtype, lform, Intrinsic.IDENTITY);
    } else {
        try {
            return ValueType.forClass(MinimalValueTypes_1_0.getValueCapableClass(ptype)).identity();
        } catch (ReflectiveOperationException ex) {
            throw new IllegalStateException(ex);
        }
    }
}

I am unsure how to unify these two worlds. For now it might be easiest if you keep tests for the two worlds separate i.e. when working with MethodHandles work in the MVT world.

Paul.

> On 9 Jun 2017, at 09:03, Roland Westrelin <rwestrel at redhat.com> wrote:
> test78() attempts to build a loop whose result is a value type but
> creation of the loop combinator fails with:
> 
> java.lang.ExceptionInInitializerError
>        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>        at java.base/java.lang.reflect.Method.invoke(Method.java:563)
>        at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:115)
>        at java.base/java.lang.Thread.run(Thread.java:844)
> Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: compiler.valhalla.valuetypes.My
>        at java.base/java.lang.invoke.MethodHandles.makeIdentity(MethodHandles.java:3432)
>        at java.base/java.lang.invoke.MethodHandles.identity(MethodHandles.java:3363)
>        at java.base/java.lang.invoke.MethodHandles.countedLoop(MethodHandles.java:5524)
>        at java.base/java.lang.invoke.MethodHandles.countedLoop(MethodHandles.java:5389)
>        at compiler.valhalla.valuetypes.ValueTypeTestBench.<clinit>(ValueTypeTestBench.java:2314)
>        ... 6 more
> Caused by: java.lang.ClassNotFoundException: compiler.valhalla.valuetypes.My
>        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:553)
>        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
>        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:486)
>        at java.base/java.lang.Class.forName0(Native Method)
>        at java.base/java.lang.Class.forName(Class.java:374)
>        at java.base/valhalla.shady.MinimalValueTypes_1_0.getValueCapableClass(MinimalValueTypes_1_0.java:81)
>        at java.base/java.lang.invoke.MethodHandles.makeIdentity(MethodHandles.java:3430)
>        ... 10 more
> 
> Anyone has any idea how to build the loop combinator?
> 
> Roland.



More information about the valhalla-dev mailing list