List of usage examples for org.objectweb.asm Opcodes GOTO
int GOTO
To view the source code for org.objectweb.asm Opcodes GOTO.
Click Source Link
From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java
License:Apache License
public void visitJumpInsn(int opcode, Label label) { switch (opcode) { case Opcodes.IFEQ: pop(Type.INT_TYPE, Type.BOOLEAN_TYPE); break;//from w w w .j a v a 2 s. co m case Opcodes.GOTO: break; default: throw new IllegalArgumentException("Unsupported opcode " + OPCODES[opcode]); } print(opcode, label.toString()); label(label, OPCODES[opcode]); }
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static void addReadOverride(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "read_value", "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V", null, null); mv.visitCode();/* ww w .ja v a 2s . c om*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(54, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(55, l2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_read", "(Lorg/omg/CORBA/portable/InputStream;)V"); Label l3 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l3); mv.visitLabel(l1); mv.visitLineNumber(57, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "read_value", "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V"); mv.visitLabel(l3); mv.visitLineNumber(59, l3); mv.visitInsn(Opcodes.RETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0); mv.visitLocalVariable("is", "Lorg/omg/CORBA/portable/InputStream;", null, l0, l4, 1); mv.visitLocalVariable("t", "Lorg/omg/CORBA/TypeCode;", null, l0, l4, 2); mv.visitMaxs(3, 3); mv.visitEnd(); }
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static void addWriteOverride(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "write_value", "(Lorg/omg/CORBA/portable/OutputStream;)V", null, null); mv.visitCode();/*from ww w . jav a2 s.co m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(61, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(62, l2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_write", "(Lorg/omg/CORBA/portable/OutputStream;)V"); Label l3 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l3); mv.visitLabel(l1); mv.visitLineNumber(64, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "write_value", "(Lorg/omg/CORBA/portable/OutputStream;)V"); mv.visitLabel(l3); mv.visitLineNumber(66, l3); mv.visitInsn(Opcodes.RETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0); mv.visitLocalVariable("os", "Lorg/omg/CORBA/portable/OutputStream;", null, l0, l4, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
private void doCollection(MethodVisitor mv, int x) { // List aVal = obj.getA(); // List newA = (List)lst.get(99); // if (aVal == null) { // obj.setA(newA); // } else if (newA != null) { // aVal.addAll(newA); // }/*w w w . ja va 2 s . c o m*/ Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(114, l3); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperType.getName()), getMethods[x].getName(), getMethodSignature(getMethods[x])); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitIntInsn(Opcodes.BIPUSH, x); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;"); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/List"); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 3); Label nonNullLabel = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, nonNullLabel); if (setMethods[x] == null) { mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(getMethods[x].getName() + " returned null and there isn't a set method."); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.ATHROW); } else { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitTypeInsn(Opcodes.CHECKCAST, getMethods[x].getReturnType().getName().replace('.', '/')); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperType.getName()), setMethods[x].getName(), getMethodSignature(setMethods[x])); } Label jumpOverLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, jumpOverLabel); mv.visitLabel(nonNullLabel); mv.visitLineNumber(106, nonNullLabel); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitJumpInsn(Opcodes.IFNULL, jumpOverLabel); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "addAll", "(Ljava/util/Collection;)Z"); mv.visitInsn(Opcodes.POP); mv.visitLabel(jumpOverLabel); mv.visitLineNumber(107, jumpOverLabel); }
From source file:org.apache.s4.core.gen.OverloadDispatcherGenerator.java
License:Apache License
private void generateEventDispatchMethod(ClassWriter cw, String dispatchMethodName, List<Hierarchy> eventHierarchies, String processEventMethodName) { MethodVisitor mv2 = cw.visitMethod(ACC_PUBLIC, dispatchMethodName, "(" + Type.getType(ProcessingElement.class).getDescriptor() + Type.getType(Event.class).getDescriptor() + ")V", null, null);/*from w ww. j av a2 s .c om*/ mv2.visitCode(); Label l3 = new Label(); mv2.visitLabel(l3); mv2.visitVarInsn(ALOAD, 1); mv2.visitTypeInsn(CHECKCAST, Type.getInternalName(targetClass)); mv2.visitVarInsn(ASTORE, 3); boolean first = true; Label aroundLabel = new Label(); for (Hierarchy hierarchy : eventHierarchies) { if (first) { Label l4 = new Label(); mv2.visitLabel(l4); } mv2.visitVarInsn(ALOAD, 2); mv2.visitTypeInsn(INSTANCEOF, Type.getInternalName(hierarchy.getTop())); Label l5 = new Label(); mv2.visitJumpInsn(IFEQ, l5); Label l6 = new Label(); mv2.visitLabel(l6); mv2.visitVarInsn(ALOAD, 3); mv2.visitVarInsn(ALOAD, 2); mv2.visitTypeInsn(CHECKCAST, Type.getInternalName(hierarchy.getTop())); mv2.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(targetClass), processEventMethodName, "(" + Type.getDescriptor(hierarchy.getTop()) + ")V"); mv2.visitJumpInsn(Opcodes.GOTO, aroundLabel); mv2.visitLabel(l5); if (first) { mv2.visitFrame(F_APPEND, 1, new Object[] { Type.getInternalName(targetClass) }, 0, null); first = false; } else { mv2.visitFrame(Opcodes.F_SAME, 0, null, 0, null); } } addErrorLogStatement(mv2); if (eventHierarchies.size() > 0) { mv2.visitLabel(aroundLabel); mv2.visitFrame(Opcodes.F_SAME, 0, null, 0, null); } mv2.visitInsn(RETURN); Label l8 = new Label(); mv2.visitLabel(l8); mv2.visitLocalVariable("pe", Type.getDescriptor(ProcessingElement.class), null, l3, l8, 1); mv2.visitLocalVariable("event", Type.getDescriptor(Event.class), null, l3, l8, 2); mv2.visitLocalVariable("typedPE", Type.getDescriptor(targetClass), null, l3, l8, 3); mv2.visitMaxs(4, 4); mv2.visitEnd(); }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitJumpInsn(final int opcode, final Label label) { T t = null;//w w w.j av a 2s . c om Object oValue = null; final int targetPc = getPc(label); switch (opcode) { /******** * GOTO * ********/ case Opcodes.GOTO: { final GOTO op = new GOTO(this.ops.size(), opcode, this.line); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } break; } /******** * JCMP * ********/ case Opcodes.IF_ACMPEQ: t = T.REF; oValue = CmpType.T_EQ; // fall through case Opcodes.IF_ACMPNE: if (t == null) { t = T.REF; oValue = CmpType.T_NE; } // fall through case Opcodes.IF_ICMPEQ: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_EQ; } // fall through case Opcodes.IF_ICMPGE: if (t == null) { t = T.INT; oValue = CmpType.T_GE; } // fall through case Opcodes.IF_ICMPGT: if (t == null) { t = T.INT; oValue = CmpType.T_GT; } // fall through case Opcodes.IF_ICMPLE: if (t == null) { t = T.INT; oValue = CmpType.T_LE; } // fall through case Opcodes.IF_ICMPLT: if (t == null) { t = T.INT; oValue = CmpType.T_LT; } // fall through case Opcodes.IF_ICMPNE: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_NE; } { assert oValue instanceof CmpType; final JCMP op = new JCMP(this.ops.size(), opcode, this.line, t, (CmpType) oValue); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } } break; /******** * JCND * ********/ case Opcodes.IFNULL: t = T.REF; oValue = CmpType.T_EQ; // fall through case Opcodes.IFNONNULL: if (t == null) { t = T.REF; oValue = CmpType.T_NE; } // fall through case Opcodes.IFEQ: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_EQ; } // fall through case Opcodes.IFGE: if (t == null) { t = T.INT; oValue = CmpType.T_GE; } // fall through case Opcodes.IFGT: if (t == null) { t = T.INT; oValue = CmpType.T_GT; } // fall through case Opcodes.IFLE: if (t == null) { t = T.INT; oValue = CmpType.T_LE; } // fall through case Opcodes.IFLT: if (t == null) { t = T.INT; oValue = CmpType.T_LT; } // fall through case Opcodes.IFNE: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_NE; } { assert oValue instanceof CmpType; final JCND op = new JCND(this.ops.size(), opcode, this.line, t, (CmpType) oValue); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } } break; /******* * JSR * *******/ case Opcodes.JSR: { final JSR op = new JSR(this.ops.size(), opcode, this.line); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } break; } default: log.warn(getM() + ": Unknown jump insn opcode '" + opcode + "'!"); } }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AbstractCreateDispatchCodeAdapter.java
License:Open Source License
protected InsnList createInstructionsToCheackTeams(MethodNode method) { // if (teams == null) { // break; // }//w w w .java 2 s.com InsnList instructions = new InsnList(); instructions.add(new InsnNode(Opcodes.DUP)); LabelNode label = new LabelNode(); instructions.add(new JumpInsnNode(Opcodes.IFNONNULL, label)); instructions.add(new InsnNode(Opcodes.POP)); instructions.add(new JumpInsnNode(Opcodes.GOTO, findBreakLabel(method.instructions))); instructions.add(label); return instructions; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AddGlobalTeamActivationAdapter.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { synchronized (AddGlobalTeamActivationAdapter.class) { if (!done && isMainMethod(name, desc, access)) { done = true;//from www.ja va2 s. c om final MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, null, null); return new AdviceAdapter(this.api, methodVisitor, access, name, desc) { @Override protected void onMethodEnter() { List<String> teams = getTeamsFromConfigFile(); for (String aTeam : teams) { Label start, end, typeHandler, ctorHandler, after; String aTeamSlash = aTeam.replace('.', '/'); // new SomeTeam(): methodVisitor.visitLabel(start = new Label()); methodVisitor.visitTypeInsn(Opcodes.NEW, aTeamSlash); // .activate(Team.ALL_THREADS): methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, aTeamSlash, "<init>", "()V", false); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, ClassNames.TEAM_SLASH, "ALL_THREADS", "Ljava/lang/Thread;"); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, aTeamSlash, "activate", "(Ljava/lang/Thread;)V", false); methodVisitor.visitLabel(end = new Label()); methodVisitor.visitJumpInsn(Opcodes.GOTO, after = new Label()); // catch (ClassNotFoundException, NoClassDefFoundError): // System.err.println(...) methodVisitor.visitLabel(typeHandler = new Label()); methodVisitor.visitInsn(Opcodes.POP); // discard the exception methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); methodVisitor.visitLdcInsn("Config error: Team class '" + aTeam + "' in config file '" + TEAM_CONFIG_FILE + "' can not be found!"); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); methodVisitor.visitJumpInsn(Opcodes.GOTO, after); methodVisitor.visitTryCatchBlock(start, end, typeHandler, "java/lang/ClassNotFoundException"); // dup to avoid stackmap errors (ASM bug at 1.8) methodVisitor.visitLabel(typeHandler = new Label()); methodVisitor.visitInsn(Opcodes.POP); // discard the exception methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); methodVisitor.visitLdcInsn("Config error: Team class '" + aTeam + "' in config file '" + TEAM_CONFIG_FILE + "' can not be found!"); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); methodVisitor.visitJumpInsn(Opcodes.GOTO, after); // methodVisitor.visitTryCatchBlock(start, end, typeHandler, "java/lang/NoClassDefFoundError"); // catch (NoSuchMethodError): // System.err.println(...) methodVisitor.visitLabel(ctorHandler = new Label()); methodVisitor.visitInsn(Opcodes.POP); // discard the exception methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;"); methodVisitor.visitLdcInsn( "Activation failed: Team class '" + aTeam + "' has no default constuctor!"); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); methodVisitor.visitTryCatchBlock(start, end, ctorHandler, "java/lang/NoSuchMethodError"); methodVisitor.visitLabel(after); } } @Override public void visitMaxs(int maxStack, int maxLocals) { super.visitMaxs(Math.max(maxStack, 3), maxLocals); } }; } return null; } }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateAddRemoveRoleMethod.java
License:Open Source License
@Override protected boolean transform() { // void _OT$addRemoveRole(Object role, boolean isAdding) { MethodNode method = getMethod(ConstantMembers.addOrRemoveRole); final int ROLE_SLOT = 1, IS_ADDING_SLOT = 2; Label start = new Label(), end = new Label(); method.instructions.clear();//from www .ja v a 2s.c o m method.visitLabel(start); // set = <initialized _OT$roleSet;> final int SET_SLOT = 3; method.visitLocalVariable("set", "Ljava/util/Set;", null, start, end, SET_SLOT); genGetInitializedRoleSet(method.instructions, SET_SLOT); // if (isAdding) { method.instructions.add(new IntInsnNode(Opcodes.ILOAD, IS_ADDING_SLOT)); LabelNode jumpToRemove = new LabelNode(); method.instructions.add(new JumpInsnNode(Opcodes.IFEQ, jumpToRemove)); // set.add(role); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, SET_SLOT)); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, ROLE_SLOT)); method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, ClassNames.HASH_SET_SLASH, "add", "(Ljava/lang/Object;)Z", false)); method.instructions.add(new InsnNode(Opcodes.POP)); LabelNode jumpToEnd = new LabelNode(); method.instructions.add(new JumpInsnNode(Opcodes.GOTO, jumpToEnd)); // } else { method.instructions.add(jumpToRemove); // set.remove(role); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, SET_SLOT)); method.instructions.add(new IntInsnNode(Opcodes.ALOAD, ROLE_SLOT)); method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, ClassNames.HASH_SET_SLASH, "remove", "(Ljava/lang/Object;)Z", false)); method.instructions.add(new InsnNode(Opcodes.POP)); method.instructions.add(jumpToEnd); // } method.instructions.add(new InsnNode(Opcodes.RETURN)); method.visitLabel(end); // } // maxs are computed, maxStack from flow, maxLocals from localVariable-slots return true; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateSwitchForCallAllBindingsNode.java
License:Open Source License
@Override protected void addInstructionForDefaultLabel(MethodNode method) { gotoLabel = new LabelNode(); method.instructions.add(new JumpInsnNode(Opcodes.GOTO, gotoLabel)); }