List of usage examples for org.objectweb.asm Opcodes IFEQ
int IFEQ
To view the source code for org.objectweb.asm Opcodes IFEQ.
Click Source Link
From source file:lucee.transformer.bytecode.visitor.ForDoubleVisitor.java
License:Open Source License
public void visitAfterExpressionBeginBody(GeneratorAdapter adapter) { adapter.ifZCmp(Opcodes.IFEQ, afterBody); }
From source file:lucee.transformer.bytecode.visitor.IfVisitor.java
License:Open Source License
public void visitAfterExpressionBeforeBody(BytecodeContext bc) { bc.getAdapter().ifZCmp(Opcodes.IFEQ, end); }
From source file:lucee.transformer.bytecode.visitor.NotVisitor.java
License:Open Source License
public static void visitNot(BytecodeContext bc) { GeneratorAdapter adapter = bc.getAdapter(); Label l1 = new Label(); adapter.visitJumpInsn(Opcodes.IFEQ, l1); adapter.visitInsn(Opcodes.ICONST_0); Label l2 = new Label(); adapter.visitJumpInsn(Opcodes.GOTO, l2); adapter.visitLabel(l1);//from w w w . j a va 2s.c o m adapter.visitInsn(Opcodes.ICONST_1); adapter.visitLabel(l2); }
From source file:name.martingeisse.minimal.compiler.Compiler.java
License:Open Source License
/** * Compiles a {@link MethodNode} to MCode. * /* w ww .j a v a 2s.c o m*/ * @param methodNode the method node to compile * @return the compiled code */ public ImmutableList<MCodeEntry> compile(final MethodNode methodNode) { for (int i = 0; i < methodNode.instructions.size(); i++) { final AbstractInsnNode instruction = methodNode.instructions.get(i); if (instruction instanceof LineNumberNode) { // ignored } else if (instruction instanceof FrameNode) { // this could be useful in the future } else if (instruction instanceof LabelNode) { label(((LabelNode) instruction).getLabel()); } else if (instruction instanceof InsnNode) { switch (instruction.getOpcode()) { case Opcodes.ICONST_M1: iconst(-1); break; case Opcodes.ICONST_0: iconst(0); break; case Opcodes.ICONST_1: iconst(1); break; case Opcodes.ICONST_2: iconst(2); break; case Opcodes.ICONST_3: iconst(3); break; case Opcodes.ICONST_4: iconst(4); break; case Opcodes.ICONST_5: iconst(5); break; default: unsupported(instruction); break; } } else if (instruction instanceof VarInsnNode) { final VarInsnNode varInsnNode = (VarInsnNode) instruction; switch (varInsnNode.getOpcode()) { case Opcodes.ILOAD: iload(varInsnNode.var); break; case Opcodes.ISTORE: istore(varInsnNode.var); break; default: unsupported(instruction); break; } } else if (instruction instanceof IincInsnNode) { final IincInsnNode iincInsnNode = (IincInsnNode) instruction; iinc(iincInsnNode.var, iincInsnNode.incr); } else if (instruction instanceof JumpInsnNode) { final JumpInsnNode jumpInsnNode = (JumpInsnNode) instruction; switch (jumpInsnNode.getOpcode()) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: branch1(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode()); break; case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: branch2(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode()); break; case Opcodes.IFNULL: case Opcodes.IFNONNULL: // unsupported: one-argument reference comparison operator unsupported(instruction); break; case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: // unsupported: two-argument reference comparison operator unsupported(instruction); break; case Opcodes.GOTO: jump(jumpInsnNode.label.getLabel()); break; case Opcodes.JSR: jsr(jumpInsnNode.label.getLabel()); break; default: unsupported(instruction); break; } } else if (instruction instanceof IntInsnNode) { final IntInsnNode intInsnNode = (IntInsnNode) instruction; if (instruction.getOpcode() == Opcodes.BIPUSH || instruction.getOpcode() == Opcodes.SIPUSH) { iconst(intInsnNode.operand); } else { // NEWARRAY unsupported(instruction); } } else if (instruction instanceof MethodInsnNode) { final MethodInsnNode methodInsnNode = (MethodInsnNode) instruction; if (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC) { if (methodInsnNode.owner.replace('/', '.').equals(Native.class.getName())) { nativeCall(methodInsnNode.name, methodInsnNode.desc); } else { unsupported(instruction); } } else { unsupported(instruction); } } else { unsupported(instruction); } } return builder.build(); }
From source file:name.martingeisse.minimal.compiler.Compiler.java
License:Open Source License
private MBinaryIntegerOperator mapOperator(final int jvmOpcode) { switch (jvmOpcode) { case Opcodes.IFEQ: case Opcodes.IF_ICMPEQ: return MBinaryIntegerOperator.EQUAL; case Opcodes.IFNE: case Opcodes.IF_ICMPNE: return MBinaryIntegerOperator.NOT_EQUAL; case Opcodes.IFLT: case Opcodes.IF_ICMPLT: return MBinaryIntegerOperator.LESS_THAN; case Opcodes.IFLE: case Opcodes.IF_ICMPLE: return MBinaryIntegerOperator.LESS_THAN_OR_EQUAL; case Opcodes.IFGT: case Opcodes.IF_ICMPGT: return MBinaryIntegerOperator.GREATER_THAN; case Opcodes.IFGE: case Opcodes.IF_ICMPGE: return MBinaryIntegerOperator.GREATER_THAN_OR_EQUAL; default://from w w w. j a va 2 s . co m throw new IllegalArgumentException("cannot map comparison operator for JVM opcode: " + jvmOpcode); } }
From source file:net.minecraftforge.fml.common.asm.transformers.SoundEngineFixTransformer.java
License:Open Source License
@Override public byte[] transform(String name, String transformedName, byte[] basicClass) { if (transformedName.equals("paulscode.sound.Source")) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); classNode.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "removed", "Z", null, null)); // adding field 'public boolean removed;' ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer);/*from w w w .j av a 2s.c o m*/ return writer.toByteArray(); } else if (transformedName.equals("paulscode.sound.Library")) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); MethodNode method = null; for (MethodNode m : classNode.methods) { if (m.name.equals("removeSource") && m.desc.equals("(Ljava/lang/String;)V")) // trying to find paulscode.sound.Library.removeSource(String) { method = m; break; } } if (method == null) throw new RuntimeException( "Error processing " + transformedName + " - no removeSource method found"); AbstractInsnNode referenceNode = null; for (Iterator<AbstractInsnNode> iterator = method.instructions.iterator(); iterator.hasNext();) { AbstractInsnNode insn = iterator.next(); if (insn instanceof MethodInsnNode && ((MethodInsnNode) insn).owner.equals("paulscode/sound/Source") // searching for mySource.cleanup() node (line 1086) && ((MethodInsnNode) insn).name.equals("cleanup")) { referenceNode = insn; break; } } if (referenceNode != null) { LabelNode after = (LabelNode) referenceNode.getNext(); AbstractInsnNode beginning = referenceNode.getPrevious(); int varIndex = ((VarInsnNode) beginning).var; method.instructions.insertBefore(beginning, new VarInsnNode(Opcodes.ALOAD, varIndex)); // adding extra if (mySource.toStream) method.instructions.insertBefore(beginning, new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/Source", "toStream", "Z")); LabelNode elseNode = new LabelNode(); method.instructions.insertBefore(beginning, new JumpInsnNode(Opcodes.IFEQ, elseNode)); // if fails (else) -> go to mySource.cleanup(); method.instructions.insertBefore(beginning, new VarInsnNode(Opcodes.ALOAD, varIndex)); // if (mySource.toStream) { mySource.removed = true; } method.instructions.insertBefore(beginning, new InsnNode(Opcodes.ICONST_1)); method.instructions.insertBefore(beginning, new FieldInsnNode(Opcodes.PUTFIELD, "paulscode/sound/Source", "removed", "Z")); method.instructions.insertBefore(beginning, new JumpInsnNode(Opcodes.GOTO, after)); // still inside if -> jump to sourceMap.remove( sourcename ); method.instructions.insertBefore(beginning, elseNode); } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); } else if (transformedName.equals("paulscode.sound.StreamThread")) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); MethodNode method = null; for (MethodNode m : classNode.methods) { if (m.name.equals("run") && m.desc.equals("()V")) // trying to find paulscode.sound.StreamThread.run(); { method = m; break; } } if (method == null) throw new RuntimeException("Error processing " + transformedName + " - no run method found"); AbstractInsnNode referenceNode = null; for (Iterator<AbstractInsnNode> iterator = method.instructions.iterator(); iterator.hasNext();) { AbstractInsnNode insn = iterator.next(); if (insn instanceof MethodInsnNode && ((MethodInsnNode) insn).owner.equals("java/util/ListIterator") // searching for 'src = iter.next();' node (line 110) && ((MethodInsnNode) insn).name.equals("next")) { referenceNode = insn.getNext().getNext(); break; } } if (referenceNode != null) { int varIndex = ((VarInsnNode) referenceNode).var; LabelNode after = (LabelNode) referenceNode.getNext(); method.instructions.insertBefore(after, new VarInsnNode(Opcodes.ALOAD, varIndex)); // add if(removed) method.instructions.insertBefore(after, new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/Source", "removed", "Z")); method.instructions.insertBefore(after, new JumpInsnNode(Opcodes.IFEQ, after)); // if the source has been marked as removed, clean it up and set the variable to null so it will be removed from the list method.instructions.insertBefore(after, new VarInsnNode(Opcodes.ALOAD, varIndex)); // src.cleanup(); method.instructions.insertBefore(after, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "paulscode/sound/Source", "cleanup", "()V", false)); method.instructions.insertBefore(after, new InsnNode(Opcodes.ACONST_NULL)); // src = null; method.instructions.insertBefore(after, new VarInsnNode(Opcodes.ASTORE, varIndex)); } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); } return basicClass; }
From source file:org.actorsguildframework.internal.codegenerator.BeanCreator.java
License:Apache License
/** * Writes the bean constructor to the given ClassWriter. * @param beanClass the original bean class to extend * @param bcd the descriptor of the bean * @param classNameInternal the internal name of the new class * @param cw the ClassWriter to write to * @param snippetWriter if not null, this will be invoked to add a snippet * after the invocation of the super constructor *//*from w ww . j ava 2 s. c om*/ public static void writeConstructor(Class<?> beanClass, BeanClassDescriptor bcd, String classNameInternal, ClassWriter cw, SnippetWriter snippetWriter) { String classNameDescriptor = "L" + classNameInternal + ";"; int localPropertySize = 0; ArrayList<PropertyDescriptor> localVarProperties = new ArrayList<PropertyDescriptor>(); for (int i = 0; i < bcd.getPropertyCount(); i++) { PropertyDescriptor pd = bcd.getProperty(i); if (pd.getPropertySource().isGenerating() || (pd.getDefaultValue() != null)) { localVarProperties.add(pd); localPropertySize += Type.getType(pd.getPropertyClass()).getSize(); } } final int locVarThis = 0; final int locVarController = 1; final int locVarProps = 2; final int locVarPropertiesOffset = 3; final int locVarP = 3 + localPropertySize; final int locVarK = 4 + localPropertySize; final int locVarV = 5 + localPropertySize; MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/actorsguildframework/internal/Controller;Lorg/actorsguildframework/Props;)V", null, null); mv.visitCode(); Label lTry = new Label(); Label lCatch = new Label(); mv.visitTryCatchBlock(lTry, lCatch, lCatch, "java/lang/ClassCastException"); Label lBegin = new Label(); mv.visitLabel(lBegin); mv.visitVarInsn(Opcodes.ALOAD, locVarThis); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(beanClass), "<init>", "()V"); if (snippetWriter != null) snippetWriter.write(mv); Label lPropertyInit = new Label(); mv.visitLabel(lPropertyInit); // load default values into the local variables for each property that must be set int varCount = 0; for (PropertyDescriptor pd : localVarProperties) { Type pt = Type.getType(pd.getPropertyClass()); if (pd.getDefaultValue() != null) mv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(pd.getDefaultValue().getDeclaringClass()), pd.getDefaultValue().getName(), Type.getDescriptor(pd.getDefaultValue().getType())); else GenerationUtils.generateLoadDefault(mv, pd.getPropertyClass()); mv.visitVarInsn(pt.getOpcode(Opcodes.ISTORE), locVarPropertiesOffset + varCount); varCount += pt.getSize(); } // loop through the props argument's list mv.visitVarInsn(Opcodes.ALOAD, locVarProps); mv.visitVarInsn(Opcodes.ASTORE, locVarP); Label lWhile = new Label(); Label lEndWhile = new Label(); Label lWhileBody = new Label(); mv.visitLabel(lWhile); mv.visitJumpInsn(Opcodes.GOTO, lEndWhile); mv.visitLabel(lWhileBody); mv.visitVarInsn(Opcodes.ALOAD, locVarP); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/actorsguildframework/Props", "getKey", "()Ljava/lang/String;"); mv.visitVarInsn(Opcodes.ASTORE, locVarK); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/actorsguildframework/Props", "getValue", "()Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ASTORE, locVarV); mv.visitLabel(lTry); // write an if for each property Label lEndIf = new Label(); varCount = 0; int ifCount = 0; for (int i = 0; i < bcd.getPropertyCount(); i++) { PropertyDescriptor pd = bcd.getProperty(i); boolean usesLocal = pd.getPropertySource().isGenerating() || (pd.getDefaultValue() != null); Class<?> propClass = pd.getPropertyClass(); Type pt = Type.getType(propClass); mv.visitVarInsn(Opcodes.ALOAD, locVarK); mv.visitLdcInsn(pd.getName()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z"); Label lElse = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, lElse); if (!usesLocal) mv.visitVarInsn(Opcodes.ALOAD, locVarThis); // for setter invocation, load 'this' if (propClass.isPrimitive()) { mv.visitLdcInsn(pd.getName()); mv.visitVarInsn(Opcodes.ALOAD, locVarV); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(BeanHelper.class), String.format("get%s%sFromPropValue", propClass.getName().substring(0, 1).toUpperCase(Locale.US), propClass.getName().substring(1)), "(Ljava/lang/String;Ljava/lang/Object;)" + pt.getDescriptor()); } else if (!propClass.equals(Object.class)) { mv.visitVarInsn(Opcodes.ALOAD, locVarV); mv.visitTypeInsn(Opcodes.CHECKCAST, pt.getInternalName()); } else mv.visitVarInsn(Opcodes.ALOAD, locVarV); if (!usesLocal) mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classNameInternal, pd.getSetter().getName(), Type.getMethodDescriptor(pd.getSetter())); else mv.visitVarInsn(pt.getOpcode(Opcodes.ISTORE), varCount + locVarPropertiesOffset); mv.visitJumpInsn(Opcodes.GOTO, lEndIf); mv.visitLabel(lElse); ifCount++; if (usesLocal) varCount += pt.getSize(); } // else (==> if not prop matched) throw IllegalArgumentException mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(IllegalArgumentException.class)); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("Unknown property \"%s\"."); mv.visitInsn(Opcodes.ICONST_1); mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ALOAD, locVarK); mv.visitInsn(Opcodes.AASTORE); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/String", "format", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(IllegalArgumentException.class), "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(lCatch); mv.visitInsn(Opcodes.POP); // pop the exception object (not needed) mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(IllegalArgumentException.class)); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("Incompatible type for property \"%s\". Got %s."); mv.visitInsn(Opcodes.ICONST_2); mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ALOAD, locVarK); mv.visitInsn(Opcodes.AASTORE); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.ICONST_1); mv.visitVarInsn(Opcodes.ALOAD, locVarV); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;"); mv.visitInsn(Opcodes.AASTORE); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/String", "format", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(IllegalArgumentException.class), "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(lEndIf); mv.visitVarInsn(Opcodes.ALOAD, locVarP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/actorsguildframework/Props", "tail", "()Lorg/actorsguildframework/Props;"); mv.visitVarInsn(Opcodes.ASTORE, locVarP); mv.visitLabel(lEndWhile); mv.visitVarInsn(Opcodes.ALOAD, locVarP); mv.visitJumpInsn(Opcodes.IFNONNULL, lWhileBody); // write local variables back into properties varCount = 0; for (PropertyDescriptor pd : localVarProperties) { Type pt = Type.getType(pd.getPropertyClass()); mv.visitVarInsn(Opcodes.ALOAD, locVarThis); if (pd.getPropertySource() == PropertySource.ABSTRACT_METHOD) { mv.visitVarInsn(pt.getOpcode(Opcodes.ILOAD), locVarPropertiesOffset + varCount); mv.visitFieldInsn(Opcodes.PUTFIELD, classNameInternal, String.format(PROP_FIELD_NAME_TEMPLATE, pd.getName()), pt.getDescriptor()); } else if (pd.getPropertySource() == PropertySource.USER_WRITTEN) { mv.visitVarInsn(pt.getOpcode(Opcodes.ILOAD), locVarPropertiesOffset + varCount); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classNameInternal, pd.getSetter().getName(), Type.getMethodDescriptor(pd.getSetter())); } else throw new RuntimeException("Internal error"); varCount += pt.getSize(); } // if bean is thread-safe, publish all writes now if (bcd.isThreadSafe()) { mv.visitVarInsn(Opcodes.ALOAD, locVarThis); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.MONITORENTER); mv.visitInsn(Opcodes.MONITOREXIT); } mv.visitInsn(Opcodes.RETURN); Label lEnd = new Label(); mv.visitLabel(lEnd); mv.visitLocalVariable("this", classNameDescriptor, null, lBegin, lEnd, locVarThis); mv.visitLocalVariable("controller", "Lorg/actorsguildframework/internal/Controller;", null, lBegin, lEnd, locVarController); mv.visitLocalVariable("props", "Lorg/actorsguildframework/Props;", null, lBegin, lEnd, locVarProps); varCount = 0; for (PropertyDescriptor pd : localVarProperties) { Type pt = Type.getType(pd.getPropertyClass()); mv.visitLocalVariable("__" + pd.getName(), pt.getDescriptor(), GenericTypeHelper.getSignature(pd.getPropertyType()), lPropertyInit, lEnd, locVarPropertiesOffset + varCount); varCount += pt.getSize(); } mv.visitLocalVariable("p", "Lorg/actorsguildframework/Props;", null, lPropertyInit, lEnd, locVarP); mv.visitLocalVariable("k", "Ljava/lang/String;", null, lWhile, lEndWhile, locVarK); mv.visitLocalVariable("v", "Ljava/lang/Object;", null, lWhile, lEndWhile, locVarV); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.adjective.stout.loop.ExpressionCondition.java
License:Apache License
public Operation jumpWhenFalse(Label label) { return new JumpOperation(Opcodes.IFEQ, _expression, label); }
From source file:org.adjective.stout.operation.JumpOperation.java
License:Apache License
public void getInstructions(ExecutionStack stack, InstructionCollector collector) { switch (_op) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: checkExpression(TypeDescriptor.INT, stack); break;// ww w . j a v a 2s . c o m case Opcodes.IFNULL: case Opcodes.IFNONNULL: checkExpression(TypeDescriptor.OBJECT, stack); break; default: throw new IllegalStateException("Do not know how to handle jump opcode " + getOpcodeDescription(_op)); } _expression.getInstructions(stack, collector); collector.add(new JumpInstruction(_op, _label)); }
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 ww . jav 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]); }