Mercurial > hg > truffle
comparison agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.java @ 3939:f6f3bb0ee072
7088955: add C2 IR support to the SA
Reviewed-by: kvn
author | never |
---|---|
date | Sun, 11 Sep 2011 14:48:24 -0700 |
parents | c18cbe5936b8 |
children | 117bb0519114 |
comparison
equal
deleted
inserted
replaced
3938:e6b1331a51d2 | 3939:f6f3bb0ee072 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
148 | 148 |
149 public long getOopSize() { | 149 public long getOopSize() { |
150 return VM.getVM().getOopSize(); | 150 return VM.getVM().getOopSize(); |
151 } | 151 } |
152 | 152 |
153 static HashMap typeToVtbl = new HashMap(); | |
154 | |
155 private Address vtblForType(Type type) { | |
156 Address vtblAddr = (Address)typeToVtbl.get(type); | |
157 if (vtblAddr == null) { | |
158 vtblAddr = vtblAccess.getVtblForType(type); | |
159 if (vtblAddr != null) { | |
160 typeToVtbl.put(type, vtblAddr); | |
161 } | |
162 } | |
163 return vtblAddr; | |
164 } | |
165 | |
153 public boolean addressTypeIsEqualToType(Address addr, Type type) { | 166 public boolean addressTypeIsEqualToType(Address addr, Type type) { |
154 if (addr == null) { | 167 if (addr == null) { |
155 return false; | 168 return false; |
156 } | 169 } |
157 | 170 |
158 // This implementation should be suitably platform-independent; we | 171 // This implementation should be suitably platform-independent; we |
159 // search nearby memory for the vtbl value of the given type. | 172 // search nearby memory for the vtbl value of the given type. |
160 | 173 |
161 Address vtblAddr = vtblAccess.getVtblForType(type); | 174 Address vtblAddr = vtblForType(type); |
162 | 175 |
163 if (vtblAddr == null) { | 176 if (vtblAddr == null) { |
164 // Type was not polymorphic, or an error occurred during lookup | 177 // Type was not polymorphic, or an error occurred during lookup |
165 if (DEBUG) { | 178 if (DEBUG) { |
166 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null"); | 179 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null"); |
249 } | 262 } |
250 | 263 |
251 return false; | 264 return false; |
252 } | 265 } |
253 | 266 |
267 public Type findDynamicTypeForAddress(Address addr, Type baseType) { | |
268 // This implementation should be suitably platform-independent; we | |
269 // search nearby memory for the vtbl value of the given type. | |
270 | |
271 if (vtblForType(baseType) == null) { | |
272 // Type was not polymorphic which is an error of some sort | |
273 throw new InternalError(baseType + " does not appear to be polymorphic"); | |
274 } | |
275 | |
276 // This is a more restricted version of guessTypeForAddress since | |
277 // that function has some limitations since it doesn't really know | |
278 // where in the hierarchy a virtual type starts and just poking | |
279 // around in memory is likely to trip over some vtable address, | |
280 // resulting in false positives. Eventually all uses should | |
281 // switch to this logic but in the interests of stability it will | |
282 // be separate for the moment. | |
283 | |
284 // Assuming that the base type is truly the first polymorphic type | |
285 // then the vtbl for all subclasss should be at several defined | |
286 // locations so only those locations will be checked. It's also | |
287 // required that the caller knows that the static type is at least | |
288 // baseType. See the notes in guessTypeForAddress for the logic of | |
289 // the locations searched. | |
290 | |
291 Address loc1 = addr.getAddressAt(0); | |
292 Address loc2 = null; | |
293 Address loc3 = null; | |
294 long offset2 = baseType.getSize(); | |
295 // I don't think this should be misaligned under any | |
296 // circumstances, but I'm not sure (FIXME: also not sure which | |
297 // way to go here, up or down -- assuming down) | |
298 offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize(); | |
299 if (offset2 > 0) { | |
300 loc2 = addr.getAddressAt(offset2); | |
301 } | |
302 long offset3 = offset2 - getAddressSize(); | |
303 if (offset3 > 0) { | |
304 loc3 = addr.getAddressAt(offset3); | |
305 } | |
306 | |
307 Type loc2Match = null; | |
308 Type loc3Match = null; | |
309 for (Iterator iter = getTypes(); iter.hasNext(); ) { | |
310 Type type = (Type) iter.next(); | |
311 Type superClass = type; | |
312 while (superClass != baseType && superClass != null) { | |
313 superClass = superClass.getSuperclass(); | |
314 } | |
315 if (superClass == null) continue; | |
316 Address vtblAddr = vtblForType(type); | |
317 if (vtblAddr == null) { | |
318 // This occurs sometimes for intermediate types that are never | |
319 // instantiated. | |
320 if (DEBUG) { | |
321 System.err.println("null vtbl for " + type); | |
322 } | |
323 continue; | |
324 } | |
325 // Prefer loc1 match | |
326 if (vtblAddr.equals(loc1)) return type; | |
327 if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) { | |
328 loc2Match = type; | |
329 } | |
330 if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) { | |
331 loc3Match = type; | |
332 } | |
333 } | |
334 if (loc2Match != null) return loc2Match; | |
335 if (loc3Match != null) return loc3Match; | |
336 return null; | |
337 } | |
338 | |
254 public Type guessTypeForAddress(Address addr) { | 339 public Type guessTypeForAddress(Address addr) { |
255 for (Iterator iter = getTypes(); iter.hasNext(); ) { | 340 for (Iterator iter = getTypes(); iter.hasNext(); ) { |
256 Type t = (Type) iter.next(); | 341 Type t = (Type) iter.next(); |
257 if (addressTypeIsEqualToType(addr, t)) { | 342 if (addressTypeIsEqualToType(addr, t)) { |
258 return t; | 343 return t; |