List of usage examples for org.objectweb.asm Opcodes F_CHOP
int F_CHOP
To view the source code for org.objectweb.asm Opcodes F_CHOP.
Click Source Link
From source file:blockphysics.asm.BPTransformer.java
License:Open Source License
private byte[] transformBlockPhysics(byte[] bytes) { /*try//www. ja v a 2s.c o m { FileOutputStream fos = new FileOutputStream("d:/BlockPhysics.orig.class"); fos.write(bytes); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ try { Class.forName("org.bukkit.Bukkit"); System.out.println("[BlockPhysics] Bukkit detected."); } catch (ClassNotFoundException e) { return bytes; } System.out.print("[BlockPhysics] Patching BlockPhysics.class ............"); boolean ok = false; ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); MethodNode m; Iterator<MethodNode> methods = classNode.methods.iterator(); while (methods.hasNext()) { m = methods.next(); if (m.name.equals("tickBlocksRandomMove") && m.desc.equals("(Ljr;)V")) { m.instructions.clear(); m.localVariables.clear(); InsnList toInject = new InsnList(); toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "skipMove", "Z")); LabelNode l0 = new LabelNode(); toInject.add(new JumpInsnNode(IFEQ, l0)); toInject.add(new InsnNode(RETURN)); toInject.add(l0); toInject.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new FieldInsnNode(GETFIELD, "jr", "G", "Lgnu/trove/map/hash/TLongShortHashMap;")); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "gnu/trove/map/hash/TLongShortHashMap", "iterator", "()Lgnu/trove/iterator/TLongShortIterator;")); toInject.add(new VarInsnNode(ASTORE, 1)); LabelNode l1 = new LabelNode(); toInject.add(l1); toInject.add(new FrameNode(Opcodes.F_APPEND, 1, new Object[] { "gnu/trove/iterator/TLongShortIterator" }, 0, null)); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new MethodInsnNode(INVOKEINTERFACE, "gnu/trove/iterator/TLongShortIterator", "hasNext", "()Z")); LabelNode l2 = new LabelNode(); toInject.add(new JumpInsnNode(IFEQ, l2)); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add(new MethodInsnNode(INVOKEINTERFACE, "gnu/trove/iterator/TLongShortIterator", "advance", "()V")); toInject.add(new VarInsnNode(ALOAD, 1)); toInject.add( new MethodInsnNode(INVOKEINTERFACE, "gnu/trove/iterator/TLongShortIterator", "key", "()J")); toInject.add(new VarInsnNode(LSTORE, 2)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(POP)); toInject.add(new VarInsnNode(LLOAD, 2)); toInject.add(new MethodInsnNode(INVOKESTATIC, "abv", "keyToX", "(J)I")); toInject.add(new VarInsnNode(ISTORE, 4)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new InsnNode(POP)); toInject.add(new VarInsnNode(LLOAD, 2)); toInject.add(new MethodInsnNode(INVOKESTATIC, "abv", "keyToZ", "(J)I")); toInject.add(new VarInsnNode(ISTORE, 5)); toInject.add(new VarInsnNode(ILOAD, 4)); toInject.add(new IntInsnNode(BIPUSH, 16)); toInject.add(new InsnNode(IMUL)); toInject.add(new VarInsnNode(ISTORE, 6)); toInject.add(new VarInsnNode(ILOAD, 5)); toInject.add(new IntInsnNode(BIPUSH, 16)); toInject.add(new InsnNode(IMUL)); toInject.add(new VarInsnNode(ISTORE, 7)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ILOAD, 4)); toInject.add(new VarInsnNode(ILOAD, 5)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "jr", "e", "(II)Ladq;")); toInject.add(new VarInsnNode(ASTORE, 8)); toInject.add(new VarInsnNode(ALOAD, 8)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adq", "i", "()[Ladr;")); toInject.add(new VarInsnNode(ASTORE, 12)); toInject.add(new VarInsnNode(ALOAD, 12)); toInject.add(new InsnNode(ARRAYLENGTH)); toInject.add(new VarInsnNode(ISTORE, 9)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new VarInsnNode(ISTORE, 10)); LabelNode l3 = new LabelNode(); toInject.add(l3); toInject.add(new FrameNode(Opcodes.F_FULL, 12, new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator", Opcodes.LONG, Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, "adq", Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.TOP, "[Ladr;" }, 0, new Object[] {})); toInject.add(new VarInsnNode(ILOAD, 10)); toInject.add(new VarInsnNode(ILOAD, 9)); LabelNode l4 = new LabelNode(); toInject.add(new JumpInsnNode(IF_ICMPGE, l4)); toInject.add(new VarInsnNode(ALOAD, 12)); toInject.add(new VarInsnNode(ILOAD, 10)); toInject.add(new InsnNode(AALOAD)); toInject.add(new VarInsnNode(ASTORE, 13)); toInject.add(new VarInsnNode(ALOAD, 13)); LabelNode l5 = new LabelNode(); toInject.add(new JumpInsnNode(IFNULL, l5)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new VarInsnNode(ISTORE, 14)); LabelNode l6 = new LabelNode(); toInject.add(l6); toInject.add(new FrameNode(Opcodes.F_APPEND, 2, new Object[] { "adr", Opcodes.INTEGER }, 0, null)); toInject.add(new VarInsnNode(ILOAD, 14)); toInject.add(new InsnNode(ICONST_3)); toInject.add(new JumpInsnNode(IF_ICMPGE, l5)); toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "updateLCG", "I")); toInject.add(new InsnNode(ICONST_3)); toInject.add(new InsnNode(IMUL)); toInject.add(new LdcInsnNode(new Integer(1013904223))); toInject.add(new InsnNode(IADD)); toInject.add(new FieldInsnNode(PUTSTATIC, "blockphysics/BlockPhysics", "updateLCG", "I")); toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "updateLCG", "I")); toInject.add(new InsnNode(ICONST_2)); toInject.add(new InsnNode(ISHR)); toInject.add(new VarInsnNode(ISTORE, 11)); toInject.add(new VarInsnNode(ILOAD, 11)); toInject.add(new IntInsnNode(BIPUSH, 15)); toInject.add(new InsnNode(IAND)); toInject.add(new VarInsnNode(ISTORE, 15)); toInject.add(new VarInsnNode(ILOAD, 11)); toInject.add(new IntInsnNode(BIPUSH, 8)); toInject.add(new InsnNode(ISHR)); toInject.add(new IntInsnNode(BIPUSH, 15)); toInject.add(new InsnNode(IAND)); toInject.add(new VarInsnNode(ISTORE, 16)); toInject.add(new VarInsnNode(ILOAD, 11)); toInject.add(new IntInsnNode(BIPUSH, 16)); toInject.add(new InsnNode(ISHR)); toInject.add(new IntInsnNode(BIPUSH, 15)); toInject.add(new InsnNode(IAND)); toInject.add(new VarInsnNode(ISTORE, 17)); toInject.add(new VarInsnNode(ALOAD, 13)); toInject.add(new VarInsnNode(ILOAD, 15)); toInject.add(new VarInsnNode(ILOAD, 17)); toInject.add(new VarInsnNode(ILOAD, 16)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "a", "(III)I")); toInject.add(new VarInsnNode(ISTORE, 18)); toInject.add(new VarInsnNode(ALOAD, 13)); toInject.add(new VarInsnNode(ILOAD, 15)); toInject.add(new VarInsnNode(ILOAD, 17)); toInject.add(new VarInsnNode(ILOAD, 16)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "b", "(III)I")); toInject.add(new VarInsnNode(ISTORE, 19)); toInject.add(new FieldInsnNode(GETSTATIC, "blockphysics/BlockPhysics", "blockSet", "[[Lblockphysics/BlockDef;")); toInject.add(new VarInsnNode(ILOAD, 18)); toInject.add(new InsnNode(AALOAD)); toInject.add(new VarInsnNode(ILOAD, 19)); toInject.add(new InsnNode(AALOAD)); toInject.add(new FieldInsnNode(GETFIELD, "blockphysics/BlockDef", "randomtick", "Z")); LabelNode l7 = new LabelNode(); toInject.add(new JumpInsnNode(IFEQ, l7)); toInject.add(new VarInsnNode(ALOAD, 0)); toInject.add(new VarInsnNode(ILOAD, 15)); toInject.add(new VarInsnNode(ILOAD, 6)); toInject.add(new InsnNode(IADD)); toInject.add(new VarInsnNode(ILOAD, 17)); toInject.add(new VarInsnNode(ALOAD, 13)); toInject.add(new MethodInsnNode(INVOKEVIRTUAL, "adr", "d", "()I")); toInject.add(new InsnNode(IADD)); toInject.add(new VarInsnNode(ILOAD, 16)); toInject.add(new VarInsnNode(ILOAD, 7)); toInject.add(new InsnNode(IADD)); toInject.add(new VarInsnNode(ILOAD, 18)); toInject.add(new VarInsnNode(ILOAD, 19)); toInject.add(new InsnNode(ICONST_0)); toInject.add(new MethodInsnNode(INVOKESTATIC, "blockphysics/BlockPhysics", "tryToMove", "(Labv;IIIIIZ)Z")); toInject.add(new InsnNode(POP)); toInject.add(l7); toInject.add(new FrameNode(Opcodes.F_FULL, 14, new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator", Opcodes.LONG, Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, "adq", Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, "[Ladr;", "adr", Opcodes.INTEGER }, 0, new Object[] {})); toInject.add(new IincInsnNode(14, 1)); toInject.add(new JumpInsnNode(GOTO, l6)); toInject.add(l5); toInject.add(new FrameNode(Opcodes.F_FULL, 12, new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator", Opcodes.LONG, Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.INTEGER, "adq", Opcodes.INTEGER, Opcodes.INTEGER, Opcodes.TOP, "[Ladr;" }, 0, new Object[] {})); toInject.add(new IincInsnNode(10, 1)); toInject.add(new JumpInsnNode(GOTO, l3)); toInject.add(l4); toInject.add(new FrameNode(Opcodes.F_FULL, 2, new Object[] { "jr", "gnu/trove/iterator/TLongShortIterator" }, 0, new Object[] {})); toInject.add(new JumpInsnNode(GOTO, l1)); toInject.add(l2); toInject.add(new FrameNode(Opcodes.F_CHOP, 1, null, 0, null)); toInject.add(new InsnNode(RETURN)); m.instructions.add(toInject); ok = true; break; } } ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(cw); if (ok) System.out.println("OK"); else System.out.println("Failed." + ok); /*try { FileOutputStream fos = new FileOutputStream("d:/BlockPhysics.class"); fos.write(cw.toByteArray()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return cw.toByteArray(); }
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. * /*from w ww. j ava2 s.co 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>//from w ww. ja va 2s. c om * 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;//www . ja v a2 s .co 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.google.code.jconts.instrument.gen.AsyncMethodAdapter.java
License:Apache License
@Override public void visitFrame(int type, int nLocal, Object[] locs, int nStack, Object[] stack) { if (type == Opcodes.F_NEW) { throw new IllegalArgumentException("Expanded frames are not supported!"); }/* www . j a va 2s.c o m*/ mv.visitFrame(type, nLocal, locs, nStack, stack); if (type == Opcodes.F_APPEND) { for (int i = 0; i < nLocal; ++i) { locals.add(Frames.fromFrameType(locs[i])); } } else if (type == Opcodes.F_CHOP) { for (int i = 0; i < nLocal; ++i) { locals.remove(locals.size() - 1); } } else if (type == Opcodes.F_FULL) { locals.clear(); for (int i = 0; i < nLocal; ++i) { locals.add(Frames.fromFrameType(locs[i])); } } }
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;// w w w .ja v a 2 s.c om 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); }
From source file:com.ibm.layout.GenArray2D.java
License:Open Source License
/** * Generate bytecodes for runtime class//from www. ja v a 2s . c om * * @return byte array containing bytecodes for runtime class * @throws Exception */ public byte[] genBytecode() throws Exception { ClassWriter cw = new ClassWriter(0); MethodVisitor mv = null; FieldVisitor fv = null; final boolean itf = false; cw.visit(V1_8, ACC_FINAL + ACC_SUPER, arrayImplClassName, arrayInterfaceClassSig, "java/lang/Object", new String[] { arrayInterfaceClassName }); { fv = cw.visitField(ACC_PROTECTED + ACC_FINAL, "dim1", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PROTECTED + ACC_FINAL, "dim2", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, "elementSize", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, "arraySize", "J", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PROTECTED, "<init>", "(JJJ)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitFieldInsn(PUTFIELD, arrayImplClassName, "dim1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 3); mv.visitFieldInsn(PUTFIELD, arrayImplClassName, "dim2", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 5); mv.visitFieldInsn(PUTFIELD, arrayImplClassName, "elementSize", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 5); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LMUL); mv.visitVarInsn(LLOAD, 3); mv.visitInsn(LMUL); mv.visitFieldInsn(PUTFIELD, arrayImplClassName, "arraySize", "J"); mv.visitInsn(RETURN); mv.visitMaxs(5, 7); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "at", "(JJ)L" + elementInterfaceClassName + ";", null, null); mv.visitCode(); mv.visitTypeInsn(NEW, elementImplClassName); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, elementImplClassName, "<init>", "()V", itf); mv.visitVarInsn(ASTORE, 5); mv.visitTypeInsn(NEW, "com/ibm/layout/Location"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, arrayImplClassName, "location", "Lcom/ibm/layout/Location;"); mv.visitVarInsn(LLOAD, 1); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, arrayImplClassName, "dim2", "J"); mv.visitInsn(LMUL); mv.visitVarInsn(LLOAD, 3); mv.visitInsn(LADD); mv.visitVarInsn(ALOAD, 5); mv.visitMethodInsn(INVOKEVIRTUAL, elementImplClassName, "sizeof", "()J", itf); mv.visitInsn(LMUL); mv.visitMethodInsn(INVOKESPECIAL, "com/ibm/layout/Location", "<init>", "(Lcom/ibm/layout/Location;J)V", itf); mv.visitVarInsn(ASTORE, 6); mv.visitVarInsn(ALOAD, 5); mv.visitVarInsn(ALOAD, 6); mv.visitMethodInsn(INVOKEVIRTUAL, elementImplClassName, "bindLocation", "(Lcom/ibm/layout/Location;)V", itf); mv.visitVarInsn(ALOAD, 5); mv.visitInsn(ARETURN); mv.visitMaxs(7, 7); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "put", "(JJL" + elementInterfaceClassName + ";)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitVarInsn(LLOAD, 3); mv.visitMethodInsn(INVOKEVIRTUAL, arrayImplClassName, "at", "(JJ)L" + elementInterfaceClassName + ";", itf); mv.visitTypeInsn(CHECKCAST, elementImplClassName); mv.visitVarInsn(ALOAD, 5); mv.visitTypeInsn(CHECKCAST, elementImplClassName); mv.visitMethodInsn(INVOKEVIRTUAL, elementImplClassName, "copyFrom", "(L" + elementImplClassName + ";)V", itf); mv.visitInsn(RETURN); mv.visitMaxs(5, 6); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "at", "(JJ)Lcom/ibm/layout/Layout;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitVarInsn(LLOAD, 3); mv.visitMethodInsn(INVOKEVIRTUAL, arrayImplClassName, "at", "(JJ)L" + elementInterfaceClassName + ";", itf); mv.visitInsn(ARETURN); mv.visitMaxs(5, 5); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "put", "(JJLcom/ibm/layout/Layout;)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitVarInsn(LLOAD, 3); mv.visitVarInsn(ALOAD, 5); mv.visitTypeInsn(CHECKCAST, elementInterfaceClassName); mv.visitMethodInsn(INVOKEVIRTUAL, arrayImplClassName, "put", "(JJL" + elementInterfaceClassName + ";)V", itf); mv.visitInsn(RETURN); mv.visitMaxs(6, 6); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "dim1", "()J", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, arrayImplClassName, "dim1", "J"); mv.visitInsn(LRETURN); mv.visitMaxs(2, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "dim2", "()J", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, arrayImplClassName, "dim2", "J"); mv.visitInsn(LRETURN); mv.visitMaxs(2, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "sizeof", "()J", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, arrayImplClassName, "arraySize", "J"); mv.visitInsn(LRETURN); mv.visitMaxs(2, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); mv.visitTypeInsn(NEW, "java/lang/StringBuffer"); mv.visitInsn(DUP); mv.visitLdcInsn("["); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuffer", "<init>", "(Ljava/lang/String;)V", false); mv.visitVarInsn(ASTORE, 1); mv.visitInsn(LCONST_0); mv.visitVarInsn(LSTORE, 2); Label l0 = new Label(); mv.visitJumpInsn(GOTO, l0); Label l1 = new Label(); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/lang/StringBuffer", Opcodes.LONG }, 0, null); mv.visitInsn(LCONST_0); mv.visitVarInsn(LSTORE, 4); Label l2 = new Label(); mv.visitJumpInsn(GOTO, l2); Label l3 = new Label(); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { Opcodes.LONG }, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(NEW, "java/lang/StringBuilder"); mv.visitInsn(DUP); mv.visitLdcInsn(" "); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 2); mv.visitVarInsn(LLOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, arrayImplClassName, "at", "(JJ)Lcom/ibm/layout/Layout;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;", false); mv.visitInsn(POP); mv.visitVarInsn(LLOAD, 4); mv.visitInsn(LCONST_1); mv.visitInsn(LADD); mv.visitVarInsn(LSTORE, 4); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(LLOAD, 4); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, arrayImplClassName, "dim2", "J"); mv.visitInsn(LCMP); mv.visitJumpInsn(IFLT, l3); mv.visitVarInsn(LLOAD, 2); mv.visitInsn(LCONST_1); mv.visitInsn(LADD); mv.visitVarInsn(LSTORE, 2); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(LLOAD, 2); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, arrayImplClassName, "dim1", "J"); mv.visitInsn(LCMP); mv.visitJumpInsn(IFLT, l1); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn(" ]"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;", false); mv.visitInsn(POP); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;", false); mv.visitInsn(ARETURN); mv.visitMaxs(7, 6); mv.visitEnd(); } ImplHelper.genLayoutTypeImpl(cw, mv, fv, arrayImplClassName, false); cw.visitEnd(); return cw.toByteArray(); }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.VisitFrame.java
License:Open Source License
public String toString() { String result = "VisitFrame: type = "; switch (type) { case Opcodes.F_NEW: result = result + " F_NEW "; break;//from w w w . ja v a 2 s . com case Opcodes.F_FULL: result = result + " F_FULL "; break; case Opcodes.F_APPEND: result = result + " F_APPEND "; break; case Opcodes.F_CHOP: result = result + " F_CHOP "; break; case Opcodes.F_SAME: result = result + " F_SAME "; break; case Opcodes.F_SAME1: result = result + " F_SAME1 "; break; default: throw new RuntimeException("Unknown Frame Type " + type); } result = result + "locals = ["; for (int i = 0; i < nLocal; i++) result = result + local[i] + " "; result = result + "] Stack = ["; for (int i = 0; i < nStack; i++) result = result + stack[i] + " "; result = result + "]"; return result; }
From source file:de.dynamicfiles.projects.gradle.plugins.javafx.tasks.internal.MonkeyPatcher.java
License:Apache License
private static void doMonkeyPatchFileHandleLeak(ClassReader classReader, ClassWriter classWriter) { classReader.accept(new ClassVisitor(Opcodes.ASM5, classWriter) { @Override//from ww w. j a v a 2s. c o m public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (!(name.equals(METHOD_TO_MONKEY_PATCH) && desc.equals(METHOD_SIGNATURE_TO_MONKEY_PATCH))) { return super.visitMethod(access, name, desc, signature, exceptions); } // helpful source: http://web.cs.ucla.edu/~msb/cs239-tutorial/ // "We will do this using the Adapter Pattern. Adapters wrap an object, overriding some of its methods, and delegating to the others." // ugly adapter-pattern ... took me more time than I really can tell here <.< return getMonkeyPatchedFileHandleLeakMethodVisitor(access, name, desc, signature, exceptions); } private MethodVisitor getMonkeyPatchedFileHandleLeakMethodVisitor(int access, String name, String desc, String signature, String[] exceptions) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { /* TODO improve detection of lambda-positions, numbers might vary on different compile-versions */ @Override public void visitCode() { // This mostly got generated from ASM itself, except some adjustments for lambda-IDs and removed "visitMaxs()"-call String javalangThrowable = "java/lang/Throwable"; String javaioFile = "java/io/File"; String javalangString = "java/lang/String"; Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, javalangThrowable); Label l3 = new Label(); Label l4 = new Label(); Label l5 = new Label(); mv.visitTryCatchBlock(l3, l4, l5, javalangThrowable); Label l6 = new Label(); mv.visitTryCatchBlock(l3, l4, l6, null); Label l7 = new Label(); Label l8 = new Label(); Label l9 = new Label(); mv.visitTryCatchBlock(l7, l8, l9, javalangThrowable); Label l10 = new Label(); mv.visitTryCatchBlock(l5, l10, l6, null); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitVarInsn(Opcodes.ALOAD, 2); Label l11 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l11); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javaioFile, "isDirectory", "()Z", false); Label l12 = new Label(); mv.visitJumpInsn(Opcodes.IFNE, l12); mv.visitLabel(l11); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { javalangString }, 0, null); mv.visitTypeInsn(Opcodes.NEW, javaioFile); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("java.home"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "getProperty", "(Ljava/lang/String;)Ljava/lang/String;", false); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, javaioFile, "<init>", "(Ljava/lang/String;)V", false); mv.visitVarInsn(Opcodes.ASTORE, 2); mv.visitLabel(l12); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitFieldInsn(Opcodes.GETSTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "VS_VERS", "[Ljava/lang/String;"); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitVarInsn(Opcodes.ISTORE, 5); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, 6); Label l13 = new Label(); mv.visitLabel(l13); mv.visitFrame(Opcodes.F_APPEND, 3, new Object[] { "[Ljava/lang/String;", Opcodes.INTEGER, Opcodes.INTEGER }, 0, null); mv.visitVarInsn(Opcodes.ILOAD, 6); mv.visitVarInsn(Opcodes.ILOAD, 5); Label l14 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPGE, l14); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitVarInsn(Opcodes.ILOAD, 6); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/oracle/tools/packager/windows/WinAppBundler", "copyMSVCDLLs", "(Ljava/io/File;Ljava/lang/String;)Z", false); Label l15 = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, l15); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitJumpInsn(Opcodes.GOTO, l14); mv.visitLabel(l15); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitIincInsn(6, 1); mv.visitJumpInsn(Opcodes.GOTO, l13); mv.visitLabel(l14); mv.visitFrame(Opcodes.F_CHOP, 3, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 3); Label l16 = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, l16); mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("Not found MSVC dlls"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l16); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(Opcodes.NEW, "java/util/concurrent/atomic/AtomicReference"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/concurrent/atomic/AtomicReference", "<init>", "()V", false); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitVarInsn(Opcodes.ASTORE, 5); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javaioFile, "toPath", "()Ljava/nio/file/Path;", false); mv.visitLdcInsn("bin"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/nio/file/Path", "resolve", "(Ljava/lang/String;)Ljava/nio/file/Path;", true); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/nio/file/Files", "list", "(Ljava/nio/file/Path;)Ljava/util/stream/Stream;", false); mv.visitVarInsn(Opcodes.ASTORE, 6); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitLabel(l3); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitInvokeDynamicInsn("test", "()Ljava/util/function/Predicate;", 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;"), new Object[] { Type.getType("(Ljava/lang/Object;)Z"), new Handle(Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "lambda$copyMSVCDLLs$261", "(Ljava/nio/file/Path;)Z"), Type.getType("(Ljava/nio/file/Path;)Z") }); // modified lambda-name mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "filter", "(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;", true); mv.visitVarInsn(Opcodes.ALOAD, 5); mv.visitInvokeDynamicInsn("test", "(Ljava/lang/String;)Ljava/util/function/Predicate;", 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;"), new Object[] { Type.getType("(Ljava/lang/Object;)Z"), new Handle( Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "lambda$copyMSVCDLLs$262", "(Ljava/lang/String;Ljava/nio/file/Path;)Z"), Type.getType("(Ljava/nio/file/Path;)Z") }); // modified lambda-name mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "filter", "(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;", true); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitInvokeDynamicInsn("accept", "(Ljava/io/File;Ljava/util/concurrent/atomic/AtomicReference;)Ljava/util/function/Consumer;", 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;"), new Object[] { Type.getType("(Ljava/lang/Object;)V"), new Handle( Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "lambda$copyMSVCDLLs$263", "(Ljava/io/File;Ljava/util/concurrent/atomic/AtomicReference;Ljava/nio/file/Path;)V"), Type.getType("(Ljava/nio/file/Path;)V") }); // modified lambda-name mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "forEach", "(Ljava/util/function/Consumer;)V", true); mv.visitLabel(l4); mv.visitVarInsn(Opcodes.ALOAD, 6); Label l17 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l17); mv.visitVarInsn(Opcodes.ALOAD, 7); Label l18 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l18); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitLabel(l1); mv.visitJumpInsn(Opcodes.GOTO, l17); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_FULL, 8, new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile, javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference", javalangString, "java/util/stream/Stream", javalangThrowable }, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 8); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitVarInsn(Opcodes.ALOAD, 8); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javalangThrowable, "addSuppressed", "(Ljava/lang/Throwable;)V", false); mv.visitJumpInsn(Opcodes.GOTO, l17); mv.visitLabel(l18); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitJumpInsn(Opcodes.GOTO, l17); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 8); mv.visitVarInsn(Opcodes.ALOAD, 8); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitVarInsn(Opcodes.ALOAD, 8); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 9); mv.visitLabel(l10); mv.visitVarInsn(Opcodes.ALOAD, 6); Label l19 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l19); mv.visitVarInsn(Opcodes.ALOAD, 7); Label l20 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l20); mv.visitLabel(l7); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitLabel(l8); mv.visitJumpInsn(Opcodes.GOTO, l19); mv.visitLabel(l9); mv.visitFrame(Opcodes.F_FULL, 10, new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile, javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference", javalangString, "java/util/stream/Stream", javalangThrowable, Opcodes.TOP, javalangThrowable }, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 10); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitVarInsn(Opcodes.ALOAD, 10); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javalangThrowable, "addSuppressed", "(Ljava/lang/Throwable;)V", false); mv.visitJumpInsn(Opcodes.GOTO, l19); mv.visitLabel(l20); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitLabel(l19); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 9); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l17); mv.visitFrame(Opcodes.F_FULL, 6, new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile, javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference", javalangString }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicReference", "get", "()Ljava/lang/Object;", false); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/io/IOException"); mv.visitVarInsn(Opcodes.ASTORE, 6); mv.visitVarInsn(Opcodes.ALOAD, 6); Label l21 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l21); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l21); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/io/IOException" }, 0, null); mv.visitInsn(Opcodes.RETURN); } }; } }, ClassReader.EXPAND_FRAMES); // ClassReader.EXPAND_FRAMES required for Java 8 }
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();//from w ww. j a v a 2 s. c o m 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(); }