changeset 11691:22d70546af81

8160647: [JVMCI] need to be able to copy internal arrays from LocalVariableTable and LineNumberTable Reviewed-by: twisti, never
author dnsimon
date Sat, 02 Jul 2016 00:27:19 +0000
parents 6ab8be269224
children cfb594b3cdbe
files src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LineNumberTable.java src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LocalVariableTable.java
diffstat 2 files changed, 43 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LineNumberTable.java	Thu Jun 30 05:05:52 2016 -0700
+++ b/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LineNumberTable.java	Sat Jul 02 00:27:19 2016 +0000
@@ -30,32 +30,46 @@
 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();
+    }
 }
--- a/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LocalVariableTable.java	Thu Jun 30 05:05:52 2016 -0700
+++ b/src/jdk.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LocalVariableTable.java	Sat Jul 02 00:27:19 2016 +0000
@@ -26,6 +26,8 @@
 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 @@
     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 @@
         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 @@
         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) {