use of com.ibm.dtfj.image.j9.CorruptData 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.j9.CorruptData 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.j9.CorruptData in project openj9 by eclipse.
the class JavaStaticField method parse.
private long parse(int maxLength) throws CorruptDataException {
if (null == _value)
throw new CorruptDataException(new CorruptData("parse error: value is null", null));
if (_value.length() > maxLength)
throw new CorruptDataException(new CorruptData("parse error: value [" + _value + "] length " + _value.length() + " exceeds maximum of " + maxLength, null));
if (16 == _value.length()) {
// split and shift since this would overflow
String highS = _value.substring(0, 8);
String lowS = _value.substring(8, 16);
long high = Long.parseLong(highS, 16);
long low = Long.parseLong(lowS, 16);
return (high << 32) | low;
}
return Long.parseLong(_value, 16);
}
use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaThread method getName.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaThread#getName()
*/
public String getName() throws CorruptDataException {
JavaObject theObject = getObject();
if (null != theObject) {
JavaClass threadClass = _javaLangThreadSuperclass();
Iterator fields = threadClass.getDeclaredFields();
while (fields.hasNext()) {
JavaField oneField = (JavaField) fields.next();
if (oneField.getName().equals("name")) {
try {
return oneField.getString(theObject);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to read memory for 'name' field", null));
}
}
}
throw new CorruptDataException(new CorruptData("unable to find 'name' field", null));
} else {
return "vmthread @" + _jniEnv.getAddress();
}
}
use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaHeapRegion method getObjectAtAddress.
public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException {
JavaObject object = null;
if ((null != address) && (0 != address.getAddress())) {
// try the special objects cache first...
JavaObject specialObject = _javaVM.getSpecialObject(address);
if (null != specialObject) {
return specialObject;
}
// CMVC 173262 - check alignment
if ((address.getAddress() & (_objectAlignment - 1)) != 0) {
throw new IllegalArgumentException("Invalid alignment for JavaObject should be " + _objectAlignment + " aligned. Address = " + address.toString());
}
long arrayletIdentificationBitmask = 0;
long arrayletIdentificationResult = 0;
int arrayletIdentificationWidth = 0;
int arrayletIdentificationOffset = 0;
int arrayletSpineSize = 0;
long arrayletLeafSize = 0;
arrayletIdentificationBitmask = _parentHeap.getArrayletIdentificationBitmask();
arrayletIdentificationResult = _parentHeap.getArrayletIdentificationResult();
arrayletIdentificationWidth = _parentHeap.getArrayletIdentificationWidth();
arrayletIdentificationOffset = _parentHeap.getArrayletIdentificationOffset();
arrayletSpineSize = getArrayletSpineSize();
arrayletLeafSize = getArrayletLeafSize();
boolean isArraylet = false;
if (0 != arrayletIdentificationResult) {
// note that this may be an arraylet so we need to do some extra work here
long maskedFlags = 0;
if (4 == arrayletIdentificationWidth) {
try {
maskedFlags = 0xFFFFFFFFL & (long) (address.getIntAt(arrayletIdentificationOffset));
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to access object flags", address));
}
} else if (8 == arrayletIdentificationWidth) {
try {
maskedFlags = address.getLongAt(arrayletIdentificationOffset);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to access object flags", address));
}
} else {
// this size cannot be read without exposing endian of the underlying core
System.err.println("Arraylet identification width is invalid: " + arrayletIdentificationWidth + " (should be 4 or 8)");
}
isArraylet = arrayletIdentificationResult == (arrayletIdentificationBitmask & maskedFlags);
}
object = new com.ibm.dtfj.java.j9.JavaObject(_javaVM, address, _parentHeap, arrayletSpineSize, arrayletLeafSize, isArraylet, _objectAlignment);
}
return object;
}
Aggregations