List of usage examples for org.objectweb.asm Opcodes LOOKUPSWITCH
int LOOKUPSWITCH
To view the source code for org.objectweb.asm Opcodes LOOKUPSWITCH.
Click Source Link
From source file:edu.ubc.mirrors.holograms.FrameAnalyzer.java
License:Open Source License
@Override protected void newControlFlowEdge(int insn, int successor) { if (successor == insn + 1 && (currentInsn == null || (currentInsn.getOpcode() != Opcodes.TABLESWITCH && currentInsn.getOpcode() != Opcodes.LOOKUPSWITCH && currentInsn.getOpcode() != Opcodes.GOTO))) { stepIn[successor] = true;/*from w w w .j a va 2s .c om*/ } else { jumpIn[successor] = true; } super.newControlFlowEdge(insn, successor); }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitLookupSwitchInsn(final Label dflt, final int[] caseKeys, final Label[] labels) { /**********//from www .j av a2s . c o m * SWITCH * **********/ final SWITCH op = new SWITCH(this.ops.size(), Opcodes.LOOKUPSWITCH, this.line); add(op); // default int targetPc = getPc(dflt); op.setDefaultPc(targetPc); if (targetPc < 0) { getUnresolved(dflt).add(op); } // keys final int[] casePcs = new int[labels.length]; for (int i = labels.length; i-- > 0;) { casePcs[i] = targetPc = getPc(labels[i]); if (targetPc < 0) { getUnresolved(labels[i]).add(op); } } op.setCaseKeys(caseKeys); op.setCasePcs(casePcs); }
From source file:org.evosuite.coverage.branch.BranchPool.java
License:Open Source License
private void registerSwitchInstruction(BytecodeInstruction v) { if (!v.isSwitch()) throw new IllegalArgumentException("expect a switch instruction"); LabelNode defaultLabel = null;// w w w .java2s . com switch (v.getASMNode().getOpcode()) { case Opcodes.TABLESWITCH: TableSwitchInsnNode tableSwitchNode = (TableSwitchInsnNode) v.getASMNode(); registerTableSwitchCases(v, tableSwitchNode); defaultLabel = tableSwitchNode.dflt; break; case Opcodes.LOOKUPSWITCH: LookupSwitchInsnNode lookupSwitchNode = (LookupSwitchInsnNode) v.getASMNode(); registerLookupSwitchCases(v, lookupSwitchNode); defaultLabel = lookupSwitchNode.dflt; break; default: throw new IllegalStateException("expect ASMNode of a switch to either be a LOOKUP- or TABLESWITCH"); } registerDefaultCase(v, defaultLabel); }
From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java
License:Open Source License
/** * Determine how many bytes the current instruction occupies together with * its operands//from w w w . j av a 2 s. c o m * * @return */ private int getBytecodeIncrement(AbstractInsnNode instructionNode) { int opcode = instructionNode.getOpcode(); switch (opcode) { case Opcodes.ALOAD: // index case Opcodes.ASTORE: // index case Opcodes.DLOAD: case Opcodes.DSTORE: case Opcodes.FLOAD: case Opcodes.FSTORE: case Opcodes.ILOAD: case Opcodes.ISTORE: case Opcodes.LLOAD: case Opcodes.LSTORE: VarInsnNode varNode = (VarInsnNode) instructionNode; if (varNode.var > 3) return 1; else return 0; case Opcodes.BIPUSH: // byte case Opcodes.NEWARRAY: case Opcodes.RET: return 1; case Opcodes.LDC: LdcInsnNode ldcNode = (LdcInsnNode) instructionNode; if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long) return 2; // LDC2_W else return 1; case 19: //LDC_W case 20: //LDC2_W return 2; case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2 case Opcodes.CHECKCAST: // indexbyte1, indexbyte2 case Opcodes.GETFIELD: case Opcodes.GETSTATIC: case Opcodes.GOTO: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ICMPLT: case Opcodes.IFLE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFNE: case Opcodes.IFEQ: case Opcodes.IFNONNULL: case Opcodes.IFNULL: case Opcodes.IINC: case Opcodes.INSTANCEOF: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: case Opcodes.JSR: case Opcodes.NEW: case Opcodes.PUTFIELD: case Opcodes.PUTSTATIC: case Opcodes.SIPUSH: // case Opcodes.LDC_W // case Opcodes.LDC2_W return 2; case Opcodes.MULTIANEWARRAY: return 3; case Opcodes.INVOKEDYNAMIC: case Opcodes.INVOKEINTERFACE: return 4; case Opcodes.LOOKUPSWITCH: case Opcodes.TABLESWITCH: // TODO: Could be more return 4; // case Opcodes.GOTO_W // case Opcodes.JSR_W } return 0; }
From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcher.java
License:Open Source License
/** * Moves {@link #cursor} to next instruction if it is * <code>TABLESWITCH</code> or <code>LOOKUPSWITCH</code>, otherwise sets it * to <code>null</code>./*w w w . ja v a2 s . c om*/ */ final void nextIsSwitch() { next(); if (cursor == null) { return; } switch (cursor.getOpcode()) { case Opcodes.TABLESWITCH: case Opcodes.LOOKUPSWITCH: return; default: cursor = null; } }
From source file:org.jacoco.core.internal.analysis.filter.KotlinWhenFilter.java
License:Open Source License
private static LabelNode getDefaultLabel(final AbstractInsnNode i) { switch (i.getOpcode()) { case Opcodes.LOOKUPSWITCH: return ((LookupSwitchInsnNode) i).dflt; case Opcodes.TABLESWITCH: return ((TableSwitchInsnNode) i).dflt; default:// w w w .j a v a 2 s . c o m return null; } }
From source file:org.jacoco.core.internal.analysis.filter.KotlinWhenFilter.java
License:Open Source License
private static void ignoreDefaultBranch(final AbstractInsnNode switchNode, final IFilterOutput output) { final List<LabelNode> labels; if (switchNode.getOpcode() == Opcodes.LOOKUPSWITCH) { labels = ((LookupSwitchInsnNode) switchNode).labels; } else {// w ww. j a v a2 s .c om labels = ((TableSwitchInsnNode) switchNode).labels; } final Set<AbstractInsnNode> newTargets = new HashSet<AbstractInsnNode>(); for (final LabelNode label : labels) { newTargets.add(AbstractMatcher.skipNonOpcodes(label)); } output.replaceBranches(switchNode, newTargets); }
From source file:org.jacoco.core.internal.analysis.filter.StringSwitchJavacFilter.java
License:Open Source License
/** * javac generates two switches. First one by {@link String#hashCode()}. * Number of handlers in the second switch is equal to number of handlers in * source code, so it is enough to completely filter-out first switch. * Handler for default case of the first switch - is the second switch. */// w ww .jav a 2s .com private void filter(final AbstractInsnNode start, final IFilterOutput output) { final LabelNode dflt; if (start.getOpcode() == Opcodes.LOOKUPSWITCH) { dflt = ((LookupSwitchInsnNode) start).dflt; } else if (start.getOpcode() == Opcodes.TABLESWITCH) { dflt = ((TableSwitchInsnNode) start).dflt; } else { return; } if (new Matcher().match(start, dflt)) { output.ignore(start, dflt); } }
From source file:org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor.java
License:Open Source License
@Override public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { currentBlock.terminator = new Instruction(Opcodes.LOOKUPSWITCH); blockByLabel.computeIfAbsent(dflt, l -> currentBlock.createSuccessor()); for (Label label : labels) { blockByLabel.computeIfAbsent(label, l -> currentBlock.createSuccessor()); }/*from w w w . j av a2s.com*/ }
From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java
License:Open Source License
@Test public void test_switch_enqueuing_in_trycatch() throws Exception { Instructions mv = new Instructions(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); mv.visitLabel(l0);/*from w ww. j a v a2 s . c o m*/ mv.visitVarInsn(ILOAD, 1); mv.visitLookupSwitchInsn(l1, new int[] { 0 }, new Label[] { l1 }); mv.visitLabel(l1); Label l3 = new Label(); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitVarInsn(ASTORE, 2); mv.visitLabel(l3); mv.visitInsn(RETURN); BytecodeCFG cfg = mv.cfg(); BytecodeCFG.Block switchBlock = cfg.blocks().get(2); assertThat(switchBlock.terminator().opcode).isEqualTo(Opcodes.LOOKUPSWITCH); walker.programState = ProgramState.EMPTY_STATE; walker.handleBlockExit(new ProgramPoint(switchBlock)); assertThat(walker.workList).hasSize(1); }