8160647: [JVMCI] need to be able to copy internal arrays from LocalVariableTable and LineNumberTable

Reviewed-by: twisti, never
This commit is contained in:
Doug Simon 2016-07-02 00:27:19 +00:00
parent 77c3e19380
commit 037c3a6c39
2 changed files with 43 additions and 9 deletions

View File

@ -30,32 +30,46 @@ package jdk.vm.ci.meta;
public class LineNumberTable {
private final int[] lineNumbers;
private final int[] bci;
private final int[] bcis;
/**
*
* @param lineNumbers an array or source line numbers. This array is now owned by this object
* @param lineNumbers an array of source line numbers. This array is now owned by this object
* and should not be mutated by the caller.
* @param bci an array of bytecode indexes the same length at {@code lineNumbers} whose entries
* @param bcis an array of bytecode indexes the same length at {@code lineNumbers} whose entries
* are sorted in ascending order. This array is now owned by this object and must not
* be mutated by the caller.
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `lineNumbers` and `bcis`")
public LineNumberTable(int[] lineNumbers, int[] bci) {
assert bci.length == lineNumbers.length;
public LineNumberTable(int[] lineNumbers, int[] bcis) {
assert bcis.length == lineNumbers.length;
this.lineNumbers = lineNumbers;
this.bci = bci;
this.bcis = bcis;
}
/**
* Gets a source line number for {@code atBci}.
* Gets a source line number for bytecode index {@code atBci}.
*/
public int getLineNumber(int atBci) {
for (int i = 0; i < this.bci.length - 1; i++) {
if (this.bci[i] <= atBci && atBci < this.bci[i + 1]) {
for (int i = 0; i < this.bcis.length - 1; i++) {
if (this.bcis[i] <= atBci && atBci < this.bcis[i + 1]) {
return lineNumbers[i];
}
}
return lineNumbers[lineNumbers.length - 1];
}
/**
* Gets a copy of the array of line numbers that was passed to this object's constructor.
*/
public int[] getLineNumbers() {
return lineNumbers.clone();
}
/**
* Gets a copy of the array of bytecode indexes that was passed to this object's constructor.
*/
public int[] getBcis() {
return bcis.clone();
}
}

View File

@ -26,6 +26,8 @@ import java.util.ArrayList;
import java.util.List;
/**
* Describes the {@link Local}s for a Java method.
*
* @see "https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.13"
*/
public class LocalVariableTable {
@ -33,6 +35,7 @@ public class LocalVariableTable {
private final Local[] locals;
/**
* Creates an object describing the {@link Local}s for a Java method.
*
* @param locals array of objects describing local variables. This array is now owned by this
* object and must not be mutated by the caller.
@ -42,6 +45,13 @@ public class LocalVariableTable {
this.locals = locals;
}
/**
* Gets a description of a local variable that occupies the bytecode frame slot indexed by
* {@code slot} and is live at the bytecode index {@code bci}
*
* @return a description of the requested local variable or null if no such variable matches
* {@code slot} and {@code bci}
*/
public Local getLocal(int slot, int bci) {
Local result = null;
for (Local local : locals) {
@ -56,6 +66,16 @@ public class LocalVariableTable {
return result;
}
/**
* Gets a copy of the array of {@link Local}s that was passed to this object's constructor.
*/
public Local[] getLocals() {
return locals.clone();
}
/**
* Gets a description of all the local variables live at the bytecode index {@code bci}
*/
public Local[] getLocalsAt(int bci) {
List<Local> result = new ArrayList<>();
for (Local l : locals) {