[vector] Non capturing lambda

Viswanathan, Sandhya sandhya.viswanathan at intel.com
Thu Feb 28 00:32:07 UTC 2019


Hi Vladimir,

I was trying to port and push the "species as value" patch that we have so far. When I port it to the tip of panama/dev vectorIntrinsics branch, I see assertions in VectorIntrinsics.java that the lambda used in highlighted part is not a "non capturing lambda" e.g. in VectorInstrinsics.Load the lambda in highlighted part.
    @SuppressWarnings("unchecked")
    public static IntVector fromArray(IntSpecies species, int[] a, int i){
        Objects.requireNonNull(a);
        i = VectorIntrinsics.checkIndex(i, a.length, species.length());
        return VectorIntrinsics.load((Class<IntVector>) species.boxType(), int.class, species.length(),
                                     a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_INT_BASE_OFFSET,
                                     a, i,
                                     (c, idx) -> species.op(n -> c[idx + n]));
    }

All the tests pass if I modify the isNonCapturingLambda method in VectorIntrinsics.java to return true always as follows:
    static boolean isNonCapturingLambda(Object o) {
//        return o.getClass().getDeclaredFields().length == 0;
        return true;
    }

The ported webrev is at:
http://cr.openjdk.java.net/~sviswanathan/vectorIntrinsics/Brian/zero/webrev.02/

The question I have is why is the following lambda considered a capturing lambda?  The "species" is a parameter so cannot be capturing, am I correct? The rest of the lambda is as before.
                                     (c, idx) -> species.op(n -> c[idx + n])


I don't have experience with lambdas so bewildered at this point. Looking for your help ...

Best Regards,
Sandhya





More information about the panama-dev mailing list