comparison jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/LocalVariableTable.java @ 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 9e1235406b59
children a52d7039723b
comparison
equal deleted inserted replaced
23717:41fa89f93355 23718:0bd91cd9869d
24 24
25 import java.util.ArrayList; 25 import java.util.ArrayList;
26 import java.util.List; 26 import java.util.List;
27 27
28 /** 28 /**
29 * Describes the {@link Local}s for a Java method.
30 *
29 * @see "https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.13" 31 * @see "https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.13"
30 */ 32 */
31 public class LocalVariableTable { 33 public class LocalVariableTable {
32 34
33 private final Local[] locals; 35 private final Local[] locals;
34 36
35 /** 37 /**
38 * Creates an object describing the {@link Local}s for a Java method.
36 * 39 *
37 * @param locals array of objects describing local variables. This array is now owned by this 40 * @param locals array of objects describing local variables. This array is now owned by this
38 * object and must not be mutated by the caller. 41 * object and must not be mutated by the caller.
39 */ 42 */
40 @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `locals`") 43 @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "caller transfers ownership of `locals`")
41 public LocalVariableTable(Local[] locals) { 44 public LocalVariableTable(Local[] locals) {
42 this.locals = locals; 45 this.locals = locals;
43 } 46 }
44 47
48 /**
49 * Gets a description of a local variable that occupies the bytecode frame slot indexed by
50 * {@code slot} and is live at the bytecode index {@code bci}
51 *
52 * @return a description of the requested local variable or null if no such variable matches
53 * {@code slot} and {@code bci}
54 */
45 public Local getLocal(int slot, int bci) { 55 public Local getLocal(int slot, int bci) {
46 Local result = null; 56 Local result = null;
47 for (Local local : locals) { 57 for (Local local : locals) {
48 if (local.getSlot() == slot && local.getStartBCI() <= bci && local.getEndBCI() >= bci) { 58 if (local.getSlot() == slot && local.getStartBCI() <= bci && local.getEndBCI() >= bci) {
49 if (result == null) { 59 if (result == null) {
54 } 64 }
55 } 65 }
56 return result; 66 return result;
57 } 67 }
58 68
69 /**
70 * Gets a copy of the array of {@link Local}s that was passed to this object's constructor.
71 */
72 public Local[] getLocalsCopy() {
73 return locals.clone();
74 }
75
76 /**
77 * Gets a description of all the local variables live at the bytecode index {@code bci}
78 */
59 public Local[] getLocalsAt(int bci) { 79 public Local[] getLocalsAt(int bci) {
60 List<Local> result = new ArrayList<>(); 80 List<Local> result = new ArrayList<>();
61 for (Local l : locals) { 81 for (Local l : locals) {
62 if (l.getStartBCI() <= bci && bci <= l.getEndBCI()) { 82 if (l.getStartBCI() <= bci && bci <= l.getEndBCI()) {
63 result.add(l); 83 result.add(l);