Search in sources :

Example 1 with ClassWriter

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

the class LambdaStackTrace method generateMaker.

private static byte[] generateMaker() {
    // interface Maker {
    //   Object make();
    // }
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_7, ACC_INTERFACE | ACC_ABSTRACT, "Maker", null, "java/lang/Object", null);
    cw.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "make", "()Ljava/lang/Object;", null, null);
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter)

Example 2 with ClassWriter

use of jdk.internal.org.objectweb.asm.ClassWriter 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)

Example 3 with ClassWriter

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

the class LambdaStackTrace method generateStringMaker.

private static byte[] generateStringMaker() {
    // interface StringMaker extends Maker {
    //   String make();
    // }
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_7, ACC_INTERFACE | ACC_ABSTRACT, "StringMaker", null, "java/lang/Object", new String[] { "Maker" });
    cw.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "make", "()Ljava/lang/String;", null, null);
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter)

Aggregations

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