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

Doug Simon dnsimon at openjdk.org
Sat Mar 2 12:12:51 UTC 2024


On Sat, 2 Mar 2024 11:28:43 GMT, Guoxiong Li <gli at openjdk.org> wrote:

>> In class files, in the local variable table, local variables have a start BCI and a length. The local variable has a value from BCI (inclusive) until BCI + length (exclusive).
>> On the other end, JVMCI stores that information in `Local` objects with a start BCI and an end BCI (inclusive).
>> Currently the parser just uses BCI+length to compute the end BCI, leading to an off-by-one error.
>> 
>> A simple test checking that the start and end BCIs are within the method's bytecode is added. It fails without the fix.
>
> 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.

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

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


More information about the hotspot-compiler-dev mailing list