RFR: 8282722: Regard mapping array in enum switches as stable for constant folding

Rémi Forax forax at openjdk.java.net
Tue Mar 8 17:39:08 UTC 2022


On Tue, 8 Mar 2022 16:29:56 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> I came across a performance issue when using scatter store VectorAPI for Integer and Long simultaneously in the same application. The poor performance was caused by vector intrinsic inlining failure because of non-determined IntSpecies for a constant VectorShape of IndexMap in this scenario.
>> 
>> For ScatterStore operation of LongVector.SPECIES_512/IntVector.SPECIES_512, VectorShape.S_256_BIT/S_512_BIT is the actual length of indexMap vector respectively.
>> 
>> IntSpecies species(VectorShape s)
>> 
>> returns the corresponding IntSpecies by Switch on Enum type "VectorShape". [1] 
>> 
>> With this change introduced, elements in the SwitchMap array (initialized in clinit) can be constant-folded so that determined IntSpecies can be acquired for a constant VectorShape.
>> 
>> jtreg test passed without new failure.
>> Please help review this change and let me know if any comments.
>> 
>> [1] https://github.com/openjdk/jdk/blob/894ffb098c80bfeb4209038c017d01dbf53fac0f/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java#L4043
>
> Unfortunately the `@Stable` annotation can only be used by classes in the `java.base` module and other select modules. It cannot be used generally by application code given its unsafe nature.
> 
> We need read-only/frozen/constant arrays to do this properly in code outside of the JDK. 
> 
> Perhaps there is a clever alternative strategy javac could use, e.g. using a bootstrap method although nothing specific comes to mind at this moment. I would hold off on that until the code generation strategy for patterns in switch settles down.

@PaulSandoz,
i believe you can add "Stable" to the VarHandle API, as a kind of access like plain, opaque, volatile, etc.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7721


More information about the hotspot-dev mailing list