Example usage for org.objectweb.asm MethodVisitor visitMaxs

List of usage examples for org.objectweb.asm MethodVisitor visitMaxs

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitMaxs.

Prototype

public void visitMaxs(final int maxStack, final int maxLocals) 

Source Link

Document

Visits the maximum stack size and the maximum number of local variables of the method.

Usage

From source file:de.zib.sfs.instrument.ZipFileAdapter.java

License:BSD License

@Override
public void visitEnd() {
    if (!this.skip.contains(OperationCategory.ZIP)) {
        // public void close() {
        MethodVisitor closeMethodMV = this.cv.visitMethod(Opcodes.ACC_PUBLIC, "close",
                Type.getMethodDescriptor(Type.VOID_TYPE), null,
                new String[] { Type.getInternalName(IOException.class) });
        closeMethodMV.visitCode();// w  w  w.ja va  2 s .c  o m

        // ZipFileCallback.closeCallback(jzfile);
        closeMethodMV.visitVarInsn(Opcodes.ALOAD, 0);
        closeMethodMV.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(ZipFile.class), "jzfile",
                Type.getDescriptor(Long.TYPE));
        closeMethodMV.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ZipFileCallback.class),
                "closeCallback", Type.getMethodDescriptor(Type.VOID_TYPE, Type.LONG_TYPE), false);

        // methodPrefixclose();
        closeMethodMV.visitVarInsn(Opcodes.ALOAD, 0);
        closeMethodMV.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ZipFile.class),
                this.methodPrefix + "close", Type.getMethodDescriptor(Type.VOID_TYPE), false);

        // }
        closeMethodMV.visitInsn(Opcodes.RETURN);
        closeMethodMV.visitMaxs(0, 0);
        closeMethodMV.visitEnd();
    }

    this.cv.visitEnd();
}

From source file:dijkstra.gen.DijkstraCodeGenerator.java

License:Open Source License

public byte[] visit(ClassDeclarationNode classDecl) {
    // prolog/* w  w w.jav a  2 s.c om*/
    cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    programName = classDecl.getID().getName();
    fullPath = classPackage + "/" + classDecl.getID().getName();
    cw.visit(V1_8, ACC_PUBLIC + ACC_STATIC, fullPath, null, "java/lang/Object", null);
    cw.visitSource(classDecl.getID().getName() + ".java", null);

    FieldVisitor fv;
    List<Symbol> classSymbols = new ArrayList<Symbol>();
    classSymbols.addAll(SymbolTableManager.getInstance().getClassSymbolManager(programName)
            .getCurrentSymbolTable().getSymbols());
    for (ASTNode property : classDecl.getProperties()) {
        classSymbols.add(((PropertyNode) property).getID().symbol);
    }
    for (Symbol symbol : classSymbols) {
        String type;
        if (symbol.getType() == DijkstraType.ARRAY) {
            ArraySymbol as = (ArraySymbol) symbol;
            if (as.getArrayType() == DijkstraType.INT) {
                type = "[J";
            } else if (as.getArrayType() == DijkstraType.FLOAT) {
                type = "[D";
            } else {
                type = "[Z";
            }
        } else {
            if (symbol.getType() == DijkstraType.INT) {
                type = "J";
            } else if (symbol.getType() == DijkstraType.FLOAT) {
                type = "D";
            } else {
                type = "Z";
            }
        }
        fv = cw.visitField(ACC_PUBLIC, symbol.getId(), type, null, null);
        fv.visitEnd();
    }
    final StringBuilder sig = new StringBuilder();
    sig.append('(');
    for (Symbol property : ((ClassSymbol) classDecl.getID().symbol).getPropertySymbols()) {
        if (property.getType() == DijkstraType.INT) {
            sig.append('J');
        } else if (property.getType() == DijkstraType.FLOAT) {
            sig.append('D');
        } else {
            sig.append('Z');
        }
    }
    sig.append(")V");
    mvStack.push(cw.visitMethod(ACC_PUBLIC, "<init>", sig.toString(), null, null));
    MethodVisitor mv = mvStack.peek();
    mv.visitCode();
    final Label startLabel = new Label();
    mv.visitLabel(startLabel);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);

    int localAddr = 1;
    for (Symbol param : ((ClassSymbol) classDecl.getID().symbol).getPropertySymbols()) {
        mv.visitVarInsn(ALOAD, 0);
        if (param.getType() == DijkstraType.INT) {
            mv.visitVarInsn(LLOAD, localAddr);
            mv.visitFieldInsn(PUTFIELD, fullPath, param.getId(), "J");
            localAddr += 2;
        } else if (param.getType() == DijkstraType.FLOAT) {
            mv.visitVarInsn(DLOAD, localAddr);
            mv.visitFieldInsn(PUTFIELD, fullPath, param.getId(), "D");
            localAddr += 2;
        } else {
            mv.visitVarInsn(ILOAD, localAddr);
            mv.visitFieldInsn(PUTFIELD, fullPath, param.getId(), "Z");
            localAddr += 1;
        }
    }

    processingClassFields = true;
    inClass = true;
    for (ASTNode body : classDecl.getDeclarations()) {
        body.accept(this);
    }
    inClass = false;
    processingClassFields = false;

    mv.visitInsn(RETURN);
    final Label endLabel = new Label();
    mv.visitLabel(endLabel);
    mv.visitLocalVariable("this", "L" + fullPath + ";", null, startLabel, endLabel, 0);
    int paramLoc = 1;
    for (Symbol param : ((ClassSymbol) classDecl.getID().symbol).getPropertySymbols()) {
        if (param.getType() == DijkstraType.INT) {
            mv.visitLocalVariable(param.getId(), "J", null, startLabel, endLabel, paramLoc);
            paramLoc += 2;
        } else if (param.getType() == DijkstraType.FLOAT) {
            mv.visitLocalVariable(param.getId(), "D", null, startLabel, endLabel, paramLoc);
            paramLoc += 2;
        } else {
            mv.visitLocalVariable(param.getId(), "Z", null, startLabel, endLabel, paramLoc);
            paramLoc += 1;
        }
    }
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    mvStack.pop();

    inClass = true;
    for (ASTNode body : classDecl.getDeclarations()) {
        body.accept(this);
    }
    inClass = false;

    // Actual end of generation
    cw.visitEnd();
    return cw.toByteArray();
}

From source file:dijkstra.gen.DijkstraCodeGenerator.java

License:Open Source License

/**
 * Generate the program prolog, then visit the children, then generate
 * the program end.//  w  w w .j  a  v a 2s .c om
 * @see dijkstra.ast.ASTVisitor#visit(dijkstra.ast.ASTNodeFactory.ProgramNode)
 */
public byte[] visit(ProgramNode program) {
    // prolog
    cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    programName = program.programName;
    fullPath = classPackage + "/" + program.programName;
    cw.visit(V1_8, ACC_PUBLIC + ACC_STATIC, fullPath, null, "java/lang/Object", null);
    cw.visitSource(program.programName + ".java", null);

    FieldVisitor fv;
    for (Symbol symbol : SymbolTableManager.getInstance().getCurrentSymbolTable().getSymbols()) {
        String type;
        if (symbol.getType() == DijkstraType.ARRAY) {
            ArraySymbol as = (ArraySymbol) symbol;
            if (as.getArrayType() == DijkstraType.INT) {
                type = "[J";
            } else if (as.getArrayType() == DijkstraType.FLOAT) {
                type = "[D";
            } else if (as.getArrayType() == DijkstraType.BOOLEAN) {
                type = "[Z";
            } else {
                type = "L" + classPackage + "/" + ((ObjectSymbol) symbol).getObjectType() + ";";
            }
        } else {
            if (symbol.getType() == DijkstraType.INT) {
                type = "J";
            } else if (symbol.getType() == DijkstraType.FLOAT) {
                type = "D";
            } else if (symbol.getType() == DijkstraType.BOOLEAN) {
                type = "Z";
            } else {
                type = "L" + classPackage + "/" + ((ObjectSymbol) symbol).getObjectType() + ";";
            }
        }
        fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, symbol.getId(), type, null, null);
        fv.visitEnd();
    }
    mvStack.push(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
    MethodVisitor mv = mvStack.peek();
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    mvStack.pop();
    // Start the main() method
    mvStack.push(cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null));
    mv = mvStack.peek();
    mv.visitCode();

    visitChildren(program);

    // program end
    //  End of main
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    // Actual end of generation
    cw.visitEnd();
    return cw.toByteArray();
}

From source file:dijkstra.gen.DijkstraCodeGenerator.java

License:Open Source License

public byte[] visit(ProcedureDeclarationNode procDeclNode) {
    if (processingClassFields) {
        return null;
    }//from  w w w .j  a  va 2s  . co  m
    final String methodName = procDeclNode.getIDNode().getName();
    final StringBuilder sig = new StringBuilder();
    sig.append('(');
    for (IDNode param : procDeclNode.getParamList()) {
        if (param.getType() == DijkstraType.INT) {
            sig.append('J');
        } else if (param.getType() == DijkstraType.FLOAT) {
            sig.append('D');
        } else {
            sig.append('Z');
        }
    }
    sig.append(")V");
    if (inClass) {
        mvStack.push(cw.visitMethod(ACC_PUBLIC, methodName, sig.toString(), null, null));
    } else {
        mvStack.push(cw.visitMethod(ACC_PUBLIC + ACC_STATIC, methodName, sig.toString(), null, null));
    }
    final MethodVisitor mv = mvStack.peek();

    JVMInfo.enterScope(inClass);
    // Load the parameters into the JVMInfo so it knows the proper addresses
    for (IDNode param : procDeclNode.getParamList()) {
        param.getAddress();
    }
    mv.visitCode();
    final Label startLabel = new Label();
    mv.visitLabel(startLabel);

    procDeclNode.getCompoundNode().accept(this);

    mv.visitInsn(RETURN);
    final Label endLabel = new Label();
    mv.visitLabel(endLabel);
    int paramLoc = 0;
    for (IDNode param : procDeclNode.getParamList()) {
        if (param.getType() == DijkstraType.INT) {
            mv.visitLocalVariable(param.getName(), "J", null, startLabel, endLabel, paramLoc);
            paramLoc += 2;
        } else if (param.getType() == DijkstraType.FLOAT) {
            mv.visitLocalVariable(param.getName(), "D", null, startLabel, endLabel, paramLoc);
            paramLoc += 2;
        } else {
            mv.visitLocalVariable(param.getName(), "Z", null, startLabel, endLabel, paramLoc);
            paramLoc += 1;
        }
    }
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    JVMInfo.exitScope();
    mvStack.pop();
    return null;
}

From source file:dijkstra.gen.DijkstraCodeGenerator.java

License:Open Source License

public byte[] visit(FunctionDeclarationNode funDeclNode) {
    if (processingClassFields) {
        return null;
    }/*w w  w .ja  v a2  s  .  c  o  m*/
    final String methodName = funDeclNode.getIDNode().getName();
    final StringBuilder sig = new StringBuilder();
    sig.append('(');
    for (IDNode param : funDeclNode.getParamList()) {
        if (param.getType() == DijkstraType.INT) {
            sig.append('J');
        } else if (param.getType() == DijkstraType.FLOAT) {
            sig.append('D');
        } else {
            sig.append('Z');
        }
    }
    sig.append(')');
    sig.append("[Ljava/lang/Object;");

    if (inClass) {
        mvStack.push(cw.visitMethod(ACC_PUBLIC, methodName, sig.toString(), null, null));
    } else {
        mvStack.push(cw.visitMethod(ACC_PUBLIC + ACC_STATIC, methodName, sig.toString(), null, null));
    }
    final MethodVisitor mv = mvStack.peek();

    JVMInfo.enterScope(inClass);
    // Load the parameters into the JVMInfo so it knows the proper addresses
    for (IDNode param : funDeclNode.getParamList()) {
        param.getAddress();
    }

    mv.visitIntInsn(SIPUSH, funDeclNode.getReturnTypes().size());
    mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
    returnArrayStack.push(new ArraySymbol(null, UNDEFINED));
    mv.visitVarInsn(ASTORE, JVMInfo.getAddressForSymbol(returnArrayStack.peek()));

    mv.visitInsn(ICONST_0);
    returnIndexStack.push(new Symbol(null, UNDEFINED));
    mv.visitVarInsn(ISTORE, JVMInfo.getAddressForSymbol(returnIndexStack.peek()));

    mv.visitCode();
    final Label startLabel = new Label();
    mv.visitLabel(startLabel);

    funDeclNode.getCompoundNode().accept(this);

    returnIndexStack.pop();
    mv.visitVarInsn(ALOAD, JVMInfo.getAddressForSymbol(returnArrayStack.pop()));
    mv.visitInsn(ARETURN);
    final Label endLabel = new Label();
    mv.visitLabel(endLabel);
    int paramLoc = 0;
    for (IDNode param : funDeclNode.getParamList()) {
        if (param.getType() == DijkstraType.INT) {
            mv.visitLocalVariable(param.getName(), "J", null, startLabel, endLabel, paramLoc);
            paramLoc += 2;
        } else if (param.getType() == DijkstraType.FLOAT) {
            mv.visitLocalVariable(param.getName(), "D", null, startLabel, endLabel, paramLoc);
            paramLoc += 2;
        } else {
            mv.visitLocalVariable(param.getName(), "Z", null, startLabel, endLabel, paramLoc);
            paramLoc += 1;
        }
    }
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    JVMInfo.exitScope();
    mvStack.pop();
    return null;
}

From source file:dodola.anole.lib.InstantRunTransform.java

License:Apache License

/**
 * Use asm to generate a concrete subclass of the AppPathLoaderImpl class.
 * It only implements one method :/*ww  w  .ja va 2s.  co m*/
 * String[] getPatchedClasses();
 * <p>
 * The method is supposed to return the list of classes that were patched in this iteration.
 * This will be used by the InstantRun runtime to load all patched classes and register them
 * as overrides on the original classes.2 class files.
 *
 * @param patchFileContents list of patched class names.
 * @param outputDir         output directory where to generate the .class file in.
 * @return the generated .class files
 */
public static File writePatchFileContents(List<String> patchFileContents, File outputDir) {

    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, IncrementalVisitor.APP_PATCHES_LOADER_IMPL,
            null, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, null);

    {
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, "<init>",
                "()V", false);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPatchedClasses", "()[Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitIntInsn(Opcodes.BIPUSH, patchFileContents.size());
        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String");
        for (int index = 0; index < patchFileContents.size(); index++) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitIntInsn(Opcodes.BIPUSH, index);
            mv.visitLdcInsn(patchFileContents.get(index));
            mv.visitInsn(Opcodes.AASTORE);
        }
        mv.visitInsn(Opcodes.ARETURN);
        mv.visitMaxs(4, 1);
        mv.visitEnd();
    }
    cw.visitEnd();

    byte[] classBytes = cw.toByteArray();
    File outputFile = new File(outputDir, IncrementalVisitor.APP_PATCHES_LOADER_IMPL + ".class");
    try {
        Files.createParentDirs(outputFile);
        Files.write(classBytes, outputFile);
        // add the files to the list of files to be processed by subsequent tasks.
        return outputFile;
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:edu.illinois.nondex.instr.HashMapShufflingAdder.java

License:Open Source License

public void addNextType() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "next" + type,
            "()Ljava/util/HashMap$" + type + ";", "()Ljava/util/HashMap$" + type + "<TK;TV;>;", null);

    mv.visitCode();// w  ww .  java2  s  .co m

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/HashMap$HashIterator", "shuffler",
            "Ljava/util/HashMap$HashIterator$HashIteratorShuffler;");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/HashMap$HashIterator", "this$0", "Ljava/util/HashMap;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/HashMap", "modCount", "I");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/HashMap$HashIterator$HashIteratorShuffler",
            "next" + type, "(I)Ljava/util/HashMap$" + type + ";", false);
    mv.visitInsn(Opcodes.ARETURN);

    mv.visitMaxs(2, 1);
    mv.visitEnd();
}

From source file:edu.illinois.nondex.instr.HashMapShufflingAdder.java

License:Open Source License

public void addHasNext() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, "hasNext", "()Z", null, null);

    mv.visitCode();//from  www  . j a  v  a2  s  . com

    mv.visitVarInsn(Opcodes.ALOAD, 0);

    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/HashMap$HashIterator", "shuffler",
            "Ljava/util/HashMap$HashIterator$HashIteratorShuffler;");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/HashMap$HashIterator$HashIteratorShuffler", "hasNext",
            "()Z", false);

    mv.visitInsn(Opcodes.IRETURN);

    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:edu.illinois.nondex.instr.IdentityHashMapShufflingAdder.java

License:Open Source License

public void addNextIndex() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PROTECTED, "nextIndex", "()I", null, null);
    mv.visitCode();/* ww w.  j  a  v  a2s. c om*/
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0",
            "Ljava/util/IdentityHashMap;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "modCount", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "expectedModCount",
            "I");
    Label l0 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l0);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/ConcurrentModificationException");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ConcurrentModificationException", "<init>", "()V",
            false);
    mv.visitInsn(Opcodes.ATHROW);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/IdentityHashMap$IdentityHashMapIterator", "hasNext",
            "()Z", false);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNE, l1);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/NoSuchElementException");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/NoSuchElementException", "<init>", "()V", false);
    mv.visitInsn(Opcodes.ATHROW);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "keys",
            "Ljava/util/List;");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.DUP);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I");
    mv.visitInsn(Opcodes.DUP_X1);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IADD);
    mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;", true);
    mv.visitVarInsn(Opcodes.ASTORE, 1);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitVarInsn(Opcodes.ISTORE, 2);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/lang/Object", Opcodes.INTEGER }, 0, null);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0",
            "Ljava/util/IdentityHashMap;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;");
    mv.visitInsn(Opcodes.ARRAYLENGTH);
    Label l3 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPGE, l3);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0",
            "Ljava/util/IdentityHashMap;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;");
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitInsn(Opcodes.AALOAD);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    Label l4 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ACMPNE, l4);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
            "lastReturnedIndex", "I");
    mv.visitJumpInsn(Opcodes.GOTO, l3);
    mv.visitLabel(l4);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitIincInsn(2, 2);
    mv.visitJumpInsn(Opcodes.GOTO, l2);
    mv.visitLabel(l3);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
            "lastReturnedIndex", "I");
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(5, 3);
    mv.visitEnd();
}

From source file:edu.illinois.nondex.instr.IdentityHashMapShufflingAdder.java

License:Open Source License

public void addHasNext() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hasNext", "()Z", null, null);
    mv.visitCode();/*from www .jav  a2 s  .  com*/
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "order",
            "Ljava/util/List;");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "size", "()I", true);
    Label l0 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPGE, l0);
    mv.visitInsn(Opcodes.ICONST_1);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l1);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(2, 1);
    mv.visitEnd();
}