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

Joshua Zhu jzhu at openjdk.java.net
Tue Mar 8 08:37:05 UTC 2022


On Mon, 7 Mar 2022 22:27:15 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> AFAICT the field detection is not specific to what javac generates. Although the likelihood is small, there might be other fields that start with the same prefix and that the same type?
> 
> Further, if javac changes its code generation strategy then this code may become redundant for newly generated code, but we might need to keep it around and maybe add another specific case for new code. (Pattern matching for switch is and will like further impact javac's generation strategy, although i don't know if it will impact this particular area.)
> 
> I understand the motivation, but the approach is fragile and is difficult to maintain over time. Unfortunately we don't yet have a general mechanism for read-only arrays.
> 
> My recommendation is to instead change the code in the Vector API.

The following minor adjustment for IntVector.species() could be made to resolve the performance issue I mentioned.
https://github.com/JoshuaZhuwj/jdk/commit/f817809d6846a5b64d014476d98da98a85933950
But it seems not elegant.

How about adding @Stable annotation for the SwitchMap generated for enum switches in javac compiler instead.
Although class files compiled by old version javac cannot be constant-folded, it overcomes the drawback that may be introduced by my initial change you described.

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

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


More information about the hotspot-dev mailing list