Java Code Examples for org.objectweb.asm.Opcodes#RETURN

The following examples show how to use org.objectweb.asm.Opcodes#RETURN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuiContainerCreativeVisitor.java    From ForgeWurst with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void visitInsn(int opcode)
{
	if(opcode == Opcodes.RETURN)
	{
		System.out.println(
			"GuiContainerCreativeVisitor.InitGuiVisitor.visitInsn()");
		
		mv.visitVarInsn(Opcodes.ALOAD, 0);
		mv.visitFieldInsn(Opcodes.GETFIELD,
			"net/minecraft/client/gui/inventory/GuiContainerCreative",
			buttonList_name, "Ljava/util/List;");
		mv.visitMethodInsn(Opcodes.INVOKESTATIC,
			"net/wurstclient/forge/compatibility/WEventFactory",
			"onGuiInventoryInit", "(Ljava/util/List;)V", false);
	}
	
	super.visitInsn(opcode);
}
 
Example 2
Source File: Java7Compatibility.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void visitInsn(int opcode) {
  switch (opcode) {
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.ARETURN:
    case Opcodes.RETURN:
      checkState(mv != null, "Encountered a second return it would seem: %s", opcode);
      mv = null; // Done: we don't expect anything to follow
      return;
    default:
      super.visitInsn(opcode);
  }
}
 
Example 3
Source File: MethodJob.java    From RuntimeTransformer with MIT License 6 votes vote down vote up
private void insert() {
    InsnList trInsns = transformerNode.instructions;

    AbstractInsnNode node = trInsns.getLast();

    while (true) {
        if (node == null)
            break;

        if (node instanceof LabelNode) {
            node = node.getPrevious();
            continue;
        } else if (node.getOpcode() == Opcodes.RETURN) {
            trInsns.remove(node);
        } else if (node.getOpcode() == Opcodes.ATHROW && node.getPrevious().getOpcode() == Opcodes.ACONST_NULL) {
            AbstractInsnNode prev = node.getPrevious();
            trInsns.remove(node);
            trInsns.remove(prev);
        }

        break;
    }

    resultNode.instructions.insert(trInsns);
}
 
Example 4
Source File: ASMUtils.java    From radon with GNU General Public License v3.0 6 votes vote down vote up
public static int getReturnOpcode(Type type) {
    switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
        case Type.INT:
            return Opcodes.IRETURN;
        case Type.FLOAT:
            return Opcodes.FRETURN;
        case Type.LONG:
            return Opcodes.LRETURN;
        case Type.DOUBLE:
            return Opcodes.DRETURN;
        case Type.ARRAY:
        case Type.OBJECT:
            return Opcodes.ARETURN;
        case Type.VOID:
            return Opcodes.RETURN;
        default:
            throw new AssertionError("Unknown type sort: " + type.getClassName());
    }
}
 
Example 5
Source File: ReturnAdapter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * visit end method for intrumentation	
 */
@Override
public void visitEnd() {
	for (Object o : methods) {
		MethodNode mn = (MethodNode) o;

		if (validateMethods(mn)
				&& InstrumentUtil.validateMethodName(mn.name, "<clinit>")
				&& mn.name.indexOf("access$") < 0) {

			logger.debug("instrumenting " + getClassName() + "##" + mn.name);

			InsnList insnList = mn.instructions;
			AbstractInsnNode[] insnArr = insnList.toArray();
			for (AbstractInsnNode abstractInsnNode : insnArr) {
				if (Opcodes.RETURN >= abstractInsnNode.getOpcode()
						&& Opcodes.IRETURN <= abstractInsnNode.getOpcode()) {
					String msg = new StringBuilder("[Return] [method] [] ")
							.toString();

					String cSymbol = env.getClassSymbol(getClassName());
					String mSymbol = env.getMethodSymbol(getClassName(), cSymbol, mn.name);

					InsnList il = InstrumentUtil.addReturnLogging(
							cSymbol, mSymbol, msg);
					insnList.insertBefore(abstractInsnNode, il);
				}
			}
		}
		mn.visitMaxs(0, 0);
	}
	accept(cv);
}
 
Example 6
Source File: ClassVisitorImpl.java    From SocialSdkLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void visitInsn(int opcode) {
    //判断RETURN
    if (opcode == Opcodes.RETURN) {
        //在这里插入代码
    }
    super.visitInsn(opcode);
}
 
Example 7
Source File: PerfMarkTransformer.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Override
public void visitInsn(int opcode) {
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    if (autoMatch) {
      emitAutoMatchEvent();
    }
  }
  super.visitInsn(opcode);
}
 
Example 8
Source File: AnalyzerAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public void visitInsn(final int opcode) {
  super.visitInsn(opcode);
  execute(opcode, 0, null);
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    this.locals = null;
    this.stack = null;
  }
}
 
Example 9
Source File: MixinApplicatorStandard.java    From Mixin with MIT License 5 votes vote down vote up
/**
 * Identifies line numbers in the supplied ctor which correspond to the
 * start and end of the method body.
 * 
 * @param ctor constructor to scan
 * @return range indicating the line numbers of the specified constructor
 *      and the position of the superclass ctor invocation
 */
private Range getConstructorRange(MethodNode ctor) {
    boolean lineNumberIsValid = false;
    AbstractInsnNode endReturn = null;
    
    int line = 0, start = 0, end = 0, superIndex = -1;
    for (Iterator<AbstractInsnNode> iter = ctor.instructions.iterator(); iter.hasNext();) {
        AbstractInsnNode insn = iter.next();
        if (insn instanceof LineNumberNode) {
            line = ((LineNumberNode)insn).line;
            lineNumberIsValid = true;
        } else if (insn instanceof MethodInsnNode) {
            if (insn.getOpcode() == Opcodes.INVOKESPECIAL && Constants.CTOR.equals(((MethodInsnNode)insn).name) && superIndex == -1) {
                superIndex = ctor.instructions.indexOf(insn);
                start = line;
            }
        } else if (insn.getOpcode() == Opcodes.PUTFIELD) {
            lineNumberIsValid = false;
        } else if (insn.getOpcode() == Opcodes.RETURN) {
            if (lineNumberIsValid) {
                end = line;
            } else {
                end = start;
                endReturn = insn;
            }
        }
    }
    
    if (endReturn != null) {
        LabelNode label = new LabelNode(new Label());
        ctor.instructions.insertBefore(endReturn, label);
        ctor.instructions.insertBefore(endReturn, new LineNumberNode(start, label));
    }
    
    return new Range(start, end, superIndex);
}
 
Example 10
Source File: LayerArmorBaseVisitor.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void visitInsn(int opcode) {
    if (opcode == Opcodes.RETURN) {
        super.visitVarInsn(ALOAD, 0); //this
        super.visitVarInsn(ALOAD, 1); //entityLivingBaseIn
        for (int i = 0; i < 7; i++) super.visitVarInsn(FLOAD, 2 + i); //limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale
        super.visitVarInsn(ALOAD, 9); //slotIn
        super.visitMethodInsn(INVOKESTATIC, ARMOR_HOOKS_OWNER, ARMOR_HOOKS_METHOD_NAME, ARMOR_HOOKS_SIGNATURE, false);
    }
    super.visitInsn(opcode);
}
 
Example 11
Source File: AnalyzerAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public void visitInsn(final int opcode) {
  super.visitInsn(opcode);
  execute(opcode, 0, null);
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    this.locals = null;
    this.stack = null;
  }
}
 
Example 12
Source File: NbJShellAgent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an existin &lt;clinit> method. Adds bytecode before the return, if
 * exists.
 * @param className
 * @param target 
 */
private void transformClassInit(String className, MethodNode target) {
    Type classType = Type.getObjectType(className);
    if (target.instructions.size() > 0) {
        if (target.instructions.getLast().getOpcode() == Opcodes.RETURN) {
            target.instructions.remove(target.instructions.getLast());
        }
    }
    // ldc
    target.visitLdcInsn(classType);
    // invokevirtual --> classloader on stack
    target.visitMethodInsn(
            Opcodes.INVOKEVIRTUAL,
            JAVA_LANG_CLASS,
            CLASS_GET_CLASSLODER_METHOD,
            CLASS_GET_CLASSLOADER_DESC,
            false
    );
    // putstatic
    target.visitFieldInsn(
            Opcodes.PUTSTATIC,
            AGENT_CLASS,
            AGENT_CLASSLOADER_FIELD,
            AGENT_CLASSLOADER_DESC
    );
    target.visitInsn(Opcodes.RETURN);
    // ldc || classloader instance
    target.maxStack = Math.max(target.maxStack, 1);
    target.maxLocals = Math.max(target.maxLocals, 1);
    target.visitEnd();
}
 
Example 13
Source File: AnalyzerAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public void visitInsn(final int opcode) {
  super.visitInsn(opcode);
  execute(opcode, 0, null);
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    this.locals = null;
    this.stack = null;
  }
}
 
Example 14
Source File: GrandExchangeOfferUpdatedExtender.java    From 07kit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void apply(Map<String, ClassDefinition> classes, ClassNode clazz) {
	for (MethodNode node : (List<MethodNode>) clazz.methods) {
		if (node.name.equals("<init>")) {
			InsnList current = node.instructions;
			InsnList inject = new InsnList();
			inject.add(new MethodInsnNode(INVOKESTATIC, "client", "getEventBus", "()L" + Events.class.getCanonicalName().replaceAll("\\.", "/") + ";"));
			inject.add(new TypeInsnNode(NEW, GrandExchangeOfferUpdatedEvent.class.getCanonicalName().replaceAll("\\.", "/")));

			inject.add(new InsnNode(Opcodes.DUP));
			inject.add(new VarInsnNode(Opcodes.ALOAD, 0));
			inject.add(new TypeInsnNode(Opcodes.CHECKCAST, OFFER_CLASS_NAME));
			inject.add(new MethodInsnNode(INVOKESPECIAL, GrandExchangeOfferUpdatedEvent.class.getCanonicalName().replaceAll("\\.", "/"), "<init>", "(L" +
					OFFER_CLASS_NAME + ";)V"));
			inject.add(new MethodInsnNode(INVOKEVIRTUAL, Events.class.getCanonicalName().replaceAll("\\.", "/"), "submit", "(Ljava/lang/Object;)V"));
			AbstractInsnNode returnInsn = null;
			for (AbstractInsnNode ain : node.instructions.toArray()) {
				if (ain.getOpcode() == Opcodes.RETURN) {
					returnInsn = ain;
					break;
				}
			}
			current.insertBefore(returnInsn, inject);
			node.visitEnd();
		}
	}
}
 
Example 15
Source File: StateTrackingMethodVisitor.java    From scott with MIT License 5 votes vote down vote up
private void instrumentToTrackReturn(int opcode) {
	if (!VariableType.isReturnOperation(opcode)) {
		return;
	}
	
	if (Opcodes.RETURN == opcode) {
		super.visitLdcInsn(lineNumber);
		super.visitLdcInsn(methodName);
		super.visitLdcInsn(Type.getType("L" + className + ";"));
		super.visitMethodInsn(Opcodes.INVOKESTATIC, instrumentationActions.trackerClass, "trackReturn", "(ILjava/lang/String;Ljava/lang/Class;)V", false);
	} else {
		if (opcode == Opcodes.DRETURN || opcode == Opcodes.LRETURN) {
			super.visitInsn(Opcodes.DUP2);
		} else {
			super.visitInsn(Opcodes.DUP);
		}
		
		final VariableType variableType;
		if (opcode == Opcodes.IRETURN) {
			variableType = VariableType.getReturnTypeFromMethodDesc(desc);
		} else {
			variableType = VariableType.getByReturnOpCode(opcode);
		}
		
		super.visitLdcInsn(lineNumber);
		super.visitLdcInsn(methodName);
		super.visitLdcInsn(Type.getType("L" + className + ";"));
		super.visitMethodInsn(Opcodes.INVOKESTATIC, instrumentationActions.trackerClass, "trackReturn", "(" + variableType.desc + "ILjava/lang/String;Ljava/lang/Class;)V", false);
	}
}
 
Example 16
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
boolean isReturnCode(final int opcode) {
    return opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN;
}
 
Example 17
Source File: ASMUtils.java    From radon with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isReturn(int opcode) {
    return (opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN);
}
 
Example 18
Source File: NullMutateEverything.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public void visitInsn(int opcode) {
  if (opcode != Opcodes.RETURN) {
    mutate("visitInsn", opcode);
  }
}
 
Example 19
Source File: ReturnCode.java    From yql-plus with Apache License 2.0 4 votes vote down vote up
public ReturnCode() {
    this.op = Opcodes.RETURN;
}
 
Example 20
Source File: MREntryExitAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * visit end for instrumentation of map-reduce methods
 */
@Override
public void visitEnd() {
	if (isMapperClass() || isReducerClass()) {
		for (Object o : methods) {
			MethodNode mn = (MethodNode) o;
			/**
			 * Valid map/reduce method
			 */
			if (InstrumentUtil.validateMapReduceMethod(mn)) {
				InsnList insnList = mn.instructions;
				AbstractInsnNode[] insnArr = insnList.toArray();

				// adding entry logging
				LOGGER.debug(MessageFormat.format(
						InstrumentationMessageLoader
								.getMessage(MessageConstants.LOG_MAPREDUCE_METHOD_ENTRY),
						getClassName() + "##" + mn.name + "##" + mn.desc));
				String logMsg = new StringBuilder(
						MessageFormat.format(
								InstrumentationMessageLoader
										.getMessage(MessageConstants.ENTERED_MAPREDUCE),
								mn.name)).toString();

				// setting the logger number in ThreadLocal
				InsnList il1 = new InsnList();
				il1.add(new LabelNode());
				il1.add(new VarInsnNode(Opcodes.ALOAD, 0));
				il1.add(new FieldInsnNode(
						Opcodes.GETFIELD,
						ConfigurationUtil.convertQualifiedClassNameToInternalName(getClassName()),
						InstrumentConstants.FIELD_LOGGERNUMBER, "I"));
				il1.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
						CLASSNAME_MAPREDUCEEXECUTIL, "setLoggerNumber",
						Type.getMethodDescriptor(Type.VOID_TYPE,
								Type.INT_TYPE)));
				
				String symbol = env.getClassSymbol(getClassName());
				il1.add(InstrumentUtil.addLogMessage(symbol,
						mn.name, logMsg));

				il1.add(addMapCounter(mn));
				insnList.insertBefore(insnList.getFirst(), il1);

				// traversing the instructions for exit logging
				for (AbstractInsnNode abstractInsnNode : insnArr) {
					// return statement
					if (abstractInsnNode.getOpcode() >= Opcodes.IRETURN
							&& abstractInsnNode.getOpcode() <= Opcodes.RETURN) {
						LOGGER.debug(MessageFormat.format(
								InstrumentationMessageLoader
										.getMessage(MessageConstants.LOG_MAPREDUCE_METHOD_EXIT),
								getClassName() + "##" + mn.name));
						String logMsg2 = new StringBuilder(
								MessageFormat.format(
										InstrumentationMessageLoader
												.getMessage(MessageConstants.EXITING_MAPREDUCE),
										mn.name)).toString();
						
						symbol = getLogClazzName(); 
						InsnList il = InstrumentUtil.addLogMessage(
								symbol, mn.name, logMsg2);
						insnList.insert(abstractInsnNode.getPrevious(), il);
					}
				}
			}
			mn.visitMaxs(0, 0);
		}
	}
	accept(cv);
}