org.objectweb.asm.tree.JumpInsnNode Java Examples
The following examples show how to use
org.objectweb.asm.tree.JumpInsnNode.
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: ControlFlowAnalyser.java From QuickTheories with Apache License 2.0 | 6 votes |
private static Set<AbstractInsnNode> findJumpTargets(final InsnList instructions) { final Set<AbstractInsnNode> jumpTargets = new HashSet<>(); final ListIterator<AbstractInsnNode> it = instructions.iterator(); while (it.hasNext()) { final AbstractInsnNode o = it.next(); if (o instanceof JumpInsnNode) { jumpTargets.add(((JumpInsnNode) o).label); } else if (o instanceof TableSwitchInsnNode) { final TableSwitchInsnNode twn = (TableSwitchInsnNode) o; jumpTargets.add(twn.dflt); jumpTargets.addAll(twn.labels); } else if (o instanceof LookupSwitchInsnNode) { final LookupSwitchInsnNode lsn = (LookupSwitchInsnNode) o; jumpTargets.add(lsn.dflt); jumpTargets.addAll(lsn.labels); } } return jumpTargets; }
Example #2
Source File: BlockLogMethodAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 6 votes |
/** * <p> * This method gets the end index for the provided Jump instruction * </p> * * @param ain * The given jump node * @return int end index */ private int getEndIndexForBlock(AbstractInsnNode ain) { int retIndex = 0; if (ain instanceof JumpInsnNode) { JumpInsnNode jin = (JumpInsnNode) ain; LabelNode targetAIN = jin.label; if (targetAIN.getPrevious() instanceof JumpInsnNode && Opcodes.GOTO == targetAIN.getPrevious().getOpcode()) { retIndex = CollectionUtil.getObjectIndexInArray(this.insnArr, targetAIN .getPrevious().getPrevious()); } else { retIndex = CollectionUtil.getObjectIndexInArray(this.insnArr, targetAIN.getPrevious()); } } return retIndex; }
Example #3
Source File: EntityPlayerSPPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook to disable pushing out of blocks") public void inject(MethodNode main) { AbstractInsnNode preNode = main.instructions.getFirst(); AbstractInsnNode postNode = ASMHelper.findPattern(main.instructions.getFirst(), new int[]{ICONST_0, IRETURN}, "xx"); Objects.requireNonNull(preNode, "Find pattern failed for pre node"); Objects.requireNonNull(postNode, "Find pattern failed for post node"); LabelNode endJump = new LabelNode(); InsnList insnPre = new InsnList(); insnPre.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onPushOutOfBlocks)); insnPre.add(new JumpInsnNode(IFNE, endJump)); main.instructions.insertBefore(preNode, insnPre); main.instructions.insertBefore(postNode, endJump); }
Example #4
Source File: IfElseCompiler.java From jphp with Apache License 2.0 | 6 votes |
private void writeBody(IfStmtToken token) { LabelNode end = new LabelNode(); LabelNode elseL = new LabelNode(); expr.writePopBoolean(); add(new JumpInsnNode(IFEQ, token.getElseBody() != null ? elseL : end)); expr.stackPop(); if (token.getBody() != null) { expr.write(token.getBody()); } if (token.getElseBody() != null){ add(new JumpInsnNode(GOTO, end)); add(elseL); expr.write(token.getElseBody()); } add(end); add(new LineNumberNode(token.getMeta().getEndLine(), end)); }
Example #5
Source File: GenericGenerators.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
/** * Compares two objects and performs some action if the objects are NOT the same (uses != to check if not same). * @param lhs left hand side instruction list -- must leave an object on the stack * @param rhs right hand side instruction list -- must leave an object on the stack * @param action action to perform if results of {@code lhs} and {@code rhs} are not equal * @return instructions instruction list to perform some action if two objects are not equal * @throws NullPointerException if any argument is {@code null} */ public static InsnList ifObjectsNotEqual(InsnList lhs, InsnList rhs, InsnList action) { Validate.notNull(lhs); Validate.notNull(rhs); Validate.notNull(action); InsnList ret = new InsnList(); LabelNode equalLabelNode = new LabelNode(); ret.add(lhs); ret.add(rhs); ret.add(new JumpInsnNode(Opcodes.IF_ACMPEQ, equalLabelNode)); ret.add(action); ret.add(equalLabelNode); return ret; }
Example #6
Source File: ClinitCutter.java From zelixkiller with GNU General Public License v3.0 | 6 votes |
public static AbstractInsnNode findEndLabel(InsnList insns) { AbstractInsnNode ain = insns.getFirst(); while (ain != null) { if (ain.getOpcode() == GOTO && ain.getPrevious() != null && (blockContainsSetter(ain.getPrevious()) || ain.getPrevious().getOpcode() == ASTORE)) { return ((JumpInsnNode) ain).label; } ain = ain.getNext(); } ain = insns.getLast(); while (ain != null) { if (ain.getOpcode() == IF_ICMPGE && ain.getPrevious() != null && (ain.getPrevious().getOpcode() == ILOAD)) { return ((JumpInsnNode) ain).label; } ain = ain.getPrevious(); } throw new RuntimeException(); }
Example #7
Source File: BlockLogMethodAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 6 votes |
/** * <p> * This method scans the instructions for 'else' and returns the node * </p> * * @param ifTargetIndex * Index of the target instruction of 'if' * @param endIndex * Index of the end instruction upto which scanner will work * @param nestingLevel * nesting level * @return Node */ private AbstractInsnNode scanForElse(int ifTargetIndex, int endIndex) { boolean lineNumberFound = false; LabelNode ln = (LabelNode) this.insnArr[ifTargetIndex]; for (int i = ifTargetIndex + 1; i <= endIndex; i++) { AbstractInsnNode ain = this.insnArr[i]; if (ain instanceof JumpInsnNode && InstrumentUtil.getJumpInsnOpcodesMap().containsKey( ain.getOpcode())) { if (!lineNumberFound) { return ain; } } else if (ain instanceof LineNumberNode) { LineNumberNode lnn = (LineNumberNode) ain; // if the line does not belong to the label if (lnn.start != ln) { lineNumberFound = true; return null; } } } return null; }
Example #8
Source File: EntityPlayerSPPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook to disable the use slowdown effect") public void inject(MethodNode main) { AbstractInsnNode applySlowdownSpeedNode = ASMHelper.findPattern( main.instructions.getFirst(), new int[]{IFNE, 0x00, 0x00, ALOAD, GETFIELD, DUP, GETFIELD, LDC, FMUL, PUTFIELD}, "x??xxxxxxx"); Objects.requireNonNull( applySlowdownSpeedNode, "Find pattern failed for applySlowdownSpeedNode"); // get label it jumps to LabelNode jumpTo = ((JumpInsnNode) applySlowdownSpeedNode).label; InsnList insnList = new InsnList(); insnList.add(ASMHelper.call(GETSTATIC, TypesHook.Fields.ForgeHaxHooks_isNoSlowDownActivated)); insnList.add(new JumpInsnNode(IFNE, jumpTo)); main.instructions.insert(applySlowdownSpeedNode, insnList); }
Example #9
Source File: PlayerControllerMCPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add callback at top of method") public void inject(MethodNode node) { AbstractInsnNode last = ASMHelper.findPattern(node.instructions.getFirst(), new int[]{RETURN}, "x"); Objects.requireNonNull(last, "Could not find RET opcode"); LabelNode label = new LabelNode(); InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 0)); list.add(new VarInsnNode(ALOAD, 1)); list.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onPlayerStopUse)); list.add(new JumpInsnNode(IFNE, label)); node.instructions.insert(list); node.instructions.insertBefore(last, label); }
Example #10
Source File: WorldPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook before everything") public void inject(MethodNode method) { AbstractInsnNode node = method.instructions.getFirst(); Objects.requireNonNull(node, "Failed to find node."); LabelNode label = new LabelNode(); InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 1)); // enum list.add(new VarInsnNode(ALOAD, 2)); // blockpos list.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onWorldCheckLightFor)); list.add(new JumpInsnNode(IFEQ, label)); list.add(new InsnNode(ICONST_0)); list.add(new InsnNode(IRETURN)); list.add(label); method.instructions.insertBefore(node, list); }
Example #11
Source File: GotoCompiler.java From jphp with Apache License 2.0 | 6 votes |
@Override public void write(GotoStmtToken token) { LabelNode labelNode = method.getOrCreateGotoLabel(token.getLabel().getName()); LabelStmtToken labelStmtToken = method.statement.findLabel(token.getLabel().getName()); if (labelStmtToken == null) { compiler.getEnvironment().error( token.getLabel().toTraceInfo(compiler.getContext()), "'goto' to undefined label '%s'", token.getLabel().getName() ); return; } if (labelStmtToken.getLevel() > token.getLevel()) { compiler.getEnvironment().error( token.toTraceInfo(compiler.getContext()), "'goto' into loop, switch or finally statement is disallowed" ); } add(new JumpInsnNode(GOTO, labelNode)); }
Example #12
Source File: Subroutine.java From Concurnas with MIT License | 6 votes |
/** * Merges the given subroutine into this subroutine. The local variables read or written by the * given subroutine are marked as read or written by this one, and the callers of the given * subroutine are added as callers of this one (if both have the same start). * * @param subroutine another subroutine. This subroutine is left unchanged by this method. * @return whether this subroutine has been modified by this method. */ public boolean merge(final Subroutine subroutine) { boolean changed = false; for (int i = 0; i < localsUsed.length; ++i) { if (subroutine.localsUsed[i] && !localsUsed[i]) { localsUsed[i] = true; changed = true; } } if (subroutine.start == start) { for (int i = 0; i < subroutine.callers.size(); ++i) { JumpInsnNode caller = subroutine.callers.get(i); if (!callers.contains(caller)) { callers.add(caller); changed = true; } } } return changed; }
Example #13
Source File: Subroutine.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
public boolean merge(final Subroutine subroutine) throws AnalyzerException { boolean changes = false; for (int i = 0; i < access.length; ++i) { if (subroutine.access[i] && !access[i]) { access[i] = true; changes = true; } } if (subroutine.start == start) { for (int i = 0; i < subroutine.callers.size(); ++i) { JumpInsnNode caller = subroutine.callers.get(i); if (!callers.contains(caller)) { callers.add(caller); changes = true; } } } return changes; }
Example #14
Source File: GenericGenerators.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
/** * Compares two objects and performs some action if the objects are the same (uses == to check if same, not the equals method). * @param lhs left hand side instruction list -- must leave an object on the stack * @param rhs right hand side instruction list -- must leave an object on the stack * @param action action to perform if results of {@code lhs} and {@code rhs} are equal * @return instructions instruction list to perform some action if two objects are equal * @throws NullPointerException if any argument is {@code null} */ public static InsnList ifObjectsEqual(InsnList lhs, InsnList rhs, InsnList action) { Validate.notNull(lhs); Validate.notNull(rhs); Validate.notNull(action); InsnList ret = new InsnList(); LabelNode notEqualLabelNode = new LabelNode(); ret.add(lhs); ret.add(rhs); ret.add(new JumpInsnNode(Opcodes.IF_ACMPNE, notEqualLabelNode)); ret.add(action); ret.add(notEqualLabelNode); return ret; }
Example #15
Source File: Subroutine.java From Cafebabe with GNU General Public License v3.0 | 6 votes |
/** * Merges the given subroutine into this subroutine. The local variables read or written by the given subroutine are marked as read or written by this one, and the callers of the given subroutine are added as callers of this one (if both have the same start). * * @param subroutine * another subroutine. This subroutine is left unchanged by this method. * @return whether this subroutine has been modified by this method. */ public boolean merge(final Subroutine subroutine) { boolean changed = false; for (int i = 0; i < localsUsed.length; ++i) { if (subroutine.localsUsed[i] && !localsUsed[i]) { localsUsed[i] = true; changed = true; } } if (subroutine.start == start) { for (int i = 0; i < subroutine.callers.size(); ++i) { JumpInsnNode caller = subroutine.callers.get(i); if (!callers.contains(caller)) { callers.add(caller); changed = true; } } } return changed; }
Example #16
Source File: BoatPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook to disable boat gravity") public void inject(MethodNode main) { AbstractInsnNode gravityNode = ASMHelper.findPattern( main.instructions.getFirst(), new int[]{ALOAD, DUP, GETFIELD, DLOAD, DADD, PUTFIELD}, "xxxxxx"); Objects.requireNonNull(gravityNode, "Find pattern failed for gravityNode"); AbstractInsnNode putFieldNode = gravityNode; for (int i = 0; i < 5; i++) { putFieldNode = putFieldNode.getNext(); } LabelNode newLabelNode = new LabelNode(); InsnList insnList = new InsnList(); insnList.add( ASMHelper.call(GETSTATIC, TypesHook.Fields.ForgeHaxHooks_isNoBoatGravityActivated)); insnList.add(new JumpInsnNode(IFNE, newLabelNode)); // if nogravity is enabled main.instructions.insertBefore(gravityNode, insnList); // insert if main.instructions.insert(putFieldNode, newLabelNode); // end if }
Example #17
Source File: ControlFlowAnalyser.java From pitest with Apache License 2.0 | 6 votes |
private static Set<LabelNode> findJumpTargets(final InsnList instructions) { final Set<LabelNode> jumpTargets = new HashSet<>(); for (AbstractInsnNode o : instructions) { if (o instanceof JumpInsnNode) { jumpTargets.add(((JumpInsnNode) o).label); } else if (o instanceof TableSwitchInsnNode) { final TableSwitchInsnNode twn = (TableSwitchInsnNode) o; jumpTargets.add(twn.dflt); jumpTargets.addAll(twn.labels); } else if (o instanceof LookupSwitchInsnNode) { final LookupSwitchInsnNode lsn = (LookupSwitchInsnNode) o; jumpTargets.add(lsn.dflt); jumpTargets.addAll(lsn.labels); } } return jumpTargets; }
Example #18
Source File: ModifyConstantInjector.java From Mixin with MIT License | 6 votes |
/** * Injects a constant modifier at an implied-zero * * @param target target method * @param jumpNode jump instruction (must be IFLT, IFGE, IFGT or IFLE) */ private void injectExpandedConstantModifier(Target target, JumpInsnNode jumpNode) { int opcode = jumpNode.getOpcode(); if (opcode < Opcodes.IFLT || opcode > Opcodes.IFLE) { throw new InvalidInjectionException(this.info, String.format("%s annotation selected an invalid opcode %s in %s in %s", this.annotationType, Bytecode.getOpcodeName(opcode), target, this)); } Extension extraStack = target.extendStack(); final InsnList insns = new InsnList(); insns.add(new InsnNode(Opcodes.ICONST_0)); AbstractInsnNode invoke = this.invokeConstantHandler(Type.getType("I"), target, extraStack, insns, insns); insns.add(new JumpInsnNode(opcode + ModifyConstantInjector.OPCODE_OFFSET, jumpNode.label)); extraStack.add(1).apply(); target.replaceNode(jumpNode, invoke, insns); }
Example #19
Source File: GameDataTransformer.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
private void transformAddPrefix(ClassNode cnode) { ObfMapping mapping = new ObfMapping("net/minecraftforge/fml/common/registry/GameData", "addPrefix", "(Ljava/lang/String;)Ljava/lang/String;"); MethodNode method = ASMHelper.findMethod(mapping, cnode); if (method == null) { throw new IllegalStateException("[NOVA] Lookup " + mapping + " failed!"); } Game.logger().info("Transforming method {}", method.name); @SuppressWarnings("unchecked") JumpInsnNode prev = (JumpInsnNode) method.instructions.get(49); InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 4)); list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v18/asm/StaticForwarder", "isNovaPrefix", "(Ljava/lang/String;)Z", false)); list.add(new JumpInsnNode(IFNE, prev.label)); method.instructions.insert(prev, list); Game.logger().info("Injected instruction to method: {}", method.name); }
Example #20
Source File: IForgeRegistryEntryTransformer.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void transform(ClassNode cnode) { Game.logger().info("Transforming IForgeRegistryEntry class for correct NOVA mod id mapping."); ObfMapping mapping = new ObfMapping("net/minecraftforge/fml/common/registry/IForgeRegistryEntry$Impl", "setRegistryName", "(Ljava/lang/String;)Lnet/minecraftforge/fml/common/registry/IForgeRegistryEntry;"); MethodNode method = ASMHelper.findMethod(mapping, cnode); if (method == null) { throw new IllegalStateException("[NOVA] Lookup " + mapping + " failed!"); } Game.logger().info("Transforming method {}", method.name); InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 5)); list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v1_11_2/asm/StaticForwarder", "isNovaPrefix", "(Ljava/lang/String;)Z", false)); list.add(new JumpInsnNode(IFNE, (LabelNode) method.instructions.get(120))); method.instructions.insert(method.instructions.get(101), list); Game.logger().info("Injected instruction to method: {}", method.name); }
Example #21
Source File: MyCodeList.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
protected void duplicate(MethodNode mn, AbstractInsnNode ain) { try { if (ain instanceof LabelNode) { mn.instructions.insert(ain, new LabelNode()); OpUtils.clearLabelCache(); } else if (ain instanceof JumpInsnNode) { mn.instructions.insert(ain, new JumpInsnNode(ain.getOpcode(), ((JumpInsnNode) ain).label)); } else { mn.instructions.insert(ain, ain.clone(new HashMap<>())); } MyCodeList.this.loadInstructions(mn); } catch (Exception e1) { new ErrorDisplay(e1); } }
Example #22
Source File: BlockLogMethodAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 6 votes |
/** * <p> * This method scans to find GoTo instruction * </p> * * @param nestingLevel * nesting level */ private void scanGoTo(int nestingLevel) { if (this.currentTarget[nestingLevel].getPrevious() instanceof JumpInsnNode && Opcodes.GOTO == this.currentTarget[nestingLevel] .getPrevious().getOpcode()) { logger.debug(InstrumentationMessageLoader .getMessage(MessageConstants.LOG_GOTO_FOUND)); this.isGoToFound[nestingLevel] = true; this.currentJIN[nestingLevel] = (JumpInsnNode) this.currentTarget[nestingLevel] .getPrevious(); this.currentTarget[nestingLevel] = this.currentJIN[nestingLevel].label; } else { logger.debug(InstrumentationMessageLoader .getMessage(MessageConstants.LOG_GOTO_NOT_FOUND)); this.isGoToFound[nestingLevel] = false; } }
Example #23
Source File: NetManager$4Patch.java From ForgeHax with MIT License | 5 votes |
@Inject(description = "Add a pre and post hook that allows the method to be disabled") public void inject(MethodNode main) { AbstractInsnNode preNode = ASMHelper.findPattern( main.instructions.getFirst(), new int[]{ALOAD, GETFIELD, ALOAD, GETFIELD, IF_ACMPEQ}, "xxxxx"); AbstractInsnNode postNode = ASMHelper.findPattern(main.instructions.getFirst(), new int[]{RETURN}, "x"); Objects.requireNonNull(preNode, "Find pattern failed for preNode"); Objects.requireNonNull(postNode, "Find pattern failed for postNode"); LabelNode endJump = new LabelNode(); InsnList insnPre = new InsnList(); insnPre.add(new VarInsnNode(ALOAD, 0)); insnPre.add(ASMHelper.call(GETFIELD, Fields.NetworkManager$4_val$inPacket)); insnPre.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onSendingPacket)); insnPre.add(new JumpInsnNode(IFNE, endJump)); InsnList insnPost = new InsnList(); insnPost.add(new VarInsnNode(ALOAD, 0)); insnPost.add(ASMHelper.call(GETFIELD, Fields.NetworkManager$4_val$inPacket)); insnPost.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onSentPacket)); insnPost.add(endJump); main.instructions.insertBefore(preNode, insnPre); main.instructions.insertBefore(postNode, insnPost); }
Example #24
Source File: BlockPatch.java From ForgeHax with MIT License | 5 votes |
@Inject( description = "Redirects method to our hook and allows the vanilla code to be canceled from executing", priority = InjectPriority.LOWEST ) public void inject(MethodNode main) { AbstractInsnNode node = main.instructions.getFirst(); AbstractInsnNode end = ASMHelper.findPattern(main.instructions.getFirst(), new int[]{RETURN}, "x"); Objects.requireNonNull(node, "Find pattern failed for node"); Objects.requireNonNull(end, "Find pattern failed for end"); LabelNode jumpPast = new LabelNode(); InsnList insnList = new InsnList(); insnList.add(new VarInsnNode(ALOAD, 0)); // block insnList.add(new VarInsnNode(ALOAD, 1)); // state insnList.add(new VarInsnNode(ALOAD, 2)); // world insnList.add(new VarInsnNode(ALOAD, 3)); // pos insnList.add(new VarInsnNode(ALOAD, 4)); // entityBox insnList.add(new VarInsnNode(ALOAD, 5)); // collidingBoxes insnList.add(new VarInsnNode(ALOAD, 6)); // entityIn insnList.add(new VarInsnNode(ILOAD, 7)); // bool insnList.add( ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onAddCollisionBoxToList)); insnList.add(new JumpInsnNode(IFNE, jumpPast)); main.instructions.insertBefore(end, jumpPast); main.instructions.insertBefore(node, insnList); }
Example #25
Source File: GameDataTransformer.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
private void transformRegisterItem(ClassNode cnode) { ObfMapping obfMap = new ObfMapping("net/minecraftforge/fml/common/registry/GameData", "registerItem", "(Lalq;Ljava/lang/String;)I"); ObfMapping deobfMap = new ObfMapping("net/minecraftforge/fml/common/registry/GameData", "registerItem", "(Lnet/minecraft/item/Item;Ljava/lang/String;)I"); MethodNode method = ASMHelper.findMethod(obfMap, cnode); if (method == null) { Game.logger().warn("Lookup {} failed. You are probably in a deobf environment.", obfMap); method = ASMHelper.findMethod(deobfMap, cnode); if (method == null) { throw new IllegalStateException("[NOVA] Lookup " + deobfMap + " failed!"); } } Game.logger().info("Transforming method {}", method.name); @SuppressWarnings("unchecked") JumpInsnNode prev = (JumpInsnNode) method.instructions.get(12); InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 2)); list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v18/asm/StaticForwarder", "hasNovaPrefix", "(Ljava/lang/String;)Z", false)); list.add(new JumpInsnNode(IFNE, prev.label)); method.instructions.insert(prev, list); Game.logger().info("Injected instruction to method: {}", method.name); }
Example #26
Source File: GenericGenerators.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generates instructions for an unconditional jump to a label. * @param labelNode label to jump to * @throws NullPointerException if any argument is {@code null} * @return instructions for an unconditional jump to {@code labelNode} */ public static InsnList jumpTo(LabelNode labelNode) { Validate.notNull(labelNode); InsnList ret = new InsnList(); ret.add(new JumpInsnNode(Opcodes.GOTO, labelNode)); return ret; }
Example #27
Source File: ModifyConstantInjector.java From Mixin with MIT License | 5 votes |
@Override protected void inject(Target target, InjectionNode node) { if (!this.preInject(node)) { return; } if (node.isReplaced()) { throw new UnsupportedOperationException("Target failure for " + this.info); } AbstractInsnNode targetNode = node.getCurrentTarget(); if (targetNode instanceof TypeInsnNode) { this.checkTargetModifiers(target, false); this.injectTypeConstantModifier(target, (TypeInsnNode)targetNode); return; } if (targetNode instanceof JumpInsnNode) { this.checkTargetModifiers(target, false); this.injectExpandedConstantModifier(target, (JumpInsnNode)targetNode); return; } if (Bytecode.isConstant(targetNode)) { this.checkTargetModifiers(target, false); this.injectConstantModifier(target, targetNode); return; } throw new InvalidInjectionException(this.info, String.format("%s annotation is targetting an invalid insn in %s in %s", this.annotationType, target, this)); }
Example #28
Source File: JSRInlinerAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitJumpInsn(final int opcode, final Label label) { super.visitJumpInsn(opcode, label); LabelNode labelNode = ((JumpInsnNode) instructions.getLast()).label; if (opcode == JSR && !subroutinesInsns.containsKey(labelNode)) { subroutinesInsns.put(labelNode, new BitSet()); } }
Example #29
Source File: ReturnInstructionUnifier.java From grappa with Apache License 2.0 | 5 votes |
@Override public void process(@Nonnull final ParserClassNode classNode, @Nonnull final RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); AbstractInsnNode current = method.instructions.getLast(); // find last return while (current.getOpcode() != ARETURN) current = current.getPrevious(); final 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) continue; final JumpInsnNode insn = new JumpInsnNode(GOTO, lastReturnLabel); method.instructions.set(current, insn); current = insn; } }
Example #30
Source File: JSRInlinerAdapter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public void visitJumpInsn(final int opcode, final Label label) { super.visitJumpInsn(opcode, label); LabelNode labelNode = ((JumpInsnNode) instructions.getLast()).label; if (opcode == JSR && !subroutinesInsns.containsKey(labelNode)) { subroutinesInsns.put(labelNode, new BitSet()); } }