Search in sources :

Example 11 with FieldDescriptor

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);
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Aggregations

FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)11 StructureDescriptor (com.ibm.j9ddr.StructureReader.StructureDescriptor)4 CorruptDataException (com.ibm.j9ddr.CorruptDataException)2 ConstantDescriptor (com.ibm.j9ddr.StructureReader.ConstantDescriptor)2 CTypeParser (com.ibm.j9ddr.CTypeParser)1 StructureReader (com.ibm.j9ddr.StructureReader)1 AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)1 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)1 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)1 SlotType (com.ibm.j9ddr.vm29.tools.ddrinteractive.IClassWalkCallbacks.SlotType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 DigestInputStream (java.security.DigestInputStream)1 LinkedList (java.util.LinkedList)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)1 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)1 FieldVisitor (jdk.internal.org.objectweb.asm.FieldVisitor)1 MethodVisitor (jdk.internal.org.objectweb.asm.MethodVisitor)1