List of usage examples for org.objectweb.asm Opcodes IFNONNULL
int IFNONNULL
To view the source code for org.objectweb.asm Opcodes IFNONNULL.
Click Source Link
From source file:lucee.transformer.bytecode.statement.tag.TagTry2.java
License:Open Source License
@Override public void _writeOut(BytecodeContext bc) throws TransformerException { GeneratorAdapter adapter = bc.getAdapter(); adapter.visitLabel(begin);/* w ww . j ava2s. c o m*/ Body tryBody = new BodyBase(getFactory()); List<Tag> catches = new ArrayList<Tag>(); Tag tmpFinal = null; tryBody.setParent(getBody().getParent()); List<Statement> statements = getBody().getStatements(); Statement stat; Tag tag; { Iterator<Statement> it = statements.iterator(); while (it.hasNext()) { stat = it.next(); if (stat instanceof Tag) { tag = (Tag) stat; if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Catch")) { catches.add(tag); continue; } else if (tag.getTagLibTag().getTagClassDefinition() .isClassNameEqualTo("lucee.runtime.tag.Finally")) { tmpFinal = tag; continue; } } tryBody.addStatement(stat); } ; } final Tag _finally = tmpFinal; // has no try body, if there is no try body, no catches are executed, only finally if (!tryBody.hasStatements()) { if (_finally != null && _finally.getBody() != null) { BodyBase.writeOut(bc, _finally.getBody()); //ExpressionUtil.writeOut(_finally.getBody(), bc); } return; } TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(new OnFinally() { @Override public void _writeOut(BytecodeContext bc) throws TransformerException { if (_finally != null) { ExpressionUtil.visitLine(bc, _finally.getStart()); BodyBase.writeOut(bc, _finally.getBody()); //ExpressionUtil.writeOut(_finally.getBody(), bc); } } }, getFlowControlFinal()); // Try tcfv.visitTryBegin(bc); BodyBase.writeOut(bc, tryBody); //ExpressionUtil.writeOut(tryBody, bc); int e = tcfv.visitTryEndCatchBeging(bc); // if(e instanceof lucee.runtime.exp.Abort) throw e; Label abortEnd = new Label(); adapter.loadLocal(e); // Abort.isAbort(t); adapter.invokeStatic(Types.ABORT, TryCatchFinally.IS_ABORT); //adapter.instanceOf(Types.ABORT); adapter.ifZCmp(Opcodes.IFEQ, abortEnd); adapter.loadLocal(e); adapter.throwException(); adapter.visitLabel(abortEnd); // PageExceptionImpl old=pc.getCatch(); int oldPE = adapter.newLocal(Types.PAGE_EXCEPTION); int oldName = adapter.newLocal(Types.STRING); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_CATCH); adapter.storeLocal(oldPE); adapter.loadArg(0); adapter.checkCast(Types.PAGE_CONTEXT_IMPL); adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, GET_CATCH_NAME); adapter.storeLocal(oldName); // PageException pe=Caster.toPageEception(e); int pe = adapter.newLocal(Types.PAGE_EXCEPTION); adapter.loadLocal(e); adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION); adapter.storeLocal(pe); Iterator<Tag> it = catches.iterator(); Attribute attrType; Expression type; Label endAllIfs = new Label(); Tag tagElse = null; while (it.hasNext()) { tag = it.next(); Label endIf = new Label(); // type attrType = tag.getAttribute("type"); type = bc.getFactory().createLitString("any"); if (attrType != null) type = attrType.getValue(); if (type instanceof LitString && ((LitString) type).getString().equalsIgnoreCase("any")) { tagElse = tag; continue; } ExpressionUtil.visitLine(bc, tag.getStart()); // if(pe.typeEqual(@type) adapter.loadLocal(pe); type.writeOut(bc, Expression.MODE_REF); adapter.invokeVirtual(Types.PAGE_EXCEPTION, TYPE_EQUAL); adapter.ifZCmp(Opcodes.IFEQ, endIf); catchBody(bc, adapter, tag, pe, true, true, extractName(tag)); adapter.visitJumpInsn(Opcodes.GOTO, endAllIfs); adapter.visitLabel(endIf); } // else if (tagElse != null) { catchBody(bc, adapter, tagElse, pe, true, true, extractName(tagElse)); } else { // pc.setCatch(pe,true); adapter.loadArg(0); adapter.loadLocal(pe); adapter.push(false); adapter.push(true); adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH3); //throw pe; adapter.loadLocal(pe); adapter.throwException(); } adapter.visitLabel(endAllIfs); adapter.loadLocal(oldName); Label notNull = new Label(); adapter.visitJumpInsn(Opcodes.IFNONNULL, notNull); // NULL adapter.loadArg(0); adapter.loadLocal(oldPE); adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH_PE); Label end = new Label(); adapter.visitJumpInsn(Opcodes.GOTO, end); adapter.visitLabel(notNull); // NOT NULL adapter.loadArg(0); adapter.checkCast(Types.PAGE_CONTEXT_IMPL); adapter.loadLocal(oldPE); adapter.loadLocal(oldName); adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, SET_CATCH_PE2); adapter.visitLabel(end); tcfv.visitCatchEnd(bc); }
From source file:name.martingeisse.minimal.compiler.Compiler.java
License:Open Source License
/** * Compiles a {@link MethodNode} to MCode. * //from w w w . j ava 2 s . 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:net.sourceforge.cobertura.instrument.pass3.AtomicArrayCodeProvider.java
License:GNU General Public License
public void generateCINITmethod(MethodVisitor mv, String className, int counters_cnt) { mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, l1); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(AtomicIntegerArray.class)); mv.visitInsn(Opcodes.DUP);/*from www .j a va2s. c o m*/ mv.visitLdcInsn(counters_cnt); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(AtomicIntegerArray.class), "<init>", "(I)V"); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); generateRegisterClass(mv, className); mv.visitLabel(l1); }
From source file:net.sourceforge.cobertura.instrument.pass3.FastArrayCodeProvider.java
License:GNU General Public License
public void generateCINITmethod(MethodVisitor mv, String className, int counters_cnt) { mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, l1); mv.visitLdcInsn(counters_cnt);/*from w ww . ja v a 2s. c o m*/ mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); generateRegisterClass(mv, className); mv.visitLabel(l1); }
From source file:net.sourceforge.cobertura.instrument.pass3.TestUnitCodeProvider.java
License:GNU General Public License
/** * Generates:/*from w w w . ja v a 2 s . c o m*/ * public static void __cobertura_init() * { * if (__cobertura_counters == null) * { * __cobertura_counters = new TestUnitInformationHolder[class.length]; * } * TouchCollector.registerClass("mypackage/HelloWorld"); * } */ public void generateCINITmethod(MethodVisitor mv, String className, int counters_cnt) { mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, l1); mv.visitLdcInsn(counters_cnt); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(TestUnitInformationHolder.class)); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 1); Label l11 = new Label(); mv.visitLabel(l11); Label l2 = new Label(); mv.visitJumpInsn(GOTO, l2); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(24, l3); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { Opcodes.INTEGER }, 0, null); mv.visitFieldInsn(GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(ILOAD, 1); mv.visitTypeInsn(NEW, "net/sourceforge/cobertura/coveragedata/TestUnitInformationHolder"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "net/sourceforge/cobertura/coveragedata/TestUnitInformationHolder", "<init>", "()V"); mv.visitInsn(AASTORE); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLineNumber(23, l4); mv.visitIincInsn(1, 1); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, 1); mv.visitFieldInsn(GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitInsn(ARRAYLENGTH); mv.visitJumpInsn(IF_ICMPLT, l3); mv.visitLabel(l1); generateRegisterClass(mv, className); }
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 w w . j a v a 2s. c o m 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.IsNullCondition.java
License:Apache License
public Operation jumpWhenFalse(Label label) { return new JumpOperation(Opcodes.IFNONNULL, _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 2 s. com 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.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); // }/*from w w w.j a v a 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.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static void createMethodCheck(final String enhancedClassName, final String descEnhancer, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PRIVATE, Enhancer.METHOD_ENHANCED_CHECK, Enhancer.makeDescription(Void.TYPE), null, null); mv.visitCode();//from ww w . j a v a2 s .c o m final Label lCheckInternal = new Label(); final Label lCheckInitialized = new Label(); final Label lReturn = new Label(); final Label lFind = new Label(); final Label lInitialized = new Label(); final Label lChanged = new Label(); final Label lOut = new Label(); // if (!this.__enhanced__$$__internal) { return } mv.visitLabel(lCheckInternal); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INTERNAL, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitJumpInsn(Opcodes.IFEQ, lCheckInitialized); mv.visitInsn(Opcodes.RETURN); // if (!this.__enhanced__$$__initialized) { mv.visitLabel(lCheckInitialized); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitJumpInsn(Opcodes.IFNE, lChanged); // if (this.__enhanced_$$__session == null) mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitJumpInsn(Opcodes.IFNONNULL, lFind); // throw new PersistenceException("No session to initialize the instance"); mv.visitTypeInsn(Opcodes.NEW, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("No session to initialize the instance"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Enhancer.INTERNAL_PERSISTENCE_EXCEPTION, Enhancer.CONSTRUCTOR_INIT, Enhancer.makeDescription(Void.TYPE, String.class)); mv.visitInsn(Opcodes.ATHROW); // this.__enhanced_$$__session.getEntityManager().find(this.__enhanced_$$__type, this.__enhanced__$$__id); mv.visitLabel(lFind); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_SESSION, Enhancer.METHOD_GET_ENTITY_MANAGER, Enhancer.makeDescription(EntityManagerImpl.class)); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_TYPE, Enhancer.DESCRIPTOR_CLASS); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_ID, Enhancer.DESCRIPTOR_OBJECT); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_ENTITY_MANAGER, Enhancer.METHOD_FIND, Enhancer.makeDescription(Object.class, Class.class, Object.class)); mv.visitInsn(Opcodes.POP); // this.__enhanced__$$__initialized = true; mv.visitLabel(lInitialized); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_1); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); // if (this.__enhanced_$$__session != null) mv.visitLabel(lChanged); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitJumpInsn(Opcodes.IFNULL, lReturn); // this.__enhanced__$$__managedInstance.changed(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_MANAGED_INSTANCE, Enhancer.DESCRIPTOR_MANAGED_INSTANCE); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Enhancer.INTERNAL_MANAGED_INSTANCE, Enhancer.METHOD_CHANGED, Enhancer.makeDescription(Void.TYPE)); // return; mv.visitLabel(lReturn); mv.visitFrame(Opcodes.F_NEW, 1, new Object[] { enhancedClassName }, 0, new Object[] {}); mv.visitInsn(Opcodes.RETURN); mv.visitLabel(lOut); mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, lCheckInternal, lOut, 0); mv.visitMaxs(0, 0); mv.visitEnd(); }