annotate agent/src/share/classes/sun/jvm/hotspot/jdi/LocationImpl.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-2003 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
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class LocationImpl extends MirrorImpl implements Location {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private final ReferenceTypeImpl declaringType;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private Method method;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private sun.jvm.hotspot.oops.Method methodRef;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private long codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private LineInfo baseLineInfo = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private LineInfo otherLineInfo = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 LocationImpl(VirtualMachine vm,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 Method method, long codeIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 super(vm);
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 this.method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this.codeIndex = method.isNative()? -1 : codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 this.declaringType = (ReferenceTypeImpl)method.declaringType();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * This constructor allows lazy creation of the method mirror. This
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * can be a performance savings if the method mirror does not yet
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * exist.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 LocationImpl(VirtualMachine vm, ReferenceType declaringType,
a61af66fc99e Initial load
duke
parents:
diff changeset
54 sun.jvm.hotspot.oops.Method methodRef, long codeIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 super(vm);
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 this.method = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 this.codeIndex = codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 this.declaringType = (ReferenceTypeImpl)declaringType;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 this.methodRef = methodRef;
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 boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 if ((obj != null) && (obj instanceof Location)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Location other = (Location)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return (method().equals(other.method())) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
67 (codeIndex() == other.codeIndex()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
68 super.equals(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
76 * TO DO: better hash code?
a61af66fc99e Initial load
duke
parents:
diff changeset
77 */
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return method().hashCode() + (int)codeIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public int compareTo(Object object) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 LocationImpl other = (LocationImpl)object;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 int rc = method().compareTo(other.method());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (rc == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 long diff = codeIndex() - other.codeIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (diff < 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 else if (diff > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 else
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return rc;
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 ReferenceType declaringType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return declaringType;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public Method method() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (method == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 method = declaringType.getMethodMirror(methodRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (method.isNative()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 codeIndex = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return method;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public long codeIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 method(); // be sure information is up-to-date
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 LineInfo getBaseLineInfo(SDE.Stratum stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 LineInfo lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 /* check if there is cached info to use */
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (baseLineInfo != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 return baseLineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 /* compute the line info */
a61af66fc99e Initial load
duke
parents:
diff changeset
124 MethodImpl methodImpl = (MethodImpl)method();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 lineInfo = methodImpl.codeIndexToLineInfo(stratum,
a61af66fc99e Initial load
duke
parents:
diff changeset
126 codeIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 /* cache it */
a61af66fc99e Initial load
duke
parents:
diff changeset
129 addBaseLineInfo(lineInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 LineInfo getLineInfo(SDE.Stratum stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 LineInfo lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 /* base stratum is done slighly differently */
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (stratum.isJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return getBaseLineInfo(stratum);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 /* check if there is cached info to use */
a61af66fc99e Initial load
duke
parents:
diff changeset
143 lineInfo = otherLineInfo; // copy because of concurrency
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (lineInfo != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
145 stratum.id().equals(lineInfo.liStratum())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 int baseLineNumber = lineNumber(SDE.BASE_STRATUM_NAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 SDE.LineStratum lineStratum =
a61af66fc99e Initial load
duke
parents:
diff changeset
150 stratum.lineStratum(declaringType, baseLineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (lineStratum != null && lineStratum.lineNumber() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 lineInfo = new StratumLineInfo(stratum.id(),
a61af66fc99e Initial load
duke
parents:
diff changeset
154 lineStratum.lineNumber(),
a61af66fc99e Initial load
duke
parents:
diff changeset
155 lineStratum.sourceName(),
a61af66fc99e Initial load
duke
parents:
diff changeset
156 lineStratum.sourcePath());
a61af66fc99e Initial load
duke
parents:
diff changeset
157 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 /* find best match */
a61af66fc99e Initial load
duke
parents:
diff changeset
159 MethodImpl methodImpl = (MethodImpl)method();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 lineInfo = methodImpl.codeIndexToLineInfo(stratum,
a61af66fc99e Initial load
duke
parents:
diff changeset
161 codeIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 /* cache it */
a61af66fc99e Initial load
duke
parents:
diff changeset
165 addStratumLineInfo(lineInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 void addStratumLineInfo(LineInfo lineInfo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 otherLineInfo = lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 void addBaseLineInfo(LineInfo lineInfo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 baseLineInfo = lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public String sourceName() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return sourceName(vm.getDefaultStratum());
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public String sourceName(String stratumID)
a61af66fc99e Initial load
duke
parents:
diff changeset
183 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return sourceName(declaringType.stratum(stratumID));
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 String sourceName(SDE.Stratum stratum)
a61af66fc99e Initial load
duke
parents:
diff changeset
188 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return getLineInfo(stratum).liSourceName();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 public String sourcePath() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return sourcePath(vm.getDefaultStratum());
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public String sourcePath(String stratumID)
a61af66fc99e Initial load
duke
parents:
diff changeset
197 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return sourcePath(declaringType.stratum(stratumID));
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 String sourcePath(SDE.Stratum stratum)
a61af66fc99e Initial load
duke
parents:
diff changeset
202 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return getLineInfo(stratum).liSourcePath();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 public int lineNumber() {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 return lineNumber(vm.getDefaultStratum());
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 public int lineNumber(String stratumID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return lineNumber(declaringType.stratum(stratumID));
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 int lineNumber(SDE.Stratum stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return getLineInfo(stratum).liLineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (lineNumber() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 return method().toString() + "+" + codeIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return declaringType().name() + ":" + lineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }