Search in sources :

Example 1 with IEventListener

use of com.ibm.j9ddr.events.IEventListener in project openj9 by eclipse.

the class DTFJJavaClass method getDeclaredFields.

@SuppressWarnings("rawtypes")
public Iterator getDeclaredFields() {
    List<Object> list = declaredFieldsCache.get(j9class);
    if (list == null) {
        list = new LinkedList<Object>();
        final List<Object> fieldList = list;
        IEventListener corruptDataListener = new IEventListener() {

            public void corruptData(String message, com.ibm.j9ddr.CorruptDataException e, boolean fatal) {
                J9DDRCorruptData cd = J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e);
                fieldList.add(cd);
            }
        };
        try {
            register(corruptDataListener);
            J9ClassPointer superclass = J9ClassPointer.NULL;
            try {
                superclass = getSuperClassPointer();
            } catch (com.ibm.j9ddr.CorruptDataException e1) {
                // pass null for the superclass to just list this classes fields as cannot determine superclass
                fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Unable to determine superclass"));
            }
            U32 flags = new U32(J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC | J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE);
            long fieldCount = j9class.romClass().romFieldCount().longValue();
            Iterator<J9ObjectFieldOffset> fields = null;
            if (fieldCount > MAX_CLASS_FIELDS) {
                fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt field count"));
            } else {
                fields = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(j9class, superclass, flags);
            }
            while (fields != null && fields.hasNext()) {
                try {
                    J9ObjectFieldOffset field = fields.next();
                    log.fine(String.format("Declared field : %s", field.getName()));
                    if (field.isStatic()) {
                        fieldList.add(new DTFJJavaFieldStatic(this, field));
                    } else {
                        fieldList.add(new DTFJJavaFieldInstance(this, field));
                    }
                } catch (com.ibm.j9ddr.CorruptDataException e) {
                    // add the corrupted field to the iterator
                    fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e));
                }
                if (fieldList.size() > fieldCount) {
                    // The class has returned more fields than it said it contained, it is corrupt.
                    // add the corrupted field to the iterator
                    fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt class returned more fields than it declared"));
                    break;
                }
            }
            /* Large lists of fields are likely to be corrupt data so
				 * don't cache them.
				 */
            if (fieldList.size() < 1024) {
                declaredFieldsCache.put(j9class, fieldList);
            }
        } catch (Throwable t) {
            fieldList.add(J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t));
        } finally {
            unregister(corruptDataListener);
        }
    }
    return list.iterator();
}
Also used : J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ObjectFieldOffset(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) IEventListener(com.ibm.j9ddr.events.IEventListener) U32(com.ibm.j9ddr.vm29.types.U32) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object)

Example 2 with IEventListener

use of com.ibm.j9ddr.events.IEventListener in project openj9 by eclipse.

the class DTFJJavaRuntime method getMemoryCategories.

public Iterator<?> getMemoryCategories() throws DataUnavailable {
    final List<Object> returnList = new LinkedList<Object>();
    IEventListener eventListener = new IEventListener() {

        public void corruptData(String message, com.ibm.j9ddr.CorruptDataException e, boolean fatal) {
            returnList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e));
        }
    };
    EventManager.register(eventListener);
    try {
        Iterator<? extends OMRMemCategoryPointer> rootCategories = MemoryCategoryIterator.iterateCategoryRootSet(DTFJContext.getVm().portLibrary());
        while (rootCategories.hasNext()) {
            returnList.add(new DTFJJavaRuntimeMemoryCategory(this, rootCategories.next()));
        }
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        returnList.add(cd);
    } finally {
        EventManager.unregister(eventListener);
    }
    return Collections.unmodifiableList(returnList).iterator();
}
Also used : IEventListener(com.ibm.j9ddr.events.IEventListener) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) DTFJCorruptDataException(com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList)

Example 3 with IEventListener

use of com.ibm.j9ddr.events.IEventListener in project openj9 by eclipse.

the class EventManager method unregister.

public static void unregister(IEventListener listener) {
    if (listeners.isEmpty()) {
        // check that there are some entries on the stack
        log.warning("There are no listeners left on the stack, skipping unregistration");
        return;
    }
    IEventListener top = listeners.peek();
    if (top != listener) {
        // check that the top of the stack is the same as being unregistered
        String msg = String.format("The top listener on the stack does not match : expected [%s] actual [%s]", listener.getClass().getName(), top.getClass().getName());
        log.warning(msg);
        return;
    }
    listeners.removeFirst();
}
Also used : IEventListener(com.ibm.j9ddr.events.IEventListener)

Example 4 with IEventListener

use of com.ibm.j9ddr.events.IEventListener in project openj9 by eclipse.

the class EventManager method raiseCorruptDataEvent.

/**
 * Signal that corrupt data was encountered
 * @param message
 * @param e
 * @param isfatal
 */
public static void raiseCorruptDataEvent(String message, CorruptDataException e, boolean fatal) {
    if (listeners.isEmpty()) {
        // no listeners, so use the default
        defaultListener.corruptData(message, e, fatal);
    } else {
        IEventListener listener = listeners.peek();
        // send the event to the listener at the top of the stack
        listener.corruptData(message, e, fatal);
    }
}
Also used : IEventListener(com.ibm.j9ddr.events.IEventListener)

Aggregations

IEventListener (com.ibm.j9ddr.events.IEventListener)4 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)2 JavaObject (com.ibm.dtfj.java.JavaObject)2 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)2 CorruptData (com.ibm.dtfj.image.CorruptData)1 DTFJCorruptDataException (com.ibm.j9ddr.view.dtfj.DTFJCorruptDataException)1 J9ObjectFieldOffset (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)1 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)1 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)1 U32 (com.ibm.j9ddr.vm29.types.U32)1 LinkedList (java.util.LinkedList)1