changeset 23718:0bd91cd9869d

need to be able to copy internal arrays from LocalVariableTable and LineNumberTable (JDK-8160647)
author Doug Simon <doug.simon@oracle.com>
date Thu, 30 Jun 2016 22:08:57 +0200
parents 41fa89f93355
children a52d7039723b
files jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LineNumberTable.java jvmci/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/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LineNumberTable.java	Thu Jun 30 22:07:57 2016 +0200
+++ b/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LineNumberTable.java	Thu Jun 30 22:08:57 2016 +0200
@@ -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[] getLineNumbersCopy() {
+        return lineNumbers.clone();
+    }
+
+    /**
+     * Gets a copy of the array of bytecode indexes that was passed to this object's constructor.
+     */
+    public int[] getBcisCopy() {
+        return bcis.clone();
+    }
 }
--- a/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LocalVariableTable.java	Thu Jun 30 22:07:57 2016 +0200
+++ b/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LocalVariableTable.java	Thu Jun 30 22:08:57 2016 +0200
@@ -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[] getLocalsCopy() {
+        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) {