use of com.ibm.j9ddr.StructureReader.FieldDescriptor in project openj9 by eclipse.
the class RuntimeTypeResolutionHelper method findRuntimeType.
// Design 42819
// Discover runtime type based on identifier field.
public static String findRuntimeType(String type, Pointer ptr, Context context) {
StructureDescriptor fieldOwner = null;
FieldDescriptor typeIdField = null;
String classType = null;
// not just as the top of the hierarchy, so we have to look at each level.
try {
if (ptr.notNull()) {
// Skip the "!"
classType = StructureCommandUtil.typeToCommand(type).substring(1);
do {
fieldOwner = StructureCommandUtil.getStructureDescriptor(classType, context);
if (null != fieldOwner) {
for (FieldDescriptor aField : fieldOwner.getFields()) {
if (aField.getDeclaredName().equals("_typeId")) {
typeIdField = aField;
break;
}
}
if (null == typeIdField) {
classType = fieldOwner.getSuperName();
}
}
} while ((null == typeIdField) && (null != classType) && (null != fieldOwner) && (classType.length() > 0));
}
if (null != typeIdField) {
VoidPointer untypedStrPtr = PointerPointer.cast(ptr).addOffset(typeIdField.getOffset()).at(0);
if (untypedStrPtr.notNull()) {
U8Pointer typeStrPtr = U8Pointer.cast(untypedStrPtr);
type = typeStrPtr.getCStringAtOffset(0).toLowerCase();
}
}
} catch (CorruptDataException e) {
// Do nothing.
}
return RuntimeTypeResolutionUtils.cleanTypeStr(type);
}
Aggregations