use of com.ibm.dtfj.phd.util.LongEnumeration in project openj9 by eclipse.
the class PHDJavaObject method arraycopy.
public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
if (dst == null)
throw new NullPointerException("destination null");
fillInDetails(true);
if (!isArray())
throw new IllegalArgumentException(this + " is not an array");
JavaClass jc = getJavaClass();
String type;
try {
type = jc.getName();
} catch (CorruptDataException e) {
// Presume all primitive arrays will have a real name
type = "[L";
}
// System.out.println("array "+srcStart+" "+dst+" "+dstStart+" "+length);
if (srcStart < 0 || length < 0 || dstStart < 0 || srcStart + length < 0 || dstStart + length < 0)
throw new IndexOutOfBoundsException(srcStart + "," + dstStart + "," + length);
if (srcStart + length > getArraySize())
throw new IndexOutOfBoundsException(srcStart + "+" + length + ">" + getArraySize() + jc);
if (dst instanceof JavaObject[]) {
if (!type.startsWith("[[") && !type.startsWith("[L"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
JavaObject[] dst1 = (JavaObject[]) dst;
// Get to the right point in the refs
int count;
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
count = le.numberOfElements();
// Skip over the elements before the required start
for (int idx = 0; idx < srcStart && idx < count; ++idx) {
le.nextLong();
}
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
count = arefs.length;
} else if (refs instanceof long[]) {
long[] arefs = (long[]) refs;
count = arefs.length;
} else {
throw new CorruptDataException(new PHDCorruptData("Unknown array contents", getID()));
}
// Copy the data to the destination
for (int idx = srcStart; idx < srcStart + length; ++idx) {
JavaObject target;
if (idx < count) {
long ref;
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
ref = le.nextLong();
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
ref = heap.getJavaRuntime().expandAddress(arefs[idx]);
} else {
long[] arefs = (long[]) refs;
ref = arefs[idx];
}
target = new PHDJavaObject.Builder(heap, ref, null, PHDJavaObject.NO_HASHCODE, -1).build();
} else {
target = null;
}
int dstIndex = dstStart + (idx - srcStart);
if (dstIndex >= dst1.length) {
throw new IndexOutOfBoundsException("Array " + jc + " 0x" + Long.toHexString(address) + "[" + getArraySize() + "]" + "," + srcStart + "," + dst1 + "[" + dst1.length + "]" + "," + dstStart + "," + length + " at " + idx);
}
dst1[dstIndex] = target;
}
} else if (dst instanceof byte[]) {
if (!type.startsWith("[B"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
byte[] dst1 = (byte[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof short[]) {
if (!type.startsWith("[S"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
short[] dst1 = (short[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof int[]) {
if (!type.startsWith("[I"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
int[] dst1 = (int[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof long[]) {
if (!type.startsWith("[J"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
long[] dst1 = (long[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof boolean[]) {
if (!type.startsWith("[Z"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
boolean[] dst1 = (boolean[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof char[]) {
if (!type.startsWith("[C"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
char[] dst1 = (char[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof float[]) {
if (!type.startsWith("[F"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
float[] dst1 = (float[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof double[]) {
if (!type.startsWith("[D"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
double[] dst1 = (double[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else {
throw new IllegalArgumentException("Expected " + type + " not " + dst);
}
}
Aggregations