annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ConcreteMethodImpl.java @ 12226:7944aba7ba41

8015107: NPG: Use consistent naming for metaspace concepts Reviewed-by: coleenp, mgerdin, hseigel
author ehelin
date Mon, 12 Aug 2013 17:37:02 +0200
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
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 import sun.jvm.hotspot.oops.Symbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.LocalVariableTableElement;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.oops.LineNumberTableElement;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.util.List;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import java.util.Iterator;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import java.util.Map;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import java.util.HashMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import java.util.ArrayList;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import java.util.Comparator;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import java.lang.ref.SoftReference;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import java.util.Collections;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public class ConcreteMethodImpl extends MethodImpl {
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
43 * A subset of the line number info that is softly cached
a61af66fc99e Initial load
duke
parents:
diff changeset
44 */
a61af66fc99e Initial load
duke
parents:
diff changeset
45 static private class SoftLocationXRefs {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 final String stratumID; // The stratum of this information
a61af66fc99e Initial load
duke
parents:
diff changeset
47 final Map lineMapper; // Maps line number to location(s)
a61af66fc99e Initial load
duke
parents:
diff changeset
48 final List lineLocations; // List of locations ordered by code index
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * Note: these do not necessarily correspond to
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * the line numbers of the first and last elements
a61af66fc99e Initial load
duke
parents:
diff changeset
53 * in the lineLocations list. Use these only for bounds
a61af66fc99e Initial load
duke
parents:
diff changeset
54 * checking and with lineMapper.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 */
a61af66fc99e Initial load
duke
parents:
diff changeset
56 final int lowestLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 final int highestLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 SoftLocationXRefs(String stratumID, Map lineMapper, List lineLocations,
a61af66fc99e Initial load
duke
parents:
diff changeset
60 int lowestLine, int highestLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 this.stratumID = stratumID;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 this.lineMapper = Collections.unmodifiableMap(lineMapper);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 this.lineLocations =
a61af66fc99e Initial load
duke
parents:
diff changeset
64 Collections.unmodifiableList(lineLocations);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 this.lowestLine = lowestLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 this.highestLine = highestLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 private SoftReference softBaseLocationXRefsRef;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 private SoftReference softOtherLocationXRefsRef;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private SoftReference variablesRef = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private int firstIndex = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private int lastIndex = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 private Location location;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 private SoftReference bytecodesRef = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 ConcreteMethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
a61af66fc99e Initial load
duke
parents:
diff changeset
79 sun.jvm.hotspot.oops.Method saMethod ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 super(vm, declaringType, saMethod);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 int argSlotCount() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return (int) saMethod.getSizeOfParameters();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 private SoftLocationXRefs getLocations(SDE.Stratum stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (stratum.isJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return getBaseLocations();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 String stratumID = stratum.id();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 SoftLocationXRefs info =
a61af66fc99e Initial load
duke
parents:
diff changeset
93 (softOtherLocationXRefsRef == null) ? null :
a61af66fc99e Initial load
duke
parents:
diff changeset
94 (SoftLocationXRefs)softOtherLocationXRefsRef.get();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (info != null && info.stratumID.equals(stratumID)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return info;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 List lineLocations = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 Map lineMapper = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 int lowestLine = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 int highestLine = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 SDE.LineStratum lastLineStratum = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 SDE.Stratum baseStratum =
a61af66fc99e Initial load
duke
parents:
diff changeset
105 declaringType.stratum(SDE.BASE_STRATUM_NAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 Iterator it = getBaseLocations().lineLocations.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 while(it.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 LocationImpl loc = (LocationImpl)it.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 int baseLineNumber = loc.lineNumber(baseStratum);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 SDE.LineStratum lineStratum =
a61af66fc99e Initial load
duke
parents:
diff changeset
111 stratum.lineStratum(declaringType,
a61af66fc99e Initial load
duke
parents:
diff changeset
112 baseLineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (lineStratum == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // location not mapped in this stratum
a61af66fc99e Initial load
duke
parents:
diff changeset
116 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 int lineNumber = lineStratum.lineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // remove unmapped and dup lines
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if ((lineNumber != -1) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
123 (!lineStratum.equals(lastLineStratum))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 lastLineStratum = lineStratum;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Remember the largest/smallest line number
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (lineNumber > highestLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 highestLine = lineNumber;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if ((lineNumber < lowestLine) || (lowestLine == -1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 lowestLine = lineNumber;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 loc.addStratumLineInfo(
a61af66fc99e Initial load
duke
parents:
diff changeset
134 new StratumLineInfo(stratumID,
a61af66fc99e Initial load
duke
parents:
diff changeset
135 lineNumber,
a61af66fc99e Initial load
duke
parents:
diff changeset
136 lineStratum.sourceName(),
a61af66fc99e Initial load
duke
parents:
diff changeset
137 lineStratum.sourcePath()));
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Add to the location list
a61af66fc99e Initial load
duke
parents:
diff changeset
140 lineLocations.add(loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Add to the line -> locations map
a61af66fc99e Initial load
duke
parents:
diff changeset
143 Integer key = new Integer(lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 List mappedLocs = (List)lineMapper.get(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (mappedLocs == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 mappedLocs = new ArrayList(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 lineMapper.put(key, mappedLocs);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 mappedLocs.add(loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 info = new SoftLocationXRefs(stratumID,
a61af66fc99e Initial load
duke
parents:
diff changeset
154 lineMapper, lineLocations,
a61af66fc99e Initial load
duke
parents:
diff changeset
155 lowestLine, highestLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 softOtherLocationXRefsRef = new SoftReference(info);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 return info;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 private SoftLocationXRefs getBaseLocations() {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 SoftLocationXRefs info = (softBaseLocationXRefsRef == null) ? null :
a61af66fc99e Initial load
duke
parents:
diff changeset
162 (SoftLocationXRefs)softBaseLocationXRefsRef.get();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 if (info != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return info;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 byte[] codeBuf = bytecodes();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 firstIndex = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 lastIndex = codeBuf.length - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // This is odd; what is the Location of a Method?
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // A StackFrame can have a location, but a Method?
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // I guess it must be the Location for bci 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
173 location = new LocationImpl(virtualMachine(), this, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 boolean hasLineInfo = saMethod.hasLineNumberTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 LineNumberTableElement[] lntab = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 int count;
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (hasLineInfo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 lntab = saMethod.getLineNumberTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 count = lntab.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 List lineLocations = new ArrayList(count);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 Map lineMapper = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 int lowestLine = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 int highestLine = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 for (int i = 0; i < count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 long bci = lntab[i].getStartBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 int lineNumber = lntab[i].getLineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
195 * Some compilers will point multiple consecutive
a61af66fc99e Initial load
duke
parents:
diff changeset
196 * lines at the same location. We need to choose
a61af66fc99e Initial load
duke
parents:
diff changeset
197 * one of them so that we can consistently map back
a61af66fc99e Initial load
duke
parents:
diff changeset
198 * and forth between line and location. So we choose
a61af66fc99e Initial load
duke
parents:
diff changeset
199 * to record only the last line entry at a particular
a61af66fc99e Initial load
duke
parents:
diff changeset
200 * location.
a61af66fc99e Initial load
duke
parents:
diff changeset
201 */
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if ((i + 1 == count) || (bci != lntab[i+1].getStartBCI())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Remember the largest/smallest line number
a61af66fc99e Initial load
duke
parents:
diff changeset
204 if (lineNumber > highestLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 highestLine = lineNumber;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if ((lineNumber < lowestLine) || (lowestLine == -1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 lowestLine = lineNumber;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 LocationImpl loc =
a61af66fc99e Initial load
duke
parents:
diff changeset
211 new LocationImpl(virtualMachine(), this, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 loc.addBaseLineInfo(
a61af66fc99e Initial load
duke
parents:
diff changeset
213 new BaseLineInfo(lineNumber, declaringType));
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Add to the location list
a61af66fc99e Initial load
duke
parents:
diff changeset
216 lineLocations.add(loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Add to the line -> locations map
a61af66fc99e Initial load
duke
parents:
diff changeset
219 Integer key = new Integer(lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 List mappedLocs = (List)lineMapper.get(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (mappedLocs == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 mappedLocs = new ArrayList(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 lineMapper.put(key, mappedLocs);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 mappedLocs.add(loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 info = new SoftLocationXRefs(SDE.BASE_STRATUM_NAME,
a61af66fc99e Initial load
duke
parents:
diff changeset
230 lineMapper, lineLocations,
a61af66fc99e Initial load
duke
parents:
diff changeset
231 lowestLine, highestLine);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 softBaseLocationXRefsRef = new SoftReference(info);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 return info;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 List sourceNameFilter(List list,
a61af66fc99e Initial load
duke
parents:
diff changeset
237 SDE.Stratum stratum,
a61af66fc99e Initial load
duke
parents:
diff changeset
238 String sourceName)
a61af66fc99e Initial load
duke
parents:
diff changeset
239 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if (sourceName == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 /* needs sourceName filteration */
a61af66fc99e Initial load
duke
parents:
diff changeset
244 List locs = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 Iterator it = list.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
246 while (it.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 LocationImpl loc = (LocationImpl)it.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if (loc.sourceName(stratum).equals(sourceName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 locs.add(loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 return locs;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 public List allLineLocations(SDE.Stratum stratum, String sourceName)
a61af66fc99e Initial load
duke
parents:
diff changeset
257 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 List lineLocations = getLocations(stratum).lineLocations;
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (lineLocations.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return Collections.unmodifiableList(
a61af66fc99e Initial load
duke
parents:
diff changeset
265 sourceNameFilter(lineLocations, stratum, sourceName));
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 public List locationsOfLine(SDE.Stratum stratum, String sourceName,
a61af66fc99e Initial load
duke
parents:
diff changeset
269 int lineNumber) throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 SoftLocationXRefs info = getLocations(stratum);
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (info.lineLocations.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
277 * Find the locations which match the line number
a61af66fc99e Initial load
duke
parents:
diff changeset
278 * passed in.
a61af66fc99e Initial load
duke
parents:
diff changeset
279 */
a61af66fc99e Initial load
duke
parents:
diff changeset
280 List list = (List)info.lineMapper.get(
a61af66fc99e Initial load
duke
parents:
diff changeset
281 new Integer(lineNumber));
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (list == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 list = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 return Collections.unmodifiableList(
a61af66fc99e Initial load
duke
parents:
diff changeset
287 sourceNameFilter(list, stratum, sourceName));
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 LineInfo codeIndexToLineInfo(SDE.Stratum stratum,
a61af66fc99e Initial load
duke
parents:
diff changeset
291 long codeIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if (firstIndex == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 getBaseLocations();
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
297 * Check for invalid code index.
a61af66fc99e Initial load
duke
parents:
diff changeset
298 */
a61af66fc99e Initial load
duke
parents:
diff changeset
299 if (codeIndex < firstIndex || codeIndex > lastIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 throw new InternalError(
a61af66fc99e Initial load
duke
parents:
diff changeset
301 "Location with invalid code index");
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 List lineLocations = getLocations(stratum).lineLocations;
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
307 * Check for absent line numbers.
a61af66fc99e Initial load
duke
parents:
diff changeset
308 */
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (lineLocations.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return super.codeIndexToLineInfo(stratum, codeIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 Iterator iter = lineLocations.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
314 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
315 * Treat code before the beginning of the first line table
a61af66fc99e Initial load
duke
parents:
diff changeset
316 * entry as part of the first line. javac will generate
a61af66fc99e Initial load
duke
parents:
diff changeset
317 * code like this for some local classes. This "prolog"
a61af66fc99e Initial load
duke
parents:
diff changeset
318 * code contains assignments from locals in the enclosing
a61af66fc99e Initial load
duke
parents:
diff changeset
319 * scope to synthetic fields in the local class. Same for
a61af66fc99e Initial load
duke
parents:
diff changeset
320 * other language prolog code.
a61af66fc99e Initial load
duke
parents:
diff changeset
321 */
a61af66fc99e Initial load
duke
parents:
diff changeset
322 LocationImpl bestMatch = (LocationImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
323 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 LocationImpl current = (LocationImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
325 if (current.codeIndex() > codeIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 bestMatch = current;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 return bestMatch.getLineInfo(stratum);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 public Location locationOfCodeIndex(long codeIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if (firstIndex == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 getBaseLocations();
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
339 * Check for invalid code index.
a61af66fc99e Initial load
duke
parents:
diff changeset
340 */
a61af66fc99e Initial load
duke
parents:
diff changeset
341 if (codeIndex < firstIndex || codeIndex > lastIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 return new LocationImpl(virtualMachine(), this, codeIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 public List variables() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 return getVariables();
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 public List variablesByName(String name) throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 List variables = getVariables();
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 List retList = new ArrayList(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
356 Iterator iter = variables.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 while(iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 LocalVariable variable = (LocalVariable)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 if (variable.name().equals(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 retList.add(variable);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 return retList;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 public List arguments() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (argumentTypeNames().size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 return new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 List variables = getVariables();
a61af66fc99e Initial load
duke
parents:
diff changeset
371 List retList = new ArrayList(variables.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
372 Iterator iter = variables.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
373 while(iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 LocalVariable variable = (LocalVariable)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (variable.isArgument()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 retList.add(variable);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 return retList;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382 public byte[] bytecodes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 byte[] bytecodes = (bytecodesRef == null) ? null :
a61af66fc99e Initial load
duke
parents:
diff changeset
384 (byte[])bytecodesRef.get();
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if (bytecodes == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 bytecodes = saMethod.getByteCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
387 bytecodesRef = new SoftReference(bytecodes);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
390 * Arrays are always modifiable, so it is a little unsafe
a61af66fc99e Initial load
duke
parents:
diff changeset
391 * to return the cached bytecodes directly; instead, we
a61af66fc99e Initial load
duke
parents:
diff changeset
392 * make a clone at the cost of using more memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
393 */
a61af66fc99e Initial load
duke
parents:
diff changeset
394 return (byte[])bytecodes.clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397 public Location location() {
a61af66fc99e Initial load
duke
parents:
diff changeset
398 if (location == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 getBaseLocations();
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401 return location;
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 private List getVariables() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 List variables = (variablesRef == null) ? null :
a61af66fc99e Initial load
duke
parents:
diff changeset
406 (List)variablesRef.get();
a61af66fc99e Initial load
duke
parents:
diff changeset
407 if (variables != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 return variables;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 // if there are no locals, there won't be a LVT
a61af66fc99e Initial load
duke
parents:
diff changeset
412 if (saMethod.getMaxLocals() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 variables = Collections.unmodifiableList(new ArrayList(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
414 variablesRef = new SoftReference(variables);
a61af66fc99e Initial load
duke
parents:
diff changeset
415 return variables;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if (! saMethod.hasLocalVariableTable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421 //Build up the JDI view of local variable table.
a61af66fc99e Initial load
duke
parents:
diff changeset
422 LocalVariableTableElement[] locals = saMethod.getLocalVariableTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
423 int localCount = locals.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 variables = new ArrayList(localCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
425 for (int ii = 0; ii < localCount; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 String name =
a61af66fc99e Initial load
duke
parents:
diff changeset
427 saMethod.getConstants().getSymbolAt(locals[ii].getNameCPIndex()).asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
428 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
429 * Skip "this$*", "this+*", "this" entries because they are never real
a61af66fc99e Initial load
duke
parents:
diff changeset
430 * variables from the JLS perspective. "this+*" is new with 1.5.
a61af66fc99e Initial load
duke
parents:
diff changeset
431 * Instead of using '+', we check for java letter or digit to avoid
a61af66fc99e Initial load
duke
parents:
diff changeset
432 * depending on javac's current choice of '+'.
a61af66fc99e Initial load
duke
parents:
diff changeset
433 */
a61af66fc99e Initial load
duke
parents:
diff changeset
434 boolean isInternalName = name.startsWith("this") &&
a61af66fc99e Initial load
duke
parents:
diff changeset
435 (name.length() == 4 || name.charAt(4)=='$' || !Character.isJavaIdentifierPart(name.charAt(4)));
a61af66fc99e Initial load
duke
parents:
diff changeset
436 if (! isInternalName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 int slot = locals[ii].getSlot();
a61af66fc99e Initial load
duke
parents:
diff changeset
438 long codeIndex = locals[ii].getStartBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 int length = locals[ii].getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 Location scopeStart = new LocationImpl(virtualMachine(),
a61af66fc99e Initial load
duke
parents:
diff changeset
441 this, codeIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 Location scopeEnd =
a61af66fc99e Initial load
duke
parents:
diff changeset
443 new LocationImpl(virtualMachine(), this,
a61af66fc99e Initial load
duke
parents:
diff changeset
444 codeIndex + length - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
445 String signature =
a61af66fc99e Initial load
duke
parents:
diff changeset
446 saMethod.getConstants().getSymbolAt(locals[ii].getDescriptorCPIndex()).asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 int genericSigIndex = locals[ii].getSignatureCPIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
449 String genericSignature = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 if (genericSigIndex != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 genericSignature = saMethod.getConstants().getSymbolAt(genericSigIndex).asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 LocalVariable variable =
a61af66fc99e Initial load
duke
parents:
diff changeset
455 new LocalVariableImpl(virtualMachine(), this,
a61af66fc99e Initial load
duke
parents:
diff changeset
456 slot, scopeStart, scopeEnd,
a61af66fc99e Initial load
duke
parents:
diff changeset
457 name, signature, genericSignature);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 // Add to the variable list
a61af66fc99e Initial load
duke
parents:
diff changeset
459 variables.add(variable);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 variables = Collections.unmodifiableList(variables);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 variablesRef = new SoftReference(variables);
a61af66fc99e Initial load
duke
parents:
diff changeset
465 return variables;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }