Search in sources :

Example 36 with J9ObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer 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 37 with J9ObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer 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 38 with J9ObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer in project openj9 by eclipse.

the class JavaLangClassLoaderHelper method getParent.

public static J9ObjectPointer getParent(J9ObjectPointer loader) throws CorruptDataException {
    if (loader.isNull()) {
        return J9ObjectPointer.NULL;
    }
    if (parentOffset == null) {
        // Iterate through all the fields of Ljava/lang/ClassLoader; until you find "parent"
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9ClassPointer javaLangClassLoader = J9ClassLoaderHelper.findClass(vm.systemClassLoader(), "Ljava/lang/ClassLoader;");
        Iterator<J9ObjectFieldOffset> fieldIterator = J9ClassHelper.getFieldOffsets(javaLangClassLoader);
        while (fieldIterator.hasNext()) {
            Object nextField = fieldIterator.next();
            if (nextField instanceof J9ObjectFieldOffset) {
                J9ObjectFieldOffset offset = (J9ObjectFieldOffset) nextField;
                if ("parent".equals(offset.getName())) {
                    parentOffset = offset;
                    break;
                }
            }
        }
    }
    if (parentOffset != null) {
        return J9ObjectHelper.getObjectField(loader, parentOffset);
    } else {
        throw new CorruptDataException("Unable to find field offset for the 'parent' field");
    }
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 39 with J9ObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer in project openj9 by eclipse.

the class LiveSetWalker method scanObject.

private static void scanObject(HashSet<J9ObjectPointer> visitedObjects, ObjectVisitor visitor, J9ObjectPointer object, VoidPointer address) {
    if (visitedObjects.contains(object)) {
        return;
    }
    if (!visitor.visit(object, address)) {
        return;
    }
    visitedObjects.add(object);
    try {
        GCObjectIterator objectIterator = GCObjectIterator.fromJ9Object(object, true);
        GCObjectIterator addressIterator = GCObjectIterator.fromJ9Object(object, true);
        while (objectIterator.hasNext()) {
            J9ObjectPointer slot = objectIterator.next();
            VoidPointer addr = addressIterator.nextAddress();
            if (slot.notNull()) {
                scanObject(visitedObjects, visitor, slot, addr);
            }
        }
        if (J9ObjectHelper.getClassName(object).equals("java/lang/Class")) {
            J9ClassPointer clazz = ConstantPoolHelpers.J9VM_J9CLASS_FROM_HEAPCLASS(object);
            // Iterate the Object slots
            GCClassIterator classIterator = GCClassIterator.fromJ9Class(clazz);
            GCClassIterator classAddressIterator = GCClassIterator.fromJ9Class(clazz);
            while (classIterator.hasNext()) {
                J9ObjectPointer slot = classIterator.next();
                VoidPointer addr = classAddressIterator.nextAddress();
                if (slot.notNull()) {
                    scanObject(visitedObjects, visitor, slot, addr);
                }
            }
            // Iterate the Class slots
            GCClassIteratorClassSlots classSlotIterator = GCClassIteratorClassSlots.fromJ9Class(clazz);
            GCClassIteratorClassSlots classSlotAddressIterator = GCClassIteratorClassSlots.fromJ9Class(clazz);
            while (classSlotIterator.hasNext()) {
                J9ClassPointer slot = classSlotIterator.next();
                VoidPointer addr = classSlotAddressIterator.nextAddress();
                J9ObjectPointer classObject = ConstantPoolHelpers.J9VM_J9CLASS_TO_HEAPCLASS(slot);
                if (classObject.notNull()) {
                    scanObject(visitedObjects, visitor, classObject, addr);
                }
            }
        }
    } catch (CorruptDataException e) {
        EventManager.raiseCorruptDataEvent("Corruption found while walking the live set, object: " + object.getHexAddress(), e, false);
    }
    visitor.finishVisit(object, address);
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) GCClassIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassIterator) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) GCObjectIterator(com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) GCClassIteratorClassSlots(com.ibm.j9ddr.vm29.j9.gc.GCClassIteratorClassSlots)

Example 40 with J9ObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer in project openj9 by eclipse.

the class LiveSetWalker method walkLiveSet.

/*
	 * Walks the LiveSet in preorder, returns a HashSet of all walked objects.  The HashSet is generated as a byproduct of the walk.
	 * 
	 * @return a HashSet containing all visited objects 
	 */
public static void walkLiveSet(ObjectVisitor visitor, RootSetType rootSetType) throws CorruptDataException {
    /* TODO: lpnguyen, use something less stupid than a hashSet (markMap?) for this */
    HashSet<J9ObjectPointer> visitedObjects = new HashSet<J9ObjectPointer>();
    /* Not using a singleton because we want to allow users to catch corruptData events.  Not worrying about the perf loss taken
		 * by doing this as walking the live set will probably take an order of magnitude longer anyway
		 */
    RootSet rootSet = RootSet.from(rootSetType, false);
    GCIterator rootIterator = rootSet.gcIterator(rootSetType);
    GCIterator rootAddressIterator = rootSet.gcIterator(rootSetType);
    while (rootIterator.hasNext()) {
        J9ObjectPointer nextObject = (J9ObjectPointer) rootIterator.next();
        VoidPointer nextAddress = rootAddressIterator.nextAddress();
        if (nextObject.notNull()) {
            scanObject(visitedObjects, visitor, nextObject, nextAddress);
        }
    }
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) GCIterator(com.ibm.j9ddr.vm29.j9.gc.GCIterator) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) HashSet(java.util.HashSet)

Aggregations

J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)76 CorruptDataException (com.ibm.j9ddr.CorruptDataException)48 UDATA (com.ibm.j9ddr.vm29.types.UDATA)22 NoSuchElementException (java.util.NoSuchElementException)18 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)17 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)16 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)12 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)7 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)6 ObjectMonitor (com.ibm.j9ddr.vm29.j9.ObjectMonitor)5 MarkedObject (com.ibm.j9ddr.vm29.j9.gc.GCHeapMap.MarkedObject)5 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)5 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)5 GCObjectHeapIterator (com.ibm.j9ddr.vm29.j9.gc.GCObjectHeapIterator)4 GCObjectIterator (com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator)4 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)4 ArrayList (java.util.ArrayList)4 J9ObjectFieldOffset (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)3 GCHeapRegionIterator (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator)3 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)3