[vector] Non capturing lambda

Viswanathan, Sandhya sandhya.viswanathan at intel.com
Thu Feb 28 17:59:40 UTC 2019


Hi Vladimir,

Your second suggestion looks appealing to me, I will incorporate that and push the changes before any other changes to the API needing me to remerge.

Thanks a lot as always, I depend a lot on your guidance :).

Best Regards,
Sandhya
 

-----Original Message-----
From: Vladimir Ivanov [mailto:vladimir.x.ivanov at oracle.com] 
Sent: Wednesday, February 27, 2019 7:47 PM
To: Viswanathan, Sandhya <sandhya.viswanathan at intel.com>; panama-dev at openjdk.java.net
Cc: Brian Goetz <brian.goetz at oracle.com>; John Rose <john.r.rose at oracle.com>
Subject: Re: [vector] Non capturing lambda


> The whole of work suggested by Brian to make Species more as values is dependent on this e.g. moving the fromByteArray, fromArray etc methods from XxxNnnSpecies to XxxVector (Int128Species to IntVector as an example). The methods cannot be moved to XxxNnnVector as the concrete classes are not to be made visible to the user.
It can be fixed either by introducing a package-private method on 
XxxSpecies:

public static IntVector fromArray(IntSpecies species, int[] a, int i) {
     return species.*fromArrayInternal*(a, i);
}

or adding a new argument to VectorIntrinsics.load() and 
VectorIntrinsics.LoadOperation:

public static IntVector fromArray(IntSpecies species, int[] a, int i){
     ...
     return VectorIntrinsics.load(...,
                                  a, i, *species*,
                                  (c, idx, *s*) -> s.op(n -> c[idx + n]));
}

I'm fine with both.

> Is this a requirement that the lambda be non capturing? I know you added this check recently. What are the downsides? There must be some way, there always is usually :).

As previous experience showed, capturing from default implementaiont 
easily breaks vector box elimination by accessing vector box instance. 
(It's not the case in this particular case though, but I couldn't come 
up with a better way to check there's no vector box access happening.)

Best regards,
Vladimir Ivanov

> -----Original Message-----
> From: Vladimir Ivanov [mailto:vladimir.x.ivanov at oracle.com]
> Sent: Wednesday, February 27, 2019 5:08 PM
> To: Viswanathan, Sandhya <sandhya.viswanathan at intel.com>; panama-dev at openjdk.java.net
> Cc: Brian Goetz <brian.goetz at oracle.com>; John Rose <john.r.rose at oracle.com>
> Subject: Re: [vector] Non capturing lambda
> 
> Hi Sandhya,
> 
>> 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])
> 
> 'species' isn't a lambda parameter. It's a part of context and has to be captured, since it is used in the lambda body.
> 
> In order to keep lambdas which represents default implementations non-capturing, only its arguments and static fields are allowed to be used.
> 
> I don't see an easy way to fix that without introducing new VectorIntrinsics variants to pass 'species' instance into default implementation.
> 
> I suggest to move the implementation back to Species and call it from XxxVector instead.
> 
> Best regards,
> Vladimir Ivanov
> 


More information about the panama-dev mailing list