1 18 19 package alt.jiapi.instrumentor; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.apache.log4j.Category; 25 26 import alt.jiapi.Instrumentor; 27 import alt.jiapi.Runtime; 28 import alt.jiapi.reflect.InstructionList; 29 30 54 public class SplitInstrumentor extends AbstractInstrumentor { 55 private static Category log = Runtime.getLogCategory(SplitInstrumentor.class); 56 private Strategy strategy; 57 58 62 public SplitInstrumentor(Strategy strategy) { 63 log.info("SplitInstrumentor: " + strategy); 64 65 this.strategy = strategy; 66 } 67 68 69 83 public void instrument(InstructionList il) { 84 log.info("Instrumenting " + getCurrentClass().getName() + "." + 85 il.getDeclaringMethod().getName()); 86 87 ((AbstractStrategy)strategy).setInstrumentation(getInstrumentation()); 88 89 List boundaries = strategy.findHotSpots(il); 90 92 Iterator iter = boundaries.iterator(); 93 int start = 0; 94 int count = 0; 95 HotSpot boundary = null; 96 97 while (iter.hasNext()) { 98 count++; 99 boundary = (HotSpot)iter.next(); 100 102 int end = boundary.getStart() - 1; if (end < start) { 104 end = start; 107 } 108 109 InstructionList view = il.createView(start, end); 110 111 forward(view); 112 113 start = boundary.getEnd() + 1; } 115 116 if (boundary != null) { 118 int end = boundary.getEnd() + 1; 120 if (end > il.size()) { 121 124 } 127 else { 128 forward(il.createView(end, il.size())); 129 } 130 } 131 132 } 133 134 135 138 public String toString() { 139 return super.toString() + "#" + strategy.toString(); 140 } 141 } 142 143 | Popular Tags |