Java Code Examples for sun.jvm.hotspot.debugger.Address#equals()

The following examples show how to use sun.jvm.hotspot.debugger.Address#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicTypeDataBase.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 2
Source File: BasicTypeDataBase.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}
 
Example 3
Source File: BasicTypeDataBase.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 4
Source File: BasicTypeDataBase.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}
 
Example 5
Source File: BasicTypeDataBase.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 6
Source File: BasicTypeDataBase.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}
 
Example 7
Source File: BasicTypeDataBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 8
Source File: BasicTypeDataBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}
 
Example 9
Source File: BasicTypeDataBase.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 10
Source File: BasicTypeDataBase.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}
 
Example 11
Source File: BasicTypeDataBase.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 12
Source File: BasicTypeDataBase.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}
 
Example 13
Source File: BasicTypeDataBase.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 14
Source File: BasicTypeDataBase.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}
 
Example 15
Source File: BasicTypeDataBase.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean addressTypeIsEqualToType(Address addr, Type type) {
  if (addr == null) {
    return false;
  }

  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  Address vtblAddr = vtblForType(type);

  if (vtblAddr == null) {
    // Type was not polymorphic, or an error occurred during lookup
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
    }

    return false;
  }

  // The first implementation searched three locations for this vtbl
  // value; scanning through the entire object was considered, but
  // we thought we knew where we were looking, and looking only in
  // these specific locations should reduce the probability of
  // mistaking random bits as a pointer (although, realistically
  // speaking, the likelihood of finding a match between the bit
  // pattern of, for example, a double and the vtbl is vanishingly
  // small.)
  //    1. The first word of the object (should handle MSVC++ as
  //    well as the SparcWorks compilers with compatibility set to
  //    v5.0 or greater)
  //    2. and 3. The last two Address-aligned words of the part of
  //    the object defined by its topmost polymorphic superclass.
  //    This should handle the SparcWorks compilers, v4.2 or
  //    earlier, as well as any other compilers which place the vptr
  //    at the end of the user-defined fields of the first base
  //    class with virtual functions.
  //
  // Unfortunately this algorithm did not work properly for the
  // specific case of the ThreadShadow/Thread inheritance situation,
  // because the Solaris compiler seems to cleverly eliminate the
  // vtbl for ThreadShadow since the only virtual is empty. (We
  // should get rid of the ThreadShadow and fix the include
  // databases, but need to postpone this for the present.) The
  // current solution performs the three-location check for this
  // class and all of its known superclasses rather than just the
  // topmost polymorphic one.

  Type curType = type;

  try {
    while (curType != null) {
      // Using the size information we have for this type, check the
      // three locations described above.

      // (1)
      if (vtblAddr.equals(addr.getAddressAt(0))) {
        return true;
      }

      // (2)
      long offset = curType.getSize();
      // I don't think this should be misaligned under any
      // circumstances, but I'm not sure (FIXME: also not sure which
      // way to go here, up or down -- assuming down)
      offset -= (offset % getAddressSize());
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }
      offset -= getAddressSize();
      if (offset <= 0) {
        return false;
      }
      if (vtblAddr.equals(addr.getAddressAt(offset))) {
        return true;
      }

      curType = curType.getSuperclass();
    }
  }
  catch (Exception e) {
    // Any UnmappedAddressExceptions, etc. are a good indication
    // that the pointer is not of the specified type
    if (DEBUG) {
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
      e.printStackTrace();
    }

    return false;
  }

  if (DEBUG) {
    System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
                       type.getName());
  }

  return false;
}
 
Example 16
Source File: BasicTypeDataBase.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
  // This implementation should be suitably platform-independent; we
  // search nearby memory for the vtbl value of the given type.

  if (vtblForType(baseType) == null) {
    // Type was not polymorphic which is an error of some sort
    throw new InternalError(baseType + " does not appear to be polymorphic");
  }

  // This is a more restricted version of guessTypeForAddress since
  // that function has some limitations since it doesn't really know
  // where in the hierarchy a virtual type starts and just poking
  // around in memory is likely to trip over some vtable address,
  // resulting in false positives.  Eventually all uses should
  // switch to this logic but in the interests of stability it will
  // be separate for the moment.

  // Assuming that the base type is truly the first polymorphic type
  // then the vtbl for all subclasss should be at several defined
  // locations so only those locations will be checked.  It's also
  // required that the caller knows that the static type is at least
  // baseType.  See the notes in guessTypeForAddress for the logic of
  // the locations searched.

  Address loc1 = addr.getAddressAt(0);
  Address loc2 = null;
  Address loc3 = null;
  long offset2 = baseType.getSize();
  // I don't think this should be misaligned under any
  // circumstances, but I'm not sure (FIXME: also not sure which
  // way to go here, up or down -- assuming down)
  offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
  if (offset2 > 0) {
    loc2 = addr.getAddressAt(offset2);
  }
  long offset3 = offset2 - getAddressSize();
  if (offset3 > 0) {
    loc3 = addr.getAddressAt(offset3);
  }

  Type loc2Match = null;
  Type loc3Match = null;
  for (Iterator iter = getTypes(); iter.hasNext(); ) {
    Type type = (Type) iter.next();
    Type superClass = type;
    while (superClass != baseType && superClass != null) {
      superClass = superClass.getSuperclass();
    }
    if (superClass == null) continue;
    Address vtblAddr = vtblForType(type);
    if (vtblAddr == null) {
      // This occurs sometimes for intermediate types that are never
      // instantiated.
      if (DEBUG) {
        System.err.println("null vtbl for " + type);
      }
      continue;
    }
    // Prefer loc1 match
    if (vtblAddr.equals(loc1)) return type;
    if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
        loc2Match = type;
    }
    if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
        loc3Match = type;
    }
  }
  if (loc2Match != null) return loc2Match;
  if (loc3Match != null) return loc3Match;
  return null;
}