Example usage for org.objectweb.asm Opcodes F_SAME1

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

Introduction

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

Prototype

int F_SAME1

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

Click Source Link

Document

A compressed frame with exactly the same locals as the previous frame and with a single value on the stack.

Usage

From source file:blockphysics.asm.BPTransformer.java

License:Open Source License

private byte[] transformChunk(byte[] bytes) {
    /*try/*from   w w  w . j  a v a 2 s  .c  om*/
     {
         FileOutputStream fos = new FileOutputStream("d:/Chunk.orig.class");
         fos.write(bytes);
       fos.close();
     } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }*/

    System.out.print("[BlockPhysics] Patching Chunk.class ...................");

    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getBlockBPdata", "(III)I", null, null);
    mv.visitCode();
    mv.visitVarInsn(ILOAD, 2);
    mv.visitInsn(ICONST_4);
    mv.visitInsn(ISHR);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adq", "r", "[Ladr;");
    mv.visitInsn(ARRAYLENGTH);
    Label l0 = new Label();
    mv.visitJumpInsn(IF_ICMPLT, l0);
    mv.visitInsn(ICONST_0);
    mv.visitInsn(IRETURN);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adq", "r", "[Ladr;");
    mv.visitVarInsn(ILOAD, 2);
    mv.visitInsn(ICONST_4);
    mv.visitInsn(ISHR);
    mv.visitInsn(AALOAD);
    mv.visitVarInsn(ASTORE, 4);
    mv.visitVarInsn(ALOAD, 4);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNULL, l1);
    mv.visitVarInsn(ALOAD, 4);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(BIPUSH, 15);
    mv.visitInsn(IAND);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitMethodInsn(INVOKEVIRTUAL, "adr", "getBlockBPdata", "(III)I");
    Label l2 = new Label();
    mv.visitJumpInsn(GOTO, l2);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "adr" }, 0, null);
    mv.visitInsn(ICONST_0);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
    mv.visitInsn(IRETURN);
    mv.visitMaxs(4, 5);
    mv.visitEnd();

    mv = cw.visitMethod(ACC_PUBLIC, "setBlockBPdata", "(IIII)Z", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "adq", "r", "[Ladr;");
    mv.visitVarInsn(ILOAD, 2);
    mv.visitInsn(ICONST_4);
    mv.visitInsn(ISHR);
    mv.visitInsn(AALOAD);
    mv.visitVarInsn(ASTORE, 5);
    mv.visitVarInsn(ALOAD, 5);
    Label lab0 = new Label();
    mv.visitJumpInsn(IFNONNULL, lab0);
    mv.visitInsn(ICONST_0);
    mv.visitInsn(IRETURN);
    mv.visitLabel(lab0);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "adr" }, 0, null);
    mv.visitVarInsn(ALOAD, 5);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(BIPUSH, 15);
    mv.visitInsn(IAND);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitMethodInsn(INVOKEVIRTUAL, "adr", "getBlockBPdata", "(III)I");
    mv.visitVarInsn(ISTORE, 6);
    mv.visitVarInsn(ILOAD, 6);
    mv.visitVarInsn(ILOAD, 4);
    Label lab1 = new Label();
    mv.visitJumpInsn(IF_ICMPNE, lab1);
    mv.visitInsn(ICONST_0);
    mv.visitInsn(IRETURN);
    mv.visitLabel(lab1);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { Opcodes.INTEGER }, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitInsn(ICONST_1);
    mv.visitFieldInsn(PUTFIELD, "adq", "l", "Z");
    mv.visitVarInsn(ALOAD, 5);
    mv.visitVarInsn(ILOAD, 1);
    mv.visitVarInsn(ILOAD, 2);
    mv.visitIntInsn(BIPUSH, 15);
    mv.visitInsn(IAND);
    mv.visitVarInsn(ILOAD, 3);
    mv.visitVarInsn(ILOAD, 4);
    mv.visitMethodInsn(INVOKEVIRTUAL, "adr", "setBlockBPdata", "(IIII)V");
    mv.visitInsn(ICONST_1);
    mv.visitInsn(IRETURN);
    mv.visitMaxs(5, 7);
    mv.visitEnd();

    cw.visitEnd();

    System.out.println("OK");

    /*try
    {
       FileOutputStream fos = new FileOutputStream("d:/Chunk.mod.class");
       fos.write(cw.toByteArray());
     fos.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }*/

    return cw.toByteArray();
}

From source file:ch.sourcepond.utils.podescoin.internal.method.ReadObjectEnhancer.java

License:Apache License

protected void catchBlock() {
    visitJumpInsn(GOTO, l5);/*  w w  w  . j av  a  2 s. c  om*/
    visitLabel(l2);
    visitFrame(
            Opcodes.F_FULL, 3, new Object[] { inspector.getInternalClassName(),
                    OBJECT_INPUT_STREAM_INTERNAL_NAME, CONTAINER_INTERNAL_NAME },
            1, new Object[] { EXCEPTION_INTERNAL_NAME });

    visitVarInsn(ASTORE, 3);
    visitVarInsn(ALOAD, 3);
    visitInsn(ATHROW);
    visitLabel(l3);
    visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { IO_EXCEPTION_INTERNAL_NAME });
    visitVarInsn(ASTORE, 3);
    visitVarInsn(ALOAD, 3);
    visitInsn(ATHROW);
    visitLabel(l4);
    visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { EXCEPTION_INTERNAL_NAME });
    visitVarInsn(ASTORE, 3);
    visitTypeInsn(NEW, IO_EXCEPTION_INTERNAL_NAME);
    visitInsn(DUP);
    visitVarInsn(ALOAD, 3);
    visitMethodInsn(INVOKEVIRTUAL, EXCEPTION_INTERNAL_NAME, GET_MESSAGE_NAME, GET_MESSAGE_DESC, false);
    visitVarInsn(ALOAD, 3);
    visitMethodInsn(INVOKESPECIAL, IO_EXCEPTION_INTERNAL_NAME, CONSTRUCTOR_NAME, CONSTRUCTOR_DESC, false);
    visitInsn(ATHROW);
    visitLabel(l5);
}

From source file:ch.sourcepond.utils.podescoin.internal.method.WriteObjectEnhancer.java

License:Apache License

@Override
protected void catchBlock() {
    visitJumpInsn(GOTO, l4);/*ww w .  j a  va 2 s. c  om*/
    visitLabel(l2);
    visitFrame(
            Opcodes.F_FULL, 3, new Object[] { inspector.getInternalClassName(),
                    OBJECT_OUTPUT_STREAM_INTERNAL_NAME, CONTAINER_INTERNAL_NAME },
            1, new Object[] { IO_EXCEPTION_INTERNAL_NAME });
    visitVarInsn(ASTORE, 3);
    visitVarInsn(ALOAD, 3);
    visitInsn(ATHROW);
    visitLabel(l3);
    visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { EXCEPTION_INTERNAL_NAME });
    visitVarInsn(ASTORE, 3);
    visitTypeInsn(NEW, IO_EXCEPTION_INTERNAL_NAME);
    visitInsn(DUP);
    visitVarInsn(ALOAD, 3);
    visitMethodInsn(INVOKEVIRTUAL, EXCEPTION_INTERNAL_NAME, GET_MESSAGE_NAME, GET_MESSAGE_DESC, false);
    visitVarInsn(ALOAD, 3);
    visitMethodInsn(INVOKESPECIAL, IO_EXCEPTION_INTERNAL_NAME, CONSTRUCTOR_NAME, CONSTRUCTOR_DESC, false);
    visitInsn(ATHROW);
    visitLabel(l4);
}

From source file:com.centimia.orm.jaqu.ext.asm.JaquClassAdapter.java

License:Open Source License

/**
 * Generates the new method body, copy the old to a new method and connect them.
 * /*  ww w  .j  av  a2  s.  c  o  m*/
 * the structure of the new method is:<br>
 * <br><b><div style="background:lightgray">
 * <pre>
 * public [CollectionType] [getterName]() {
 *    if ([fieldName] == null){
 *       try {
 *          if (null == db || db.isClosed())
 *             throw new RuntimeException("Cannot initialize a 'Relation' outside an open session!!!. Try initializing the field directly within the class.");
 *          Method method = db.getClass().getDeclaredMethod("getRelationFromDb", String.class, Object.class, Class.class);
 *          method.setAccessible(true);
 *          children = (Collection<TestTable>)method.invoke(db, [fieldName], this, TestTable.class);
 *          method.setAccessible(false);
 *       }
 *       catch (Exception e) {
 *          if (e instanceof RuntimeException)
 *             throw (RuntimeException)e;
 *          throw new RuntimeException(e.getMessage(), e);
 *       }
 *    }
 * return $orig_[getterName]();
 * }
 * </pre>
 * </div>
 * 
 * @param access
 * @param desc
 * @param signature
 * @param exceptions
 * @param name
 * @param newName
 * @param fieldName
 */
private void generateNewMethodBody(int access, String desc, String signature, String[] exceptions, String name,
        String newName, String fieldName) {
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
    String fieldSignature = signature.substring(signature.indexOf(')') + 1, signature.lastIndexOf('<')) + ";";
    String type = signature.substring(signature.indexOf('<') + 1, signature.indexOf('>'));
    String cast = desc.substring(desc.indexOf("java/"), desc.indexOf(';'));

    mv.visitCode();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, fieldName, fieldSignature);
    Label l3 = new Label();
    mv.visitJumpInsn(IFNONNULL, l3);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    Label l4 = new Label();
    mv.visitJumpInsn(IFNULL, l4);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/Db", "isClosed", "()Z", false);
    Label l5 = new Label();
    mv.visitJumpInsn(IFEQ, l5);
    mv.visitLabel(l4);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(
            "Cannot initialize a 'Relation' outside an open session!!!. Try initializing the field directly within the class.");
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l5);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    mv.visitLdcInsn("getRelationFromDb");
    mv.visitInsn(ICONST_3);
    mv.visitTypeInsn(ANEWARRAY, "java/lang/Class");
    mv.visitInsn(DUP);
    mv.visitInsn(ICONST_0);
    mv.visitLdcInsn(Type.getType("Ljava/lang/String;"));
    mv.visitInsn(AASTORE);
    mv.visitInsn(DUP);
    mv.visitInsn(ICONST_1);
    mv.visitLdcInsn(Type.getType("Ljava/lang/Object;"));
    mv.visitInsn(AASTORE);
    mv.visitInsn(DUP);
    mv.visitInsn(ICONST_2);
    mv.visitLdcInsn(Type.getType("Ljava/lang/Class;"));
    mv.visitInsn(AASTORE);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredMethod",
            "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false);
    mv.visitVarInsn(ASTORE, 1);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(ICONST_1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "setAccessible", "(Z)V", false);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    mv.visitInsn(ICONST_3);
    mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
    mv.visitInsn(DUP);
    mv.visitInsn(ICONST_0);
    mv.visitLdcInsn(fieldName);
    mv.visitInsn(AASTORE);
    mv.visitInsn(DUP);
    mv.visitInsn(ICONST_1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitInsn(AASTORE);
    mv.visitInsn(DUP);
    mv.visitInsn(ICONST_2);
    mv.visitLdcInsn(Type.getType(type));
    mv.visitInsn(AASTORE);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "invoke",
            "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false);
    mv.visitTypeInsn(CHECKCAST, cast);
    mv.visitFieldInsn(PUTFIELD, className, fieldName, fieldSignature);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(ICONST_0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "setAccessible", "(Z)V", false);
    mv.visitLabel(l1);
    mv.visitJumpInsn(GOTO, l3);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" });
    mv.visitVarInsn(ASTORE, 1);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(INSTANCEOF, "java/lang/RuntimeException");
    Label l6 = new Label();
    mv.visitJumpInsn(IFEQ, l6);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(CHECKCAST, "java/lang/RuntimeException");
    mv.visitInsn(ATHROW);
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/Exception" }, 0, null);
    mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "getMessage", "()Ljava/lang/String;", false);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
            "(Ljava/lang/String;Ljava/lang/Throwable;)V", false);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l3);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, className, newName, desc, false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(7, 2);
    mv.visitEnd();
}

From source file:com.centimia.orm.jaqu.ext.asm.JaquClassAdapter.java

License:Open Source License

/**
 * Generates the new method body, copy the old to a new method and connect them.
 * the structure of the new method is:<br>
 * <br><b><div style="background:lightgray">
 * <pre>/*  w ww .j a  v a  2  s .  co m*/
 * public [entityType] [getterName]() {
 *   if ([field] == null) {
 *      try {
 *         if (null == db)
 *            throw new RuntimeException("Cannot initialize 'Relation' outside an open session!!!. Try initializing field directly within the class.");
 *         
 *         [parentType] parent = this.getClass().newInstance();
 *         [entityType] desc = TestB.class.newInstance();
 *         
 *         // get the primary key
 *         Object pk = db.getPrimaryKey(this);
 *         
 *         // get the object
 *         [entityValue] = db.from(desc).innerJoin(parent).on(parent.[entityValue]).is(desc).where(db.getPrimaryKey(parent)).is(pk).selectFirst();
 *      }
 *      catch (Exception e) {
 *         if (e instanceof RuntimeException)
 *            throw (RuntimeException)e;
 *         throw new RuntimeException(e.getMessage(), e);
 *      }
 *   }
 *   return $orig_[getterName]();
 *  }
 * </pre>
 * </div>
 * 
 * @param access
 * @param desc
 * @param exceptions
 * @param name - current method name
 * @param newName - new method name (the orig...)
 * @param fieldName
 */
public void generateLazyRelation(int access, String desc, String[] exceptions, String name, String newName,
        String fieldName) {
    MethodVisitor mv = cv.visitMethod(access, name, desc, null, exceptions);
    String fieldSignature = desc.substring(desc.indexOf(')') + 1);
    String fieldClassName = desc.substring(desc.indexOf(')') + 2, desc.length() - 1);

    mv.visitCode();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, fieldName, fieldSignature);
    Label l3 = new Label();
    mv.visitJumpInsn(IFNULL, l3);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, fieldName, fieldSignature);
    mv.visitFieldInsn(GETFIELD, fieldClassName, "isLazy", "Z");
    mv.visitJumpInsn(IFEQ, l3);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    Label l4 = new Label();
    mv.visitJumpInsn(IFNULL, l4);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/Db", "isClosed", "()Z", false);
    Label l5 = new Label();
    mv.visitJumpInsn(IFEQ, l5);
    mv.visitLabel(l4);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(
            "Cannot initialize 'Relation' outside an open session!!!. Try initializing field directly within the class.");
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l5);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "newInstance", "()Ljava/lang/Object;", false);
    mv.visitTypeInsn(CHECKCAST, className);
    mv.visitVarInsn(ASTORE, 1);
    mv.visitLdcInsn(Type.getType(fieldSignature));
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "newInstance", "()Ljava/lang/Object;", false);
    mv.visitTypeInsn(CHECKCAST, fieldClassName);
    mv.visitVarInsn(ASTORE, 2);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/Db", "getPrimaryKey",
            "(Ljava/lang/Object;)Ljava/lang/Object;", false);
    mv.visitVarInsn(ASTORE, 3);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    mv.visitVarInsn(ALOAD, 2);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/Db", "from",
            "(Ljava/lang/Object;)Lcom/centimia/orm/jaqu/QueryInterface;", false);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEINTERFACE, "com/centimia/orm/jaqu/QueryInterface", "innerJoin",
            "(Ljava/lang/Object;)Lcom/centimia/orm/jaqu/QueryJoin;", true);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitFieldInsn(GETFIELD, className, fieldName, fieldSignature);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/QueryJoin", "on",
            "(Ljava/lang/Object;)Lcom/centimia/orm/jaqu/QueryJoinCondition;", false);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/QueryJoinCondition", "is",
            "(Ljava/lang/Object;)Lcom/centimia/orm/jaqu/QueryJoinWhere;", false);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, "db", "Lcom/centimia/orm/jaqu/Db;");
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/Db", "getPrimaryKey",
            "(Ljava/lang/Object;)Ljava/lang/Object;", false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/QueryJoinWhere", "where",
            "(Ljava/lang/Object;)Lcom/centimia/orm/jaqu/QueryCondition;", false);
    mv.visitVarInsn(ALOAD, 3);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/QueryCondition", "is",
            "(Ljava/lang/Object;)Lcom/centimia/orm/jaqu/QueryWhere;", false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "com/centimia/orm/jaqu/QueryWhere", "selectFirst", "()Ljava/lang/Object;",
            false);
    mv.visitTypeInsn(CHECKCAST, fieldClassName);
    mv.visitFieldInsn(PUTFIELD, className, fieldName, fieldSignature);
    mv.visitLabel(l1);
    mv.visitJumpInsn(GOTO, l3);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" });
    mv.visitVarInsn(ASTORE, 1);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(INSTANCEOF, "java/lang/RuntimeException");
    Label l6 = new Label();
    mv.visitJumpInsn(IFEQ, l6);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(CHECKCAST, "java/lang/RuntimeException");
    mv.visitInsn(ATHROW);
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/Exception" }, 0, null);
    mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "getMessage", "()Ljava/lang/String;", false);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
            "(Ljava/lang/String;Ljava/lang/Throwable;)V", false);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l3);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, className, newName, desc, false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(4, 4);
    mv.visitEnd();
}

From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java

License:Open Source License

@Override
public void visitFrame(final int type, final int nLocal, final Object[] local, final int nStack,
        final Object[] stack) {
    final StringBuilder sb = new StringBuilder();
    sb.append("frame ");
    switch (type) {
    case Opcodes.F_NEW:
    case Opcodes.F_FULL:
        sb.append("full [");
        appendFrameTypes(sb, nLocal, local);
        sb.append("] [");
        appendFrameTypes(sb, nStack, stack);
        sb.append(']');
        break;/*from w  ww.  j a  v a  2 s .  c  o  m*/
    case Opcodes.F_APPEND:
        sb.append("append [");
        appendFrameTypes(sb, nLocal, local);
        sb.append(']');
        break;
    case Opcodes.F_CHOP:
        sb.append("chop ").append(nLocal);
        break;
    case Opcodes.F_SAME:
        sb.append("same");
        break;
    case Opcodes.F_SAME1:
        sb.append("same1 ");
        appendFrameTypes(sb, 1, stack);
        break;
    default:
        assert false;
        break;
    }
    sb.append('\n');
    sb.append('\n');
    addText(sb);
}

From source file:com.github.fge.grappa.transform.CodeBlock.java

License:Apache License

/**
 * adds a compressed frame to the stack//  w w  w.j av  a  2s .  c  o m
 *
 * @param stackArguments the argument types on the stack, represented as
 * "class path names" e.g java/lang/RuntimeException
 */
public CodeBlock frame_same(Object... stackArguments) {
    int type;

    switch (stackArguments.length) {
    case 0:
        type = Opcodes.F_SAME;
        break;
    case 1:
        type = Opcodes.F_SAME1;
        break;
    default:
        throw new IllegalArgumentException("same frame should have 0" + " or 1 arguments on stack");
    }

    instructionList.add(new FrameNode(type, 0, null, stackArguments.length, stackArguments));
    return this;
}

From source file:com.github.wolf480pl.mias4j.MakeTestMH.java

License:Open Source License

public static byte[] dump() throws Exception {

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    MethodVisitor mv;// w  w  w. j av  a 2  s .c o m

    cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "TestMH", null, "java/lang/Object", null);

    cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
            ACC_PUBLIC + ACC_FINAL + ACC_STATIC);

    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
        mv.visitCode();
        Label l0 = new Label();
        Label l1 = new Label();
        Label l2 = new Label();
        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable");
        mv.visitLabel(l0);
        /*mv.visitMethodInsn(INVOKESTATIC, "java/lang/invoke/MethodHandles", "lookup", "()Ljava/lang/invoke/MethodHandles$Lookup;", false);
        mv.visitLdcInsn(Type.getType("Ljava/io/PrintStream;"));
        mv.visitLdcInsn("println");
        mv.visitFieldInsn(GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;");
        mv.visitLdcInsn(Type.getType("Ljava/lang/String;"));
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/invoke/MethodType", "methodType", "(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/invoke/MethodType;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandles$Lookup", "findVirtual", "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", false);*/
        mv.visitLdcInsn(new Handle(H_INVOKEVIRTUAL, "java/io/PrintStream", "println",
                Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class))));
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn("hey");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invoke",
                "(Ljava/io/PrintStream;Ljava/lang/String;)V", false);
        mv.visitLabel(l1);
        Label l3 = new Label();
        mv.visitJumpInsn(GOTO, l3);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" });
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V", false);
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(RETURN);
        mv.visitMaxs(5, 2);
        mv.visitEnd();
    }
    cw.visitEnd();

    return cw.toByteArray();
}

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

License:Open Source License

private static byte[] createClass() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    MethodVisitor mv;/* w w w  .ja v  a 2 s . c  o m*/
    cw.visit(V1_8, ACC_PUBLIC | ACC_SUPER, CLASS_NAME, null, "java/lang/Object", null);

    cw.visitInnerClass(INTERFACE_TYPE_NAME, CLASS_NAME, "Interface",
            ACC_PUBLIC | ACC_STATIC | ACC_ABSTRACT | ACC_INTERFACE);

    cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup",
            ACC_PUBLIC | ACC_FINAL | ACC_STATIC);

    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "method", "(Ljava/lang/String;)Ljava/lang/String;", null,
                null);
        mv.visitParameter("str", 0);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ARETURN);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PRIVATE | ACC_STATIC, "method",
                "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", null,
                null);
        mv.visitParameter("bool", 0);
        mv.visitParameter("c", 0);
        mv.visitParameter("b", 0);
        mv.visitParameter("f", 0);
        mv.visitParameter("d", 0);
        mv.visitParameter("l", 0);
        mv.visitParameter("i", 0);
        mv.visitParameter("s", 0);
        mv.visitParameter("o", 0);
        mv.visitParameter("array", 0);
        mv.visitParameter("str", 0);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 10);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf",
                "(Ljava/lang/Object;)Ljava/lang/String;", false);
        mv.visitVarInsn(ASTORE, 13);
        mv.visitVarInsn(ALOAD, 11);
        Label l0 = new Label();
        mv.visitJumpInsn(IFNONNULL, l0);
        mv.visitInsn(ICONST_1);
        Label l1 = new Label();
        mv.visitJumpInsn(GOTO, l1);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/String" }, 0, null);
        mv.visitInsn(ICONST_0);
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
        mv.visitVarInsn(ISTORE, 14);
        mv.visitIntInsn(BIPUSH, 91);
        mv.visitVarInsn(ALOAD, 12);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf",
                "(Ljava/lang/Object;)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", false);
        mv.visitInsn(IADD);
        mv.visitVarInsn(ALOAD, 13);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf",
                "(Ljava/lang/Object;)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", false);
        mv.visitInsn(IADD);
        mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
        mv.visitInsn(DUP_X1);
        mv.visitInsn(SWAP);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(I)V", false);
        mv.visitVarInsn(ALOAD, 12);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        mv.visitVarInsn(ILOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(FLOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(F)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(DLOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(D)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(LLOAD, 6);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(J)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 8);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ILOAD, 9);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ALOAD, 13);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        mv.visitVarInsn(ILOAD, 14);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;",
                false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
        mv.visitInsn(ARETURN);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "lambdaWithConstantArguments",
                "()L" + INTERFACE_TYPE_NAME + ";", null, null);
        mv.visitCode();
        mv.visitInsn(ICONST_0);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(ICONST_2);
        mv.visitInsn(FCONST_0);
        mv.visitInsn(DCONST_0);
        mv.visitInsn(LCONST_0);
        mv.visitInsn(ICONST_4);
        mv.visitIntInsn(SIPUSH, 9);
        mv.visitInsn(ACONST_NULL);
        mv.visitInsn(ACONST_NULL);
        mv.visitInvokeDynamicInsn("call",
                "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;)L" + INTERFACE_TYPE_NAME + ";",
                new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
                        "(Ljava/lang/invoke/MethodHandles$Lookup;"
                                + "Ljava/lang/String;Ljava/lang/invoke/MethodType;"
                                + "Ljava/lang/invoke/MethodType;" + "Ljava/lang/invoke/MethodHandle;"
                                + "Ljava/lang/invoke/MethodType;" + ")Ljava/lang/invoke/CallSite;",
                        false),
                new Object[] { Type.getType("(Ljava/lang/String;)Ljava/lang/String;"),
                        new Handle(Opcodes.H_INVOKESTATIC, CLASS_NAME, "method",
                                "(ZCBFDJISLjava/lang/Object;[Ljava/lang/Object;Ljava/lang/String;"
                                        + ")Ljava/lang/String;",
                                false),
                        Type.getType("(Ljava/lang/String;)Ljava/lang/String;") });
        mv.visitInsn(ARETURN);
        mv.visitEnd();
    }

    cw.visitEnd();

    return cw.toByteArray();
}

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

License:Open Source License

@Override
public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) {
    switch (type) {
    case Opcodes.F_NEW:
        // Expanded form.
        previousFrame = FrameInfo.create(convertTypesInStackMapFrame(nLocal, local),
                convertTypesInStackMapFrame(nStack, stack));
        break;//from w  ww  . j  av a2  s .  co m
    case Opcodes.F_SAME:
        // This frame type indicates that the frame has exactly the same local variables as the
        // previous frame and that the operand stack is empty.
        previousFrame = FrameInfo.create(previousFrame.locals(), ImmutableList.of());
        break;
    case Opcodes.F_SAME1:
        // This frame type indicates that the frame has exactly the same local variables as the
        // previous frame and that the operand stack has one entry.
        previousFrame = FrameInfo.create(previousFrame.locals(), convertTypesInStackMapFrame(nStack, stack));
        break;
    case Opcodes.F_APPEND:
        // This frame type indicates that the frame has the same locals as the previous frame except
        // that k additional locals are defined, and that the operand stack is empty.
        previousFrame = FrameInfo.create(appendArrayToList(previousFrame.locals(), nLocal, local),
                ImmutableList.of());
        break;
    case Opcodes.F_CHOP:
        // This frame type indicates that the frame has the same local variables as the previous
        // frame except that the last k local variables are absent, and that the operand stack is
        // empty.
        previousFrame = FrameInfo.create(removeBackFromList(previousFrame.locals(), nLocal),
                ImmutableList.of());
        break;
    case Opcodes.F_FULL:
        previousFrame = FrameInfo.create(convertTypesInStackMapFrame(nLocal, local),
                convertTypesInStackMapFrame(nStack, stack));
        break;
    default:
        // continue below
    }
    // Update types for operand stack and local variables.
    operandStack.clear();
    operandStack.addAll(previousFrame.stack());
    localVariableSlots.clear();
    localVariableSlots.addAll(previousFrame.locals());
    super.visitFrame(type, nLocal, local, nStack, stack);
}