Search in sources :

Example 6 with StructureDescriptor

use of com.ibm.j9ddr.StructureReader.StructureDescriptor in project openj9 by eclipse.

the class BaseStructureCommand method recognises.

/* (non-Javadoc)
	 * @see com.ibm.j9ddr.tools.ddrinteractive.ICommand#recognises(java.lang.String)
	 */
public final boolean recognises(String command, Context context) {
    if (command.length() < 2) {
        return false;
    }
    // Strip the !
    command = command.substring(1);
    StructureDescriptor desc = StructureCommandUtil.getStructureDescriptor(command, context);
    return desc != null;
}
Also used : StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor)

Example 7 with StructureDescriptor

use of com.ibm.j9ddr.StructureReader.StructureDescriptor in project openj9 by eclipse.

the class J9DDRStructureStore method updateSuperset.

public void updateSuperset() throws IOException {
    StructureReader reader = null;
    if ((structureBytes.length > 2) && (structureBytes[0] == SUPERSET_ID[0]) && (structureBytes[1] == SUPERSET_ID[1])) {
        // creating a reader using an input stream treats it as a superset input i.e. text
        InputStream in = new ByteArrayInputStream(structureBytes);
        reader = new StructureReader(in);
    } else {
        // using an image input stream to the reader indicates that is in binary blob format
        ImageInputStream inputStream = new MemoryCacheImageInputStream(new ByteArrayInputStream(structureBytes));
        reader = new StructureReader(inputStream);
    }
    for (StructureDescriptor structure : reader.getStructures()) {
        String structureHeader = structure.deflate();
        HashSet<String> structureContents = superset.get(structureHeader);
        if (structureContents == null) {
            structureContents = new HashSet<String>();
            superset.put(structureHeader, structureContents);
        }
        for (FieldDescriptor field : structure.getFields()) {
            addFieldToSuperset(structureContents, field);
        }
        for (ConstantDescriptor constant : structure.getConstants()) {
            String constantHeader = constant.deflate();
            structureContents.add(constantHeader);
        }
    }
    writeSuperset();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream) ConstantDescriptor(com.ibm.j9ddr.StructureReader.ConstantDescriptor) StructureReader(com.ibm.j9ddr.StructureReader) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 8 with StructureDescriptor

use of com.ibm.j9ddr.StructureReader.StructureDescriptor in project openj9 by eclipse.

the class ClassWalker method addObjectsAsSlot.

/**
 * It walks through each field in this structure that is represented by methodClass and
 * registers each field as a slot into ClassWalkerCallBack
 *
 * It uses the StructureDescriptor of J9DDR to get the FieldDescriptor of a structure.
 * The name, type and address are found in the FieldDescriptor. The name, type and address
 * are guaranteed to match the current core file, since they are taken from it.
 *
 * @param methodClass pointer class that is generated for the VM structure
 * @param renameFields	list of names to rename the original field names in the structure
 * @throws CorruptDataException
 */
protected void addObjectsAsSlot(StructurePointer methodClass, HashMap<String, String> renameFields) throws CorruptDataException {
    /* Get the structure name by removing "Pointer" suffix from the DDR generated class name*/
    String structureName = methodClass.getClass().getSimpleName().substring(0, methodClass.getClass().getSimpleName().indexOf("Pointer"));
    /* Get structure descriptor by using structure name */
    StructureDescriptor sd = StructureCommandUtil.getStructureDescriptor(structureName, getContext());
    /* Structure descriptor can not be null in normal circumstances, 
		 * because StructurePointer "methodClass" is generated for an existing structure in the VM, 
		 * so it should exist. If not, throw an exception. 
		 */
    if (sd == null) {
        throw new CorruptDataException("Structure \"" + structureName + "\" can not be found.");
    }
    for (FieldDescriptor fd : sd.getFields()) {
        /* Get the name of the field from field descriptor */
        String outName = fd.getName();
        /* Get SlotType by using field type name */
        SlotType type = getTypeByFieldTypeName(fd.getType());
        /* Get the address of the field by adding the offset to the methodClass'address */
        AbstractPointer address = U8Pointer.cast(methodClass).addOffset(fd.getOffset());
        /* Rename fields if any defined. */
        if (null != renameFields) {
            if (renameFields.containsKey(outName)) {
                outName = renameFields.get(outName);
            }
        }
        /*add the field into classWalkerCallback by its name, type, address and debug extension method name */
        classWalkerCallback.addSlot(clazz, type, address, outName, getDebugExtForMethodName(outName));
    }
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor) SlotType(com.ibm.j9ddr.vm29.tools.ddrinteractive.IClassWalkCallbacks.SlotType)

Example 9 with StructureDescriptor

use of com.ibm.j9ddr.StructureReader.StructureDescriptor 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)

Example 10 with StructureDescriptor

use of com.ibm.j9ddr.StructureReader.StructureDescriptor in project openj9 by eclipse.

the class PrintBlob method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Expected 1 argument. Got " + args.length);
        System.exit(1);
    }
    File blobFile = new File(args[0]);
    ImageInputStream iis = new FileImageInputStream(blobFile);
    iis.setByteOrder(ByteOrder.LITTLE_ENDIAN);
    StructureReader structReader = new StructureReader(iis);
    List<StructureDescriptor> structures = new ArrayList<StructureDescriptor>(structReader.getStructures());
    Collections.sort(structures, new Comparator<StructureDescriptor>() {

        public int compare(StructureDescriptor o1, StructureDescriptor o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (StructureDescriptor thisStruct : structures) {
        String superClass = thisStruct.getSuperName();
        if (superClass != null && superClass.length() > 0) {
            System.out.println("Structure: " + thisStruct.getName() + " extends " + superClass);
        } else {
            System.out.println("Structure: " + thisStruct.getName());
        }
    // List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(thisStruct.getFields());
    // 
    // Collections.sort(fields, new Comparator<FieldDescriptor>(){
    // 
    // public int compare(FieldDescriptor o1, FieldDescriptor o2)
    // {
    // return o1.getName().compareTo(o2.getName());
    // }});
    // 
    // System.out.println("\tFields");
    // 
    // for (FieldDescriptor thisField : fields) {
    // System.out.println("\t\t" + thisField.getName() + " - " + thisField.getType());
    // }
    // 
    // List<ConstantDescriptor> constants = new ArrayList<ConstantDescriptor>(thisStruct.getConstants());
    // 
    // Collections.sort(constants, new Comparator<ConstantDescriptor>(){
    // 
    // public int compare(ConstantDescriptor o1, ConstantDescriptor o2)
    // {
    // return o1.getName().compareTo(o2.getName());
    // }});
    // 
    // System.out.println("\tConstants:");
    // for (ConstantDescriptor thisConstant : constants) {
    // System.out.println("\t\t" + thisConstant.getName());
    // }
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) StructureReader(com.ibm.j9ddr.StructureReader) ArrayList(java.util.ArrayList) File(java.io.File) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor)

Aggregations

StructureDescriptor (com.ibm.j9ddr.StructureReader.StructureDescriptor)10 StructureReader (com.ibm.j9ddr.StructureReader)4 FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 CorruptDataException (com.ibm.j9ddr.CorruptDataException)2 ConstantDescriptor (com.ibm.j9ddr.StructureReader.ConstantDescriptor)2 StructureTypeManager (com.ibm.j9ddr.StructureTypeManager)2 J9DDRStructureStore (com.ibm.j9ddr.tools.store.J9DDRStructureStore)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ImageInputStream (javax.imageio.stream.ImageInputStream)2 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 File (java.io.File)1 DigestInputStream (java.security.DigestInputStream)1 ArrayList (java.util.ArrayList)1