RFR: 8326692: JVMCI Local.endBci is off-by-one

Guoxiong Li gli at openjdk.org
Sat Mar 2 12:24:52 UTC 2024


On Sat, 2 Mar 2024 12:10:35 GMT, Doug Simon <dnsimon at openjdk.org> wrote:

>> src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java line 635:
>> 
>>> 633:         for (int i = 0; i < localVariableTableLength; i++) {
>>> 634:             final int startBci = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementStartBciOffset);
>>> 635:             final int endBci = startBci + UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementLengthOffset) - 1;
>> 
>> Just a question: Can the length of a local variable be 0?
>> 
>> **If the code length is 0, the `endBci` here may be less than `startBci`.**
>
> I don't see anything in [JVMS 4.7.13](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.13) that says it cannot be 0. It basically means the LVT entry is useless (denotes a local that is never alive) but is otherwise harmless.
> Maybe add this to the javadoc for `getEndBci()` to make the API user aware of this corner case:
> 
> If the value returned is less than {@link #getStartBCI}, this object denotes a local that is never live.

The reason, which causes this problem, is that the `Local::endBci` includes itself instead of excluding it. But now, we can only fix the javadoc just as you suggested.

> If the value returned is less than {@link #getStartBCI}, this object denotes a local that is never live.

`a local variable` may be better to `a local` above.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18087#discussion_r1509957764


More information about the hotspot-compiler-dev mailing list