use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class VMConstantPool method getFieldOffset.
/**
* Get a field offset from the constant pool.
* @param index A J9VmconstantpoolConstants index into the constant pool. Must be for a static or instance field reference.
* @return Either the offset to the object, or null if the field's class is not resolved in the constant pool.
* @throws CorruptDataException If the field cannot be found in the related class or the CP index is not a field reference.
*/
public static J9ObjectFieldOffset getFieldOffset(long index) throws CorruptDataException {
if (_constantPool.length <= index || 0 > index) {
throw new IndexOutOfBoundsException("Index outside of constant pool bounds");
}
int cpIndex = (int) index;
long shapeDesc = ConstantPoolHelpers.J9_CP_TYPE(_cpShapeDescription, cpIndex);
if (J9CPTYPE_FIELD != shapeDesc) {
throw new CorruptDataException("VMConstantPool[" + index + "] CP_TYPE is not J9CPTYPE_FIELD");
}
/* The offset of the field, to be returned */
J9ObjectFieldOffset offset = null;
if (null != _constantPool[cpIndex]) {
offset = (J9ObjectFieldOffset) _constantPool[cpIndex];
} else {
J9ROMFieldRefPointer romRef = J9ROMFieldRefPointer.cast(_romCPStart.add(cpIndex));
J9ClassPointer refClass = getClass(romRef.classRefCPIndex().longValue());
J9ClassPointer currentClass = refClass;
if (currentClass.notNull()) {
/* If the current class is J9ClassPointer.NULL, return null as the field offset */
/* Resolve the fieldname, starting from the current class,
* and working up the class hierarchy towards the super classes. This should
* properly handle shadowed fields.
*/
String fieldName = J9UTF8Helper.stringValue(romRef.nameAndSignature().name());
String signature = J9UTF8Helper.stringValue(romRef.nameAndSignature().signature());
while (currentClass.notNull() && (null == offset)) {
Iterator<J9ObjectFieldOffset> fields = J9ClassHelper.getFieldOffsets(currentClass);
while (fields.hasNext()) {
J9ObjectFieldOffset field = fields.next();
if (field.getName().equals(fieldName) && field.getSignature().equals(signature)) {
offset = field;
break;
}
}
currentClass = J9ClassHelper.superclass(currentClass);
}
if (null == offset) {
/* The field should exist in the class it points to, unless the constant pool is corrupt or wrong */
throw new CorruptDataException("VMConstantPool[" + index + "] field not found: " + J9ClassHelper.getName(refClass) + "." + fieldName + " " + signature);
} else {
_constantPool[cpIndex] = offset;
}
}
}
return offset;
}
use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class RamClassWalker method allSlotsInRAMStaticsDo.
private void allSlotsInRAMStaticsDo() throws CorruptDataException {
if (ramClass.ramStatics().isNull()) {
return;
}
Iterator<?> ofoIterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(ramClass, J9ClassHelper.superclass(ramClass), new U32(J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC));
J9ObjectFieldOffset fields = null;
while (ofoIterator.hasNext()) {
fields = (J9ObjectFieldOffset) ofoIterator.next();
J9ROMFieldShapePointer field = fields.getField();
String info = fields.getName();
U32 modifiers = field.modifiers();
UDATAPointer fieldAddress = ramClass.ramStatics().addOffset(fields.getOffsetOrAddress());
String additionalInfo = modifiers.anyBitsIn(J9FieldFlagObject) ? "!j9object" : "";
if (modifiers.anyBitsIn(J9FieldSizeDouble)) {
classWalkerCallback.addSlot(clazz, SlotType.J9_I64, I64Pointer.cast(fieldAddress), info, additionalInfo);
} else {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, fieldAddress, info, additionalInfo);
}
}
U32 staticSlotCount = ramClass.romClass().objectStaticCount().add(ramClass.romClass().singleScalarStaticCount());
if (J9BuildFlags.env_data64) {
staticSlotCount = staticSlotCount.add(ramClass.romClass().doubleScalarStaticCount());
} else {
staticSlotCount = staticSlotCount.add(1).bitAnd(~1L).add(ramClass.romClass().doubleScalarStaticCount().mult(2));
}
UDATA size = Scalar.convertSlotsToBytes(new UDATA(staticSlotCount));
classWalkerCallback.addSection(clazz, ramClass.ramStatics(), size.longValue(), "Ram static", false);
}
use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class J9StaticsCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
try {
if (args.length != 1) {
CommandUtils.dbgPrint(out, "Usage: !j9statics <classAddress>\n");
return;
}
long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
J9ClassPointer ramClass = J9ClassPointer.cast(address);
J9ROMClassPointer romClass = ramClass.romClass();
J9UTF8Pointer className = romClass.className();
CommandUtils.dbgPrint(out, "Static fields in %s:\n", J9UTF8Helper.stringValue(className));
Iterator<J9ObjectFieldOffset> ofoIterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(ramClass, J9ClassHelper.superclass(ramClass), new U32(J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC));
while (ofoIterator.hasNext()) {
J9ObjectFieldOffset fieldOffset = ofoIterator.next();
J9ROMFieldShapePointer field = fieldOffset.getField();
String name = J9ROMFieldShapeHelper.getName(field);
String sig = J9ROMFieldShapeHelper.getSignature(field);
UDATAPointer fieldAddress = ramClass.ramStatics().addOffset(fieldOffset.getOffsetOrAddress());
switch(sig.charAt(0)) {
case 'L':
case '[':
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticstringfieldshape %s) = !j9object %s\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
break;
case 'D':
DoublePointer doublePointer = DoublePointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticdoublefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), doublePointer.getHexValue(), new Double(doublePointer.doubleAt(0)).toString());
break;
case 'F':
FloatPointer floatPointer = FloatPointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), floatPointer.getHexValue(), new Float(floatPointer.floatAt(0)).toString());
break;
case 'J':
I64Pointer longPointer = I64Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticdoublefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), longPointer.getHexValue(), longPointer.at(0).longValue());
break;
case 'I':
I32Pointer intPointer = I32Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), intPointer.getHexValue(), intPointer.at(0).intValue());
break;
case 'B':
I8Pointer bytePointer = I8Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), bytePointer.getHexValue(), bytePointer.at(0).byteValue());
break;
case 'S':
I16Pointer shortPointer = I16Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), shortPointer.getHexValue(), shortPointer.at(0).shortValue());
break;
case 'Z':
BoolPointer booleanPointer = BoolPointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), booleanPointer.getHexValue(), booleanPointer.boolAt(0) ? "true" : "false");
break;
default:
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
break;
}
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset 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.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class J9ObjectStructureFormatter method printObjectField.
public void printObjectField(PrintStream out, int tabLevel, J9ClassPointer localClazz, U8Pointer dataStart, J9ClassPointer fromClass, J9ObjectFieldOffset objectFieldOffset) throws CorruptDataException {
J9ROMFieldShapePointer fieldShape = objectFieldOffset.getField();
UDATA fieldOffset = objectFieldOffset.getOffsetOrAddress();
boolean isHiddenField = objectFieldOffset.isHidden();
String className = J9UTF8Helper.stringValue(fromClass.romClass().className());
String fieldName = J9UTF8Helper.stringValue(fieldShape.nameAndSignature().name());
String fieldSignature = J9UTF8Helper.stringValue(fieldShape.nameAndSignature().signature());
U8Pointer valuePtr = dataStart;
valuePtr = valuePtr.add(fieldOffset);
padding(out, tabLevel);
out.print(String.format("%s %s = ", fieldSignature, fieldName));
if (fieldShape.modifiers().anyBitsIn(J9FieldSizeDouble)) {
out.print(U64Pointer.cast(valuePtr).at(0).getHexValue());
} else if (fieldShape.modifiers().anyBitsIn(J9FieldFlagObject)) {
AbstractPointer ptr = J9BuildFlags.gc_compressedPointers ? U32Pointer.cast(valuePtr) : UDATAPointer.cast(valuePtr);
out.print(String.format("!fj9object 0x%x", ptr.at(0).longValue()));
} else {
out.print(I32Pointer.cast(valuePtr).at(0).getHexValue());
}
out.print(String.format(" (offset=%d) (%s)", fieldOffset.longValue(), className));
if (isHiddenField) {
out.print(" <hidden>");
}
}
Aggregations