On Sun, 22 Sep 2024 14:08:38 GMT, Shaojin Wen <[email protected]> wrote:
>> src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java
>> line 1102:
>>
>>> 1100: target.localsSize = localsSize;
>>> 1101: if (stackSize > 0) {
>>> 1102: target.stack = Arrays.copyOf(stack, stackSize);
>>
>> Do you think we should use `.clone()` to avoid `getClass` checks and to
>> avoid extra array growing in case the new stack/local immediately grows due
>> to instructions after target?
>>
>> Also I think you can do `localsSize > 0` check for locals assignment too.
>
> stack.length may be larger than stackSize. In this case, the length of the
> array copied by clone will be longer than Arrays.copyOf. However, I have no
> evidence that Arrays.copyOf is faster than clone.
I found through debugging that in the `target.flags == -1` branch of
checkAssignableTo, `localsSize > 0 and stackSize = 0` are always, so I made
this optimization.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21121#discussion_r1770564307