agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 7088955 Sdiff agent/src/share/classes/sun/jvm/hotspot/types/basic

agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 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  *


 133   public Type getJIntType() {
 134     return jintType;
 135   }
 136 
 137   public Type getJLongType() {
 138     return jlongType;
 139   }
 140 
 141   public Type getJShortType() {
 142     return jshortType;
 143   }
 144 
 145   public long getAddressSize() {
 146     return machDesc.getAddressSize();
 147   }
 148 
 149   public long getOopSize() {
 150     return VM.getVM().getOopSize();
 151   }
 152 













 153   public boolean addressTypeIsEqualToType(Address addr, Type type) {
 154     if (addr == null) {
 155       return false;
 156     }
 157 
 158     // This implementation should be suitably platform-independent; we
 159     // search nearby memory for the vtbl value of the given type.
 160 
 161     Address vtblAddr = vtblAccess.getVtblForType(type);
 162 
 163     if (vtblAddr == null) {
 164       // Type was not polymorphic, or an error occurred during lookup
 165       if (DEBUG) {
 166         System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
 167       }
 168 
 169       return false;
 170     }
 171 
 172     // The first implementation searched three locations for this vtbl
 173     // value; scanning through the entire object was considered, but
 174     // we thought we knew where we were looking, and looking only in
 175     // these specific locations should reduce the probability of
 176     // mistaking random bits as a pointer (although, realistically
 177     // speaking, the likelihood of finding a match between the bit
 178     // pattern of, for example, a double and the vtbl is vanishingly
 179     // small.)
 180     //    1. The first word of the object (should handle MSVC++ as
 181     //    well as the SparcWorks compilers with compatibility set to


 234     }
 235     catch (Exception e) {
 236       // Any UnmappedAddressExceptions, etc. are a good indication
 237       // that the pointer is not of the specified type
 238       if (DEBUG) {
 239         System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
 240         e.printStackTrace();
 241       }
 242 
 243       return false;
 244     }
 245 
 246     if (DEBUG) {
 247       System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
 248                          type.getName());
 249     }
 250 
 251     return false;
 252   }
 253 








































































 254   public Type guessTypeForAddress(Address addr) {
 255     for (Iterator iter = getTypes(); iter.hasNext(); ) {
 256       Type t = (Type) iter.next();
 257       if (addressTypeIsEqualToType(addr, t)) {
 258         return t;
 259       }
 260     }
 261     return null;
 262   }
 263 
 264   public long cIntegerTypeMaxValue(long sizeInBytes, boolean isUnsigned) {
 265     return machDesc.cIntegerTypeMaxValue(sizeInBytes, isUnsigned);
 266   }
 267 
 268   public long cIntegerTypeMinValue(long sizeInBytes, boolean isUnsigned) {
 269     return machDesc.cIntegerTypeMinValue(sizeInBytes, isUnsigned);
 270   }
 271 
 272   public Iterator getTypes() {
 273     return nameToTypeMap.values().iterator();


   1 /*
   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.
   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  *


 133   public Type getJIntType() {
 134     return jintType;
 135   }
 136 
 137   public Type getJLongType() {
 138     return jlongType;
 139   }
 140 
 141   public Type getJShortType() {
 142     return jshortType;
 143   }
 144 
 145   public long getAddressSize() {
 146     return machDesc.getAddressSize();
 147   }
 148 
 149   public long getOopSize() {
 150     return VM.getVM().getOopSize();
 151   }
 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 
 166   public boolean addressTypeIsEqualToType(Address addr, Type type) {
 167     if (addr == null) {
 168       return false;
 169     }
 170 
 171     // This implementation should be suitably platform-independent; we
 172     // search nearby memory for the vtbl value of the given type.
 173 
 174     Address vtblAddr = vtblForType(type);
 175 
 176     if (vtblAddr == null) {
 177       // Type was not polymorphic, or an error occurred during lookup
 178       if (DEBUG) {
 179         System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
 180       }
 181 
 182       return false;
 183     }
 184 
 185     // The first implementation searched three locations for this vtbl
 186     // value; scanning through the entire object was considered, but
 187     // we thought we knew where we were looking, and looking only in
 188     // these specific locations should reduce the probability of
 189     // mistaking random bits as a pointer (although, realistically
 190     // speaking, the likelihood of finding a match between the bit
 191     // pattern of, for example, a double and the vtbl is vanishingly
 192     // small.)
 193     //    1. The first word of the object (should handle MSVC++ as
 194     //    well as the SparcWorks compilers with compatibility set to


 247     }
 248     catch (Exception e) {
 249       // Any UnmappedAddressExceptions, etc. are a good indication
 250       // that the pointer is not of the specified type
 251       if (DEBUG) {
 252         System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
 253         e.printStackTrace();
 254       }
 255 
 256       return false;
 257     }
 258 
 259     if (DEBUG) {
 260       System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
 261                          type.getName());
 262     }
 263 
 264     return false;
 265   }
 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 
 339   public Type guessTypeForAddress(Address addr) {
 340     for (Iterator iter = getTypes(); iter.hasNext(); ) {
 341       Type t = (Type) iter.next();
 342       if (addressTypeIsEqualToType(addr, t)) {
 343         return t;
 344       }
 345     }
 346     return null;
 347   }
 348 
 349   public long cIntegerTypeMaxValue(long sizeInBytes, boolean isUnsigned) {
 350     return machDesc.cIntegerTypeMaxValue(sizeInBytes, isUnsigned);
 351   }
 352 
 353   public long cIntegerTypeMinValue(long sizeInBytes, boolean isUnsigned) {
 354     return machDesc.cIntegerTypeMinValue(sizeInBytes, isUnsigned);
 355   }
 356 
 357   public Iterator getTypes() {
 358     return nameToTypeMap.values().iterator();


agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File