List of usage examples for org.objectweb.asm Opcodes ILOAD
int ILOAD
To view the source code for org.objectweb.asm Opcodes ILOAD.
Click Source Link
From source file:org.evosuite.instrumentation.testability.transformer.ImplicitElseTransformer.java
License:Open Source License
private void handleDependency(ControlDependency dependency, ControlDependenceGraph cdg, MethodNode mn, VarInsnNode varNode, BytecodeInstruction parentLevel) { if (addedNodes.contains(dependency)) return;/* www. ja va2s. c o m*/ // Get the basic blocks reachable if the dependency would evaluate different Set<BasicBlock> blocks = cdg.getAlternativeBlocks(dependency); addedNodes.add(dependency); Set<ControlDependency> dependencies = dependency.getBranch().getInstruction().getControlDependencies(); //if (dependencies.size() == 1) { // ControlDependency dep = dependencies.iterator().next(); for (ControlDependency dep : dependencies) { if (!addedNodes.contains(dep) && dep != dependency) handleDependency(dep, cdg, mn, varNode, dependency.getBranch().getInstruction()); } // TODO: Need to check that there is an assignment in every alternative path through CDG boolean hasAssignment = false; for (BasicBlock block : blocks) { // If this block also assigns a value to the same variable for (BytecodeInstruction instruction : block) { if (instruction.getASMNode().getOpcode() == Opcodes.ISTORE) { VarInsnNode otherVarNode = (VarInsnNode) instruction.getASMNode(); VarInsnNode thisVarNode = varNode; if (otherVarNode.var == thisVarNode.var) { hasAssignment = true; break; } } } if (hasAssignment) { break; } } // The Flag assignment is is the dependency evaluates to the given value // We thus need to insert the tautoligical assignment either directly after the IF (if the value is true) // or before the jump target (if the value is false) if (!hasAssignment) { TransformationStatistics.transformedImplicitElse(); if (dependency.getBranch().getInstruction().isSwitch()) { BooleanTestabilityTransformation.logger.warn("Don't know how to handle Switches yet"); return; } JumpInsnNode jumpNode = (JumpInsnNode) dependency.getBranch().getInstruction().getASMNode(); VarInsnNode newStore = new VarInsnNode(Opcodes.ISTORE, varNode.var); VarInsnNode newLoad = new VarInsnNode(Opcodes.ILOAD, varNode.var); if (dependency.getBranchExpressionValue()) { BooleanTestabilityTransformation.logger.info("Inserting else branch directly after if"); // Insert directly after if if (isDefinedBefore(mn, varNode, jumpNode)) { mn.instructions.insert(jumpNode, newStore); mn.instructions.insert(jumpNode, newLoad); registerInstruction(mn, varNode, newStore); registerInstruction(mn, varNode, newLoad); } } else { BooleanTestabilityTransformation.logger.info("Inserting else branch as jump target"); // Insert as jump target if (isDefinedBefore(mn, varNode, jumpNode)) { LabelNode target = jumpNode.label; LabelNode newTarget = new LabelNode(new Label()); // jumpNode or target? registerInstruction(mn, jumpNode.getNext(), newStore); registerInstruction(mn, jumpNode.getNext(), newLoad); InsnList assignment = new InsnList(); assignment.add(new JumpInsnNode(Opcodes.GOTO, target)); assignment.add(newTarget); assignment.add(newLoad); assignment.add(newStore); jumpNode.label = newTarget; mn.instructions.insertBefore(target, assignment); } } } }
From source file:org.evosuite.testcarver.instrument.Instrumenter.java
License:Open Source License
/** * public int myMethod(int i)/*w ww. j av a 2 s .c o m*/ { try { return _sw_prototype_original_myMethod(i) } finally { Capturer.enable(); } } * @param classNode * @param className * @param methodNode */ @SuppressWarnings("unchecked") private MethodNode wrapMethod(final ClassNode classNode, final String className, final MethodNode methodNode) { methodNode.maxStack += 4; // create wrapper for original method final MethodNode wrappingMethodNode = new MethodNode(methodNode.access, methodNode.name, methodNode.desc, methodNode.signature, (String[]) methodNode.exceptions.toArray(new String[methodNode.exceptions.size()])); wrappingMethodNode.maxStack = methodNode.maxStack; // assign annotations to wrapping method wrappingMethodNode.visibleAnnotations = methodNode.visibleAnnotations; wrappingMethodNode.visibleParameterAnnotations = methodNode.visibleParameterAnnotations; // remove annotations from wrapped method to avoid wrong behavior controlled by annotations methodNode.visibleAnnotations = null; methodNode.visibleParameterAnnotations = null; // rename original method methodNode.access = TransformerUtil.modifyVisibility(methodNode.access, Opcodes.ACC_PRIVATE); final LabelNode l0 = new LabelNode(); final LabelNode l1 = new LabelNode(); final LabelNode l2 = new LabelNode(); final InsnList wInstructions = wrappingMethodNode.instructions; if ("<init>".equals(methodNode.name)) { // wrap a constructor methodNode.name = WRAP_NAME_PREFIX + "init" + WRAP_NAME_PREFIX; // move call to other constructors to new method AbstractInsnNode ins = null; ListIterator<AbstractInsnNode> iter = methodNode.instructions.iterator(); int numInvokeSpecials = 0; // number of invokespecial calls before actual constructor call while (iter.hasNext()) { ins = iter.next(); iter.remove(); wInstructions.add(ins); if (ins instanceof MethodInsnNode) { MethodInsnNode mins = (MethodInsnNode) ins; if (ins.getOpcode() == Opcodes.INVOKESPECIAL) { if (mins.name.startsWith("<init>")) { if (numInvokeSpecials == 0) { break; } else { numInvokeSpecials--; } } } } else if (ins instanceof TypeInsnNode) { TypeInsnNode typeIns = (TypeInsnNode) ins; if (typeIns.getOpcode() == Opcodes.NEW || typeIns.getOpcode() == Opcodes.NEWARRAY) { numInvokeSpecials++; } } } } else { methodNode.name = WRAP_NAME_PREFIX + methodNode.name; } int varReturnValue = 0; final Type returnType = Type.getReturnType(methodNode.desc); if (returnType.equals(Type.VOID_TYPE)) { wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l1, "java/lang/Throwable")); } else { wrappingMethodNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Throwable")); //--- create "Object returnValue = null;" if (!TransformerUtil.isStatic(methodNode.access)) { // load "this" varReturnValue++; } // consider method arguments to find right variable index final Type[] argTypes = Type.getArgumentTypes(methodNode.desc); for (int i = 0; i < argTypes.length; i++) { varReturnValue++; // long/double take two registers if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) { varReturnValue++; } } // push NULL on the stack and initialize variable for return value for it wInstructions.add(new InsnNode(Opcodes.ACONST_NULL)); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue)); } int var = 0; // --- L0 wInstructions.add(l0); wInstructions.add(this.addCaptureCall(TransformerUtil.isStatic(methodNode.access), className, wrappingMethodNode.name, wrappingMethodNode.desc, Type.getArgumentTypes(methodNode.desc))); // --- construct call to wrapped methode if (!TransformerUtil.isStatic(methodNode.access)) { // load "this" to call method wInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); var++; } final Type[] argTypes = Type.getArgumentTypes(methodNode.desc); for (int i = 0; i < argTypes.length; i++) { this.addLoadInsn(wInstructions, argTypes[i], var++); // long/double take two registers if (argTypes[i].equals(Type.LONG_TYPE) || argTypes[i].equals(Type.DOUBLE_TYPE)) { var++; } } if (TransformerUtil.isStatic(methodNode.access)) { wInstructions.add( new MethodInsnNode(Opcodes.INVOKESTATIC, classNode.name, methodNode.name, methodNode.desc)); } else { wInstructions.add( new MethodInsnNode(Opcodes.INVOKEVIRTUAL, classNode.name, methodNode.name, methodNode.desc)); } var++; if (returnType.equals(Type.VOID_TYPE)) { wInstructions.add(new JumpInsnNode(Opcodes.GOTO, l2)); // --- L1 wInstructions.add(l1); wInstructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" })); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var)); this.addCaptureEnableStatement(className, methodNode, wInstructions, -1); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var)); wInstructions.add(new InsnNode(Opcodes.ATHROW)); // FIXME <--- DUPLICATE CODE // --- L2 wInstructions.add(l2); wInstructions.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); this.addCaptureEnableStatement(className, methodNode, wInstructions, -1); wInstructions.add(new InsnNode(Opcodes.RETURN)); } else { // construct store of the wrapped method call's result this.addBoxingStmt(wInstructions, returnType); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, varReturnValue)); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, varReturnValue)); this.addUnBoxingStmt(wInstructions, returnType); final int storeOpcode = returnType.getOpcode(Opcodes.ISTORE); wInstructions.add(new VarInsnNode(storeOpcode, ++var)); // might be only var // --- L1 wInstructions.add(l1); this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue); // construct load of the wrapped method call's result int loadOpcode = returnType.getOpcode(Opcodes.ILOAD); wInstructions.add(new VarInsnNode(loadOpcode, var)); // construct return of the wrapped method call's result this.addReturnInsn(wInstructions, returnType); //---- L2 wInstructions.add(l2); wInstructions.add( new FrameNode(Opcodes.F_FULL, 2, new Object[] { className, this.getInternalName(returnType) }, 1, new Object[] { "java/lang/Throwable" })); wInstructions.add(new VarInsnNode(Opcodes.ASTORE, --var)); this.addCaptureEnableStatement(className, methodNode, wInstructions, varReturnValue); wInstructions.add(new VarInsnNode(Opcodes.ALOAD, var)); wInstructions.add(new InsnNode(Opcodes.ATHROW)); } transformWrapperCalls(methodNode); return wrappingMethodNode; }
From source file:org.evosuite.testcarver.instrument.Instrumenter.java
License:Open Source License
private void addLoadInsn(final InsnList il, final Type type, final int argLocation) { if (type.equals(Type.BOOLEAN_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); } else if (type.equals(Type.CHAR_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); } else if (type.equals(Type.BYTE_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); } else if (type.equals(Type.SHORT_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); } else if (type.equals(Type.INT_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); } else if (type.equals(Type.FLOAT_TYPE)) { il.add(new VarInsnNode(Opcodes.FLOAD, argLocation)); } else if (type.equals(Type.LONG_TYPE)) { il.add(new VarInsnNode(Opcodes.LLOAD, argLocation)); } else if (type.equals(Type.DOUBLE_TYPE)) { il.add(new VarInsnNode(Opcodes.DLOAD, argLocation)); } else {// www . ja v a2s. com il.add(new VarInsnNode(Opcodes.ALOAD, argLocation)); } }
From source file:org.evosuite.testcarver.instrument.Instrumenter.java
License:Open Source License
private void loadAndConvertToObject(final InsnList il, final Type type, final int argLocation) { if (type.equals(Type.BOOLEAN_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;")); } else if (type.equals(Type.CHAR_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;")); } else if (type.equals(Type.BYTE_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;")); } else if (type.equals(Type.SHORT_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;")); } else if (type.equals(Type.INT_TYPE)) { il.add(new VarInsnNode(Opcodes.ILOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;")); } else if (type.equals(Type.FLOAT_TYPE)) { il.add(new VarInsnNode(Opcodes.FLOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;")); } else if (type.equals(Type.LONG_TYPE)) { il.add(new VarInsnNode(Opcodes.LLOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;")); } else if (type.equals(Type.DOUBLE_TYPE)) { il.add(new VarInsnNode(Opcodes.DLOAD, argLocation)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;")); } else {//from w ww . j a v a2s .com il.add(new VarInsnNode(Opcodes.ALOAD, argLocation)); } }
From source file:org.fabric3.implementation.bytecode.proxy.common.ProxyFactoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public void emitWrappedParameters(Method method, MethodVisitor mv, int[] index, int[] stack) { int numberOfParameters = method.getParameterTypes().length; // create the Object[] used to pass the parameters to _f3_invoke and push it on the stack if (numberOfParameters >= 0 && numberOfParameters <= 5) { // use an integer constant if within range mv.visitInsn(Opcodes.ICONST_0 + numberOfParameters); } else {// w ww. ja v a2 s .c om mv.visitIntInsn(Opcodes.BIPUSH, numberOfParameters); } mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitInsn(DUP); for (Class<?> param : method.getParameterTypes()) { if (Integer.TYPE.equals(param)) { mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(Opcodes.ILOAD, stack[0]); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } } else if (Float.TYPE.equals(param)) { mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(Opcodes.FLOAD, stack[0]); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } } else if (Boolean.TYPE.equals(param)) { mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(Opcodes.ILOAD, stack[0]); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } } else if (Short.TYPE.equals(param)) { mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(Opcodes.ILOAD, stack[0]); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;"); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } } else if (Byte.TYPE.equals(param)) { mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(Opcodes.ILOAD, stack[0]); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;"); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } } else if (Double.TYPE.equals(param)) { mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(Opcodes.DLOAD, stack[0]); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } stack[0]++; // double occupies two positions } else if (Long.TYPE.equals(param)) { mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(Opcodes.LLOAD, stack[0]); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } stack[0]++; // long occupies two positions } else { // object type mv.visitInsn(Opcodes.ICONST_0 + index[0]); mv.visitVarInsn(ALOAD, stack[0]); mv.visitInsn(AASTORE); if (index[0] < numberOfParameters - 1) { mv.visitInsn(DUP); } } index[0]++; } // TODO other primitive types stack[0]++; }
From source file:org.fabric3.implementation.bytecode.proxy.common.ProxyFactoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public void emitUnWrappedParameters(Method method, MethodVisitor mv, int[] index, int[] stack) { int numberOfParameters = method.getParameterTypes().length; if (numberOfParameters > 1) { // FIXME/*from ww w. j a v a 2 s . c om*/ throw new AssertionError("Not supported"); } Class<?> param = method.getParameterTypes()[0]; if (Integer.TYPE.equals(param)) { mv.visitVarInsn(ILOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); } else if (Float.TYPE.equals(param)) { mv.visitVarInsn(Opcodes.FLOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"); } else if (Boolean.TYPE.equals(param)) { mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"); } else if (Short.TYPE.equals(param)) { mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;"); } else if (Byte.TYPE.equals(param)) { mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;"); } else if (Double.TYPE.equals(param)) { mv.visitVarInsn(Opcodes.DLOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"); } else if (Long.TYPE.equals(param)) { mv.visitVarInsn(Opcodes.LLOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"); } else { // object type mv.visitVarInsn(ALOAD, 1); } }
From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompiler.java
License:Open Source License
private void compileScanArray(ForEachElementCompilation _forElement) throws CompilerException { final GeneratorAdapter mv = mv(); final int loc = localsOffset(); incLocalsOffset(4);/* w ww. j a va2 s. c o m*/ // store array mv.visitVarInsn(Opcodes.ASTORE, loc); // store array length mv.visitVarInsn(Opcodes.ALOAD, loc); mv.arrayLength(); mv.visitVarInsn(Opcodes.ISTORE, 1 + loc); // loop index mv.push(0); mv.visitVarInsn(Opcodes.ISTORE, 2 + loc); // loop start final Label l0 = mv.mark(); // check loop condition mv.visitVarInsn(Opcodes.ILOAD, 2 + loc); mv.visitVarInsn(Opcodes.ILOAD, 1 + loc); final Label l1 = new Label(); mv.ifICmp(GeneratorAdapter.GE, l1); // loop body mv.visitVarInsn(Opcodes.ALOAD, loc); mv.visitVarInsn(Opcodes.ILOAD, 2 + loc); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ASTORE, 3 + loc); _forElement.compile(3 + loc, 2 + loc); // inc loop index mv.visitIincInsn(2 + loc, 1); mv.goTo(l0); mv.visitLabel(l1); }
From source file:org.formulacompiler.compiler.internal.bytecode.HelperCompilerForFoldApply.java
License:Open Source License
private void compileAccuSetup() throws CompilerException { final int nAccus = fold.accuCount(); accuTypes = new Type[nAccus]; accuVars = new int[nAccus]; for (int i = 0; i < nAccus; i++) { final ExpressionNode initNode = fold.accuInit(i); final DataType initType = initNode.getDataType(); final Type accuType = section().engineCompiler().typeCompiler(initType).type(); final int accuVar = newLocal(accuType.getSize()); accuTypes[i] = accuType;//from w w w . j a va 2 s.co m accuVars[i] = accuVar; expressionCompiler().compile(initNode); compileAccumulatorStore(i); letDict().let(fold.accuName(i), initType, new Compilable() { public void compile(ExpressionCompiler _exp) throws CompilerException { mv().visitVarInsn(accuType.getOpcode(Opcodes.ILOAD), accuVar); } public boolean isArray() { return false; } }); } }
From source file:org.formulacompiler.compiler.internal.bytecode.HelperCompilerForFoldApply.java
License:Open Source License
private void compileAccumulatorLoad(int _iAccu) { mv().visitVarInsn(accuTypes[_iAccu].getOpcode(Opcodes.ILOAD), accuVars[_iAccu]); }
From source file:org.formulacompiler.compiler.internal.bytecode.HelperCompilerForFoldApply.java
License:Open Source License
private void letIndexVarAs(String _nameOrNull) { if (null != _nameOrNull) { letDict().let(_nameOrNull, numericCompiler().dataType(), new Compilable() { public void compile(ExpressionCompiler _exp) throws CompilerException { mv().visitVarInsn(Opcodes.ILOAD, indexVar); _exp.compileConversionFrom(Integer.TYPE); }/*from w w w .j a v a2 s.co m*/ public boolean isArray() { return false; } }); } }