use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class ImagePointerComparator method testEquals.
// address
// addressSpace
// isExecutable
// isReadOnly
// isShared
public void testEquals(Object ddrObject, Object jextractObject, int members) {
ImagePointer ddrImagePointer = (ImagePointer) ddrObject;
ImagePointer jextractImagePointer = (ImagePointer) jextractObject;
// getAddress()
if ((members & ADDRESS) != 0)
testJavaEquals(ddrImagePointer, jextractImagePointer, "getAddress");
// getAddressSpace() (but not deeply to avoid circular reference)
if ((members & ADDRESS_SPACE) != 0)
new ImageAddressSpaceComparator().testComparatorEquals(ddrImagePointer, jextractImagePointer, "getAddressSpace");
// isExecutable
if ((members & IS_EXECUTABLE) != 0)
testJavaEquals(ddrImagePointer, jextractImagePointer, "isExecutable");
// isShared
if ((members & IS_SHARED) != 0)
testJavaEquals(ddrImagePointer, jextractImagePointer, "isShared");
// isReadOnly
if ((members & IS_READ_ONLY) != 0)
testJavaEquals(ddrImagePointer, jextractImagePointer, "isReadOnly");
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class JavaClass method getReferences.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClass#getReferences()
*/
public Iterator getReferences() {
// need to build a list of references from this class.
Vector references = new Vector();
JavaReference jRef = null;
// get the Constant Pool references from this class.
Iterator constantPoolIt = getConstantPoolReferences();
while (constantPoolIt.hasNext()) {
// get each reference in turn, note that the iterator can return JavaClass
// JavaObject and CorruptData. The CorruptData objects are ignored.
Object cpObject = constantPoolIt.next();
if (cpObject instanceof JavaObject) {
// add the reference to the container.
jRef = new JavaReference(_javaVM, this, cpObject, "Constant Pool Object", JavaReference.REFERENCE_CONSTANT_POOL, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
} else if (cpObject instanceof JavaClass) {
// got a JavaClass
JavaClass jClass = (JavaClass) cpObject;
// add the reference to the container.
jRef = new JavaReference(_javaVM, this, jClass, "Constant Pool Class", JavaReference.REFERENCE_CONSTANT_POOL, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
}
if (null != jRef) {
references.add(jRef);
}
}
// get the static field references from this class.
Iterator declaredFieldIt = getDeclaredFields();
while (declaredFieldIt.hasNext()) {
JavaField jField = (JavaField) declaredFieldIt.next();
// got a field, now test it to see if it is a static reference.
if (jField instanceof JavaStaticField) {
JavaStaticField sField = (JavaStaticField) jField;
try {
Object obj = sField.getReferenceType(null);
if (null != obj) {
if (obj instanceof JavaObject) {
// build a JavaReference type and add the reference to the container.
String fieldName = sField.getName();
String description = "Static field";
if (null != fieldName) {
description = description + " [field name:" + fieldName + "]";
}
JavaObject jObject = (JavaObject) obj;
jRef = new JavaReference(_javaVM, this, jObject, description, JavaReference.REFERENCE_STATIC_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
references.add(jRef);
}
}
} catch (CorruptDataException e) {
// Corrupt data, so add it to the container.
references.add(e.getCorruptData());
} catch (MemoryAccessException e) {
// Memory access problems, so create a CorruptData object
// to describe the problem and add it to the container.
ImagePointer ptrInError = e.getPointer();
String message = e.getMessage();
references.add(new CorruptData(message, ptrInError));
} catch (IllegalArgumentException e) {
// No static data, so ignore.
}
}
}
addSuperclassReference(references);
addClassLoaderReference(references);
addClassObjectReference(references);
return references.iterator();
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class JavaObject method arraycopy.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaObject#arraycopy(int, java.lang.Object, int, int)
*/
public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
JavaClass javaClass = getJavaClass();
if (javaClass instanceof JavaArrayClass) {
JavaArrayClass isa = (JavaArrayClass) javaClass;
String type = javaClass.getName();
int elementCount = getArraySize();
// do some rudimentary sanity checking before attempting the copy.
if (null == dst) {
// cannot copy to a null object, so raise an exception.
throw new NullPointerException("dst is null");
}
if (length < 0) {
// length cannot be negative, so raise an exception.
throw new ArrayIndexOutOfBoundsException("length out of range: " + length);
}
if (dstStart < 0) {
// array index cannot be negative, so raise an exception.
throw new ArrayIndexOutOfBoundsException("dstStart out of range: " + dstStart);
}
if (srcStart < 0) {
// array index cannot be negative, so raise an exception.
throw new ArrayIndexOutOfBoundsException("srcStart out of range: " + srcStart);
}
if (srcStart + length > elementCount) {
throw new ArrayIndexOutOfBoundsException("source array index out of range: " + (int) (srcStart + length));
}
// boolean
if (type.equals(ARRAY_PREFIX_SIGNATURE + BYTE_SIGNATURE)) {
if (dst instanceof byte[]) {
byte[] target = (byte[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
target[x + dstStart] = leafBase.getByteAt(leafIndex);
}
} else {
throw new IllegalArgumentException("destination array type must be byte");
}
// boolean
} else if (type.equals(ARRAY_PREFIX_SIGNATURE + BOOLEAN_SIGNATURE)) {
if (dst instanceof boolean[]) {
boolean[] target = (boolean[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 1));
target[x + dstStart] = (0 != leafBase.getByteAt(leafIndex));
}
} else {
throw new IllegalArgumentException("destination array type must be boolean");
}
// char
} else if (type.equals(ARRAY_PREFIX_SIGNATURE + CHAR_SIGNATURE)) {
if (dst instanceof char[]) {
char[] target = (char[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
target[x + dstStart] = (char) (leafBase.getShortAt(leafIndex));
}
} else {
throw new IllegalArgumentException("destination array type must be char");
}
// short
} else if (type.equals(ARRAY_PREFIX_SIGNATURE + SHORT_SIGNATURE)) {
if (dst instanceof short[]) {
short[] target = (short[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 2));
target[x + dstStart] = leafBase.getShortAt(leafIndex);
}
} else {
throw new IllegalArgumentException("destination array type must be short");
}
// int
} else if (type.equals(ARRAY_PREFIX_SIGNATURE + INTEGER_SIGNATURE)) {
if (dst instanceof int[]) {
int[] target = (int[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
target[x + dstStart] = leafBase.getIntAt(leafIndex);
}
} else {
throw new IllegalArgumentException("destination array type must be int");
}
// long
} else if (type.equals(ARRAY_PREFIX_SIGNATURE + LONG_SIGNATURE)) {
if (dst instanceof long[]) {
long[] target = (long[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
target[x + dstStart] = leafBase.getLongAt(leafIndex);
}
} else {
throw new IllegalArgumentException("destination array type must be long");
}
// float
} else if (type.equals(ARRAY_PREFIX_SIGNATURE + FLOAT_SIGNATURE)) {
if (dst instanceof float[]) {
float[] target = (float[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 4));
target[x + dstStart] = leafBase.getFloatAt(leafIndex);
}
} else {
throw new IllegalArgumentException("destination array type must be float");
}
// double
} else if (type.equals(ARRAY_PREFIX_SIGNATURE + DOUBLE_SIGNATURE)) {
if (dst instanceof double[]) {
double[] target = (double[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
for (int x = 0; x < length; x++) {
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * 8));
target[x + dstStart] = leafBase.getDoubleAt(leafIndex);
}
} else {
throw new IllegalArgumentException("destination array type must be double");
}
// object
} else {
// type must be Object
if (!(dst instanceof Object[])) {
throw new IllegalArgumentException("destination array type must be Object");
}
Object[] target = (Object[]) dst;
if (dstStart + length > target.length) {
throw new ArrayIndexOutOfBoundsException("destination array index out of range: " + (int) (dstStart + length));
}
// gather all the JavaObject refs into an intermediate array, throwing exceptions if we encounter an error
Object[] intermediateArray = new Object[length];
for (int x = 0; x < length; x++) {
int fobjectSize = _containingHeap.getFObjectSize();
ImagePointer leafBase = leafBaseForIndex(isa.getFirstElementOffset(), ((srcStart + x) * fobjectSize));
long leafIndex = leafIndexForIndex(isa.getFirstElementOffset(), ((srcStart + x) * fobjectSize));
ImagePointer pointer = _containingHeap.readFObjectAt(leafBase, leafIndex);
try {
// an object.
if (pointer.getAddress() == 0) {
// CMVC 175864 : the getObjectAtAddress function enforces stricter address checking, so need to exclude uninitialised slots up front
intermediateArray[x] = null;
} else {
try {
intermediateArray[x] = _javaVM.getObjectAtAddress(pointer);
} catch (IllegalArgumentException e) {
// an IllegalArgumentException might be thrown if the address is not aligned
throw new CorruptDataException(new CorruptData(e.getMessage(), pointer));
}
}
} catch (ArrayStoreException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
// if no exceptions were thrown, update the caller's array all in one go
for (int i = 0; i < length; i++) {
try {
target[dstStart + i] = intermediateArray[i];
} catch (ArrayStoreException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
}
} else {
throw new IllegalArgumentException("this JavaObject instance is not an array");
}
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class JavaObject method getArrayReferences.
private List getArrayReferences(JavaArrayClass arrayClass) {
List references = new ArrayList();
try {
String type = arrayClass.getComponentType().getName();
if (type.equals("byte")) {
// ignore byte arrays.
} else if (type.equals("boolean")) {
// ignore boolean arrays.
} else if (type.equals("char")) {
// ignore char arrays.
} else if (type.equals("short")) {
// ignore short arrays.
} else if (type.equals("int")) {
// ignore int arrays.
} else if (type.equals("long")) {
// ignore long arrays.
} else if (type.equals("float")) {
// ignore float arrays.
} else if (type.equals("double")) {
// ignore double arrays.
} else {
// must be Object array so handle it.
Object[] dst = null;
int arraySize = getArraySize();
if (arraySize > 0) {
// only deal with arrays that have space for Object references.
dst = new Object[arraySize];
try {
// copy the objects into our own array and then build the JavaReference
// objects from them.
arraycopy(0, dst, 0, arraySize);
for (int i = 0; i < dst.length; i++) {
if (null != dst[i]) {
String description = "Array Reference";
description = description + " [index:" + i + "]";
JavaReference jRef = new JavaReference(_javaVM, this, dst[i], description, JavaReference.REFERENCE_ARRAY_ELEMENT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
references.add(jRef);
}
}
} catch (MemoryAccessException e) {
// Memory access problems, so create a CorruptData object
// to describe the problem and add it to the container.
ImagePointer ptrInError = e.getPointer();
String message = e.getMessage();
references.add(new CorruptData(message, ptrInError));
}
}
}
} catch (CorruptDataException e) {
// Corrupt data, so add it to the container.
references.add(e.getCorruptData());
}
return references;
}
use of com.ibm.dtfj.image.ImagePointer in project openj9 by eclipse.
the class JavaHeapRegion method addNewHeapRegionExtent.
public void addNewHeapRegionExtent(long start, long end, int count) {
ImagePointer baseAddress = _javaVM.pointerInAddressSpace(start);
int size = (int) (end - start);
addExtent(baseAddress, size, count);
}
Aggregations