annotate agent/src/share/classes/sun/jvm/hotspot/debugger/cdbg/basic/BasicCDebugInfoDataBase.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
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) 2001, 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.debugger.cdbg.basic;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.utilities.AddressOps;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.utilities.Assert;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class BasicCDebugInfoDataBase implements CDebugInfoDataBase {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static final int INITIALIZED_STATE = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static final int CONSTRUCTION_STATE = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static final int RESOLVED_STATE = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static final int COMPLETE_STATE = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private int state = INITIALIZED_STATE;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 ///////////
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Types //
a61af66fc99e Initial load
duke
parents:
diff changeset
43 ///////////
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Used only during construction
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private Map lazyTypeMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Used during construction and at run time for iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private List types;
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // Used only during runtime
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private Map nameToTypeMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 /////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Symbols //
a61af66fc99e Initial load
duke
parents:
diff changeset
56 /////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // Used only during construction
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private Map lazySymMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // List of blocks in increasing order by starting address. These can
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // then be binary searched.
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private List blocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Name-to-global symbol table
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private Map nameToSymMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 //////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // Line numbers //
a61af66fc99e Initial load
duke
parents:
diff changeset
70 //////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private BasicLineNumberMapping lineNumbers;
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 /** Supports lazy instantiation and references between types and
a61af66fc99e Initial load
duke
parents:
diff changeset
75 symbols via insertion using arbitrary Object keys that are
a61af66fc99e Initial load
duke
parents:
diff changeset
76 wrapped by LazyTypes. Once the database has been fully
a61af66fc99e Initial load
duke
parents:
diff changeset
77 constructed and all types are present, one should call
a61af66fc99e Initial load
duke
parents:
diff changeset
78 resolveTypes(), which will resolve all LazyTypes down to
a61af66fc99e Initial load
duke
parents:
diff changeset
79 concrete types (and signal an error if some lazy types were
a61af66fc99e Initial load
duke
parents:
diff changeset
80 unresolved). */
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public void beginConstruction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Assert.that(state == INITIALIZED_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 state = CONSTRUCTION_STATE;
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Types
a61af66fc99e Initial load
duke
parents:
diff changeset
88 lazyTypeMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 types = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Symbols
a61af66fc99e Initial load
duke
parents:
diff changeset
92 lazySymMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 blocks = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 nameToSymMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Line numbers
a61af66fc99e Initial load
duke
parents:
diff changeset
97 lineNumbers = new BasicLineNumberMapping();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 /** Add a type which may later in construction be referred to via a
a61af66fc99e Initial load
duke
parents:
diff changeset
101 LazyType with this key. lazyKey may be null. */
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public void addType(Object lazyKey, Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 Assert.that(state == CONSTRUCTION_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (lazyKey != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (lazyTypeMap.put(lazyKey, type) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 throw new RuntimeException("Type redefined for lazy key " + lazyKey);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 types.add(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public void resolve(ResolveListener listener) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 Assert.that(state == CONSTRUCTION_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Go through all types in lazyTypeMap and types.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Resolve all LazyTypes.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 resolveLazyMap(listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 for (ListIterator iter = types.listIterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 BasicType t = (BasicType) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 BasicType t2 = (BasicType) t.resolveTypes(this, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (t != t2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 iter.set(t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // Go through all symbols and resolve references to types and
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // references to other symbols
a61af66fc99e Initial load
duke
parents:
diff changeset
131 for (Iterator iter = blocks.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 ((BasicSym) iter.next()).resolve(this, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 for (Iterator iter = nameToSymMap.values().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 ((BasicSym) iter.next()).resolve(this, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Sort blocks in ascending order of starting address (but do not
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // change ordering among blocks with the same starting address)
a61af66fc99e Initial load
duke
parents:
diff changeset
140 Collections.sort(blocks, new Comparator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public int compare(Object o1, Object o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 BlockSym b1 = (BlockSym) o1;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 BlockSym b2 = (BlockSym) o2;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 Address a1 = b1.getAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Address a2 = b2.getAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (AddressOps.lt(a1, a2)) { return -1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (AddressOps.gt(a1, a2)) { return 1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 });
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 state = RESOLVED_STATE;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public void endConstruction() {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 Assert.that(state == RESOLVED_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Move all types to type list
a61af66fc99e Initial load
duke
parents:
diff changeset
160 for (Iterator iter = lazyTypeMap.values().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 types.add(iter.next());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Build name-to-type map
a61af66fc99e Initial load
duke
parents:
diff changeset
164 nameToTypeMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 for (Iterator iter = types.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 Type t = (Type) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 if (!t.isConst() && !t.isVolatile()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 nameToTypeMap.put(t.getName(), t);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // Lose lazy maps
a61af66fc99e Initial load
duke
parents:
diff changeset
172 lazyTypeMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 lazySymMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Sort and finish line number information
a61af66fc99e Initial load
duke
parents:
diff changeset
175 lineNumbers.sort();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // FIXME: on some platforms it might not be necessary to call
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // recomputeEndPCs(). Will have to see what stabs information
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // looks like. Should make configurable whether we make this call
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // or not.
a61af66fc99e Initial load
duke
parents:
diff changeset
180 lineNumbers.recomputeEndPCs();
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 state = COMPLETE_STATE;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 public Type lookupType(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return lookupType(name, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public Type lookupType(String name, int cvAttributes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 Assert.that(state == COMPLETE_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 BasicType t = (BasicType) nameToTypeMap.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (t != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (cvAttributes != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 t = (BasicType) t.getCVVariant(cvAttributes);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 public void iterate(TypeVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 Assert.that(state == COMPLETE_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 for (Iterator iter = types.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 BasicType t = (BasicType) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 t.visit(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 /** Add a BlockSym to the debug information database. The given
a61af66fc99e Initial load
duke
parents:
diff changeset
213 BlockSym may be referred to by a LazyBlockSym wrapping the given
a61af66fc99e Initial load
duke
parents:
diff changeset
214 Object key, which must be non-null. Any references to other
a61af66fc99e Initial load
duke
parents:
diff changeset
215 blocks (for example, the parent scope) should be made with
a61af66fc99e Initial load
duke
parents:
diff changeset
216 LazyBlockSyms. These references will be resolved after the
a61af66fc99e Initial load
duke
parents:
diff changeset
217 database is built. */
a61af66fc99e Initial load
duke
parents:
diff changeset
218 public void addBlock(Object key, BlockSym block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 Assert.that(key != null, "key must be non-null");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 lazySymMap.put(key, block);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 blocks.add(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 public void addGlobalSym(GlobalSym sym) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 nameToSymMap.put(sym.getName(), sym);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 public BlockSym debugInfoForPC(Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 return searchBlocks(pc, 0, blocks.size() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 public GlobalSym lookupSym(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return (GlobalSym) nameToSymMap.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 public void addLineNumberInfo(BasicLineNumberInfo info) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 lineNumbers.addLineNumberInfo(info);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 public LineNumberInfo lineNumberForPC(Address pc) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 return lineNumbers.lineNumberForPC(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 public void iterate(LineNumberVisitor v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 lineNumbers.iterate(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
252 //
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 /** Intended only to be used by the BasicType implementation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
255 public Type resolveType(Type containingType, Type targetType, ResolveListener listener, String detail) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 BasicType basicTargetType = (BasicType) targetType;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 Assert.that(state == CONSTRUCTION_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (basicTargetType.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 BasicType resolved = (BasicType) lazyTypeMap.get(((LazyType) targetType).getKey());
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // FIXME: would like to have an assert here that the target is
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // non-null, but apparently have bugs here with forward
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // references of pointer types
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (resolved == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 listener.resolveFailed(containingType, (LazyType) targetType, detail + " because target type was not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
267 return targetType;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269 if (resolved.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // Might happen for const/var variants for forward references
a61af66fc99e Initial load
duke
parents:
diff changeset
271 if (resolved.isConst() || resolved.isVolatile()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 resolved = (BasicType) resolved.resolveTypes(this, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (resolved.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 listener.resolveFailed(containingType, (LazyType) targetType,
a61af66fc99e Initial load
duke
parents:
diff changeset
276 detail + " because target type (with key " +
a61af66fc99e Initial load
duke
parents:
diff changeset
277 ((Integer) ((LazyType) resolved).getKey()).intValue() +
a61af66fc99e Initial load
duke
parents:
diff changeset
278 (resolved.isConst() ? ", const" : ", not const") +
a61af66fc99e Initial load
duke
parents:
diff changeset
279 (resolved.isVolatile() ? ", volatile" : ", not volatile") +
a61af66fc99e Initial load
duke
parents:
diff changeset
280 ") was lazy");
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 return resolved;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 return targetType;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 /** Intended only to be usd by the BasicSym implementation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
289 public Type resolveType(Sym containingSymbol, Type targetType, ResolveListener listener, String detail) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 BasicType basicTargetType = (BasicType) targetType;
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 Assert.that(state == CONSTRUCTION_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (basicTargetType.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 BasicType resolved = (BasicType) lazyTypeMap.get(((LazyType) targetType).getKey());
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // FIXME: would like to have an assert here that the target is
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // non-null, but apparently have bugs here
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (resolved == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 listener.resolveFailed(containingSymbol, (LazyType) targetType, detail);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 return targetType;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 if (resolved.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // Might happen for const/var variants for forward references
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (resolved.isConst() || resolved.isVolatile()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 resolved = (BasicType) resolved.resolveTypes(this, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (resolved.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 listener.resolveFailed(containingSymbol, (LazyType) targetType, detail);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311 return resolved;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 return targetType;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 /** Intended only to be usd by the BasicSym implementation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
317 public Sym resolveSym(Sym containingSymbol, Sym targetSym, ResolveListener listener, String detail) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 if (targetSym == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 BasicSym basicTargetSym = (BasicSym) targetSym;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 Assert.that(state == CONSTRUCTION_STATE, "wrong state");
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (basicTargetSym.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 BasicSym resolved = (BasicSym) lazySymMap.get(((LazyBlockSym) targetSym).getKey());
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // FIXME: would like to have an assert here that the target is
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // non-null, but apparently have bugs here
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if (resolved == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 listener.resolveFailed(containingSymbol, (LazyBlockSym) targetSym, detail);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 return targetSym;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (resolved.isLazy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 listener.resolveFailed(containingSymbol, (LazyBlockSym) targetSym, detail);
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334 return resolved;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 return targetSym;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 private void resolveLazyMap(ResolveListener listener) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 for (Iterator iter = lazyTypeMap.entrySet().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 Map.Entry entry = (Map.Entry) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 BasicType t = (BasicType) entry.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
343 BasicType t2 = (BasicType) t.resolveTypes(this, listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (t2 != t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 entry.setValue(t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 /** Find the block whose starting address is closest to but less
a61af66fc99e Initial load
duke
parents:
diff changeset
351 than the given address. */
a61af66fc99e Initial load
duke
parents:
diff changeset
352 private BlockSym searchBlocks(Address addr, int lowIdx, int highIdx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 if (highIdx < lowIdx) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 if ((lowIdx == highIdx) || (lowIdx == highIdx - 1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // Base case: start with highIdx and walk backward. See whether
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // addr is greater than any of the blocks' starting addresses,
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // and if so, return that block.
a61af66fc99e Initial load
duke
parents:
diff changeset
358 Address lastAddr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
359 BlockSym ret = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 for (int i = highIdx; i >= 0; --i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 BlockSym block = (BlockSym) blocks.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 if (AddressOps.lte(block.getAddress(), addr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 if ((lastAddr == null) || (AddressOps.equal(block.getAddress(), lastAddr))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 lastAddr = block.getAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
365 ret = block;
a61af66fc99e Initial load
duke
parents:
diff changeset
366 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 int midIdx = (lowIdx + highIdx) >> 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 BlockSym block = (BlockSym) blocks.get(midIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // See address relationship
a61af66fc99e Initial load
duke
parents:
diff changeset
376 if (AddressOps.lte(block.getAddress(), addr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // Always move search up
a61af66fc99e Initial load
duke
parents:
diff changeset
378 return searchBlocks(addr, midIdx, highIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // Always move search down
a61af66fc99e Initial load
duke
parents:
diff changeset
381 return searchBlocks(addr, lowIdx, midIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }