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