annotate agent/src/share/classes/sun/jvm/hotspot/debugger/linux/LinuxAddress.java @ 0:a61af66fc99e jdk7-b24

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