Search in sources :

Example 6 with FieldDescriptor

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

the class PointerGenerator method generateImplementationMethods.

private void generateImplementationMethods(PrintWriter writer, StructureDescriptor structure) {
    Collections.sort(structure.getFields());
    for (FieldDescriptor fieldDescriptor : structure.getFields()) {
        if (omitFieldImplementation(structure, fieldDescriptor)) {
            continue;
        }
        int type = typeManager.getType(fieldDescriptor.getType());
        switch(type) {
            case TYPE_STRUCTURE:
                writeStructureMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_STRUCTURE_POINTER:
                writeStructurePointerMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_POINTER:
                writePointerMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_ARRAY:
                writeArrayMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_J9SRP:
                writeSRPMethod(writer, structure, fieldDescriptor, false);
                break;
            case TYPE_J9WSRP:
                writeSRPMethod(writer, structure, fieldDescriptor, true);
                break;
            case TYPE_J9SRP_POINTER:
                writeSRPPointerMethod(writer, structure, fieldDescriptor, false);
                break;
            case TYPE_J9WSRP_POINTER:
                writeSRPPointerMethod(writer, structure, fieldDescriptor, true);
                break;
            case TYPE_FJ9OBJECT:
                writeFJ9ObjectMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_FJ9OBJECT_POINTER:
                writeFJ9ObjectPointerMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_J9OBJECTCLASS:
                writeJ9ObjectClassMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_J9OBJECTCLASS_POINTER:
                writeJ9ObjectClassPointerMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_J9OBJECTMONITOR:
                writeJ9ObjectMonitorMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_J9OBJECTMONITOR_POINTER:
                writeJ9ObjectMonitorPointerMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_VOID:
                writeStructureMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_BOOL:
                writeBoolMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_DOUBLE:
                writeDoubleMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_FLOAT:
                writeFloatMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_ENUM:
                writeEnumMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_ENUM_POINTER:
                writeEnumPointerMethod(writer, structure, fieldDescriptor);
                break;
            case TYPE_BITFIELD:
                String typeName = fieldDescriptor.getType();
                int colonIndex = typeName.indexOf(':');
                if (colonIndex == -1) {
                    throw new IllegalArgumentException(String.format("%s is not a bitfield", fieldDescriptor));
                }
                writeBitFieldMethod(writer, structure, fieldDescriptor, type, fieldDescriptor.getName());
                break;
            default:
                if ((type >= TYPE_SIMPLE_MIN) && (type <= TYPE_SIMPLE_MAX)) {
                    writeSimpleTypeMethod(writer, structure, fieldDescriptor, type);
                } else {
                    String error = String.format("Unhandled structure type: %s->%s %s", structure.getPointerName(), fieldDescriptor.getName(), fieldDescriptor.getType());
                    System.out.println(error);
                }
                break;
        }
    }
}
Also used : FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 7 with FieldDescriptor

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

the class StructureStubGenerator method writeOffsetStubs.

private static void writeOffsetStubs(PrintWriter writer, StructureDescriptor structure) {
    List<FieldDescriptor> fields = structure.getFields();
    if (fields.isEmpty()) {
        return;
    }
    writer.println("\t// Offsets");
    writer.println();
    Collections.sort(fields);
    for (FieldDescriptor fieldDescriptor : fields) {
        if (PointerGenerator.getOffsetConstant(fieldDescriptor).equals(fieldDescriptor.getName())) {
            writeOffsetStub(writer, fieldDescriptor, structure.getName(), "Offset");
        }
    }
}
Also used : FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 8 with FieldDescriptor

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

the class StructureStubGenerator method writeOffsetInitializer.

private static void writeOffsetInitializer(PrintWriter writer, StructureDescriptor structure) {
    Collections.sort(structure.getFields());
    for (FieldDescriptor fieldDescriptor : structure.getFields()) {
        if (PointerGenerator.getOffsetConstant(fieldDescriptor).equals(fieldDescriptor.getName())) {
            String fieldName = fieldDescriptor.getName();
            CTypeParser parser = new CTypeParser(fieldDescriptor.getType());
            if (parser.getSuffix().contains(":")) {
                String bitfieldName = fieldName;
                writer.format("\t\t_%s_s_ = 0;%n", bitfieldName);
                writer.format("\t\t_%s_b_ = 0;%n", bitfieldName);
            } else {
                writer.format("\t\t_%sOffset_ = 0;%n", fieldName);
            }
        }
    }
}
Also used : CTypeParser(com.ibm.j9ddr.CTypeParser) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 9 with FieldDescriptor

use of com.ibm.j9ddr.StructureReader.FieldDescriptor 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 10 with FieldDescriptor

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

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