List of usage examples for org.objectweb.asm Opcodes AALOAD
int AALOAD
To view the source code for org.objectweb.asm Opcodes AALOAD.
Click Source Link
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AbstractCreateDispatchCodeAdapter.java
License:Open Source License
protected InsnList getDispatchCode(MethodNode method, int joinPointId, int boundMethodId) { InsnList instructions = new InsnList(); // teams = TeamManager.getTeams(joinpointId) instructions.add(createLoadIntConstant(joinPointId)); instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ClassNames.TEAM_MANAGER_SLASH, ConstantMembers.getTeams.getName(), ConstantMembers.getTeams.getSignature(), false)); instructions.add(createInstructionsToCheackTeams(method)); // get the first team instructions.add(new InsnNode(Opcodes.DUP)); instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.AALOAD)); instructions.add(new InsnNode(Opcodes.SWAP)); if (isStatic) { instructions.add(new InsnNode(Opcodes.ACONST_NULL)); } else {/*from ww w. j av a 2s . co m*/ // put "this" on the stack and cast it to IBoundBase2 instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, ClassNames.I_BOUND_BASE_SLASH)); } instructions.add(new InsnNode(Opcodes.SWAP)); // start index instructions.add(new InsnNode(Opcodes.ICONST_0)); // TeamManager.getCallinIds(joinpointId) instructions.add(createLoadIntConstant(joinPointId)); instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ClassNames.TEAM_MANAGER_SLASH, ConstantMembers.getCallinIds.getName(), ConstantMembers.getCallinIds.getSignature(), false)); instructions.add(createLoadIntConstant(boundMethodId)); args = Type.getArgumentTypes(method.desc); // box the arguments instructions.add(getBoxedArguments(args)); instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, ClassNames.ITEAM_SLASH, ConstantMembers.callAllBindingsTeam.getName(), ConstantMembers.callAllBindingsTeam.getSignature(), true)); Type returnType = Type.getReturnType(method.desc); instructions.add(getUnboxingInstructionsForReturnValue(returnType)); return instructions; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateFieldAccessAdapter.java
License:Open Source License
@Override public boolean transform() { InsnList instructions = new InsnList(); // put accessId on the stack instructions.add(new IntInsnNode(Opcodes.ILOAD, firstArgIndex + 1)); // read or write access LabelNode writeAccess = new LabelNode(); instructions.add(new JumpInsnNode(Opcodes.IFNE, writeAccess)); // read access if (field.isStatic()) { // get value of field instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, name, field.getName(), field.getSignature())); } else {/*from ww w .j a va2s . com*/ // put "this" on the stack instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); // get value of field instructions.add(new FieldInsnNode(Opcodes.GETFIELD, name, field.getName(), field.getSignature())); } //box value as "Object" Type type = Type.getType(field.getSignature()); instructions.add(AsmTypeHelper.getBoxingInstructionForType(type)); instructions.add(new InsnNode(Opcodes.ARETURN)); //write access instructions.add(writeAccess); //put "args" on the stack instructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + 2)); //get the first element of "args" instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.AALOAD)); //unbox it if (type.getSort() != Type.ARRAY && type.getSort() != Type.OBJECT) { String objectType = AsmTypeHelper.getObjectType(type); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType)); instructions.add(AsmTypeHelper.getUnboxingInstructionForType(type, objectType)); } else { instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, type.getInternalName())); } if (field.isStatic()) { //save value in field instructions.add(new FieldInsnNode(Opcodes.PUTSTATIC, name, field.getName(), field.getSignature())); } else { //put "this" on the stack instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); instructions.add(new InsnNode(Opcodes.SWAP)); //save value in field instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, name, field.getName(), field.getSignature())); } //dummy return instructions.add(new InsnNode(Opcodes.ACONST_NULL)); instructions.add(new InsnNode(Opcodes.ARETURN)); //add the instructions to a new label in the existing switch MethodNode method = getMethod(access); addNewLabelToSwitch(method.instructions, instructions, accessId); return true; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateMethodAccessAdapter.java
License:Open Source License
@Override public boolean transform() { MethodNode methodNode = getMethod(method); InsnList instructions = new InsnList(); if (isConstructor) { // create empty object for constructor invocation: instructions.add(new TypeInsnNode(Opcodes.NEW, name)); instructions.add(new InsnNode(Opcodes.DUP)); } else if (!method.isStatic()) { //put "this" on the stack for a non-static method instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); }//ww w. j av a 2 s . com //Unbox arguments Type[] args = Type.getArgumentTypes(methodNode.desc); if (args.length > 0) { for (int i = 0; i < args.length; i++) { instructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + 2)); instructions.add(createLoadIntConstant(i)); instructions.add(new InsnNode(Opcodes.AALOAD)); Type arg = args[i]; if (arg.getSort() != Type.ARRAY && arg.getSort() != Type.OBJECT) { String objectType = AsmTypeHelper.getObjectType(arg); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType)); instructions.add(AsmTypeHelper.getUnboxingInstructionForType(arg, objectType)); } else { instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, arg.getInternalName())); } } } //call original method int opcode = Opcodes.INVOKEVIRTUAL; if (method.isStatic()) { opcode = Opcodes.INVOKESTATIC; } else if (isConstructor) { opcode = Opcodes.INVOKESPECIAL; } instructions.add(new MethodInsnNode(opcode, name, method.getName(), method.getSignature())); //box return value Type returnType = Type.getReturnType(methodNode.desc); if (returnType.getSort() != Type.OBJECT && returnType.getSort() != Type.ARRAY && returnType.getSort() != Type.VOID) { instructions.add(AsmTypeHelper.getBoxingInstructionForType(returnType)); instructions.add(new InsnNode(Opcodes.ARETURN)); } else if (returnType.getSort() == Type.VOID && !isConstructor) { instructions.add(new InsnNode(Opcodes.ACONST_NULL)); instructions.add(new InsnNode(Opcodes.ARETURN)); } else { instructions.add(new InsnNode(Opcodes.ARETURN)); } //add the instructions to a new label in the existing switch MethodNode access = getMethod(this.access); addNewLabelToSwitch(access.instructions, instructions, accessId); return true; }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.MoveCodeToCallOrigAdapter.java
License:Open Source License
public boolean transform() { MethodNode orgMethod = getMethod(method); if ((orgMethod.access & Opcodes.ACC_ABSTRACT) != 0) return false; MethodNode callOrig = getMethod(this.callOrig); Type returnType = Type.getReturnType(orgMethod.desc); InsnList newInstructions = new InsnList(); //Unboxing arguments Type[] args = Type.getArgumentTypes(orgMethod.desc); int boundMethodIdSlot = firstArgIndex; if (args.length > 0) { // move boundMethodId to a higher slot, to make lower slots available for original locals newInstructions.add(new IntInsnNode(Opcodes.ILOAD, boundMethodIdSlot)); boundMethodIdSlot = callOrig.maxLocals + 1; newInstructions.add(new IntInsnNode(Opcodes.ISTORE, boundMethodIdSlot)); newInstructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + argOffset + 1)); int slot = firstArgIndex + argOffset; for (int i = argOffset; i < args.length; i++) { if (i < args.length - 1) { newInstructions.add(new InsnNode(Opcodes.DUP)); }/*from www.j a v a2 s . com*/ newInstructions.add(createLoadIntConstant(i)); newInstructions.add(new InsnNode(Opcodes.AALOAD)); Type arg = args[i]; if (arg.getSort() != Type.ARRAY && arg.getSort() != Type.OBJECT) { String objectType = AsmTypeHelper.getObjectType(arg); newInstructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType)); newInstructions.add(AsmTypeHelper.getUnboxingInstructionForType(arg, objectType)); } else { newInstructions.add(new TypeInsnNode(Opcodes.CHECKCAST, arg.getInternalName())); } newInstructions.add(new IntInsnNode(args[i].getOpcode(Opcodes.ISTORE), slot)); slot += arg.getSize(); } } if (superIsWeavable) adjustSuperCalls(orgMethod.instructions, orgMethod.name, args, returnType, boundMethodIdSlot); // replace return of the original method with areturn and box the result value if needed replaceReturn(orgMethod.instructions, returnType); newInstructions.add(orgMethod.instructions); addNewLabelToSwitch(callOrig.instructions, newInstructions, boundMethodId); // a minimum stacksize of 3 is needed to box the arguments callOrig.maxStack = Math.max(Math.max(callOrig.maxStack, orgMethod.maxStack), 3); // we have to increment the max. stack size, because we have to put NULL on the stack if (returnType.getSort() == Type.VOID) { callOrig.maxStack += 1; } callOrig.maxLocals = Math.max(callOrig.maxLocals, orgMethod.maxLocals); return true; }
From source file:org.evosuite.graphs.cfg.ASMWrapper.java
License:Open Source License
public boolean isArrayLoadInstruction() { return asmNode.getOpcode() == Opcodes.IALOAD || asmNode.getOpcode() == Opcodes.LALOAD || asmNode.getOpcode() == Opcodes.FALOAD || asmNode.getOpcode() == Opcodes.DALOAD || asmNode.getOpcode() == Opcodes.AALOAD; }
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);//from w w w . j a va 2s . c o m 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 . ja v a 2s . com 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.evosuite.instrumentation.mutation.ReplaceArithmeticOperator.java
License:Open Source License
@SuppressWarnings("rawtypes") private static int getNextIndexFromLoad(MethodNode mn) { Iterator it = mn.instructions.iterator(); int index = 0; while (it.hasNext()) { AbstractInsnNode node = (AbstractInsnNode) it.next(); if (node instanceof VarInsnNode) { VarInsnNode varNode = (VarInsnNode) node; int varIndex = varNode.var; switch (varNode.getOpcode()) { case Opcodes.ALOAD: case Opcodes.ILOAD: case Opcodes.FLOAD: case Opcodes.IALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.AALOAD: case Opcodes.ASTORE: case Opcodes.ISTORE: case Opcodes.FSTORE: case Opcodes.IASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.AASTORE: index = Math.max(index, varIndex + 1); break; case Opcodes.DLOAD: case Opcodes.DSTORE: case Opcodes.LLOAD: case Opcodes.LSTORE: case Opcodes.DALOAD: case Opcodes.DASTORE: case Opcodes.LALOAD: case Opcodes.LASTORE: index = Math.max(index, varIndex + 2); break; }//from w w w. ja va2s.co m } } return index; }
From source file:org.fabric3.implementation.bytecode.reflection.BytecodeConsumerInvokerFactory.java
License:Open Source License
private void writeTargetInvoke(Method method, String internalTargetName, ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "invoke", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", null, EXCEPTIONS); mv.visitCode();/*from w w w. java 2 s .c o m*/ Label label1 = new Label(); mv.visitLabel(label1); mv.visitLineNumber(9, label1); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitTypeInsn(Opcodes.CHECKCAST, internalTargetName); if (method.getParameterTypes().length == 1) { // single argument method, load the parameter passes on to the stack Class<?> paramType = method.getParameterTypes()[0]; mv.visitVarInsn(Opcodes.ALOAD, 2); writeParam(paramType, mv); } else if (method.getParameterTypes().length > 1) { // multi-argument method: cast the parameter to an object array and then load each element on the stack to be passed as params mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;"); mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;"); mv.visitVarInsn(Opcodes.ASTORE, 3); int pos = 0; mv.visitVarInsn(Opcodes.ALOAD, 3); for (Class<?> paramType : method.getParameterTypes()) { mv.visitInsn(Opcodes.ICONST_0 + pos); mv.visitInsn(Opcodes.AALOAD); writeParam(paramType, mv); if (pos < method.getParameterTypes().length - 1) { mv.visitVarInsn(Opcodes.ALOAD, 3); } pos++; } } // invoke the instance String methodName = method.getName(); String methodDescriptor = Type.getMethodDescriptor(method); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, internalTargetName, methodName, methodDescriptor); Class<?> returnType = method.getReturnType(); writeReturn(returnType, mv); Label label2 = new Label(); mv.visitLabel(label2); String descriptor = Type.getDescriptor(ServiceInvoker.class); mv.visitLocalVariable("this", descriptor, null, label1, label2, 0); mv.visitLocalVariable("instance", "Ljava/lang/Object;", null, label1, label2, 1); mv.visitLocalVariable("arg", "Ljava/lang/Object;", null, label1, label2, 2); mv.visitMaxs(2, 3); mv.visitEnd(); }
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 w w . ja v a 2s.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); }