Search in sources :

Example 1 with DTFJJavaObject

use of com.ibm.j9ddr.vm29.view.dtfj.java.DTFJJavaObject in project openj9 by eclipse.

the class DTFJJavaObject method arraycopy.

public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
    fetchDeferredData();
    if (!objectIsArray) {
        throw new IllegalArgumentException("Object is not an array");
    }
    J9IndexableObjectPointer array = J9IndexableObjectPointer.cast(object);
    try {
        validateArrayCopyParameters(array, srcStart, dst, dstStart, length);
        // CMVC 171150 : use helper object to correctly get the class name
        String className = J9IndexableObjectHelper.getClassName(array);
        if ((null == className) || (className.length() < 2)) {
            J9DDRCorruptData cd = new J9DDRCorruptData(DTFJContext.getProcess(), "The class name for this object could not be determined", object.getAddress());
            throw new CorruptDataException(cd);
        }
        if (className.charAt(1) == 'L' || className.charAt(1) == '[') {
            // JExtract/DTFJ can cope with dst of either Object[] or JavaObject[] - but we need to detect other things
            if (!dst.getClass().equals(Object[].class) && !(dst instanceof JavaObject[])) {
                throw new IllegalArgumentException("Type of dst object (" + dst.getClass().getName() + ") incompatible with Object array. Should be JavaObject[] or Object[]");
            }
            J9ObjectPointer[] intermediateArray = new J9ObjectPointer[length];
            Object[] castedDst = (Object[]) dst;
            if (dstStart + (long) length > castedDst.length) {
                throw new ArrayIndexOutOfBoundsException("Supplied destination array too small. Requires: " + (dstStart + (long) length) + ", was " + castedDst.length);
            }
            J9IndexableObjectHelper.getData(array, intermediateArray, srcStart, length, 0);
            for (int i = 0; i < length; i++) {
                if (intermediateArray[i].isNull()) {
                    castedDst[dstStart + i] = null;
                } else {
                    castedDst[dstStart + i] = new DTFJJavaObject(intermediateArray[i]);
                }
            }
        } else {
            // For primitives we can pass through the client object. The type verification will be done in J9IndexableObjectPointer
            J9IndexableObjectHelper.getData(array, dst, srcStart, length, dstStart);
        }
    } catch (Throwable t) {
        throw J9DDRDTFJUtils.handleAllButMemAccExAsCorruptDataException(DTFJContext.getProcess(), t, whitelist);
    }
}
Also used : J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) J9IndexableObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)

Example 2 with DTFJJavaObject

use of com.ibm.j9ddr.vm29.view.dtfj.java.DTFJJavaObject in project openj9 by eclipse.

the class DTFJJavaFieldInstance method get.

public Object get(JavaObject object) throws CorruptDataException, MemoryAccessException {
    if (null == object) {
        throw new NullPointerException("JavaObject is null");
    }
    try {
        switch(getSigFlag()) {
            case BOOLEAN_SIGNATURE:
                return Boolean.valueOf(getBoolean(object));
            case BYTE_SIGNATURE:
                return Byte.valueOf(getByte(object));
            case CHAR_SIGNATURE:
                return Character.valueOf(getChar(object));
            case SHORT_SIGNATURE:
                return Short.valueOf(getShort(object));
            case INTEGER_SIGNATURE:
                return Integer.valueOf(getInt(object));
            case FLOAT_SIGNATURE:
                return new Float(getFloat(object));
            case LONG_SIGNATURE:
                return Long.valueOf(getLong(object));
            case DOUBLE_SIGNATURE:
                return new Double(getDouble(object));
            case ARRAY_PREFIX_SIGNATURE:
            case OBJECT_PREFIX_SIGNATURE:
                J9ROMFieldShapePointer fieldShape = fieldOffset.getField();
                DTFJJavaObject jobj = validateJavaObject(object);
                checkDataTypeConversion(jobj, FIELD_OBJECT | FIELD_ARRAY);
                J9ObjectPointer data = J9ObjectHelper.getObjectField(jobj.getJ9ObjectPointer(), fieldOffset);
                if (data.isNull()) {
                    return null;
                } else {
                    return new DTFJJavaObject(null, data);
                }
            default:
                throw new IllegalArgumentException("Cannot determine the correct data type");
        }
    } catch (Throwable t) {
        // the whitelist will cause IllegalArgumentException to be re-thrown
        throw J9DDRDTFJUtils.handleAllButMemAccExAsCorruptDataException(DTFJContext.getProcess(), t, whitelist);
    }
}
Also used : J9ROMFieldShapePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 3 with DTFJJavaObject

use of com.ibm.j9ddr.vm29.view.dtfj.java.DTFJJavaObject in project openj9 by eclipse.

the class DTFJConstantPoolIterator method next.

public Object next() {
    if (hasNext()) {
        Object retval = null;
        if (!EOIObjects) {
            // if there are some more items to retrieve from the pool
            try {
                // register this class for notifications
                register(this);
                // get the next item
                retval = new DTFJJavaObject(poolObjects.next());
                // see if there are any more
                EOIObjects = !poolObjects.hasNext();
            } finally {
                // remove notifier registration
                unregister(this);
            }
            return retval;
        }
        if (!EOIClasses) {
            // if there are some more items to retrieve from the pool
            try {
                // register this class for notifications
                register(this);
                try {
                    // DTFJ returns the java.lang.Class object associated with this class
                    // get the next item
                    retval = new DTFJJavaObject(poolClasses.next().classObject());
                } catch (CorruptDataException e) {
                    // return the corrupt data
                    retval = J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e);
                }
                // see if there are any more
                EOIClasses = !poolClasses.hasNext();
            } finally {
                // remove notifier registration
                unregister(this);
            }
            return retval;
        }
        if (cdata != null) {
            // there are no more items in the pool
            // but there may be corrupt data items to return
            retval = cdata;
            cdata = null;
        }
        return retval;
    }
    throw new NoSuchElementException("There are no more elements in this iterator");
}
Also used : DTFJJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.DTFJJavaObject) DTFJJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.DTFJJavaObject) CorruptDataException(com.ibm.j9ddr.CorruptDataException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 CorruptDataException (com.ibm.j9ddr.CorruptDataException)1 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)1 J9IndexableObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer)1 J9ROMFieldShapePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer)1 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)1 DTFJJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.DTFJJavaObject)1 CorruptJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)1 NoSuchElementException (java.util.NoSuchElementException)1