Search in sources :

Example 1 with MethodVisitor

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

the class MethodNode method accept.

/**
     * Makes the given class visitor visit this method.
     *
     * @param cv
     *            a class visitor.
     */
public void accept(final ClassVisitor cv) {
    String[] exceptions = new String[this.exceptions.size()];
    this.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    if (mv != null) {
        accept(mv);
    }
}
Also used : MethodVisitor(jdk.internal.org.objectweb.asm.MethodVisitor)

Example 2 with MethodVisitor

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

the class StaticInitMerger method visitMethod.

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
    MethodVisitor mv;
    if ("<clinit>".equals(name)) {
        int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC;
        String n = prefix + counter++;
        mv = cv.visitMethod(a, n, desc, signature, exceptions);
        if (clinit == null) {
            clinit = cv.visitMethod(a, name, desc, null, null);
        }
        clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc, false);
    } else {
        mv = cv.visitMethod(access, name, desc, signature, exceptions);
    }
    return mv;
}
Also used : MethodVisitor(jdk.internal.org.objectweb.asm.MethodVisitor)

Example 3 with MethodVisitor

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

the class RemappingClassAdapter method visitMethod.

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    String newDesc = remapper.mapMethodDesc(desc);
    MethodVisitor mv = super.visitMethod(access, remapper.mapMethodName(className, name, desc), newDesc, remapper.mapSignature(signature, false), exceptions == null ? null : remapper.mapTypes(exceptions));
    return mv == null ? null : createRemappingMethodAdapter(access, newDesc, mv);
}
Also used : MethodVisitor(jdk.internal.org.objectweb.asm.MethodVisitor)

Example 4 with MethodVisitor

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

the class TraceClassVisitor method visitMethod.

@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
    Printer p = this.p.visitMethod(access, name, desc, signature, exceptions);
    MethodVisitor mv = cv == null ? null : cv.visitMethod(access, name, desc, signature, exceptions);
    return new TraceMethodVisitor(mv, p);
}
Also used : MethodVisitor(jdk.internal.org.objectweb.asm.MethodVisitor)

Example 5 with MethodVisitor

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

the class LambdaAsm method verifyASM.

static void verifyASM() throws Exception {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_8, ACC_PUBLIC, "X", null, "java/lang/Object", null);
    MethodVisitor mv = cw.visitMethod(ACC_STATIC, "foo", "()V", null, null);
    mv.visitMaxs(2, 1);
    mv.visitMethodInsn(INVOKESTATIC, "java/util/function/Function.class", "identity", "()Ljava/util/function/Function;", true);
    mv.visitInsn(RETURN);
    cw.visitEnd();
    byte[] carray = cw.toByteArray();
    // for debugging
    // write((new File("X.class")).toPath(), carray, CREATE, TRUNCATE_EXISTING);
    // verify using javap/classfile reader
    ClassFile cf = ClassFile.read(new ByteArrayInputStream(carray));
    int mcount = checkMethod(cf, "foo");
    if (mcount < 1) {
        throw new RuntimeException("unexpected method count, expected 1" + "but got " + mcount);
    }
}
Also used : ClassFile(com.sun.tools.classfile.ClassFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter) MethodVisitor(jdk.internal.org.objectweb.asm.MethodVisitor)

Aggregations

MethodVisitor (jdk.internal.org.objectweb.asm.MethodVisitor)5 ClassFile (com.sun.tools.classfile.ClassFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)1