Java Code Examples for org.objectweb.asm.Opcodes#GOTO
The following examples show how to use
org.objectweb.asm.Opcodes#GOTO .
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: BytecodeOutputter.java From Concurnas with MIT License | 6 votes |
public void visitJumpInsn(int ifne, Label ifFalse) { if (!((lastWroteThrow || lastWroteRet) && ifne == Opcodes.GOTO)) { consumeNextLabelIfExists(); if (null == ifFalse) { throw new RuntimeException("null label"); } lastWroteThrow = false; lastWriteLabel = false; lastWroteRet = false; Label togo = labelOverride.containsKey(ifFalse) ? labelOverride.get(ifFalse) : ifFalse; if (PRINT_OPCODES) { System.out.println(" " + opcodeToBytecode.get(ifne) + " " + togo); } this.mv.visitJumpInsn(ifne, togo); // int t = 8; } // skip otherwise }
Example 2
Source File: RemoveConditionalMutator.java From pitest with Apache License 2.0 | 6 votes |
@Override public void visitJumpInsn(final int opcode, final Label label) { if (canMutate(opcode)) { final MutationIdentifier newId = this.context.registerMutation( this.factory, this.description); if (this.context.shouldMutate(newId)) { emptyStack(opcode); if (!RemoveConditionalMutator.this.replaceWith) { super.visitJumpInsn(Opcodes.GOTO, label); } } else { this.mv.visitJumpInsn(opcode, label); } } else { this.mv.visitJumpInsn(opcode, label); } }
Example 3
Source File: RuntimeInstrument.java From dacapobench with Apache License 2.0 | 6 votes |
@SuppressWarnings("unused") protected void onMethodEnter() { if (done) return; overridden = true; Label start = new Label(); Label normal = new Label(); super.visitLabel(start); super.visitFieldInsn(Opcodes.GETSTATIC, CONFIGURATION, CONFIGURATION_FIELD_NAME, Type.INT_TYPE.getDescriptor()); super.visitInsn(Opcodes.DUP); super.visitJumpInsn(Opcodes.IFEQ, normal); super.visitInsn(Opcodes.IRETURN); super.visitLabel(normal); super.visitInsn(Opcodes.POP); Label end = new Label(); super.visitJumpInsn(Opcodes.GOTO, end); super.visitLabel(end); super.visitTryCatchBlock(start, normal, end, Type.getType(Throwable.class).getDescriptor()); }
Example 4
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 5
Source File: ClinitInstrument.java From dacapobench with Apache License 2.0 | 5 votes |
protected void onMethodEnter() { Label target = super.newLabel(); // invoke the logger, note that we may not know about the Log class yet so we must catch and ignore the // exception here. super.visitLdcInsn(className); Label start = super.mark(); super.visitMethodInsn(Opcodes.INVOKESTATIC, LOG_INTERNAL, LOG_METHOD_NAME, LOG_METHOD_SIGNATURE); Label end = super.mark(); super.visitJumpInsn(Opcodes.GOTO,target); // catch the exception, discard the exception super.catchException(start,end,JAVA_LANG_THROWABLE_TYPE); super.pop(); super.mark(target); // remainder of the <clinit> }
Example 6
Source File: BuildStackInfoAdapter.java From copper-engine with Apache License 2.0 | 5 votes |
@Override public void visitJumpInsn(int arg0, Label arg1) { savePreviousFrame(); switch (arg0) { case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPNE: currentFrame.popStack(); case Opcodes.IFEQ: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: case Opcodes.IFLT: case Opcodes.IFNE: case Opcodes.IFNONNULL: case Opcodes.IFNULL: currentFrame.popStack(); case Opcodes.GOTO: forwardFrames.put(arg1, new StackInfo(currentFrame)); break; case Opcodes.JSR: currentFrame.pushStack(retAddressType); forwardFrames.put(arg1, new StackInfo(currentFrame)); break; default: logger.debug("Unhandled: "); } if (logger.isDebugEnabled()) logger.debug("jumpInsn " + getOpCode(arg0) + " " + arg1); delegate.visitJumpInsn(arg0, arg1); }
Example 7
Source File: BytecodeTypeInference.java From bazel with Apache License 2.0 | 5 votes |
@Override public void visitJumpInsn(int opcode, Label label) { switch (opcode) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: pop(); break; case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: pop(2); break; case Opcodes.GOTO: break; case Opcodes.JSR: throw new RuntimeException("The JSR instruction is not supported."); case Opcodes.IFNULL: case Opcodes.IFNONNULL: pop(1); break; default: throw new RuntimeException("Unhandled opcode " + opcode); } super.visitJumpInsn(opcode, label); }
Example 8
Source File: BlockLogMethodAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 5 votes |
/** * <p> * This method processes loops and add logging * </p> * * @param firstStmtInLoopIndex * Index of the first statement in the loop. * @param loopEndIndex * Index where loop ends. * @param nestingLevel * nesting level */ private void processLoop(int firstStmtInLoopIndex, int loopEndIndex, int nestingLevel) { logger.debug(firstStmtInLoopIndex + " " + loopEndIndex); this.currentLoopCount[nestingLevel]++; AbstractInsnNode abstractInsnNode; // adding loop entry abstractInsnNode = this.insnArr[firstStmtInLoopIndex]; AbstractInsnNode gotoNode = abstractInsnNode.getPrevious(); AbstractInsnNode lineNode = abstractInsnNode.getNext(); if ((gotoNode instanceof JumpInsnNode && Opcodes.GOTO == gotoNode .getOpcode()) || (!(lineNode instanceof LineNumberNode))) { lineNode = getPreviousLineNode(abstractInsnNode); } Integer lineNumber = ((LineNumberNode) lineNode).line; String cSymbol = env.getClassSymbol(getClassName()); String mSymbol = env.getMethodSymbol(getClassName(), cSymbol, name); InsnList il1 = InstrumentUtil.addLogMessage(cSymbol,mSymbol, InstrumentationMessageLoader .getMessage(MessageConstants.ENTERED_LOOP), lineNumber .toString(), this.currentLoopCount[nestingLevel] .toString()); instructions.insertBefore(lineNode.getPrevious(), il1); // handling map reduce output in the loop handleCtxWrite(firstStmtInLoopIndex, loopEndIndex); // adding loop exit abstractInsnNode = this.insnArr[loopEndIndex]; InsnList il2 = InstrumentUtil.addloopCounterLogging(cSymbol, mSymbol, InstrumentationMessageLoader .getMessage(MessageConstants.EXITING_LOOP), this.localVariableSize, this.currentLoopCount[nestingLevel] .toString()); // resetting the counter to ZERO il2.add(new LabelNode()); il2.add(new InsnNode(Opcodes.ICONST_0)); il2.add(new VarInsnNode(Opcodes.ISTORE, this.localVariableSize)); instructions.insert(abstractInsnNode.getNext(), il2); this.addLocalVariable(this.localVariableSize); }
Example 9
Source File: ChunkSerializerMixin.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "serialize", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;saveToTag(Lnet/minecraft/nbt/CompoundTag;)Z"), to = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/ProtoChunk;getEntities()Ljava/util/List;")), at = @At(value = "JUMP", opcode = Opcodes.GOTO, ordinal = 2), locals = LocalCapture.CAPTURE_FAILHARD) private static void serializeCapabilities(ServerWorld serverWorld, Chunk chunk, CallbackInfoReturnable<CompoundTag> callbackInfoReturnable, ChunkPos chunkPos, CompoundTag compoundTag, CompoundTag level) { CompoundTag tag = ((CapabilityProviderHolder) chunk).serializeCaps(); if (tag != null) { level.put("ForgeCaps", tag); } }
Example 10
Source File: AnalyzerAdapter.java From JReFrameworker with MIT License | 5 votes |
@Override public void visitJumpInsn(final int opcode, final Label label) { super.visitJumpInsn(opcode, label); execute(opcode, 0, null); if (opcode == Opcodes.GOTO) { this.locals = null; this.stack = null; } }
Example 11
Source File: Utils.java From obfuscator with MIT License | 5 votes |
public static AbstractInsnNode getNextFollowGoto(AbstractInsnNode node) { AbstractInsnNode next = node.getNext(); while (next instanceof LabelNode || next instanceof LineNumberNode || next instanceof FrameNode) { next = next.getNext(); } if (next.getOpcode() == Opcodes.GOTO) { JumpInsnNode cast = (JumpInsnNode) next; next = cast.label; while (Utils.isNotInstruction(next)) { next = next.getNext(); } } return next; }
Example 12
Source File: AnalyzerAdapter.java From Concurnas with MIT License | 5 votes |
@Override public void visitJumpInsn(final int opcode, final Label label) { super.visitJumpInsn(opcode, label); execute(opcode, 0, null); if (opcode == Opcodes.GOTO) { this.locals = null; this.stack = null; } }
Example 13
Source File: InstructionAdapter.java From JReFrameworker with MIT License | 4 votes |
@Override public void visitJumpInsn(final int opcode, final Label label) { switch (opcode) { case Opcodes.IFEQ: ifeq(label); break; case Opcodes.IFNE: ifne(label); break; case Opcodes.IFLT: iflt(label); break; case Opcodes.IFGE: ifge(label); break; case Opcodes.IFGT: ifgt(label); break; case Opcodes.IFLE: ifle(label); break; case Opcodes.IF_ICMPEQ: ificmpeq(label); break; case Opcodes.IF_ICMPNE: ificmpne(label); break; case Opcodes.IF_ICMPLT: ificmplt(label); break; case Opcodes.IF_ICMPGE: ificmpge(label); break; case Opcodes.IF_ICMPGT: ificmpgt(label); break; case Opcodes.IF_ICMPLE: ificmple(label); break; case Opcodes.IF_ACMPEQ: ifacmpeq(label); break; case Opcodes.IF_ACMPNE: ifacmpne(label); break; case Opcodes.GOTO: goTo(label); break; case Opcodes.JSR: jsr(label); break; case Opcodes.IFNULL: ifnull(label); break; case Opcodes.IFNONNULL: ifnonnull(label); break; default: throw new IllegalArgumentException(); } }
Example 14
Source File: UnconditionalJumpEdge.java From maple-ir with GNU General Public License v3.0 | 4 votes |
public UnconditionalJumpEdge(N src, N dst) { super(UNCOND, src, dst, Opcodes.GOTO); }
Example 15
Source File: JumpInsnNode.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
public JumpInsnNode() { super(Opcodes.GOTO); }
Example 16
Source File: JVMImpl.java From serianalyzer with GNU General Public License v3.0 | 4 votes |
/** * @param opcode * @param label * @param s * @return */ static boolean handleJVMJump ( int opcode, Label label, JVMStackState s ) { boolean tainted; switch ( opcode ) { case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: BaseType o1 = s.pop(); BaseType o2 = s.pop(); tainted = ! ( o1 != null ) || ! ( o2 != null ) || o1.isTainted() || o2.isTainted(); break; case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: case Opcodes.IFNULL: case Opcodes.IFNONNULL: BaseType c = s.pop(); tainted = ( c == null || c.isTainted() ); break; case Opcodes.JSR: s.push(new BasicConstant(Type.INT_TYPE, label)); tainted = false; break; case Opcodes.GOTO: tainted = false; break; default: log.warn("Unsupported opcode " + opcode); //$NON-NLS-1$ tainted = true; } return tainted; }
Example 17
Source File: RepeatedConditionals.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { if (hasSideEffect(seen)) { reset(); } else if (stack.getStackDepth() == 0) { if (emptyStackLocations.size() > 1) { for (int n = 1; n <= emptyStackLocations.size() / 2; n++) { int first = emptyStackLocations.get(emptyStackLocations.size() - 2 * n); int second = emptyStackLocations.get(emptyStackLocations.size() - n); int third = getPC(); if (third - second == second - first) { int endOfFirstSegment = prevOpcodeLocations.get(emptyStackLocations.size() - n); int endOfSecondSegment = oldPC; int opcodeAtEndOfFirst = getCodeByte(endOfFirstSegment); int opcodeAtEndOfSecond = getCodeByte(endOfSecondSegment); if (!isBranch(opcodeAtEndOfFirst) || !isBranch(opcodeAtEndOfSecond)) { continue; } if (opcodeAtEndOfFirst == Opcodes.GOTO || opcodeAtEndOfSecond == Opcodes.GOTO) { continue; } if (opcodeAtEndOfFirst != opcodeAtEndOfSecond && !areOppositeBranches(opcodeAtEndOfFirst, opcodeAtEndOfSecond)) { continue; } if (first == endOfFirstSegment) { continue; } Integer firstTarget = branchTargets.get(endOfFirstSegment); Integer secondTarget = branchTargets.get(endOfSecondSegment); if (firstTarget == null || secondTarget == null) { continue; } if (firstTarget >= second && firstTarget <= endOfSecondSegment) { // first jumps inside second continue; } boolean identicalCheck = firstTarget.equals(secondTarget) && opcodeAtEndOfFirst == opcodeAtEndOfSecond || (firstTarget.intValue() == getPC() && opcodeAtEndOfFirst != opcodeAtEndOfSecond); if (!compareCode(first, endOfFirstSegment, second, endOfSecondSegment, !identicalCheck)) { continue; } SourceLineAnnotation firstSourceLine = SourceLineAnnotation.fromVisitedInstructionRange(getClassContext(), this, first, endOfFirstSegment - 1); SourceLineAnnotation secondSourceLine = SourceLineAnnotation.fromVisitedInstructionRange(getClassContext(), this, second, endOfSecondSegment - 1); int priority = HIGH_PRIORITY; if (firstSourceLine.getStartLine() == -1 || firstSourceLine.getStartLine() != secondSourceLine.getEndLine()) { priority++; } if (stack.isJumpTarget(second)) { priority++; } if (!identicalCheck) { // opposite checks priority += 2; } BugInstance bug = new BugInstance(this, "RpC_REPEATED_CONDITIONAL_TEST", priority).addClassAndMethod(this) .add(firstSourceLine).add(secondSourceLine); bugReporter.reportBug(bug); } } } emptyStackLocations.add(getPC()); prevOpcodeLocations.add(oldPC); } oldPC = getPC(); }
Example 18
Source File: InstructionAdapter.java From Concurnas with MIT License | 4 votes |
@Override public void visitJumpInsn(final int opcode, final Label label) { switch (opcode) { case Opcodes.IFEQ: ifeq(label); break; case Opcodes.IFNE: ifne(label); break; case Opcodes.IFLT: iflt(label); break; case Opcodes.IFGE: ifge(label); break; case Opcodes.IFGT: ifgt(label); break; case Opcodes.IFLE: ifle(label); break; case Opcodes.IF_ICMPEQ: ificmpeq(label); break; case Opcodes.IF_ICMPNE: ificmpne(label); break; case Opcodes.IF_ICMPLT: ificmplt(label); break; case Opcodes.IF_ICMPGE: ificmpge(label); break; case Opcodes.IF_ICMPGT: ificmpgt(label); break; case Opcodes.IF_ICMPLE: ificmple(label); break; case Opcodes.IF_ACMPEQ: ifacmpeq(label); break; case Opcodes.IF_ACMPNE: ifacmpne(label); break; case Opcodes.GOTO: goTo(label); break; case Opcodes.JSR: jsr(label); break; case Opcodes.IFNULL: ifnull(label); break; case Opcodes.IFNONNULL: ifnonnull(label); break; default: throw new IllegalArgumentException(); } }
Example 19
Source File: AllocationMethodAdapter.java From allocation-instrumenter with Apache License 2.0 | 4 votes |
void calculateArrayLengthAndDispatch(String typeName, int dimCount) { // Since the dimensions of the array are not known at instrumentation // time, we take the created multi-dimensional array and peel off nesting // levels from the left. For each nesting layer we probe the array length // and accumulate a partial product which we can then feed the recording // function. // below we note the partial product of dimensions 1 to X-1 as productToX // (so productTo1 == 1 == no dimensions yet). We denote by aref0 the // array reference at the current nesting level (the containing aref's [0] // element). If we hit a level whose arraylength is 0 or whose // reference is null, there's no point continuing, so we shortcut // out. // This approach works pretty well when you create a new array with the // newarray bytecodes. You can also create a new array by cloning an // existing array; an existing multidimensional array might have had some // of its [0] elements nulled out. We currently deal with this by bailing // out, but arguably we should do something more principled (like calculate // the size of the multidimensional array from scratch if you are using // clone()). // TODO(java-platform-team): Do something about modified multidimensional // arrays and clone(). Label zeroDimension = new Label(); super.visitInsn(Opcodes.DUP); // -> stack: ... origaref aref0 super.visitLdcInsn(1); // -> stack: ... origaref aref0 productTo1 for (int i = 0; i < dimCount; ++i) { // pre: stack: ... origaref aref0 productToI super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref productToI aref super.visitInsn(Opcodes.DUP); Label nonNullDimension = new Label(); // -> stack: ... origaref productToI aref aref super.visitJumpInsn(Opcodes.IFNONNULL, nonNullDimension); // -> stack: ... origaref productToI aref super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref aref productToI super.visitJumpInsn(Opcodes.GOTO, zeroDimension); super.visitLabel(nonNullDimension); // -> stack: ... origaref productToI aref super.visitInsn(Opcodes.DUP_X1); // -> stack: ... origaref aref0 productToI aref super.visitInsn(Opcodes.ARRAYLENGTH); // -> stack: ... origaref aref0 productToI dimI Label nonZeroDimension = new Label(); super.visitInsn(Opcodes.DUP); // -> stack: ... origaref aref0 productToI dimI dimI super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension); // -> stack: ... origaref aref0 productToI dimI super.visitInsn(Opcodes.POP); // -> stack: ... origaref aref0 productToI super.visitJumpInsn(Opcodes.GOTO, zeroDimension); super.visitLabel(nonZeroDimension); // -> stack: ... origaref aref0 productToI max(dimI,1) super.visitInsn(Opcodes.IMUL); // -> stack: ... origaref aref0 productTo{I+1} if (i < dimCount - 1) { super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref productTo{I+1} aref0 super.visitInsn(Opcodes.ICONST_0); // -> stack: ... origaref productTo{I+1} aref0 0 super.visitInsn(Opcodes.AALOAD); // -> stack: ... origaref productTo{I+1} aref0' super.visitInsn(Opcodes.SWAP); } // post: stack: ... origaref aref0 productTo{I+1} } super.visitLabel(zeroDimension); super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref product aref0 super.visitInsn(Opcodes.POP); // -> stack: ... origaref product super.visitInsn(Opcodes.SWAP); // -> stack: ... product origaref invokeRecordAllocation(typeName); }
Example 20
Source File: ASMHelper.java From TFC2 with GNU General Public License v3.0 | 3 votes |
/** * Note: This is an alternative to {@link #removeFromInsnListUntil(InsnList, AbstractInsnNode, AbstractInsnNode) removeFromInsnListUntil} and will achieve a similar result. <br> * <br> * * Skip instructions from {@code insnList} starting with {@code startInclusive} * up until reaching {@code endNotInclusive} ({@code endNotInclusive} will not be skipped). * * This is achieved by inserting a GOTO instruction before {@code startInclusive} which is branched to a * LabelNode that is inserted before {@code endNotInclusive}. */ public static void skipInstructions(InsnList insnList, AbstractInsnNode startInclusive, AbstractInsnNode endNotInclusive) { LabelNode skipLabel = new LabelNode(); JumpInsnNode gotoInsn = new JumpInsnNode(Opcodes.GOTO, skipLabel); insnList.insertBefore(startInclusive, gotoInsn); insnList.insertBefore(endNotInclusive, skipLabel); }