List of usage examples for org.objectweb.asm Opcodes ARRAYLENGTH
int ARRAYLENGTH
To view the source code for org.objectweb.asm Opcodes ARRAYLENGTH.
Click Source Link
From source file:edu.ubc.mirrors.holograms.HologramMethodGenerator.java
License:Open Source License
@Override public void visitInsn(int opcode) { Type arrayElementType = null; boolean isArrayLoad = (Opcodes.IALOAD <= opcode && opcode < Opcodes.IALOAD + 8); boolean isArrayStore = (Opcodes.IASTORE <= opcode && opcode < Opcodes.IASTORE + 8); if (isArrayLoad || isArrayStore) { switch (opcode) { case Opcodes.IALOAD: arrayElementType = Type.INT_TYPE; break; case Opcodes.LALOAD: arrayElementType = Type.LONG_TYPE; break; case Opcodes.FALOAD: arrayElementType = Type.FLOAT_TYPE; break; case Opcodes.DALOAD: arrayElementType = Type.DOUBLE_TYPE; break; case Opcodes.AALOAD: arrayElementType = hologramType; break; case Opcodes.BALOAD: arrayElementType = Type.BYTE_TYPE; break; case Opcodes.CALOAD: arrayElementType = Type.CHAR_TYPE; break; case Opcodes.SALOAD: arrayElementType = Type.SHORT_TYPE; break; case Opcodes.IASTORE: arrayElementType = Type.INT_TYPE; break; case Opcodes.LASTORE: arrayElementType = Type.LONG_TYPE; break; case Opcodes.FASTORE: arrayElementType = Type.FLOAT_TYPE; break; case Opcodes.DASTORE: arrayElementType = Type.DOUBLE_TYPE; break; case Opcodes.AASTORE: arrayElementType = hologramType; break; case Opcodes.BASTORE: arrayElementType = Type.BYTE_TYPE; break; case Opcodes.CASTORE: arrayElementType = Type.CHAR_TYPE; break; case Opcodes.SASTORE: arrayElementType = Type.SHORT_TYPE; break; }//from w ww . ja va 2s .c o m Type mirrorType = HologramClassGenerator.objectArrayMirrorType; if (arrayElementType.getSort() != Type.OBJECT && arrayElementType.getSort() != Type.ARRAY) { mirrorType = getPrimitiveArrayMirrorType(arrayElementType); } // Use the analyzer to figure out the expected array element type Type arrayElementTypeForMirrorCall = arrayElementType; Type hologramArrayType = Type .getObjectType((String) stackType(isArrayStore ? 1 + arrayElementType.getSize() : 1)); if (hologramArrayType == null) { hologramArrayType = Type.getType(ObjectArrayHologram.class); } if (arrayElementType.equals(hologramType)) { Type originalType = Type .getObjectType(getOriginalInternalClassName(hologramArrayType.getInternalName())); arrayElementType = getHologramType( Reflection.makeArrayType(originalType.getDimensions() - 1, originalType.getElementType())); hologramArrayType = Type.getType(ObjectArrayHologram.class); } // Call the appropriate getter/setter method on the hologram String methodDesc; if (isArrayStore) { methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, mirrorType, Type.INT_TYPE, arrayElementTypeForMirrorCall); } else { methodDesc = Type.getMethodDescriptor(arrayElementTypeForMirrorCall, mirrorType, Type.INT_TYPE); } invokestatic(hologramArrayType.getInternalName(), (isArrayStore ? "setHologram" : "getHologram"), methodDesc); if (!isArrayStore && arrayElementTypeForMirrorCall.equals(hologramType)) { checkcast(arrayElementType); } return; } if (opcode == Opcodes.ARRAYLENGTH) { invokeinterface(arrayMirrorType.getInternalName(), "length", Type.getMethodDescriptor(Type.INT_TYPE)); return; } if (opcode == Opcodes.ARETURN) { if (isToString) { invokestatic(objectHologramType.getInternalName(), "getRealStringForHologram", Type.getMethodDescriptor(Type.getType(String.class), Type.getType(ObjectHologram.class))); } else if (isGetStackTrace) { invokestatic(objectHologramType.getInternalName(), "getRealStackTraceForHologram", Type.getMethodDescriptor(Type.getType(StackTraceElement[].class), Type.getType(Hologram.class))); } } if (opcode == Opcodes.RETURN && owner.equals(hologramThrowableType) && name.equals("<init>")) { load(0, owner); new MethodHandle() { protected void methodCall() throws Throwable { ObjectHologram.register(null); ; } }.invoke(this); } super.visitInsn(opcode); }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
private void classMapContent(ClassVisitor cv, int nr, List<TouchPointDescriptor> touchPointDescriptors) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_CLASSMAP_METHOD_NAME + "_" + nr, "(" + Type.getType(LightClassmapListener.class).toString() + ")V", null, null); mv.visitCode();//from ww w . ja v a2 s . c om mv.visitVarInsn(Opcodes.ALOAD, 0); for (TouchPointDescriptor tpd : touchPointDescriptors) { mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(tpd.getLineNumber()); if (tpd instanceof LineTouchPointDescriptor) { mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getCounterId()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodName()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodSignature()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putLineTouchPoint", "(IILjava/lang/String;Ljava/lang/String;)V"); } else if (tpd instanceof JumpTouchPointDescriptor) { mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForTrue()); mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForFalse()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putJumpTouchPoint", "(III)V"); } else if (tpd instanceof SwitchTouchPointDescriptor) { SwitchTouchPointDescriptor stpd = (SwitchTouchPointDescriptor) tpd; final String enum_sign = ((SwitchTouchPointDescriptor) tpd).getEnumType(); if (enum_sign == null) { mv.visitLdcInsn(Integer.MAX_VALUE); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, enum_sign, "values", "()[L" + enum_sign + ";"); mv.visitInsn(Opcodes.ARRAYLENGTH); } Collection<Integer> ci = stpd.getCountersForLabels(); mv.visitLdcInsn(ci.size());//Size of a new table mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); int i = 0; for (Integer counterId : ci) { mv.visitInsn(Opcodes.DUP); //First for addition of items, second ad putSwitchTouchPoint parameter (or next loop iteration) mv.visitLdcInsn(i); mv.visitLdcInsn(counterId); mv.visitInsn(Opcodes.IASTORE); i++; } mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putSwitchTouchPoint", "(II[I)V"); } } mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.FastArrayCodeProvider.java
License:GNU General Public License
public void generateCoberturaGetAndResetCountersMethod(ClassVisitor cv, String className) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_GET_AND_RESET_COUNTERS_METHOD_NAME, "()[I", null, null); mv.visitCode();/*from w w w . ja va 2 s . c om*/ /*cobertura_counters.*/ mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(Opcodes.ASTORE, 0); /*cobertura_counters.*/ mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.TestUnitCodeProvider.java
License:GNU General Public License
/** * Generates://w w w. jav a 2s . c om * public static TestUnitInformationHolder[] __cobertura_get_and_reset_counters() * { * TestUnitInformationHolder[] local = __cobertura_counters; * __cobertura_counters = new TestUnitInformationHolder[__cobertura_counters.length]; * return local; * } */ public void generateCoberturaGetAndResetCountersMethod(ClassVisitor cv, String className) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_GET_AND_RESET_COUNTERS_METHOD_NAME, "()" + COBERTURA_COUNTERS_FIELD_TYPE, null, null); mv.visitCode(); /*cobertura_counters.*/ mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(Opcodes.ASTORE, 0); /*cobertura_counters.*/ mv.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(TestUnitInformationHolder.class)); mv.visitFieldInsn(Opcodes.PUTSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitInsn(final int opcode) { T t = null;// ww w . j a va 2 s . co m int iValue = Integer.MIN_VALUE; Object oValue = null; switch (opcode) { case Opcodes.NOP: // nothing to do, ignore break; /******* * ADD * *******/ case Opcodes.DADD: t = T.DOUBLE; // fall through case Opcodes.FADD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IADD: if (t == null) { t = T.INT; } // fall through case Opcodes.LADD: if (t == null) { t = T.LONG; } add(new ADD(this.ops.size(), opcode, this.line, t)); break; /********* * ALOAD * *********/ case Opcodes.AALOAD: t = T.REF; // fall through case Opcodes.BALOAD: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CALOAD: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DALOAD: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FALOAD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IALOAD: if (t == null) { t = T.INT; } // fall through case Opcodes.LALOAD: if (t == null) { t = T.LONG; } // fall through case Opcodes.SALOAD: if (t == null) { t = T.SHORT; } add(new ALOAD(this.ops.size(), opcode, this.line, t)); break; /******* * AND * *******/ case Opcodes.IAND: t = T.AINT; // fall through case Opcodes.LAND: if (t == null) { t = T.LONG; } add(new AND(this.ops.size(), opcode, this.line, t)); break; /*************** * ARRAYLENGTH * ***************/ case Opcodes.ARRAYLENGTH: add(new ARRAYLENGTH(this.ops.size(), opcode, this.line)); break; /********** * ASTORE * **********/ case Opcodes.AASTORE: t = T.REF; // fall through case Opcodes.BASTORE: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CASTORE: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DASTORE: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FASTORE: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IASTORE: if (t == null) { t = T.INT; } // fall through case Opcodes.LASTORE: if (t == null) { t = T.LONG; } // fall through case Opcodes.SASTORE: if (t == null) { t = T.SHORT; } add(new ASTORE(this.ops.size(), opcode, this.line, t)); break; /******** * CAST * ********/ case Opcodes.D2F: t = T.DOUBLE; oValue = T.FLOAT; // fall through case Opcodes.D2I: if (t == null) { t = T.DOUBLE; oValue = T.INT; } // fall through case Opcodes.D2L: if (t == null) { t = T.DOUBLE; oValue = T.LONG; } // fall through case Opcodes.F2D: if (t == null) { t = T.FLOAT; oValue = T.DOUBLE; } // fall through case Opcodes.F2I: if (t == null) { t = T.FLOAT; oValue = T.INT; } // fall through case Opcodes.F2L: if (t == null) { t = T.FLOAT; oValue = T.LONG; } // fall through case Opcodes.I2B: if (t == null) { t = T.INT; oValue = T.BYTE; } // fall through case Opcodes.I2C: if (t == null) { t = T.INT; oValue = T.CHAR; } // fall through case Opcodes.I2D: if (t == null) { t = T.INT; oValue = T.DOUBLE; } // fall through case Opcodes.I2F: if (t == null) { t = T.INT; oValue = T.FLOAT; } // fall through case Opcodes.I2L: if (t == null) { t = T.INT; oValue = T.LONG; } // fall through case Opcodes.I2S: if (t == null) { t = T.INT; oValue = T.SHORT; } // fall through case Opcodes.L2D: if (t == null) { t = T.LONG; oValue = T.DOUBLE; } // fall through case Opcodes.L2F: if (t == null) { t = T.LONG; oValue = T.FLOAT; } // fall through case Opcodes.L2I: if (t == null) { t = T.LONG; oValue = T.INT; } assert oValue instanceof T; add(new CAST(this.ops.size(), opcode, this.line, t, (T) oValue)); break; /******* * CMP * *******/ case Opcodes.DCMPG: t = T.DOUBLE; iValue = CMP.T_G; // fall through case Opcodes.DCMPL: if (t == null) { t = T.DOUBLE; iValue = CMP.T_L; } // fall through case Opcodes.FCMPG: if (t == null) { t = T.FLOAT; iValue = CMP.T_G; } // fall through case Opcodes.FCMPL: if (t == null) { t = T.FLOAT; iValue = CMP.T_L; } // fall through case Opcodes.LCMP: if (t == null) { t = T.LONG; iValue = CMP.T_0; } add(new CMP(this.ops.size(), opcode, this.line, t, iValue)); break; /******* * DIV * *******/ case Opcodes.DDIV: t = T.DOUBLE; // fall through case Opcodes.FDIV: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IDIV: if (t == null) { t = T.INT; } // fall through case Opcodes.LDIV: if (t == null) { t = T.LONG; } add(new DIV(this.ops.size(), opcode, this.line, t)); break; /******* * DUP * *******/ case Opcodes.DUP: oValue = DUP.Kind.DUP; // fall through case Opcodes.DUP_X1: if (oValue == null) { oValue = DUP.Kind.DUP_X1; } // fall through case Opcodes.DUP_X2: if (oValue == null) { oValue = DUP.Kind.DUP_X2; } // fall through case Opcodes.DUP2: if (oValue == null) { oValue = DUP.Kind.DUP2; } // fall through case Opcodes.DUP2_X1: if (oValue == null) { oValue = DUP.Kind.DUP2_X1; } // fall through case Opcodes.DUP2_X2: if (oValue == null) { oValue = DUP.Kind.DUP2_X2; } add(new DUP(this.ops.size(), opcode, this.line, (DUP.Kind) oValue)); break; /*********** * MONITOR * ***********/ case Opcodes.MONITORENTER: oValue = MONITOR.Kind.ENTER; // fall through case Opcodes.MONITOREXIT: if (oValue == null) { oValue = MONITOR.Kind.EXIT; } add(new MONITOR(this.ops.size(), opcode, this.line, (MONITOR.Kind) oValue)); break; /******* * MUL * *******/ case Opcodes.DMUL: t = T.DOUBLE; // fall through case Opcodes.FMUL: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IMUL: if (t == null) { t = T.INT; } // fall through case Opcodes.LMUL: if (t == null) { t = T.LONG; } add(new MUL(this.ops.size(), opcode, this.line, t)); break; /******* * NEG * *******/ case Opcodes.DNEG: t = T.DOUBLE; // fall through case Opcodes.FNEG: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.INEG: if (t == null) { t = T.INT; } // fall through case Opcodes.LNEG: if (t == null) { t = T.LONG; } add(new NEG(this.ops.size(), opcode, this.line, t)); break; /****** * OR * ******/ case Opcodes.IOR: t = T.AINT; // fall through case Opcodes.LOR: if (t == null) { t = T.LONG; } add(new OR(this.ops.size(), opcode, this.line, t)); break; /******* * POP * *******/ case Opcodes.POP: oValue = POP.Kind.POP; // fall through case Opcodes.POP2: if (oValue == null) { oValue = POP.Kind.POP2; } add(new POP(this.ops.size(), opcode, this.line, (POP.Kind) oValue)); break; /******** * PUSH * ********/ case Opcodes.ACONST_NULL: t = T.REF; // fall through case Opcodes.DCONST_0: if (t == null) { oValue = 0D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_0: if (t == null) { oValue = 0F; t = T.FLOAT; } // fall through case Opcodes.ICONST_0: if (t == null) { oValue = 0; t = T.getJvmIntT(0); } // fall through case Opcodes.LCONST_0: if (t == null) { oValue = 0L; t = T.LONG; } // fall through case Opcodes.DCONST_1: if (t == null) { oValue = 1D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_1: if (t == null) { oValue = 1F; t = T.FLOAT; } // fall through case Opcodes.ICONST_1: if (t == null) { oValue = 1; t = T.getJvmIntT(1); } // fall through case Opcodes.LCONST_1: if (t == null) { oValue = 1L; t = T.LONG; } // fall through case Opcodes.FCONST_2: if (t == null) { oValue = 2F; t = T.FLOAT; } // fall through case Opcodes.ICONST_2: if (t == null) { oValue = 2; t = T.getJvmIntT(2); } // fall through case Opcodes.ICONST_3: if (t == null) { oValue = 3; t = T.getJvmIntT(3); } // fall through case Opcodes.ICONST_4: if (t == null) { oValue = 4; t = T.getJvmIntT(4); } // fall through case Opcodes.ICONST_5: if (t == null) { oValue = 5; t = T.getJvmIntT(5); } // fall through case Opcodes.ICONST_M1: if (t == null) { oValue = -1; t = T.getJvmIntT(-1); } add(new PUSH(this.ops.size(), opcode, this.line, t, oValue)); break; /******* * REM * *******/ case Opcodes.DREM: t = T.DOUBLE; // fall through case Opcodes.FREM: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IREM: if (t == null) { t = T.INT; } // fall through case Opcodes.LREM: if (t == null) { t = T.LONG; } add(new REM(this.ops.size(), opcode, this.line, t)); break; /********** * RETURN * **********/ case Opcodes.ARETURN: t = T.REF; // fall through case Opcodes.DRETURN: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FRETURN: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IRETURN: if (t == null) { t = T.AINT; } // fall through case Opcodes.LRETURN: if (t == null) { t = T.LONG; } // fall through case Opcodes.RETURN: if (t == null) { t = T.VOID; } add(new RETURN(this.ops.size(), opcode, this.line, t)); break; /******* * SHL * *******/ case Opcodes.ISHL: t = T.INT; // fall through case Opcodes.LSHL: if (t == null) { t = T.LONG; } add(new SHL(this.ops.size(), opcode, this.line, t, T.INT)); break; /******* * SHR * *******/ case Opcodes.ISHR: case Opcodes.IUSHR: t = T.INT; // fall through case Opcodes.LSHR: case Opcodes.LUSHR: if (t == null) { t = T.LONG; } add(new SHR(this.ops.size(), opcode, this.line, t, T.INT, opcode == Opcodes.IUSHR || opcode == Opcodes.LUSHR)); break; /******* * SUB * *******/ case Opcodes.DSUB: t = T.DOUBLE; // fall through case Opcodes.FSUB: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.ISUB: if (t == null) { t = T.INT; } // fall through case Opcodes.LSUB: if (t == null) { t = T.LONG; } add(new SUB(this.ops.size(), opcode, this.line, t)); break; /******** * SWAP * ********/ case Opcodes.SWAP: add(new SWAP(this.ops.size(), opcode, this.line)); break; /********* * THROW * *********/ case Opcodes.ATHROW: add(new THROW(this.ops.size(), opcode, this.line)); break; /******* * XOR * *******/ case Opcodes.IXOR: t = T.AINT; // fall through case Opcodes.LXOR: { if (t == null) { t = T.LONG; } add(new XOR(this.ops.size(), opcode, this.line, t)); break; } default: log.warn(getM() + ": Unknown insn opcode '" + opcode + "'!"); } }
From source file:org.evosuite.instrumentation.error.ArrayInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { // Check array accesses if (opcode == Opcodes.IALOAD || opcode == Opcodes.BALOAD || opcode == Opcodes.CALOAD || opcode == Opcodes.SALOAD || opcode == Opcodes.LALOAD || opcode == Opcodes.FALOAD || opcode == Opcodes.DALOAD || opcode == Opcodes.AALOAD) { mv.visitInsn(Opcodes.DUP);// www .j ava2 s.c om insertBranch(Opcodes.IFGE, "java/lang/ArrayIndexOutOfBoundsException"); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.SWAP); //mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.ARRAYLENGTH); insertBranch(Opcodes.IF_ICMPLT, "java/lang/ArrayIndexOutOfBoundsException"); } else if (opcode == Opcodes.IASTORE || opcode == Opcodes.BASTORE || opcode == Opcodes.CASTORE || opcode == Opcodes.SASTORE || opcode == Opcodes.AASTORE || opcode == Opcodes.LASTORE || opcode == Opcodes.FASTORE || opcode == Opcodes.DASTORE) { int loc = 0; if (opcode == Opcodes.IASTORE) loc = mv.newLocal(Type.INT_TYPE); else if (opcode == Opcodes.BASTORE) loc = mv.newLocal(Type.BYTE_TYPE); else if (opcode == Opcodes.CASTORE) loc = mv.newLocal(Type.CHAR_TYPE); else if (opcode == Opcodes.SASTORE) loc = mv.newLocal(Type.SHORT_TYPE); else if (opcode == Opcodes.AASTORE) loc = mv.newLocal(Type.getType(Object.class)); else if (opcode == Opcodes.LASTORE) loc = mv.newLocal(Type.LONG_TYPE); else if (opcode == Opcodes.FASTORE) loc = mv.newLocal(Type.FLOAT_TYPE); else if (opcode == Opcodes.DASTORE) loc = mv.newLocal(Type.DOUBLE_TYPE); else throw new RuntimeException("Unknown type"); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP); insertBranch(Opcodes.IFGE, "java/lang/ArrayIndexOutOfBoundsException"); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.SWAP); //mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.ARRAYLENGTH); insertBranch(Opcodes.IF_ICMPLT, "java/lang/ArrayIndexOutOfBoundsException"); mv.loadLocal(loc); } }
From source file:org.evosuite.instrumentation.error.NullPointerExceptionInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { switch (opcode) { case Opcodes.ARRAYLENGTH: // TODO/*from ww w . j a va 2 s. c om*/ break; case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: // TODO break; case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: // TODO break; default: // Ignore everything else } super.visitInsn(opcode); }
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
@Override public void visitInsn(final int opcode) { final Object t1, t2, t3, t4; switch (opcode) { case Opcodes.NOP: case Opcodes.RETURN: break;//w w w. jav a2s . c om case Opcodes.ARETURN: case Opcodes.ATHROW: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: case Opcodes.POP: pop(1); break; case Opcodes.DRETURN: case Opcodes.LRETURN: case Opcodes.POP2: pop(2); break; case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.FASTORE: case Opcodes.IASTORE: case Opcodes.SASTORE: pop(3); break; case Opcodes.LASTORE: case Opcodes.DASTORE: pop(4); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: push(Opcodes.INTEGER); break; case Opcodes.ARRAYLENGTH: case Opcodes.F2I: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.INEG: pop(1); push(Opcodes.INTEGER); break; case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.D2I: case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.IADD: case Opcodes.IALOAD: case Opcodes.IAND: case Opcodes.IDIV: case Opcodes.IMUL: case Opcodes.IOR: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.ISUB: case Opcodes.IUSHR: case Opcodes.IXOR: case Opcodes.L2I: case Opcodes.SALOAD: pop(2); push(Opcodes.INTEGER); break; case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: pop(4); push(Opcodes.INTEGER); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(Opcodes.FLOAT); break; case Opcodes.FNEG: case Opcodes.I2F: pop(1); push(Opcodes.FLOAT); break; case Opcodes.D2F: case Opcodes.FADD: case Opcodes.FALOAD: case Opcodes.FDIV: case Opcodes.FMUL: case Opcodes.FREM: case Opcodes.FSUB: case Opcodes.L2F: pop(2); push(Opcodes.FLOAT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.F2L: case Opcodes.I2L: pop(1); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.D2L: case Opcodes.LALOAD: case Opcodes.LNEG: pop(2); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LSHL: case Opcodes.LSHR: case Opcodes.LUSHR: pop(3); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LADD: case Opcodes.LAND: case Opcodes.LDIV: case Opcodes.LMUL: case Opcodes.LOR: case Opcodes.LREM: case Opcodes.LSUB: case Opcodes.LXOR: pop(4); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.F2D: case Opcodes.I2D: pop(1); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DALOAD: case Opcodes.DNEG: case Opcodes.L2D: pop(2); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DADD: case Opcodes.DDIV: case Opcodes.DMUL: case Opcodes.DREM: case Opcodes.DSUB: pop(4); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.ACONST_NULL: push(Opcodes.NULL); break; case Opcodes.AALOAD: pop(1); t1 = pop(); push(Type.getType(((String) t1).substring(1))); break; case Opcodes.DUP: t1 = pop(); push(t1); push(t1); break; case Opcodes.DUP_X1: t1 = pop(); t2 = pop(); push(t1); push(t2); push(t1); break; case Opcodes.DUP_X2: t1 = pop(); t2 = pop(); t3 = pop(); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2: t1 = pop(); t2 = pop(); push(t2); push(t1); push(t2); push(t1); break; case Opcodes.DUP2_X1: t1 = pop(); t2 = pop(); t3 = pop(); push(t2); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2_X2: t1 = pop(); t2 = pop(); t3 = pop(); t4 = pop(); push(t2); push(t1); push(t4); push(t3); push(t2); push(t1); break; case Opcodes.SWAP: t1 = pop(); t2 = pop(); push(t1); push(t2); break; default: throw new IllegalArgumentException(); } mv.visitInsn(opcode); }
From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java
License:Open Source License
/** * Generates the instruction to compute the length of an array. */ public void arrayLength() { visitInsn(Opcodes.ARRAYLENGTH); }
From source file:org.jboss.byteman.rule.expression.FieldExpression.java
License:Open Source License
public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); int currentStack = compileContext.getStackCount(); int expected = (type.getNBytes() > 4 ? 2 : 1); if (indirectStatic != null) { // this is just wrapping a static field expression so compile it indirectStatic.compile(mv, compileContext); } else if (isArrayLength) { owner.compile(mv, compileContext); mv.visitInsn(Opcodes.ARRAYLENGTH); // we removed the owner and replaced with expected words compileContext.addStackCount(expected - 1); } else {/* w ww . j av a2s .co m*/ if (isPublicField) { // we can use GETFIELD to access a public field String ownerType = Type.internalName(field.getDeclaringClass()); String fieldName = field.getName(); String fieldType = Type.internalName(field.getType(), true); // compile the owner expression owner.compile(mv, compileContext); mv.visitFieldInsn(Opcodes.GETFIELD, ownerType, fieldName, fieldType); // we removed the owner and replaced with expected words compileContext.addStackCount(expected - 1); } else { // since this is a private field we need to do the access using reflection // stack the helper, owner and the field index mv.visitVarInsn(Opcodes.ALOAD, 0); compileContext.addStackCount(1); owner.compile(mv, compileContext); mv.visitLdcInsn(fieldIndex); compileContext.addStackCount(1); // use the HelperAdapter method getAccessibleField to get the field value mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.internalName(HelperAdapter.class), "getAccessibleField", "(Ljava/lang/Object;I)Ljava/lang/Object;"); // we popped three words and added one object as result compileContext.addStackCount(-2); // convert Object to primitive or cast to subtype if required compileTypeConversion(Type.OBJECT, type, mv, compileContext); } } // check the stack height is ok if (compileContext.getStackCount() != currentStack + expected) { throw new CompileException("FieldExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected)); } }