annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7311
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
22672
1bbd4a7c274b Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22054
diff changeset
23 package jdk.vm.ci.meta;
7311
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
23700
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
25 /**
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
26 * Maps bytecode indexes to source line numbers.
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
27 *
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
28 * @see "https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.12"
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
29 */
23393
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
30 public class LineNumberTable {
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
31
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
32 private final int[] lineNumbers;
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
33 private final int[] bci;
7311
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34
23700
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
35 /**
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
36 *
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
37 * @param lineNumbers an array or source line numbers. This array is now owned by this object
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
38 * and should not be mutated by the caller.
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
39 * @param bci an array of bytecode indexes the same length at {@code lineNumbers} whose entries
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
40 * are sorted in ascending order. This array is now owned by this object and must not
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
41 * be mutated by the caller.
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
42 */
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
43 @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `lineNumbers` and `bcis`")
23393
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
44 public LineNumberTable(int[] lineNumbers, int[] bci) {
23700
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
45 assert bci.length == lineNumbers.length;
23393
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
46 this.lineNumbers = lineNumbers;
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
47 this.bci = bci;
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
48 }
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
49
23700
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
50 /**
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
51 * Gets a source line number for {@code atBci}.
9e1235406b59 [Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
Doug Simon <doug.simon@oracle.com>
parents: 23393
diff changeset
52 */
23393
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
53 public int getLineNumber(int atBci) {
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
54 for (int i = 0; i < this.bci.length - 1; i++) {
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
55 if (this.bci[i] <= atBci && atBci < this.bci[i + 1]) {
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
56 return lineNumbers[i];
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
57 }
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
58 }
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
59 return lineNumbers[lineNumbers.length - 1];
1d4ce2d19e52 clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents: 22672
diff changeset
60 }
7311
3fda7128589e Added missing files LineNumberTable.java and LineNumberTableImpl.java.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 }