annotate agent/src/share/classes/sun/jvm/hotspot/jdi/LocalVariableImpl.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2002-2004 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 public class LocalVariableImpl extends MirrorImpl
a61af66fc99e Initial load
duke
parents:
diff changeset
29 implements LocalVariable, ValueContainer
a61af66fc99e Initial load
duke
parents:
diff changeset
30 {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 private final Method method;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private final int slot;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private final Location scopeStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private final Location scopeEnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private final String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private final String signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private final String genericSignature;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 LocalVariableImpl(VirtualMachine vm, Method method,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 int slot, Location scopeStart, Location scopeEnd,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 String name, String signature, String genericSignature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 super(vm);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 this.method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this.slot = slot;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 this.scopeStart = scopeStart;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 this.scopeEnd = scopeEnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 this.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 this.signature = signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 this.genericSignature = genericSignature;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 if ((obj != null) && (obj instanceof LocalVariableImpl)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 LocalVariableImpl other = (LocalVariableImpl)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return (method.equals(other.method) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
56 slot() == other.slot() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
57 super.equals(obj));
a61af66fc99e Initial load
duke
parents:
diff changeset
58 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
65 * TO DO: Better hash code
a61af66fc99e Initial load
duke
parents:
diff changeset
66 */
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return (int)method.hashCode() + slot();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public int compareTo(Object object) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 LocalVariableImpl other = (LocalVariableImpl)object;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 int rc = method.compareTo(other.method);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (rc == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 rc = slot() - other.slot();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return rc;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 public String name() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return name;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
84 * @return a text representation of the declared type
a61af66fc99e Initial load
duke
parents:
diff changeset
85 * of this variable.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 */
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public String typeName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 JNITypeParser parser = new JNITypeParser(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return parser.typeName();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 public Type type() throws ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return findType(signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public Type findType(String signature) throws ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 ReferenceTypeImpl enclosing = (ReferenceTypeImpl)method.declaringType();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return enclosing.findType(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public String signature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public String genericSignature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return genericSignature;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public boolean isVisible(StackFrame frame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 //validateMirror(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 Method frameMethod = frame.location().method();
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (!frameMethod.equals(method)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 throw new IllegalArgumentException(
a61af66fc99e Initial load
duke
parents:
diff changeset
115 "frame method different than variable's method");
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // this is here to cover the possibility that we will
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // allow LocalVariables for native methods. If we do
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // so we will have to re-examinine this.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (frameMethod.isNative()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return ((scopeStart.compareTo(frame.location()) <= 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
126 && (scopeEnd.compareTo(frame.location()) >= 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public boolean isArgument() {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 MethodImpl method = (MethodImpl)scopeStart.method();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return (slot < method.argSlotCount());
a61af66fc99e Initial load
duke
parents:
diff changeset
133 } catch (AbsentInformationException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // If this variable object exists, there shouldn't be absent info
a61af66fc99e Initial load
duke
parents:
diff changeset
135 throw (InternalException) new InternalException().initCause(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 int slot() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return slot;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
144 * Compilers/VMs can have byte code ranges for variables of the
a61af66fc99e Initial load
duke
parents:
diff changeset
145 * same names that overlap. This is because the byte code ranges
a61af66fc99e Initial load
duke
parents:
diff changeset
146 * aren't necessarily scopes; they may have more to do with the
a61af66fc99e Initial load
duke
parents:
diff changeset
147 * lifetime of the variable's slot, depending on implementation.
a61af66fc99e Initial load
duke
parents:
diff changeset
148 *
a61af66fc99e Initial load
duke
parents:
diff changeset
149 * This method determines whether this variable hides an
a61af66fc99e Initial load
duke
parents:
diff changeset
150 * identically named variable; ie, their byte code ranges overlap
a61af66fc99e Initial load
duke
parents:
diff changeset
151 * this one starts after the given one. If it returns true this
a61af66fc99e Initial load
duke
parents:
diff changeset
152 * variable should be preferred when looking for a single variable
a61af66fc99e Initial load
duke
parents:
diff changeset
153 * with its name when both variables are visible.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 */
a61af66fc99e Initial load
duke
parents:
diff changeset
155 boolean hides(LocalVariable other) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 LocalVariableImpl otherImpl = (LocalVariableImpl)other;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (!method.equals(otherImpl.method) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
158 !name.equals(otherImpl.name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 return (scopeStart.compareTo(otherImpl.scopeStart) > 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return name() + " in " + method.toString() +
a61af66fc99e Initial load
duke
parents:
diff changeset
167 "@" + scopeStart.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }