On Thu, 20 Jul 2023 15:53:10 GMT, Chen Liang <li...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/invoke/VarHandle.java line 2010: >> >>> 2008: static AccessMode valueFromOrdinal(int mode) { >>> 2009: return VALUES[mode]; >>> 2010: } >> >> Also, I'll throw this out there, though I'm not sure how big of an issue it >> is: this array creation might have an effect on startup. But, since it is >> only used on a slow path right before we throw an exception (at least, at >> the moment), calling `values()` every time inside the `valueFromOrdinal` >> method, and avoiding the array creation on startup, might be 'better'. > > I think this is a worthy change: see > https://github.com/openjdk/jdk/pull/14943/files#diff-556b309ea2df3f5bfe8229de944183ef19750ce4511d0328cd59af2ce2b61ae2R135 > that `VarHandle.AccessMode.values()` is called every time a polymorphic VH > call is linked. > > If the startup cost from array allocation is really problematic, we can make > it stable and allocate `VALUES` on demand (at `valueFromOrdinal` calls). Ah, so it looks like we are creating this array already, in adding the `valueFromOrdinal` method allows sharing. That sounds good! ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14928#discussion_r1269702376