Search in sources :

Example 1 with FieldVisitor

use of jdk.internal.org.objectweb.asm.FieldVisitor in project Bytecoder by mirkosertic.

the class CheckClassAdapter method visitField.

@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
    checkState();
    checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED + // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    0x40000);
    CheckMethodAdapter.checkUnqualifiedName(version, name, "field name");
    CheckMethodAdapter.checkDesc(desc, false);
    if (signature != null) {
        checkFieldSignature(signature);
    }
    if (value != null) {
        CheckMethodAdapter.checkConstant(value);
    }
    FieldVisitor av = super.visitField(access, name, desc, signature, value);
    return new CheckFieldAdapter(av);
}
Also used : FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor)

Example 2 with FieldVisitor

use of jdk.internal.org.objectweb.asm.FieldVisitor in project Bytecoder by mirkosertic.

the class FieldNode method accept.

/**
 * Makes the given class visitor visit this field.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
    if (fv == null) {
        return;
    }
    int i, n;
    n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = visibleAnnotations.get(i);
        an.accept(fv.visitAnnotation(an.desc, true));
    }
    n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = invisibleAnnotations.get(i);
        an.accept(fv.visitAnnotation(an.desc, false));
    }
    n = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
    for (i = 0; i < n; ++i) {
        TypeAnnotationNode an = visibleTypeAnnotations.get(i);
        an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true));
    }
    n = invisibleTypeAnnotations == null ? 0 : invisibleTypeAnnotations.size();
    for (i = 0; i < n; ++i) {
        TypeAnnotationNode an = invisibleTypeAnnotations.get(i);
        an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false));
    }
    n = attrs == null ? 0 : attrs.size();
    for (i = 0; i < n; ++i) {
        fv.visitAttribute(attrs.get(i));
    }
    fv.visitEnd();
}
Also used : FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor)

Example 3 with FieldVisitor

use of jdk.internal.org.objectweb.asm.FieldVisitor 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 4 with FieldVisitor

use of jdk.internal.org.objectweb.asm.FieldVisitor in project jdk8u_jdk by JetBrains.

the class TraceClassVisitor method visitField.

@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
    Printer p = this.p.visitField(access, name, desc, signature, value);
    FieldVisitor fv = cv == null ? null : cv.visitField(access, name, desc, signature, value);
    return new TraceFieldVisitor(fv, p);
}
Also used : FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor)

Example 5 with FieldVisitor

use of jdk.internal.org.objectweb.asm.FieldVisitor in project jdk8u_jdk by JetBrains.

the class CheckClassAdapter method visitField.

@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
    checkState();
    checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED + // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
    0x40000);
    CheckMethodAdapter.checkUnqualifiedName(version, name, "field name");
    CheckMethodAdapter.checkDesc(desc, false);
    if (signature != null) {
        checkFieldSignature(signature);
    }
    if (value != null) {
        CheckMethodAdapter.checkConstant(value);
    }
    FieldVisitor av = super.visitField(access, name, desc, signature, value);
    return new CheckFieldAdapter(av);
}
Also used : FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor)

Aggregations

FieldVisitor (jdk.internal.org.objectweb.asm.FieldVisitor)8 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)2 MethodVisitor (jdk.internal.org.objectweb.asm.MethodVisitor)2 ConstantDescriptor (com.ibm.j9ddr.StructureReader.ConstantDescriptor)1 FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)1 AnnotationVisitor (jdk.internal.org.objectweb.asm.AnnotationVisitor)1 ClassReader (jdk.internal.org.objectweb.asm.ClassReader)1 ClassVisitor (jdk.internal.org.objectweb.asm.ClassVisitor)1