1 /******************************************************************************* 2 * Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Marc R. Hoffmann - initial API and implementation 10 * 11 *******************************************************************************/ 12 package org.jacoco.core.internal.flow; 13 14 import org.jacoco.core.JaCoCo; 15 import org.objectweb.asm.Label; 16 import org.objectweb.asm.MethodVisitor; 17 18 /** 19 * A {@link MethodVisitor} with additional methods to get probe insertion 20 * information. 21 */ 22 public abstract class MethodProbesVisitor extends MethodVisitor { 23 24 /** 25 * New visitor instance without delegate visitor. 26 */ 27 public MethodProbesVisitor() { 28 this(null); 29 } 30 31 /** 32 * New visitor instance that delegates to the given visitor. 33 * 34 * @param mv 35 * optional next visitor in chain 36 */ 37 public MethodProbesVisitor(final MethodVisitor mv) { 38 super(JaCoCo.ASM_API_VERSION, mv); 39 } 40 41 /** 42 * Visits an unconditional probe that should be inserted at the current 43 * position. 44 * 45 * @param probeId 46 * id of the probe to insert 47 */ 48 @SuppressWarnings("unused") 49 public void visitProbe(final int probeId) { 50 } 51 52 /** 53 * Visits a jump instruction. A probe with the given id should be inserted 54 * in a way that it is executed only when the jump to the given label is 55 * executed. 56 * 57 * @param opcode 58 * the opcode of the type instruction to be visited. This opcode 59 * is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, 60 * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, 61 * IF_ACMPEQ, IF_ACMPNE, GOTO, IFNULL or IFNONNULL. 62 * @param label 63 * the operand of the instruction to be visited. This operand is 64 * a label that designates the instruction to which the jump 65 * instruction may jump. 66 * @param probeId 67 * id of the probe 68 * @param frame 69 * stackmap frame status after the execution of the jump 70 * instruction. The instance is only valid with the call of this 71 * method. 72 * @see MethodVisitor#visitJumpInsn(int, Label) 73 */ 74 @SuppressWarnings("unused") 75 public void visitJumpInsnWithProbe(final int opcode, final Label label, 76 final int probeId, final IFrame frame) { 77 } 78 79 /** 80 * Visits a zero operand instruction with a probe. This event is used only 81 * for instructions that terminate the method. Therefore the probe must be 82 * inserted before the actual instruction. 83 * 84 * @param opcode 85 * the opcode of the instruction to be visited. This opcode is 86 * either IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN or 87 * ATHROW. 88 * @param probeId 89 * id of the probe 90 * @see MethodVisitor#visitInsn(int) 91 */ 92 @SuppressWarnings("unused") 93 public void visitInsnWithProbe(final int opcode, final int probeId) { 94 } 95 96 /** 97 * Visits a TABLESWITCH instruction with optional probes for each target 98 * label. Implementations can be optimized based on the fact that the same 99 * target labels will always have the same probe id within a call to this 100 * method. The probe id for each label can be obtained with 101 * {@link LabelInfo#getProbeId(Label)}. 102 * 103 * @param min 104 * the minimum key value. 105 * @param max 106 * the maximum key value. 107 * @param dflt 108 * beginning of the default handler block. 109 * @param labels 110 * beginnings of the handler blocks. <code>labels[i]</code> is 111 * the beginning of the handler block for the 112 * <code>min + i</code> key. 113 * @param frame 114 * stackmap frame status after the execution of the switch 115 * instruction. The instance is only valid with the call of this 116 * method. 117 * @see MethodVisitor#visitTableSwitchInsn(int, int, Label, Label[]) 118 */ 119 @SuppressWarnings("unused") 120 public void visitTableSwitchInsnWithProbes(final int min, final int max, 121 final Label dflt, final Label[] labels, final IFrame frame) { 122 } 123 124 /** 125 * Visits a LOOKUPSWITCH instruction with optional probes for each target 126 * label. Implementations can be optimized based on the fact that the same 127 * target labels will always have the same probe id within a call to this 128 * method. The probe id for each label can be obtained with 129 * {@link LabelInfo#getProbeId(Label)}. 130 * 131 * @param dflt 132 * beginning of the default handler block. 133 * @param keys 134 * the values of the keys. 135 * @param labels 136 * beginnings of the handler blocks. <code>labels[i]</code> is 137 * the beginning of the handler block for the 138 * <code>keys[i]</code> key. 139 * @param frame 140 * stackmap frame status after the execution of the switch 141 * instruction. The instance is only valid with the call of this 142 * method. 143 * @see MethodVisitor#visitLookupSwitchInsn(Label, int[], Label[]) 144 */ 145 @SuppressWarnings("unused") 146 public void visitLookupSwitchInsnWithProbes(final Label dflt, 147 final int[] keys, final Label[] labels, final IFrame frame) { 148 } 149 150 } 151