author | coleenp |
Sun, 13 Apr 2008 17:43:42 -0400 | |
changeset 360 | 21d113ecbf6a |
parent 1 | 489c9b5090e2 |
child 670 | ddf3e9583f2f |
permissions | -rw-r--r-- |
1 | 1 |
/* |
2 |
* Copyright 2002 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.debugger.windbg; |
|
26 |
||
27 |
import sun.jvm.hotspot.debugger.*; |
|
28 |
||
29 |
class WindbgAddress implements Address { |
|
30 |
protected WindbgDebugger debugger; |
|
31 |
protected long addr; |
|
32 |
||
33 |
WindbgAddress(WindbgDebugger debugger, long addr) { |
|
34 |
this.debugger = debugger; |
|
35 |
this.addr = addr; |
|
36 |
} |
|
37 |
||
38 |
// |
|
39 |
// Basic Java routines |
|
40 |
// |
|
41 |
||
42 |
public boolean equals(Object arg) { |
|
43 |
if (arg == null) { |
|
44 |
return false; |
|
45 |
} |
|
46 |
||
47 |
if (!(arg instanceof WindbgAddress)) { |
|
48 |
return false; |
|
49 |
} |
|
50 |
||
51 |
return (addr == ((WindbgAddress) arg).addr); |
|
52 |
} |
|
53 |
||
54 |
public int hashCode() { |
|
55 |
// FIXME: suggestions on a better hash code? |
|
56 |
return (int) addr; |
|
57 |
} |
|
58 |
||
59 |
public String toString() { |
|
60 |
return debugger.addressValueToString(addr); |
|
61 |
} |
|
62 |
||
63 |
// |
|
64 |
// C/C++-related routines |
|
65 |
// |
|
66 |
||
67 |
public long getCIntegerAt(long offset, long numBytes, boolean isUnsigned) throws UnalignedAddressException, UnmappedAddressException { |
|
68 |
return debugger.readCInteger(addr + offset, numBytes, isUnsigned); |
|
69 |
} |
|
70 |
||
71 |
public Address getAddressAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
72 |
return debugger.readAddress(addr + offset); |
|
73 |
} |
|
74 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
75 |
public Address getCompOopAddressAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
76 |
return debugger.readCompOopAddress(addr + offset); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
77 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
78 |
|
1 | 79 |
// |
80 |
// Java-related routines |
|
81 |
// |
|
82 |
||
83 |
public boolean getJBooleanAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
84 |
return debugger.readJBoolean(addr + offset); |
|
85 |
} |
|
86 |
||
87 |
public byte getJByteAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
88 |
return debugger.readJByte(addr + offset); |
|
89 |
} |
|
90 |
||
91 |
public char getJCharAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
92 |
return debugger.readJChar(addr + offset); |
|
93 |
} |
|
94 |
||
95 |
public double getJDoubleAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
96 |
return debugger.readJDouble(addr + offset); |
|
97 |
} |
|
98 |
||
99 |
public float getJFloatAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
100 |
return debugger.readJFloat(addr + offset); |
|
101 |
} |
|
102 |
||
103 |
public int getJIntAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
104 |
return debugger.readJInt(addr + offset); |
|
105 |
} |
|
106 |
||
107 |
public long getJLongAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
108 |
return debugger.readJLong(addr + offset); |
|
109 |
} |
|
110 |
||
111 |
public short getJShortAt(long offset) throws UnalignedAddressException, UnmappedAddressException { |
|
112 |
return debugger.readJShort(addr + offset); |
|
113 |
} |
|
114 |
||
115 |
public OopHandle getOopHandleAt(long offset) |
|
116 |
throws UnalignedAddressException, UnmappedAddressException, NotInHeapException { |
|
117 |
return debugger.readOopHandle(addr + offset); |
|
118 |
} |
|
119 |
||
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
120 |
public OopHandle getCompOopHandleAt(long offset) |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
121 |
throws UnalignedAddressException, UnmappedAddressException, NotInHeapException { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
122 |
return debugger.readCompOopHandle(addr + offset); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
123 |
} |
1 | 124 |
// |
125 |
// C/C++-related mutators |
|
126 |
// |
|
127 |
||
128 |
public void setCIntegerAt(long offset, long numBytes, long value) { |
|
129 |
throw new DebuggerException("Unimplemented"); |
|
130 |
} |
|
131 |
public void setAddressAt(long offset, Address value) { |
|
132 |
throw new DebuggerException("Unimplemented"); |
|
133 |
} |
|
134 |
||
135 |
// |
|
136 |
// Java-related mutators |
|
137 |
// |
|
138 |
||
139 |
// Mutators -- not implemented for now (FIXME) |
|
140 |
public void setJBooleanAt (long offset, boolean value) |
|
141 |
throws UnmappedAddressException, UnalignedAddressException { |
|
142 |
throw new DebuggerException("Unimplemented"); |
|
143 |
} |
|
144 |
public void setJByteAt (long offset, byte value) |
|
145 |
throws UnmappedAddressException, UnalignedAddressException { |
|
146 |
throw new DebuggerException("Unimplemented"); |
|
147 |
} |
|
148 |
public void setJCharAt (long offset, char value) |
|
149 |
throws UnmappedAddressException, UnalignedAddressException { |
|
150 |
throw new DebuggerException("Unimplemented"); |
|
151 |
} |
|
152 |
public void setJDoubleAt (long offset, double value) |
|
153 |
throws UnmappedAddressException, UnalignedAddressException { |
|
154 |
throw new DebuggerException("Unimplemented"); |
|
155 |
} |
|
156 |
public void setJFloatAt (long offset, float value) |
|
157 |
throws UnmappedAddressException, UnalignedAddressException { |
|
158 |
throw new DebuggerException("Unimplemented"); |
|
159 |
} |
|
160 |
public void setJIntAt (long offset, int value) |
|
161 |
throws UnmappedAddressException, UnalignedAddressException { |
|
162 |
throw new DebuggerException("Unimplemented"); |
|
163 |
} |
|
164 |
public void setJLongAt (long offset, long value) |
|
165 |
throws UnmappedAddressException, UnalignedAddressException { |
|
166 |
throw new DebuggerException("Unimplemented"); |
|
167 |
} |
|
168 |
public void setJShortAt (long offset, short value) |
|
169 |
throws UnmappedAddressException, UnalignedAddressException { |
|
170 |
throw new DebuggerException("Unimplemented"); |
|
171 |
} |
|
172 |
public void setOopHandleAt (long offset, OopHandle value) |
|
173 |
throws UnmappedAddressException, UnalignedAddressException { |
|
174 |
throw new DebuggerException("Unimplemented"); |
|
175 |
} |
|
176 |
||
177 |
// |
|
178 |
// Arithmetic operations -- necessary evil. |
|
179 |
// |
|
180 |
||
181 |
public Address addOffsetTo (long offset) throws UnsupportedOperationException { |
|
182 |
long value = addr + offset; |
|
183 |
if (value == 0) { |
|
184 |
return null; |
|
185 |
} |
|
186 |
return new WindbgAddress(debugger, value); |
|
187 |
} |
|
188 |
||
189 |
public OopHandle addOffsetToAsOopHandle(long offset) throws UnsupportedOperationException { |
|
190 |
long value = addr + offset; |
|
191 |
if (value == 0) { |
|
192 |
return null; |
|
193 |
} |
|
194 |
return new WindbgOopHandle(debugger, value); |
|
195 |
} |
|
196 |
||
197 |
/** (FIXME: any signed/unsigned issues? Should this work for |
|
198 |
OopHandles?) */ |
|
199 |
public long minus(Address arg) { |
|
200 |
if (arg == null) { |
|
201 |
return addr; |
|
202 |
} |
|
203 |
return addr - ((WindbgAddress) arg).addr; |
|
204 |
} |
|
205 |
||
206 |
// Two's complement representation. |
|
207 |
// All negative numbers are larger than positive numbers. |
|
208 |
// Numbers with the same sign can be compared normally. |
|
209 |
// Test harness is below in main(). |
|
210 |
||
211 |
public boolean lessThan (Address a) { |
|
212 |
if (a == null) { |
|
213 |
return false; |
|
214 |
} |
|
215 |
WindbgAddress arg = (WindbgAddress) a; |
|
216 |
if ((addr >= 0) && (arg.addr < 0)) { |
|
217 |
return true; |
|
218 |
} |
|
219 |
if ((addr < 0) && (arg.addr >= 0)) { |
|
220 |
return false; |
|
221 |
} |
|
222 |
return (addr < arg.addr); |
|
223 |
} |
|
224 |
||
225 |
public boolean lessThanOrEqual (Address a) { |
|
226 |
if (a == null) { |
|
227 |
return false; |
|
228 |
} |
|
229 |
WindbgAddress arg = (WindbgAddress) a; |
|
230 |
if ((addr >= 0) && (arg.addr < 0)) { |
|
231 |
return true; |
|
232 |
} |
|
233 |
if ((addr < 0) && (arg.addr >= 0)) { |
|
234 |
return false; |
|
235 |
} |
|
236 |
return (addr <= arg.addr); |
|
237 |
} |
|
238 |
||
239 |
public boolean greaterThan (Address a) { |
|
240 |
if (a == null) { |
|
241 |
return true; |
|
242 |
} |
|
243 |
WindbgAddress arg = (WindbgAddress) a; |
|
244 |
if ((addr >= 0) && (arg.addr < 0)) { |
|
245 |
return false; |
|
246 |
} |
|
247 |
if ((addr < 0) && (arg.addr >= 0)) { |
|
248 |
return true; |
|
249 |
} |
|
250 |
return (addr > arg.addr); |
|
251 |
} |
|
252 |
||
253 |
public boolean greaterThanOrEqual(Address a) { |
|
254 |
if (a == null) { |
|
255 |
return true; |
|
256 |
} |
|
257 |
WindbgAddress arg = (WindbgAddress) a; |
|
258 |
if ((addr >= 0) && (arg.addr < 0)) { |
|
259 |
return false; |
|
260 |
} |
|
261 |
if ((addr < 0) && (arg.addr >= 0)) { |
|
262 |
return true; |
|
263 |
} |
|
264 |
return (addr >= arg.addr); |
|
265 |
} |
|
266 |
||
267 |
public Address andWithMask(long mask) throws UnsupportedOperationException { |
|
268 |
long value = addr & mask; |
|
269 |
if (value == 0) { |
|
270 |
return null; |
|
271 |
} |
|
272 |
return new WindbgAddress(debugger, value); |
|
273 |
} |
|
274 |
||
275 |
public Address orWithMask(long mask) throws UnsupportedOperationException { |
|
276 |
long value = addr | mask; |
|
277 |
if (value == 0) { |
|
278 |
return null; |
|
279 |
} |
|
280 |
return new WindbgAddress(debugger, value); |
|
281 |
} |
|
282 |
||
283 |
public Address xorWithMask(long mask) throws UnsupportedOperationException { |
|
284 |
long value = addr ^ mask; |
|
285 |
if (value == 0) { |
|
286 |
return null; |
|
287 |
} |
|
288 |
return new WindbgAddress(debugger, value); |
|
289 |
} |
|
290 |
||
291 |
||
292 |
//-------------------------------------------------------------------------------- |
|
293 |
// Internals only below this point |
|
294 |
// |
|
295 |
||
296 |
long getValue() { |
|
297 |
return addr; |
|
298 |
} |
|
299 |
||
300 |
||
301 |
private static void check(boolean arg, String failMessage) { |
|
302 |
if (!arg) { |
|
303 |
System.err.println(failMessage + ": FAILED"); |
|
304 |
System.exit(1); |
|
305 |
} |
|
306 |
} |
|
307 |
||
308 |
// Test harness |
|
309 |
public static void main(String[] args) { |
|
310 |
// p/n indicates whether the interior address is really positive |
|
311 |
// or negative. In unsigned terms, p1 < p2 < n1 < n2. |
|
312 |
||
313 |
WindbgAddress p1 = new WindbgAddress(null, 0x7FFFFFFFFFFFFFF0L); |
|
314 |
WindbgAddress p2 = (WindbgAddress) p1.addOffsetTo(10); |
|
315 |
WindbgAddress n1 = (WindbgAddress) p2.addOffsetTo(10); |
|
316 |
WindbgAddress n2 = (WindbgAddress) n1.addOffsetTo(10); |
|
317 |
||
318 |
// lessThan positive tests |
|
319 |
check(p1.lessThan(p2), "lessThan 1"); |
|
320 |
check(p1.lessThan(n1), "lessThan 2"); |
|
321 |
check(p1.lessThan(n2), "lessThan 3"); |
|
322 |
check(p2.lessThan(n1), "lessThan 4"); |
|
323 |
check(p2.lessThan(n2), "lessThan 5"); |
|
324 |
check(n1.lessThan(n2), "lessThan 6"); |
|
325 |
||
326 |
// lessThan negative tests |
|
327 |
check(!p1.lessThan(p1), "lessThan 7"); |
|
328 |
check(!p2.lessThan(p2), "lessThan 8"); |
|
329 |
check(!n1.lessThan(n1), "lessThan 9"); |
|
330 |
check(!n2.lessThan(n2), "lessThan 10"); |
|
331 |
||
332 |
check(!p2.lessThan(p1), "lessThan 11"); |
|
333 |
check(!n1.lessThan(p1), "lessThan 12"); |
|
334 |
check(!n2.lessThan(p1), "lessThan 13"); |
|
335 |
check(!n1.lessThan(p2), "lessThan 14"); |
|
336 |
check(!n2.lessThan(p2), "lessThan 15"); |
|
337 |
check(!n2.lessThan(n1), "lessThan 16"); |
|
338 |
||
339 |
// lessThanOrEqual positive tests |
|
340 |
check(p1.lessThanOrEqual(p1), "lessThanOrEqual 1"); |
|
341 |
check(p2.lessThanOrEqual(p2), "lessThanOrEqual 2"); |
|
342 |
check(n1.lessThanOrEqual(n1), "lessThanOrEqual 3"); |
|
343 |
check(n2.lessThanOrEqual(n2), "lessThanOrEqual 4"); |
|
344 |
||
345 |
check(p1.lessThanOrEqual(p2), "lessThanOrEqual 5"); |
|
346 |
check(p1.lessThanOrEqual(n1), "lessThanOrEqual 6"); |
|
347 |
check(p1.lessThanOrEqual(n2), "lessThanOrEqual 7"); |
|
348 |
check(p2.lessThanOrEqual(n1), "lessThanOrEqual 8"); |
|
349 |
check(p2.lessThanOrEqual(n2), "lessThanOrEqual 9"); |
|
350 |
check(n1.lessThanOrEqual(n2), "lessThanOrEqual 10"); |
|
351 |
||
352 |
// lessThanOrEqual negative tests |
|
353 |
check(!p2.lessThanOrEqual(p1), "lessThanOrEqual 11"); |
|
354 |
check(!n1.lessThanOrEqual(p1), "lessThanOrEqual 12"); |
|
355 |
check(!n2.lessThanOrEqual(p1), "lessThanOrEqual 13"); |
|
356 |
check(!n1.lessThanOrEqual(p2), "lessThanOrEqual 14"); |
|
357 |
check(!n2.lessThanOrEqual(p2), "lessThanOrEqual 15"); |
|
358 |
check(!n2.lessThanOrEqual(n1), "lessThanOrEqual 16"); |
|
359 |
||
360 |
// greaterThan positive tests |
|
361 |
check(n2.greaterThan(p1), "greaterThan 1"); |
|
362 |
check(n2.greaterThan(p2), "greaterThan 2"); |
|
363 |
check(n2.greaterThan(n1), "greaterThan 3"); |
|
364 |
check(n1.greaterThan(p1), "greaterThan 4"); |
|
365 |
check(n1.greaterThan(p2), "greaterThan 5"); |
|
366 |
check(p2.greaterThan(p1), "greaterThan 6"); |
|
367 |
||
368 |
// greaterThan negative tests |
|
369 |
check(!p1.greaterThan(p1), "greaterThan 7"); |
|
370 |
check(!p2.greaterThan(p2), "greaterThan 8"); |
|
371 |
check(!n1.greaterThan(n1), "greaterThan 9"); |
|
372 |
check(!n2.greaterThan(n2), "greaterThan 10"); |
|
373 |
||
374 |
check(!p1.greaterThan(n2), "greaterThan 11"); |
|
375 |
check(!p2.greaterThan(n2), "greaterThan 12"); |
|
376 |
check(!n1.greaterThan(n2), "greaterThan 13"); |
|
377 |
check(!p1.greaterThan(n1), "greaterThan 14"); |
|
378 |
check(!p2.greaterThan(n1), "greaterThan 15"); |
|
379 |
check(!p1.greaterThan(p2), "greaterThan 16"); |
|
380 |
||
381 |
// greaterThanOrEqual positive tests |
|
382 |
check(p1.greaterThanOrEqual(p1), "greaterThanOrEqual 1"); |
|
383 |
check(p2.greaterThanOrEqual(p2), "greaterThanOrEqual 2"); |
|
384 |
check(n1.greaterThanOrEqual(n1), "greaterThanOrEqual 3"); |
|
385 |
check(n2.greaterThanOrEqual(n2), "greaterThanOrEqual 4"); |
|
386 |
||
387 |
check(n2.greaterThanOrEqual(p1), "greaterThanOrEqual 5"); |
|
388 |
check(n2.greaterThanOrEqual(p2), "greaterThanOrEqual 6"); |
|
389 |
check(n2.greaterThanOrEqual(n1), "greaterThanOrEqual 7"); |
|
390 |
check(n1.greaterThanOrEqual(p1), "greaterThanOrEqual 8"); |
|
391 |
check(n1.greaterThanOrEqual(p2), "greaterThanOrEqual 9"); |
|
392 |
check(p2.greaterThanOrEqual(p1), "greaterThanOrEqual 10"); |
|
393 |
||
394 |
// greaterThanOrEqual negative tests |
|
395 |
check(!p1.greaterThanOrEqual(n2), "greaterThanOrEqual 11"); |
|
396 |
check(!p2.greaterThanOrEqual(n2), "greaterThanOrEqual 12"); |
|
397 |
check(!n1.greaterThanOrEqual(n2), "greaterThanOrEqual 13"); |
|
398 |
check(!p1.greaterThanOrEqual(n1), "greaterThanOrEqual 14"); |
|
399 |
check(!p2.greaterThanOrEqual(n1), "greaterThanOrEqual 15"); |
|
400 |
check(!p1.greaterThanOrEqual(p2), "greaterThanOrEqual 16"); |
|
401 |
||
402 |
System.err.println("WindbgAddress: all tests passed successfully."); |
|
403 |
} |
|
404 |
} |