1 18 19 package alt.jiapi.instrumentor; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import org.apache.log4j.Category; 25 26 import alt.jiapi.JiapiException; 27 import alt.jiapi.Rule; 28 import alt.jiapi.Runtime; 29 import alt.jiapi.reflect.Instruction; 30 import alt.jiapi.reflect.InstructionFactory; 31 import alt.jiapi.reflect.InstructionList; 32 import alt.jiapi.reflect.JiapiMethod; 33 import alt.jiapi.reflect.TryBlock; 34 import alt.jiapi.reflect.TryBlock.ExceptionHandler; 35 36 import alt.jiapi.reflect.instruction.OpcodeGroups; 37 import alt.jiapi.reflect.instruction.Opcodes; 38 39 44 45 53 public class CatchInstrumentor extends AbstractInstrumentor { 54 private static Category log = 55 Runtime.getLogCategory(CatchInstrumentor.class); 56 57 private Rule[] rules; 58 private boolean reverseMatch = false; 59 private String [] resolutions; 60 61 64 public CatchInstrumentor() { 65 } 66 67 68 73 public void instrument(InstructionList il) { 74 ArrayList al = new ArrayList (); 75 JiapiMethod m = il.getDeclaringMethod(); 76 Instrumentation instrumentation = getInstrumentation(); 77 InstructionList methodInstructions = m.getInstructionList(); 78 79 83 86 89 94 96 98 107 throw new RuntimeException ("NOT IMPLEMENTED"); 108 } 109 110 111 private boolean analyze(InstructionList il, 117 Instrumentation instrumentation) { 118 InstructionList targetCode = null; 119 int index = 0; 120 121 if (il.size() > 0) { 122 index = il.indexOf(OpcodeGroups.REFERENCE_STORE_INSTRUCTIONS,0); 123 log.debug("First instruction during analyze is " + il.get(0)); 124 125 if (index == 0) { 126 InstructionFactory factory = 127 il.getInstructionFactory(); 128 129 134 if (true) 136 throw new RuntimeException ("NOT IMPLEMENTED"); 137 Instruction i = il.get(0); 138 139 140 int lvIdx = -1; 141 switch(i.getOpcode()) { 142 case Opcodes.ASTORE: 143 lvIdx = -1; break; 147 case Opcodes.ASTORE_0: 148 lvIdx = 0; 149 break; 150 case Opcodes.ASTORE_1: 151 lvIdx = 1; 152 break; 153 case Opcodes.ASTORE_2: 154 lvIdx = 2; 155 break; 156 case Opcodes.ASTORE_3: 157 lvIdx = 3; 158 break; 159 default: 160 } 162 163 if (lvIdx >= 0) { 164 if (true) 165 throw new RuntimeException ("NOT IMPLEMENTED"); 166 168 log.debug("Analyze succeeded. Target code is " + 169 targetCode + ", local variable is at index " + 170 lvIdx); 171 } 172 } 173 } 174 175 if (targetCode == null) { 176 log.debug("Analyze failed, setting target code to null"); 177 } 178 179 instrumentation.setTargetCode(targetCode); 180 181 return targetCode != null; 182 } 183 184 185 public void setResolutions(String [] resolutions) { 186 this.resolutions = resolutions; 187 188 createRules(resolutions); 189 } 190 191 192 193 198 protected boolean match(String name) { 199 if (name == null || rules == null) { 200 return false; 201 } 202 203 boolean b = false; 204 for (int i = 0; i < rules.length; i++) { 205 if (rules[i].match(name)) { 206 b = true; 207 208 break; 209 } 210 } 211 212 b = b ^ reverseMatch; 214 215 return b; 216 } 217 218 219 private void createRules(String [] resolutions) { 221 if(resolutions == null) { 222 return; 223 } 224 225 this.rules = new Rule[resolutions.length]; 226 227 for (int i = 0; i < resolutions.length; i++) { 228 try { 229 rules[i] = new Rule(resolutions[i]); 230 } 231 catch(Exception e) { 232 log.error(e.getMessage()); 233 } 234 } 235 } 236 } 237 | Popular Tags |