List of usage examples for org.objectweb.asm Opcodes INVOKESTATIC
int INVOKESTATIC
To view the source code for org.objectweb.asm Opcodes INVOKESTATIC.
Click Source Link
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformArmorTexture(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_HORSE_FUNC110241CB, false)); needle.add(new VarInsnNode(Opcodes.ISTORE, 3)); AbstractInsnNode node = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); LabelNode l17 = new LabelNode(); newInstr.add(l17);// ww w. jav a2s . c om newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM, false)); newInstr.add(new VarInsnNode(Opcodes.ASTORE, 4)); LabelNode l18 = new LabelNode(); newInstr.add(l18); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.INSTANCEOF, ASMNames.CL_ITEM_HORSE_ARMOR)); LabelNode l19 = new LabelNode(); newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l19)); LabelNode l20 = new LabelNode(); newInstr.add(l20); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110280BR)); newInstr.add(new InsnNode(Opcodes.ICONST_2)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.CHECKCAST, ASMNames.CL_ITEM_HORSE_ARMOR)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_GET_ARMOR_TEXTURE, false)); newInstr.add(new InsnNode(Opcodes.AASTORE)); LabelNode l21 = new LabelNode(); newInstr.add(l21); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_STRING_BUILDER)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_STRING_VALUE_OF, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_STRINGBUILDER_INIT, false)); newInstr.add(new LdcInsnNode("cst-")); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_UNLOC_NAME, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_TO_STRING, false)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.PUTFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(new InsnNode(Opcodes.RETURN)); newInstr.add(l19); method.instructions.insert(node, newInstr); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformEntityInit(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER)); needle.add(new IntInsnNode(Opcodes.BIPUSH, 22)); needle.add(new InsnNode(Opcodes.ICONST_0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_INTEGER_VALUE_OF, false)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false)); AbstractInsnNode pointer = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(new LabelNode()); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER)); newInstr.add(new IntInsnNode(Opcodes.BIPUSH, 23)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_ITEM_STACK)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL)); newInstr.add(new InsnNode(Opcodes.ICONST_0)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false)); method.instructions.insert(pointer, newInstr); }
From source file:de.tuberlin.uebb.jbop.access.ConstructorBuilder.java
License:Open Source License
/** * Gets the boxing node.//from ww w .j a v a 2s . com * * @param field * the field * @return the boxing node */ public static AbstractInsnNode getBoxingNode(final FieldNode field) { final AbstractInsnNode boxing; Type type = Type.getType(field.desc); if (field.desc.startsWith("[")) { type = type.getElementType(); } final int sort = type.getSort(); if (sort == Type.INT) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", "(D)Ljava/lang/Integer;"); } else if (sort == Type.LONG) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Long.class), "valueOf", "(D)Ljava/lang/Long;"); } else if (sort == Type.FLOAT) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Float.class), "valueOf", "(D)Ljava/lang/Float;"); } else if (sort == Type.DOUBLE) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", "(D)Ljava/lang/Double;"); } else if (sort == Type.BOOLEAN) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", "(D)Ljava/lang/Boolean;"); } else if (sort == Type.SHORT) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", "(D)Ljava/lang/Short;"); } else if (sort == Type.CHAR) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", "(D)Ljava/lang/Character;"); } else if (sort == Type.BYTE) { boxing = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", "(D)Ljava/lang/Byte;"); } else { boxing = null; } return boxing; }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
public void visitCode() { if (!methodName.equals("<clinit>") && (instrumentLine || instrumentReturns)) { // System.out.println(className + "." + methodName); this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitLdcInsn(instrumentLine); this.visitLdcInsn(instrumentReturns); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, "begin", "(Ljava/lang/String;Ljava/lang/String;ZZ)V"); }// w ww. j av a 2 s.c o m super.visitCode(); }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
public void visitLineNumber(int line, Label start) { if (!methodName.equals("<clinit>") && instrumentLine) { this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitLdcInsn(line); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, "logLineNumber", "(ILjava/lang/String;Ljava/lang/String;)V"); }/*from w ww.ja v a 2 s. c o m*/ super.visitLineNumber(line, start); }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
private void callLogPrototype(String traceMethod, PDType type) { if (type != PDType.LONG && type != PDType.DOUBLE) { this.visitInsn(Opcodes.DUP); if (type == PDType.FLOAT) { this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "floatToRawIntBits", "(F)I"); }/* www . j a v a 2 s. c om*/ } else { this.visitInsn(Opcodes.DUP2); if (type == PDType.DOUBLE) { this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "doubleToRawLongBits", "(D)J"); } this.visitInsn(Opcodes.DUP2); this.visitIntInsn(Opcodes.BIPUSH, 32); this.visitInsn(Opcodes.LSHR); this.visitInsn(Opcodes.LXOR); this.visitInsn(Opcodes.L2I); } this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitInsn(Opcodes.SWAP); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, traceMethod, "(ILjava/lang/String;Ljava/lang/String;)V"); }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
private void callLogAReturn() { this.visitInsn(Opcodes.DUP); this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitInsn(Opcodes.SWAP); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, "logAReturn", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V"); }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.BytecodeTasks.java
License:Open Source License
/** * Inserts a mutation. The inserted code is like this: * <code>if(System.getProperty(mutationID)){ * execute mutated code/*from www.j ava 2 s . c om*/ * } * else{ * execute unmutated code * } * * @param mv * MethodVisitor where the code is inserted. * @param unMutated * code that should be used when no mutation is applied. * @param mutations * code that should be used when one of the mutations is applied. */ public static void insertIfElse(MethodVisitor mv, MutationCode unMutated, MutationCode[] mutations) { Label endLabel = new Label(); Label mutationStartLabel = new Label(); mutationStartLabel.info = new MutationMarker(true); mv.visitLabel(mutationStartLabel); for (MutationCode mutationCode : mutations) { Mutation mutation = mutationCode.getMutation(); mv.visitLdcInsn(mutation.getMutationVariable()); // mv.visitLdcInsn(mutation.getMutationType() + ""); // mv.visitInsn(Opcodes.POP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "getProperty", "(Ljava/lang/String;)Ljava/lang/String;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); // insertPrintStatements(mv, "Mutation touched: " + // mutation.getId()); insertMutationTouchedCode(mv, mutation); if (!DebugProperties.INSERT_ORIGINAL_INSTEAD_OF_MUTATION) { mutationCode.insertCodeBlock(mv); } else { logger.warn("Debug mode: not inserting mutated statement"); unMutated.insertCodeBlock(mv); } mv.visitJumpInsn(Opcodes.GOTO, endLabel); mv.visitLabel(l1); } Label mutationEndLabel = new Label(); mutationEndLabel.info = new MutationMarker(false); mv.visitLabel(mutationEndLabel); unMutated.insertCodeBlock(mv); mv.visitLabel(endLabel); }
From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.BytecodeTasks.java
License:Open Source License
/** * Insert calls that signal whether the mutated code was executed. * /*from www . j a v a 2s .co m*/ * @param mv * the method visitor to add the statements * @param mutation * the mutation that is covered or not */ private static void insertMutationTouchedCode(MethodVisitor mv, Mutation mutation) { if (DebugProperties.MUTATION_PRINT_STATEMENTS_ENABLED) { BytecodeTasks.insertPrintStatements(mv, "Mutation " + mutation.getMutationVariable() + " - " + mutation.getMutationType() + " is enabled"); } mv.visitLdcInsn(mutation.getId()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "de/unisb/cs/st/javalanche/mutation/runtime/MutationObserver", "touch", "(J)V"); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.MethodInvocationInstruction.java
License:Open Source License
public MethodInvocationInstruction(final ReadMethod readMethod, final int opcode, final int lineNumber, final String internalClassName, final String methodName, final String methodDesc) { super(readMethod, opcode, lineNumber); assert opcode == Opcodes.INVOKEVIRTUAL || opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEINTERFACE; this.internalClassName = internalClassName; this.methodName = methodName; this.methodDesc = methodDesc; final org.objectweb.asm.Type[] parameterTypes = org.objectweb.asm.Type.getArgumentTypes(methodDesc); this.parameterIsLong = new boolean[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; ++i) { this.parameterIsLong[i] = parameterTypes[i].getSize() == 2; }//from ww w . j a v a2 s .c o m org.objectweb.asm.Type returnType = org.objectweb.asm.Type.getReturnType(methodDesc); this.returnedSize = returnType == org.objectweb.asm.Type.VOID_TYPE ? 0 : (byte) returnType.getSize(); }