Mercurial > hg > graal-jvmci-8
annotate agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java @ 12227:440edcf30231
8024176: [macosx] gc/metaspace/ClassMetaspaceSizeInJmapHeap.java failed since jdk8b105, hs25b47
Summary: The code for reading compressed klass pointers in the sa-agent on Mac used readCompOopAddress instead of readCompKlassAddress, this is wrong but has been hidden because compressed oops and compressed klasses has used the same base address in the past.
Reviewed-by: sla, jmasa
Contributed-by: stefan.johansson@oracle.com
author | mgerdin |
---|---|
date | Wed, 11 Sep 2013 08:57:02 +0200 |
parents | 8e47bac5643a |
children | de6a9e811145 |
rev | line source |
---|---|
3960 | 1 /* |
2 * Copyright (c) 2002, 2008, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 package sun.jvm.hotspot.debugger.bsd; | |
26 | |
27 import sun.jvm.hotspot.debugger.*; | |
28 | |
29 class BsdAddress implements Address { | |
30 protected BsdDebugger debugger; | |
31 protected long addr; | |
32 | |
33 BsdAddress(BsdDebugger 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 BsdAddress)) { | |
48 return false; | |
49 } | |
50 | |
51 return (addr == ((BsdAddress) 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) | |
68 throws UnalignedAddressException, UnmappedAddressException { | |
69 return debugger.readCInteger(addr + offset, numBytes, isUnsigned); | |
70 } | |
71 | |
72 public Address getAddressAt(long offset) | |
73 throws UnalignedAddressException, UnmappedAddressException { | |
74 return debugger.readAddress(addr + offset); | |
75 } | |
76 | |
77 public Address getCompOopAddressAt(long offset) | |
78 throws UnalignedAddressException, UnmappedAddressException { | |
79 return debugger.readCompOopAddress(addr + offset); | |
80 } | |
81 | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
3960
diff
changeset
|
82 public Address getCompKlassAddressAt(long offset) |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
3960
diff
changeset
|
83 throws UnalignedAddressException, UnmappedAddressException { |
12227
440edcf30231
8024176: [macosx] gc/metaspace/ClassMetaspaceSizeInJmapHeap.java failed since jdk8b105, hs25b47
mgerdin
parents:
6848
diff
changeset
|
84 return debugger.readCompKlassAddress(addr + offset); |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
3960
diff
changeset
|
85 } |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
3960
diff
changeset
|
86 |
3960 | 87 // |
88 // Java-related routines | |
89 // | |
90 | |
91 public boolean getJBooleanAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
92 return debugger.readJBoolean(addr + offset); | |
93 } | |
94 | |
95 public byte getJByteAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
96 return debugger.readJByte(addr + offset); | |
97 } | |
98 | |
99 public char getJCharAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
100 return debugger.readJChar(addr + offset); | |
101 } | |
102 | |
103 public double getJDoubleAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
104 return debugger.readJDouble(addr + offset); | |
105 } | |
106 | |
107 public float getJFloatAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
108 return debugger.readJFloat(addr + offset); | |
109 } | |
110 | |
111 public int getJIntAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
112 return debugger.readJInt(addr + offset); | |
113 } | |
114 | |
115 public long getJLongAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
116 return debugger.readJLong(addr + offset); | |
117 } | |
118 | |
119 public short getJShortAt(long offset) throws UnalignedAddressException, UnmappedAddressException { | |
120 return debugger.readJShort(addr + offset); | |
121 } | |
122 | |
123 public OopHandle getOopHandleAt(long offset) | |
124 throws UnalignedAddressException, UnmappedAddressException, NotInHeapException { | |
125 return debugger.readOopHandle(addr + offset); | |
126 } | |
127 | |
128 public OopHandle getCompOopHandleAt(long offset) | |
129 throws UnalignedAddressException, UnmappedAddressException, NotInHeapException { | |
130 return debugger.readCompOopHandle(addr + offset); | |
131 } | |
132 | |
133 // Mutators -- not implemented for now (FIXME) | |
134 public void setCIntegerAt(long offset, long numBytes, long value) { | |
135 throw new DebuggerException("Unimplemented"); | |
136 } | |
137 public void setAddressAt(long offset, Address value) { | |
138 throw new DebuggerException("Unimplemented"); | |
139 } | |
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 BsdAddress(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 BsdOopHandle(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 - ((BsdAddress) 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 BsdAddress arg = (BsdAddress) 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 BsdAddress arg = (BsdAddress) 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 BsdAddress arg = (BsdAddress) 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 BsdAddress arg = (BsdAddress) 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 BsdAddress(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 BsdAddress(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 BsdAddress(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 BsdAddress p1 = new BsdAddress(null, 0x7FFFFFFFFFFFFFF0L); | |
314 BsdAddress p2 = (BsdAddress) p1.addOffsetTo(10); | |
315 BsdAddress n1 = (BsdAddress) p2.addOffsetTo(10); | |
316 BsdAddress n2 = (BsdAddress) 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("BsdAddress: all tests passed successfully."); | |
403 } | |
404 } |