comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.jdi;
26
27 import com.sun.jdi.*;
28
29 import java.util.*;
30
31 public class LocationImpl extends MirrorImpl implements Location {
32 private final ReferenceTypeImpl declaringType;
33 private Method method;
34 private sun.jvm.hotspot.oops.Method methodRef;
35 private long codeIndex;
36 private LineInfo baseLineInfo = null;
37 private LineInfo otherLineInfo = null;
38
39 LocationImpl(VirtualMachine vm,
40 Method method, long codeIndex) {
41 super(vm);
42
43 this.method = method;
44 this.codeIndex = method.isNative()? -1 : codeIndex;
45 this.declaringType = (ReferenceTypeImpl)method.declaringType();
46 }
47
48 /*
49 * This constructor allows lazy creation of the method mirror. This
50 * can be a performance savings if the method mirror does not yet
51 * exist.
52 */
53 LocationImpl(VirtualMachine vm, ReferenceType declaringType,
54 sun.jvm.hotspot.oops.Method methodRef, long codeIndex) {
55 super(vm);
56
57 this.method = null;
58 this.codeIndex = codeIndex;
59 this.declaringType = (ReferenceTypeImpl)declaringType;
60 this.methodRef = methodRef;
61 }
62
63 public boolean equals(Object obj) {
64 if ((obj != null) && (obj instanceof Location)) {
65 Location other = (Location)obj;
66 return (method().equals(other.method())) &&
67 (codeIndex() == other.codeIndex()) &&
68 super.equals(obj);
69 } else {
70 return false;
71 }
72 }
73
74 public int hashCode() {
75 /*
76 * TO DO: better hash code?
77 */
78 return method().hashCode() + (int)codeIndex();
79 }
80
81 public int compareTo(Object object) {
82 LocationImpl other = (LocationImpl)object;
83 int rc = method().compareTo(other.method());
84 if (rc == 0) {
85 long diff = codeIndex() - other.codeIndex();
86 if (diff < 0)
87 return -1;
88 else if (diff > 0)
89 return 1;
90 else
91 return 0;
92 }
93 return rc;
94 }
95
96 public ReferenceType declaringType() {
97 return declaringType;
98 }
99
100 public Method method() {
101 if (method == null) {
102 method = declaringType.getMethodMirror(methodRef);
103 if (method.isNative()) {
104 codeIndex = -1;
105 }
106 }
107 return method;
108 }
109
110 public long codeIndex() {
111 method(); // be sure information is up-to-date
112 return codeIndex;
113 }
114
115 LineInfo getBaseLineInfo(SDE.Stratum stratum) {
116 LineInfo lineInfo;
117
118 /* check if there is cached info to use */
119 if (baseLineInfo != null) {
120 return baseLineInfo;
121 }
122
123 /* compute the line info */
124 MethodImpl methodImpl = (MethodImpl)method();
125 lineInfo = methodImpl.codeIndexToLineInfo(stratum,
126 codeIndex());
127
128 /* cache it */
129 addBaseLineInfo(lineInfo);
130
131 return lineInfo;
132 }
133
134 LineInfo getLineInfo(SDE.Stratum stratum) {
135 LineInfo lineInfo;
136
137 /* base stratum is done slighly differently */
138 if (stratum.isJava()) {
139 return getBaseLineInfo(stratum);
140 }
141
142 /* check if there is cached info to use */
143 lineInfo = otherLineInfo; // copy because of concurrency
144 if (lineInfo != null &&
145 stratum.id().equals(lineInfo.liStratum())) {
146 return lineInfo;
147 }
148 int baseLineNumber = lineNumber(SDE.BASE_STRATUM_NAME);
149 SDE.LineStratum lineStratum =
150 stratum.lineStratum(declaringType, baseLineNumber);
151
152 if (lineStratum != null && lineStratum.lineNumber() != -1) {
153 lineInfo = new StratumLineInfo(stratum.id(),
154 lineStratum.lineNumber(),
155 lineStratum.sourceName(),
156 lineStratum.sourcePath());
157 } else {
158 /* find best match */
159 MethodImpl methodImpl = (MethodImpl)method();
160 lineInfo = methodImpl.codeIndexToLineInfo(stratum,
161 codeIndex());
162 }
163
164 /* cache it */
165 addStratumLineInfo(lineInfo);
166
167 return lineInfo;
168 }
169
170 void addStratumLineInfo(LineInfo lineInfo) {
171 otherLineInfo = lineInfo;
172 }
173
174 void addBaseLineInfo(LineInfo lineInfo) {
175 baseLineInfo = lineInfo;
176 }
177
178 public String sourceName() throws AbsentInformationException {
179 return sourceName(vm.getDefaultStratum());
180 }
181
182 public String sourceName(String stratumID)
183 throws AbsentInformationException {
184 return sourceName(declaringType.stratum(stratumID));
185 }
186
187 String sourceName(SDE.Stratum stratum)
188 throws AbsentInformationException {
189 return getLineInfo(stratum).liSourceName();
190 }
191
192 public String sourcePath() throws AbsentInformationException {
193 return sourcePath(vm.getDefaultStratum());
194 }
195
196 public String sourcePath(String stratumID)
197 throws AbsentInformationException {
198 return sourcePath(declaringType.stratum(stratumID));
199 }
200
201 String sourcePath(SDE.Stratum stratum)
202 throws AbsentInformationException {
203 return getLineInfo(stratum).liSourcePath();
204 }
205
206 public int lineNumber() {
207 return lineNumber(vm.getDefaultStratum());
208 }
209
210 public int lineNumber(String stratumID) {
211 return lineNumber(declaringType.stratum(stratumID));
212 }
213
214 int lineNumber(SDE.Stratum stratum) {
215 return getLineInfo(stratum).liLineNumber();
216 }
217
218 public String toString() {
219 if (lineNumber() == -1) {
220 return method().toString() + "+" + codeIndex();
221 } else {
222 return declaringType().name() + ":" + lineNumber();
223 }
224 }
225 }