use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class JavaFieldTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
List<Object> ddrClassLoaders = new ArrayList<Object>();
List<Object> jextractClassLoaders = new ArrayList<Object>();
fillLists(ddrClassLoaders, ddrRuntime.getJavaClassLoaders(), jextractClassLoaders, jextractRuntime.getJavaClassLoaders(), null);
List<Object> ddrClasses = new ArrayList<Object>();
List<Object> jextractClasses = new ArrayList<Object>();
for (int i = 0; i < ddrClassLoaders.size(); i++) {
JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
fillLists(ddrClasses, ddrClassLoader.getDefinedClasses(), jextractClasses, jextractClassLoader.getDefinedClasses(), null);
}
for (int i = 0; i < ddrClasses.size(); i++) {
JavaClass ddrClass = (JavaClass) ddrClasses.get(i);
JavaClass jextractClass = (JavaClass) jextractClasses.get(i);
fillLists(ddrObjects, ddrClass.getDeclaredFields(), jextractObjects, jextractClass.getDeclaredFields(), JavaClassTest.DECLARED_FIELDS_SORT_ORDER);
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class JavaReferenceTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
List<Object> ddrClassLoaders = new ArrayList<Object>();
List<Object> jextractClassLoaders = new ArrayList<Object>();
fillLists(ddrClassLoaders, ddrRuntime.getJavaClassLoaders(), jextractClassLoaders, jextractRuntime.getJavaClassLoaders(), null);
List<Object> ddrClasses = new ArrayList<Object>();
List<Object> jextractClasses = new ArrayList<Object>();
for (int i = 0; i < ddrClassLoaders.size(); i++) {
JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
fillLists(ddrClasses, ddrClassLoader.getDefinedClasses(), jextractClasses, jextractClassLoader.getDefinedClasses(), null);
}
for (int i = 0; i < ddrClasses.size(); i++) {
JavaClass ddrClass = (JavaClass) ddrClasses.get(i);
JavaClass jextractClass = (JavaClass) jextractClasses.get(i);
fillLists(ddrObjects, ddrClass.getReferences(), jextractObjects, jextractClass.getReferences(), JavaClassTest.REFERENCES_SORT_ORDER);
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class JavaObject method getArraySize.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaObject#getArraySize()
*/
public int getArraySize() throws CorruptDataException {
JavaClass isa = getJavaClass();
if (isa instanceof JavaArrayClass) {
JavaArrayClass blueprint = (JavaArrayClass) isa;
int offset = blueprint.getSizeOffset();
int numberOfSizeBytes = blueprint.getNumberOfSizeBytes();
try {
int numberOfElements = 0;
if (4 == numberOfSizeBytes) {
// read an int
numberOfElements = _basePointer.getIntAt(offset);
} else if (8 == numberOfSizeBytes) {
// read a long
long longCount = _basePointer.getLongAt(offset);
// the spec says to return an int here so we just truncate, for now
numberOfElements = (int) longCount;
if (((long) numberOfElements) != longCount) {
System.err.println("Error: Array element count overflow or underflow.");
}
} else {
// not sure what this is (this could be done generically but that would require exposing endian-conversion differently. Besides, stopping this at a strange number is probably a good idea since it is more likely an error)
System.err.println("Error: unable to read array size as we weren't expecting to read " + numberOfSizeBytes + " bytes.");
}
return numberOfElements;
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to read the number of elements", _basePointer.add(offset)));
}
} else {
throw new IllegalArgumentException();
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class JavaObject method getJavaClass.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaObject#getJavaClass()
*/
public JavaClass getJavaClass() throws CorruptDataException {
if (0 != _basePointer.getAddress()) {
ImagePointer classPointer;
if (_containingHeap == null)
throw new CorruptDataException(new CorruptData("unable to access class pointer as containing heap is null", _basePointer));
try {
classPointer = _containingHeap.readClassPointerRelativeTo(_basePointer);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to access class pointer", _basePointer));
}
long classID = classPointer.getAddress();
/* CMVC 167379: Lowest few bits of the class id are used as flags, and should be
* masked with ~(J9_REQUIRED_CLASS_ALIGNMENT - 1) to find real class id.
*/
long classAlignment = _containingHeap.getClassAlignment();
long alignedClassID = classID;
if (classAlignment > 0) {
alignedClassID &= (~(classAlignment - 1L));
}
JavaClass ret = _javaVM.getClassForID(alignedClassID);
if (ret == null) {
throw new CorruptDataException(new CorruptData("Unknown class ID " + Long.toHexString(alignedClassID) + " for object " + Long.toHexString(_basePointer.getAddress()) + " (read class ID from " + Long.toHexString(classPointer.getAddress()) + ", in memory value was " + Long.toHexString(classID) + ")", _basePointer));
}
return ret;
} else {
throw new NullPointerException();
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class JavaArrayClass method getName.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClass#getName()
*/
public String getName() throws CorruptDataException {
String name = "";
// Note that validation in JavaObject.arraycopy is dependent on type name constructed here
for (int x = 0; x < _dimension; x++) {
name += JavaObject.ARRAY_PREFIX_SIGNATURE;
}
JavaClass leafClass = getLeafClass();
if (null == leafClass) {
CorruptData data = new CorruptData("unable to retrieve leaf class", null);
throw new CorruptDataException(data);
}
String elementClassName = leafClass.getName();
if (elementClassName.equals("boolean")) {
name += JavaObject.BOOLEAN_SIGNATURE;
} else if (elementClassName.equals("byte")) {
name += JavaObject.BYTE_SIGNATURE;
} else if (elementClassName.equals("char")) {
name += JavaObject.CHAR_SIGNATURE;
} else if (elementClassName.equals("short")) {
name += JavaObject.SHORT_SIGNATURE;
} else if (elementClassName.equals("int")) {
name += JavaObject.INTEGER_SIGNATURE;
} else if (elementClassName.equals("long")) {
name += JavaObject.LONG_SIGNATURE;
} else if (elementClassName.equals("float")) {
name += JavaObject.FLOAT_SIGNATURE;
} else if (elementClassName.equals("double")) {
name += JavaObject.DOUBLE_SIGNATURE;
} else {
// reference type
name += JavaObject.OBJECT_PREFIX_SIGNATURE;
name += elementClassName;
name += ';';
}
return name;
}
Aggregations