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();
}
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();
}
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();
}
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);
}
}
Aggregations