1 18 19 package alt.jiapi.instrumentor; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.apache.log4j.Category; 26 27 import alt.jiapi.Instrumentor; 28 import alt.jiapi.Runtime; 29 import alt.jiapi.reflect.InstructionList; 30 31 40 public class TailInstrumentor extends AbstractInstrumentor { 41 private static Category log = Runtime.getLogCategory(TailInstrumentor.class); 42 45 protected int instructionCount = 0; 46 47 51 public TailInstrumentor() { 52 this(0); 53 } 54 55 61 public TailInstrumentor(int instructionCount) { 62 log.info("Instruction count " + instructionCount); 63 64 if (instructionCount < 0) { 65 throw new IllegalArgumentException (instructionCount + " < 0"); 66 } 67 68 this.instructionCount = instructionCount; 69 } 70 71 78 public void instrument(InstructionList il) { 79 log.info("Instrumenting " + getCurrentClass().getName() + "." + 80 il.getDeclaringMethod().getName()); 81 82 InstructionList view; 83 84 if (instructionCount > il.size()) { 85 log.warn("List size exceeded: instructions needed : " + 86 instructionCount + ", available " + il.size() + 87 ". Using all that is available."); 88 89 view = il.createView(0, il.size()); 90 } 91 else { 92 view = il.createView(il.size() - instructionCount, il.size()); 93 } 94 95 forward(view); 96 } 97 } 98 | Popular Tags |