Skip to content

Commit 31ac871

Browse files
8326692: JVMCI Local.endBci is off-by-one
Reviewed-by: dnsimon, never, gli
1 parent 37e01ef commit 31ac871

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -632,7 +632,7 @@ public LocalVariableTable getLocalVariableTable() {
632632

633633
for (int i = 0; i < localVariableTableLength; i++) {
634634
final int startBci = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementStartBciOffset);
635-
final int endBci = startBci + UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementLengthOffset);
635+
final int endBci = startBci + UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementLengthOffset) - 1;
636636
final int nameCpIndex = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementNameCpIndexOffset);
637637
final int typeCpIndex = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementDescriptorCpIndexOffset);
638638
final int slot = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementSlotOffset);

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/Local.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,10 +41,19 @@ public Local(String name, JavaType type, int startBci, int endBci, int slot) {
4141
this.type = type;
4242
}
4343

44+
/**
45+
* Returns the first BCI at which this local has a value (inclusive).
46+
*/
4447
public int getStartBCI() {
4548
return startBci;
4649
}
4750

51+
52+
/**
53+
* Returns the last BCI at which this local has a value (inclusive).
54+
* If the value returned is less than {@link #getStartBCI}, this object denotes a local
55+
* variable that is never live.
56+
*/
4857
public int getEndBCI() {
4958
return endBci;
5059
}

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaMethod.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595

9696
import jdk.vm.ci.meta.ConstantPool;
9797
import jdk.vm.ci.meta.ExceptionHandler;
98+
import jdk.vm.ci.meta.Local;
99+
import jdk.vm.ci.meta.LocalVariableTable;
98100
import jdk.vm.ci.meta.ResolvedJavaMethod;
99101
import jdk.vm.ci.meta.ResolvedJavaMethod.Parameter;
100102
import jdk.vm.ci.meta.ResolvedJavaType;
@@ -734,6 +736,24 @@ public void getOopMapAtTest() throws Exception {
734736
Assert.assertTrue(processedMethodWithManyArgs[0]);
735737
}
736738

739+
@Test
740+
public void getLocalVariableTableTest() {
741+
for (ResolvedJavaMethod m : methods.values()) {
742+
LocalVariableTable table = m.getLocalVariableTable();
743+
if (table == null) {
744+
continue;
745+
}
746+
for (Local l : table.getLocals()) {
747+
if (l.getStartBCI() < 0) {
748+
throw new AssertionError(m.format("%H.%n(%p)") + " local " + l.getName() + " starts at " + l.getStartBCI());
749+
}
750+
if (l.getEndBCI() >= m.getCodeSize()) {
751+
throw new AssertionError(m.format("%H.%n(%p)") + " (" + m.getCodeSize() + "bytes) local " + l.getName() + " ends at " + l.getEndBCI());
752+
}
753+
}
754+
}
755+
}
756+
737757
private Method findTestMethod(Method apiMethod) {
738758
String testName = apiMethod.getName() + "Test";
739759
for (Method m : getClass().getDeclaredMethods()) {
@@ -756,7 +776,6 @@ private Method findTestMethod(Method apiMethod) {
756776
"canBeInlined",
757777
"shouldBeInlined",
758778
"getLineNumberTable",
759-
"getLocalVariableTable",
760779
"isInVirtualMethodTable",
761780
"toParameterTypes",
762781
"getParameterAnnotation",

0 commit comments

Comments
 (0)