List of usage examples for org.objectweb.asm.tree AbstractInsnNode getOpcode
public int getOpcode()
From source file:com.lodgon.parboiled.transform.AsmUtils.java
License:Open Source License
public static boolean isCallOnContextAware(AbstractInsnNode insn) { checkArgNotNull(insn, "insn"); if (insn.getOpcode() != Opcodes.INVOKEVIRTUAL && insn.getOpcode() != Opcodes.INVOKEINTERFACE) return false; MethodInsnNode mi = (MethodInsnNode) insn; return isAssignableTo(mi.owner, ContextAware.class); }
From source file:com.lodgon.parboiled.transform.FlagMarkingGenerator.java
License:Apache License
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); checkState(!method.isSuperMethod()); // super methods have flag moved to the overriding method InsnList instructions = method.instructions; AbstractInsnNode ret = instructions.getLast(); while (ret.getOpcode() != ARETURN) { ret = ret.getPrevious();/* w w w . j a va 2 s . c om*/ } // stack: <rule> instructions.insertBefore(ret, new InsnNode(DUP)); // stack: <rule> :: <rule> LabelNode isNullLabel = new LabelNode(); instructions.insertBefore(ret, new JumpInsnNode(IFNULL, isNullLabel)); // stack: <rule> if (method.hasSuppressNodeAnnotation()) generateMarkerCall(instructions, ret, "suppressNode"); if (method.hasSuppressSubnodesAnnotation()) generateMarkerCall(instructions, ret, "suppressSubnodes"); if (method.hasSkipNodeAnnotation()) generateMarkerCall(instructions, ret, "skipNode"); if (method.hasMemoMismatchesAnnotation()) generateMarkerCall(instructions, ret, "memoMismatches"); // stack: <rule> instructions.insertBefore(ret, isNullLabel); // stack: <rule> }
From source file:com.lodgon.parboiled.transform.ImplicitActionsConverter.java
License:Apache License
private boolean isStoredIntoObjectArray(InstructionGraphNode dependent) { // is the single dependent an AASTORE instruction ? AbstractInsnNode insn = dependent.getInstruction(); if (insn.getOpcode() != AASTORE) return false; // Does this instruction store into an array of Object ? List<InstructionGraphNode> dependents = getDependents(dependent); checkState(dependents.size() == 1); // an AASTORE instruction should have exactly one dependent AbstractInsnNode newArrayInsn = dependents.get(0).getInstruction(); checkState(newArrayInsn.getOpcode() == ANEWARRAY); // which should be a n ANEWARRAY instruction return "java/lang/Object".equals(((TypeInsnNode) newArrayInsn).desc); }
From source file:com.lodgon.parboiled.transform.InstructionGraphNode.java
License:Open Source License
public InstructionGraphNode(AbstractInsnNode instruction, BasicValue resultValue) { super(null);//w ww . j av a 2 s .c om this.instruction = instruction; this.resultValue = resultValue; this.isActionRoot = AsmUtils.isActionRoot(instruction); this.isVarInitRoot = AsmUtils.isVarRoot(instruction); this.isCallOnContextAware = AsmUtils.isCallOnContextAware(instruction); this.isXLoad = ILOAD <= instruction.getOpcode() && instruction.getOpcode() < IALOAD; this.isXStore = ISTORE <= instruction.getOpcode() && instruction.getOpcode() < IASTORE; }
From source file:com.lodgon.parboiled.transform.LabellingGenerator.java
License:Apache License
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); checkState(!method.isSuperMethod()); // super methods have flag moved to the overriding method InsnList instructions = method.instructions; AbstractInsnNode ret = instructions.getLast(); while (ret.getOpcode() != ARETURN) { ret = ret.getPrevious();//w ww .j a v a 2 s.c om } LabelNode isNullLabel = new LabelNode(); // stack: <rule> instructions.insertBefore(ret, new InsnNode(DUP)); // stack: <rule> :: <rule> instructions.insertBefore(ret, new JumpInsnNode(IFNULL, isNullLabel)); // stack: <rule> instructions.insertBefore(ret, new LdcInsnNode(getLabelText(method))); // stack: <rule> :: <labelText> instructions.insertBefore(ret, new MethodInsnNode(INVOKEINTERFACE, Types.RULE.getInternalName(), "label", "(Ljava/lang/String;)" + Types.RULE_DESC)); // stack: <rule> instructions.insertBefore(ret, isNullLabel); // stack: <rule> }
From source file:com.lodgon.parboiled.transform.ReturnInstructionUnifier.java
License:Apache License
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); if (method.getNumberOfReturns() == 1) return;//from w ww . j a v a 2 s.co m checkState(method.getNumberOfReturns() > 1); AbstractInsnNode current = method.instructions.getLast(); // find last return while (current.getOpcode() != ARETURN) { current = current.getPrevious(); } LabelNode lastReturnLabel = new LabelNode(); method.instructions.insertBefore(current, lastReturnLabel); // iterate backwards up to first instructions while ((current = current.getPrevious()) != null) { // replace returns with gotos if (current.getOpcode() == ARETURN) { JumpInsnNode gotoInstruction = new JumpInsnNode(GOTO, lastReturnLabel); method.instructions.set(current, gotoInstruction); current = gotoInstruction; } } }
From source file:com.lodgon.parboiled.transform.RuleMethodInterpreter.java
License:Open Source License
@Override public void returnOperation(AbstractInsnNode insn, BasicValue value, BasicValue expected) throws AnalyzerException { checkState(insn.getOpcode() == ARETURN); checkState(unwrap(value).getType().equals(Types.RULE)); checkState(unwrap(expected).getType().equals(Types.RULE)); checkState(method.getReturnInstructionNode() == null); method.setReturnInstructionNode(createNode(insn, null, value)); }
From source file:com.lodgon.parboiled.transform.SuperCallRewriter.java
License:Apache License
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); InsnList instructions = method.instructions; AbstractInsnNode insn = instructions.getFirst(); while (insn.getOpcode() != ARETURN) { if (insn.getOpcode() == INVOKESPECIAL) { process(classNode, method, (MethodInsnNode) insn); }/*w w w. j a v a 2 s .co m*/ insn = insn.getNext(); } }
From source file:com.lodgon.parboiled.transform.VarFramingGenerator.java
License:Apache License
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); InsnList instructions = method.instructions; AbstractInsnNode ret = instructions.getLast(); while (ret.getOpcode() != ARETURN) { ret = ret.getPrevious();/* w ww. j a va 2s .c o m*/ } // stack: <Matcher> instructions.insertBefore(ret, new TypeInsnNode(NEW, VAR_FRAMING_MATCHER.getInternalName())); // stack: <Matcher> :: <VarFramingMatcher> instructions.insertBefore(ret, new InsnNode(DUP_X1)); // stack: <VarFramingMatcher> :: <Matcher> :: <VarFramingMatcher> instructions.insertBefore(ret, new InsnNode(SWAP)); // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher> createVarFieldArray(method, instructions, ret); // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher> :: <VarFieldArray> instructions.insertBefore(ret, new MethodInsnNode(INVOKESPECIAL, VAR_FRAMING_MATCHER.getInternalName(), "<init>", '(' + RULE_DESC + '[' + VAR_DESC + ")V")); // stack: <VarFramingMatcher> method.setBodyRewritten(); }
From source file:com.microsoft.Malmo.OverclockingClassTransformer.java
License:Open Source License
private static void overclockServer(ClassNode node, boolean isObfuscated) { // We're attempting to replace this code (from the heart of MinecraftServer.run): /* /*w ww . j a va 2 s . co m*/ { while (i > 50L) { i -= 50L; this.tick(); } } Thread.sleep(Math.max(1L, 50L - i)); */ // With this: /* { while (i > TimeHelper.serverTickLength) { i -= TimeHelper.serverTickLength; this.tick(); } } Thread.sleep(Math.max(1L, TimeHelper.serverTickLength - i)); */ // This allows us to alter the tick length via TimeHelper. final String methodName = "run"; final String methodDescriptor = "()V"; // No params, returns void. System.out.println("MALMO: Found MinecraftServer, attempting to transform it"); for (MethodNode method : node.methods) { if (method.name.equals(methodName) && method.desc.equals(methodDescriptor)) { System.out.println("MALMO: Found MinecraftServer.run() method, attempting to transform it"); for (AbstractInsnNode instruction : method.instructions.toArray()) { if (instruction.getOpcode() == Opcodes.LDC) { Object cst = ((LdcInsnNode) instruction).cst; if ((cst instanceof Long) && (Long) cst == 50) { System.out.println("MALMO: Transforming LDC"); AbstractInsnNode replacement = new FieldInsnNode(Opcodes.GETSTATIC, "com/microsoft/Malmo/Utils/TimeHelper", "serverTickLength", "J"); method.instructions.set(instruction, replacement); } } } } } }