comparison jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LineNumberTable.java @ 23700:9e1235406b59

[Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
author Doug Simon <doug.simon@oracle.com>
date Sat, 18 Jun 2016 13:19:01 +0200
parents 1d4ce2d19e52
children 0bd91cd9869d
comparison
equal deleted inserted replaced
23699:8f9709f61cd4 23700:9e1235406b59
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package jdk.vm.ci.meta; 23 package jdk.vm.ci.meta;
24 24
25 /**
26 * Maps bytecode indexes to source line numbers.
27 *
28 * @see "https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.12"
29 */
25 public class LineNumberTable { 30 public class LineNumberTable {
26 31
27 private final int[] lineNumbers; 32 private final int[] lineNumbers;
28 private final int[] bci; 33 private final int[] bci;
29 34
35 /**
36 *
37 * @param lineNumbers an array or source line numbers. This array is now owned by this object
38 * and should not be mutated by the caller.
39 * @param bci an array of bytecode indexes the same length at {@code lineNumbers} whose entries
40 * are sorted in ascending order. This array is now owned by this object and must not
41 * be mutated by the caller.
42 */
43 @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `lineNumbers` and `bcis`")
30 public LineNumberTable(int[] lineNumbers, int[] bci) { 44 public LineNumberTable(int[] lineNumbers, int[] bci) {
45 assert bci.length == lineNumbers.length;
31 this.lineNumbers = lineNumbers; 46 this.lineNumbers = lineNumbers;
32 this.bci = bci; 47 this.bci = bci;
33 } 48 }
34 49
35 public int[] getLineNumberEntries() { 50 /**
36 return lineNumbers; 51 * Gets a source line number for {@code atBci}.
37 } 52 */
38
39 public int[] getBciEntries() {
40 return bci;
41 }
42
43 public int getLineNumber(int atBci) { 53 public int getLineNumber(int atBci) {
44 for (int i = 0; i < this.bci.length - 1; i++) { 54 for (int i = 0; i < this.bci.length - 1; i++) {
45 if (this.bci[i] <= atBci && atBci < this.bci[i + 1]) { 55 if (this.bci[i] <= atBci && atBci < this.bci[i + 1]) {
46 return lineNumbers[i]; 56 return lineNumbers[i];
47 } 57 }