Example usage for org.objectweb.asm Opcodes PUTFIELD

List of usage examples for org.objectweb.asm Opcodes PUTFIELD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes PUTFIELD.

Prototype

int PUTFIELD

To view the source code for org.objectweb.asm Opcodes PUTFIELD.

Click Source Link

Usage

From source file:com.google.code.jconts.instrument.gen.ContinuationClassGenerator.java

License:Apache License

private void generateExecute(ClassVisitor cv, boolean execute) {
    final String name = info.continuationClassName;
    final Type outerType = Type.getObjectType(info.owner);

    // Generate invoke(T result);
    String signature = null;//  ww w. jav a 2  s .c  o  m
    if (execute) {
        SignatureWriter sign = new SignatureWriter();
        sign.visitParameterType().visitTypeVariable("T");
        sign.visitReturnType().visitBaseType('V'); // void
        signature = sign.toString();
    }
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC,
            execute ? CONTINUATION_INVOKE_NAME : CONTINUATION_SET_EXCEPTION_NAME,
            execute ? CONTINUATION_INVOKE_DESC : CONTINUATION_SET_EXCEPTION_DESC, signature, null);
    mv.visitCode();
    Label start = new Label();
    Label end = new Label();
    mv.visitLabel(start);

    // Load outer this
    if (!info.isStatic()) {
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, name, "this$0", outerType.getDescriptor());
    }

    // state.result = result or state.exception = throwable
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, info.stateClassName, execute ? "result" : "exception",
            execute ? OBJECT_DESC : THROWABLE_DESC);

    // Load state field
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, name, "state", stateDesc);

    // Continue from this index or index+1 (for exception)
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, name, "index", "I");
    if (!execute) {
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitInsn(Opcodes.IADD);
    }

    mv.visitMethodInsn(info.isStatic() ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL, info.owner,
            info.name + "$async",
            Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { info.stateType, Type.INT_TYPE }));

    mv.visitInsn(Opcodes.RETURN);
    mv.visitLabel(end);

    mv.visitLocalVariable("this", 'L' + name + ';', signature, start, end, 0);
    if (!info.isStatic()) {
        mv.visitLocalVariable("this$0", outerType.getDescriptor(), null, start, end, 1);
    }
    mv.visitLocalVariable("result", OBJECT_DESC, "TT;", start, end, 1 + info.thisOffset);

    mv.visitMaxs(3 + info.thisOffset + (execute ? 0 : 1), 2 + info.thisOffset);
    mv.visitEnd();
}

From source file:com.google.code.jconts.instrument.gen.TramplineMethodGenerator.java

License:Apache License

public void accept(ClassVisitor cv) {
    MethodVisitor mv = cv.visitMethod(info.access, info.name, info.desc, info.signature, info.exceptions);
    mv.visitCode();/*from  ww  w.j  a  v a 2s. c o  m*/
    mv.visitTypeInsn(Opcodes.NEW, info.computationClassName);
    mv.visitInsn(Opcodes.DUP);

    // "this' for new Computation(this, state)
    if (!info.isStatic()) {
        mv.visitVarInsn(Opcodes.ALOAD, 0);
    }

    // new State()
    mv.visitTypeInsn(Opcodes.NEW, info.stateClassName);
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, info.stateClassName, CTOR_NAME, DEFAULT_CTOR_DESC);

    // state.varX = argX
    String[] names = info.entryLocalsVars;
    for (int i = 0; i < info.entryLocals.length; ++i) {
        mv.visitInsn(Opcodes.DUP);
        mv.visitVarInsn(info.entryLocals[i].getOpcode(Opcodes.ILOAD), i + info.thisOffset);
        mv.visitFieldInsn(Opcodes.PUTFIELD, info.stateClassName, names[i], info.entryLocals[i].getDescriptor());
    }

    // new Computation(this, state);
    String ctorDesc;
    if (info.isStatic()) {
        ctorDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { info.stateType });
    } else {
        ctorDesc = Type.getMethodDescriptor(Type.VOID_TYPE,
                new Type[] { Type.getObjectType(info.owner), info.stateType });
    }
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, info.computationClassName, CTOR_NAME, ctorDesc);

    mv.visitInsn(Opcodes.ARETURN);
    mv.visitMaxs(info.isStatic() ? 5 : 6,
            info.isStatic() ? info.entryLocals.length : info.entryLocals.length + 1);
    mv.visitEnd();
}

From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java

License:Open Source License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    switch (opcode) {
    case Opcodes.GETSTATIC:
        pushDescriptor(desc);/*from   w  w  w.jav  a2  s  .  c  o  m*/
        break;
    case Opcodes.PUTSTATIC:
        popDescriptor(desc);
        break;
    case Opcodes.GETFIELD:
        pop();
        pushDescriptor(desc);
        break;
    case Opcodes.PUTFIELD:
        popDescriptor(desc);
        pop();
        break;
    default:
        throw new RuntimeException(
                "Unhandled opcode " + opcode + ", owner=" + owner + ", name=" + name + ", desc" + desc);
    }
    super.visitFieldInsn(opcode, owner, name, desc);
}

From source file:com.google.devtools.build.wireless.testing.java.injector.WhiteBoxMethodAdapter.java

License:Apache License

/**
 * Tells if the given instruction is corresponding to 
 * {@link Opcodes#PUTFIELD}.//from  ww  w  .j a v  a2  s .  c o m
 * 
 * @param opcode The given instruction;
 * @return <code>true</code> if the given instruction is 
 *    {@link Opcodes#PUTFIELD}, <code>false</code> otherwise.
 */
private boolean isField(int opcode) {
    return opcode == Opcodes.PUTFIELD;
}

From source file:com.google.test.metric.asm.MethodVisitorBuilder.java

License:Apache License

public void visitFieldInsn(final int opcode, String owner, final String name, final String desc) {
    owner = namer.nameClass(owner);/*from  ww w .ja  v a2s . c  o  m*/
    switch (opcode) {
    case Opcodes.PUTSTATIC:
        recorder.add(new PutFieldRunnable(repository, owner, name, desc, true));
        break;
    case Opcodes.PUTFIELD:
        recorder.add(new PutFieldRunnable(repository, owner, name, desc, false));
        break;
    case Opcodes.GETSTATIC:
        recorder.add(new GetFieldRunnable(repository, owner, name, desc, true));
        break;
    case Opcodes.GETFIELD:
        recorder.add(new GetFieldRunnable(repository, owner, name, desc, false));
        break;
    }
}

From source file:com.googlecode.ddom.weaver.compound.CompoundClassGenerator.java

License:Apache License

@Override
public void visitEnd() {
    for (int i = 0; i < componentClasses.length; i++) {
        String componentClass = Util.classNameToInternalName(componentClasses[i]);
        FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE, "c" + i, "L" + componentClass + ";", null, null);
        if (fv != null) {
            fv.visitEnd();//from  w  ww.  j  a va2 s .co m
        }
    }
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    if (mv != null) {
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        for (int i = 0; i < componentClasses.length; i++) {
            String componentClass = Util.classNameToInternalName(componentClasses[i]);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitTypeInsn(Opcodes.NEW, componentClass);
            mv.visitInsn(Opcodes.DUP);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, componentClass, "<init>", "()V");
            mv.visitFieldInsn(Opcodes.PUTFIELD, className, "c" + i, "L" + componentClass + ";");
        }
        mv.visitInsn(Opcodes.RETURN);
        Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
        mv.visitMaxs(3, 1);
        mv.visitEnd();
    }
    cv.visitEnd();
}

From source file:com.googlecode.ddom.weaver.ext.ModelExtensionFactoryImplementation.java

License:Apache License

public void accept(ClassVisitor classVisitor) {
    // Note: the name chosen here must match what is expected in ExtensionFactoryLocator
    String name = Util.classNameToInternalName(implementationInfo.getFactoryInterface().getName() + "$$Impl");
    String factoryInterfaceName = Util
            .classNameToInternalName(implementationInfo.getFactoryInterface().getName());
    classVisitor.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, name, null, "java/lang/Object",
            new String[] { factoryInterfaceName });
    {/*w  w  w  .j av a  2  s .c  o m*/
        FieldVisitor fw = classVisitor.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC,
                "INSTANCE", "L" + factoryInterfaceName + ";", null, null);
        if (fw != null) {
            fw.visitEnd();
        }
    }
    {
        FieldVisitor fw = classVisitor.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "delegates",
                "Ljava/util/Map;", null, null);
        if (fw != null) {
            fw.visitEnd();
        }
    }
    {
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PRIVATE, "<init>", "()V", null, null);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            // Call constructor from superclass
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
            // Create delegates map
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
            mv.visitInsn(Opcodes.DUP);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V");
            mv.visitFieldInsn(Opcodes.PUTFIELD, name, "delegates", "Ljava/util/Map;");
            // Populate delegates map
            for (ModelExtensionInfo modelExtensionInfo : implementationInfo.getModelExtensions()) {
                for (ModelExtensionInterfaceInfo extensionInterface : modelExtensionInfo
                        .getExtensionInterfaces()) {
                    if (!extensionInterface.isAbstract()) {
                        // TODO: this is stupid; we should not recreate the info object here
                        ModelExtensionClassInfo modelExtensionClassInfo = new ModelExtensionClassInfo(
                                implementationInfo.getImplementation(), modelExtensionInfo.getRootInterface(),
                                extensionInterface);
                        String factoryDelegateImplName = Util.classNameToInternalName(
                                modelExtensionClassInfo.getFactoryDelegateImplementationClassName());
                        mv.visitVarInsn(Opcodes.ALOAD, 0);
                        mv.visitFieldInsn(Opcodes.GETFIELD, name, "delegates", "Ljava/util/Map;");
                        mv.visitLdcInsn(Type.getObjectType(Util.classNameToInternalName(
                                modelExtensionClassInfo.getExtensionInterface().getClassInfo().getName())));
                        mv.visitTypeInsn(Opcodes.NEW, factoryDelegateImplName);
                        mv.visitInsn(Opcodes.DUP);
                        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, factoryDelegateImplName, "<init>", "()V");
                        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
                        mv.visitInsn(Opcodes.POP);
                    }
                }
            }
            mv.visitInsn(Opcodes.RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "L" + name + ";", null, l0, l1, 0);
            mv.visitMaxs(4, 1);
            mv.visitEnd();
        }
    }
    String factoryDelegateInterfaceName = Util
            .classNameToInternalName(implementationInfo.getFactoryDelegateInterfaceName());
    String getDelegateDesc = "(Ljava/lang/Class;)L" + factoryDelegateInterfaceName + ";";
    {
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PRIVATE, "getDelegate", getDelegateDesc, null,
                null);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, name, "delegates", "Ljava/util/Map;");
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get",
                    "(Ljava/lang/Object;)Ljava/lang/Object;");
            mv.visitTypeInsn(Opcodes.CHECKCAST, factoryDelegateInterfaceName);
            mv.visitInsn(Opcodes.ARETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "L" + name + ";", null, l0, l1, 0);
            mv.visitLocalVariable("extensionInterface", "Ljava/lang/Class;", null, l0, l1, 1);
            mv.visitMaxs(2, 2);
            mv.visitEnd();
        }
    }
    String implementationName = Util.classNameToInternalName(implementationInfo.getImplementation().getName());
    for (ConstructorInfo constructor : implementationInfo.getConstructors()) {
        Type[] constructorArgumentTypes = constructor.getArgumentTypes();
        Type[] argumentTypes = new Type[constructorArgumentTypes.length + 1];
        argumentTypes[0] = Type.getObjectType("java/lang/Class");
        System.arraycopy(constructorArgumentTypes, 0, argumentTypes, 1, constructorArgumentTypes.length);
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_PUBLIC, "create",
                Type.getMethodDescriptor(Type.getObjectType(implementationName), argumentTypes), null, null);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            Label l1 = new Label();
            mv.visitJumpInsn(Opcodes.IFNONNULL, l1);
            mv.visitTypeInsn(Opcodes.NEW, implementationName);
            mv.visitInsn(Opcodes.DUP);
            for (int i = 0; i < constructorArgumentTypes.length; i++) {
                mv.visitVarInsn(constructorArgumentTypes[i].getOpcode(Opcodes.ILOAD), i + 2);
            }
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, implementationName, "<init>",
                    constructor.getDescriptor());
            mv.visitInsn(Opcodes.ARETURN);
            mv.visitLabel(l1);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, "getDelegate", getDelegateDesc);
            for (int i = 0; i < constructorArgumentTypes.length; i++) {
                mv.visitVarInsn(constructorArgumentTypes[i].getOpcode(Opcodes.ILOAD), i + 2);
            }
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, factoryDelegateInterfaceName, "create",
                    constructor.getFactoryDelegateMethodDescriptor());
            mv.visitInsn(Opcodes.ARETURN);
            Label l3 = new Label();
            mv.visitLabel(l3);
            mv.visitLocalVariable("this", "L" + name + ";", null, l0, l3, 0);
            mv.visitLocalVariable("extensionInterface", "Ljava/lang/Class;", null, l0, l3, 1);
            for (int i = 0; i < constructorArgumentTypes.length; i++) {
                mv.visitLocalVariable("arg" + i, constructorArgumentTypes[i].getDescriptor(), null, l0, l3,
                        i + 2);
            }
            mv.visitMaxs(argumentTypes.length + 1, argumentTypes.length + 1);
            mv.visitEnd();
        }
    }
    {
        MethodVisitor mv = classVisitor.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
        if (mv != null) {
            mv.visitCode();
            mv.visitTypeInsn(Opcodes.NEW, name);
            mv.visitInsn(Opcodes.DUP);
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, name, "<init>", "()V");
            mv.visitFieldInsn(Opcodes.PUTSTATIC, name, "INSTANCE", "L" + factoryInterfaceName + ";");
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(2, 0);
            mv.visitEnd();
        }
    }
    classVisitor.visitEnd();
}

From source file:com.googlecode.ddom.weaver.inject.InjectionAdapter.java

License:Apache License

@Override
public void visitEnd() {
    for (InjectableFieldInfo fieldInfo : injectionInfo.getInjectableFields()) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
                fieldInfo.getFactoryMethodName(), fieldInfo.getFactoryMethodDesc(), null, new String[0]);
        if (mv != null) {
            fieldInfo.getInjector().generateFactoryMethodCode(mv);
        }//  w w  w.  j  a  v a 2  s .  c o  m
    }
    if (injectionInfo.hasInjectableInstanceFields()) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PRIVATE, "inject$$instance", "()V", null, new String[0]);
        if (mv != null) {
            mv.visitCode();
            Label l0 = new Label();
            mv.visitLabel(l0);
            for (InjectableFieldInfo fieldInfo : injectionInfo.getInjectableFields()) {
                if (!fieldInfo.isStatic()) {
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, fieldInfo.getFactoryMethodName(),
                            fieldInfo.getFactoryMethodDesc());
                    mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldInfo.getFieldName(),
                            fieldInfo.getFieldDesc());
                }
            }
            mv.visitInsn(Opcodes.RETURN);
            Label l1 = new Label();
            mv.visitLabel(l1);
            mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
            mv.visitMaxs(2, 1);
            mv.visitEnd();
        }
    }
    if (injectionInfo.hasInjectableClassFields()) {
        MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
                hasClassInitializer ? "inject$$class" : "<clinit>", "()V", null, new String[0]);
        if (mv != null) {
            mv.visitCode();
            for (InjectableFieldInfo fieldInfo : injectionInfo.getInjectableFields()) {
                if (fieldInfo.isStatic()) {
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, fieldInfo.getFactoryMethodName(),
                            fieldInfo.getFactoryMethodDesc());
                    mv.visitFieldInsn(Opcodes.PUTSTATIC, className, fieldInfo.getFieldName(),
                            fieldInfo.getFieldDesc());
                }
            }
            mv.visitInsn(Opcodes.RETURN);
            mv.visitMaxs(1, 0);
            mv.visitEnd();
        }
    }
    super.visitEnd();
}

From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java

License:Open Source License

/**
 * generate init./*ww w.ja v  a  2 s .c o  m*/
 * <p>
 * This inits the class members and assigns class members, such as the ExecutionContext.
 * </p>
 * <p>
 * <code>
 * public ExecutionContext executionContext = new ExecutionContext();
 * </code>
 * </p>
 */
protected void generateInit(String className, ClassWriter classWriter) throws Exception {
    try {
        final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null,
                null);
        methodVisitor.visitCode();
        /*
         * call init()
         */
        final Label l0 = new Label();
        methodVisitor.visitLabel(l0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        /*
         * create a new execution context and assign it
         */
        final Label l1 = new Label();
        methodVisitor.visitLabel(l1);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitTypeInsn(Opcodes.NEW, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT);
        methodVisitor.visitInsn(Opcodes.DUP);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "<init>",
                "()V");
        methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, className, RTLHelper.EXECUTIONCONTEXT_NAME,
                RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
        /*
         * return
         */
        final Label l2 = new Label();
        methodVisitor.visitLabel(l2);
        methodVisitor.visitLineNumber(8, l2);
        methodVisitor.visitInsn(Opcodes.RETURN);
        /*
         * declare variables
         */
        final Label l3 = new Label();
        methodVisitor.visitLabel(l3);
        methodVisitor.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0);
        methodVisitor.visitMaxs(3, 1);
        methodVisitor.visitEnd();
    } catch (final Exception e) {
        throw new Exception("Exception in generateInit", e);
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java

License:Open Source License

/**
 * generate void main(String[])//from ww w. j  a v  a2 s . c  om
 * <p>
 * <code>
 * public static void main(String[] args) {
 *   ExampleProgram exampleProgram = new ExampleProgram();
 *  try {
 *       exampleProgram.inputStream = System.in;
 *       exampleProgram.outputStream = System.out;
 *       exampleProgram.program();
 *   } catch (Exception e) {
 *       e.printStackTrace();
 *    }
 *  }
 * </code>
 * </p>
 */
protected void generateMain(String classname, ClassWriter classWriter) throws Exception {
    try {
        /*
         * make method
         */
        final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
                "main", "([Ljava/lang/String;)V", null, null);
        methodVisitor.visitCode();
        final Label l0 = new Label();
        final Label l1 = new Label();
        final Label l2 = new Label();
        methodVisitor.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
        final Label l3 = new Label();
        methodVisitor.visitLabel(l3);
        /*
         * declare a local instance of the class in the void() main, store as variable 1.
         */
        methodVisitor.visitTypeInsn(Opcodes.NEW, classname);
        methodVisitor.visitInsn(Opcodes.DUP);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, classname, "<init>", "()V");
        methodVisitor.visitVarInsn(Opcodes.ASTORE, 1);
        /*
         * assign the input stream
         */
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "in", "Ljava/io/InputStream;");
        methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "inputStream", "Ljava/io/InputStream;");
        /*
         * assign the output stream
         */
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "outputStream", "Ljava/io/PrintStream;");
        /*
         * load the class instance from variable 1 and call "program"
         */
        methodVisitor.visitLabel(l0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classname, "program", "()V");
        methodVisitor.visitLabel(l1);
        final Label l4 = new Label();
        methodVisitor.visitJumpInsn(Opcodes.GOTO, l4);
        methodVisitor.visitLabel(l2);
        methodVisitor.visitFrame(Opcodes.F_FULL, 2, new Object[] { "[Ljava/lang/String;", classname }, 1,
                new Object[] { "java/lang/Exception" });
        methodVisitor.visitVarInsn(Opcodes.ASTORE, 2);
        final Label l5 = new Label();
        methodVisitor.visitLabel(l5);
        methodVisitor.visitLineNumber(21, l5);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 2);
        methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V");
        /*
         * return
         */
        methodVisitor.visitLabel(l4);
        methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        methodVisitor.visitInsn(Opcodes.RETURN);
        /*
         * declare the parameters
         */
        final Label l6 = new Label();
        methodVisitor.visitLabel(l6);
        methodVisitor.visitLocalVariable("args", "[Ljava/lang/String;", null, l3, l6, 0);
        methodVisitor.visitLocalVariable("exampleProgram", "L" + classname + ";", null, l0, l6, 1);
        methodVisitor.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l4, 2);
        /*
         * done
         */
        methodVisitor.visitMaxs(2, 3);
        methodVisitor.visitEnd();
    } catch (final Exception e) {
        throw new Exception("Exception in generateMain", e);
    }
}