Search in sources :

Example 1 with FieldDescriptor

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

the class BytecodeGenerator method getClassBytes.

public static byte[] getClassBytes(StructureDescriptor structure, String fullClassName) throws ClassNotFoundException {
    // The className we are trying to load is FooOffsets.
    // The structure name stored in the reader is Foo
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;
    FieldVisitor fv;
    int bitFieldBitCount = 0;
    // Class definition
    cw.visit(V1_5, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, fullClassName, null, "java/lang/Object", null);
    // Constants
    // SIZEOF
    fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "SIZEOF", "J", null, Long.valueOf(structure.getSizeOf()));
    // Declared Constants
    for (ConstantDescriptor constantDescriptor : structure.getConstants()) {
        fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, constantDescriptor.getName(), "J", null, Long.valueOf(constantDescriptor.getValue()));
        fv.visitEnd();
    }
    // Offset Fields
    for (FieldDescriptor field : structure.getFields()) {
        String fieldName = field.getName();
        String type = field.getType();
        // make sure match a bit-field, not a C++ namespace
        int colonIndex = type.replace("::", "__").indexOf(':');
        if (colonIndex != -1) {
            // Bitfield
            String getter = fieldName;
            int bitSize = Integer.parseInt(type.substring(colonIndex + 1).trim());
            if (bitSize > (StructureReader.BIT_FIELD_CELL_SIZE - (bitFieldBitCount % StructureReader.BIT_FIELD_CELL_SIZE))) {
                throw new InternalError(String.format("Bitfield %s->%s must not span cells", structure.getName(), type));
            }
            // s field
            String name = String.format("_%s_s_", getter);
            fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, name, "I", null, Integer.valueOf(bitFieldBitCount));
            fv.visitEnd();
            // b field
            name = String.format("_%s_b_", getter);
            fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, name, "I", null, new Integer(bitSize));
            fv.visitEnd();
            bitFieldBitCount += bitSize;
        } else {
            // Regular field
            String name = String.format("_%sOffset_", fieldName);
            // Offset fields
            fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, name, "I", null, Integer.valueOf(field.getOffset()));
            fv.visitEnd();
        }
    }
    mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(RETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : ConstantDescriptor(com.ibm.j9ddr.StructureReader.ConstantDescriptor) FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor) ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter) MethodVisitor(jdk.internal.org.objectweb.asm.MethodVisitor) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 2 with FieldDescriptor

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

the class DDRSymbolFinder method getVoidPointerFieldsFromStructure.

private static List<String> getVoidPointerFieldsFromStructure(StructureReader reader, String structureName) throws MemoryFault {
    List<String> functionPointers = new LinkedList<String>();
    for (FieldDescriptor f : reader.getFields(structureName)) {
        String name = f.getDeclaredName();
        String type = f.getDeclaredType();
        if ("void *".equals(type)) {
            functionPointers.add(name);
        }
    }
    return functionPointers;
}
Also used : LinkedList(java.util.LinkedList) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 3 with FieldDescriptor

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

the class Declaration method writeOut.

public void writeOut(String typeName, String fieldPrefix, PrintWriter out, PrintWriter ssout) {
    if (name == null || name.length() == 0) {
        return;
    }
    // Treat bitfields differently
    String typeString = getTypeString();
    String declaredName = fieldPrefix + name;
    // superset is in java format so replace . with $
    String fieldname = (fieldPrefix + name).replace(".", "$");
    FieldDescriptor field = new FieldDescriptor(0, typeString, typeString, fieldname, declaredName);
    field.cleanUpTypes();
    field.applyAliases(aliasmap);
    if (typeString.contains(":") && !typeString.contains("::")) {
        out.println("\tJ9DDRBitFieldTableEntry(\"" + fieldPrefix + name + "\"," + typeString + ")");
        ssout.println(field.deflate());
    } else {
        if (type instanceof UserDefinedType && type.isAnonymous()) {
            ((UserDefinedType) type).writeFieldEntries(typeName, fieldPrefix + name + ".", out, ssout);
        } else {
            out.println("\tJ9DDRFieldTableEntry(" + typeName + "," + fieldPrefix + name + "," + typeString + ")");
            if (!field.getDeclaredName().startsWith("_j9padding")) {
                if (name.equals("utf8.data")) {
                    System.out.println("Def");
                }
                // don't include padding fields
                ssout.println(field.deflate());
            }
        }
    }
}
Also used : FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 4 with FieldDescriptor

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

the class CommandUtils method followPointerFromStructure.

public static long followPointerFromStructure(Context context, String structureName, long structureAddress, String fieldName) throws MemoryFault, DDRInteractiveCommandException {
    if (structureAddress == 0) {
        throw new DDRInteractiveCommandException(new NullPointerException("Null " + structureName + " found."));
    }
    StructureDescriptor desc = StructureCommandUtil.getStructureDescriptor(structureName, context);
    for (FieldDescriptor f : desc.getFields()) {
        if (f.getDeclaredName().equals(fieldName)) {
            long offset = f.getOffset();
            long pointerAddress = structureAddress + offset;
            long pointer = context.process.getPointerAt(pointerAddress);
            return pointer;
        }
    }
    return 0;
}
Also used : StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 5 with FieldDescriptor

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

the class DDRSymbolFinder method followPointerFromStructure.

private static long followPointerFromStructure(String structureName, long structureAddress, String fieldName, StructureReader reader, IProcess process) throws MemoryFault, NullPointerException {
    if (structureAddress == 0) {
        throw new NullPointerException("Null " + structureName + " found.");
    }
    for (FieldDescriptor f : reader.getFields(structureName)) {
        if (f.getDeclaredName().equals(fieldName)) {
            long offset = f.getOffset();
            long pointerAddress = structureAddress + offset;
            long pointer = process.getPointerAt(pointerAddress);
            return pointer;
        }
    }
    return 0;
}
Also used : 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