RFR: 8341415: Optimize RawBytecodeHelper::next

ExE Boss duke at openjdk.org
Wed Oct 2 20:01:36 UTC 2024


On Wed, 2 Oct 2024 13:29:22 GMT, Shaojin Wen <swen at openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/classfile/impl/RawBytecodeHelper.java line 449:
>> 
>>> 447:         }
>>> 448: 
>>> 449:         if ((nextBci += len) > end) {
>> 
>> This change makes it that `nextBci` will no longer monotonically increase in case of a malformed special instruction.
>> 
>> Suggestion:
>> 
>>         if (len <= 0 || (nextBci += len) > end) {
>
> The checkSpecialInstruction has already added the 'len <= 0' process, so there is no need to check 'len <= '0' again.

`checkSpecialInstruction` will return `-1` in the following cases:
* `code == WIDE` and `bci + 1 >= end`
* `code == TABLESWITCH` and `align(bci + 1) + 3 * 4 >= end`
* `code == LOOKUPSWITCH` and
  * `align(bci + 1) + 2 * 4 >= end`
  * or `npairs` is out of range

Which will cause `nextBci` to be decremented in those cases in the proposed implementation.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21300#discussion_r1785154110


More information about the core-libs-dev mailing list