Search in sources :

Example 6 with LongEnumeration

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);
    }
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LongEnumeration(com.ibm.dtfj.phd.util.LongEnumeration) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject)

Aggregations

LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)6 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)5 JavaClass (com.ibm.dtfj.java.JavaClass)5 JavaObject (com.ibm.dtfj.java.JavaObject)5 Iterator (java.util.Iterator)4 PortableHeapDumpListener (com.ibm.dtfj.phd.parser.PortableHeapDumpListener)3 IOException (java.io.IOException)3 NoSuchElementException (java.util.NoSuchElementException)3 ImagePointer (com.ibm.dtfj.image.ImagePointer)2 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)2 EOFException (java.io.EOFException)2 HashSet (java.util.HashSet)2 CorruptData (com.ibm.dtfj.image.CorruptData)1 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)1 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)1 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)1 JavaMethod (com.ibm.dtfj.java.JavaMethod)1 JavaReference (com.ibm.dtfj.java.JavaReference)1 HeapdumpReader (com.ibm.dtfj.phd.parser.HeapdumpReader)1 ArrayList (java.util.ArrayList)1