1 18 19 package alt.jiapi.instrumentor; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import alt.jiapi.JiapiException; 25 import alt.jiapi.Rule; 26 import alt.jiapi.Runtime; 27 import alt.jiapi.reflect.InstructionList; 28 import alt.jiapi.reflect.Instruction; 29 30 import alt.jiapi.reflect.instruction.FieldAccess; 31 import alt.jiapi.reflect.instruction.OpcodeGroups; 32 import alt.jiapi.reflect.instruction.Opcodes; 33 34 43 public class FieldAccessStrategy extends AbstractStrategy { 44 public static final int READ_ACCESS = 1; 45 public static final int WRITE_ACCESS = 2; 46 47 private int accessPolicy; 48 52 public FieldAccessStrategy() { 53 this(new String [] {"*"}, false, READ_ACCESS + WRITE_ACCESS); 54 } 55 56 65 public FieldAccessStrategy(String matcher, int accessPolicy) { 66 this(new String [] {matcher}, false, accessPolicy); 67 } 68 69 78 public FieldAccessStrategy(String matcher, boolean reverseMatch, int accessPolicy) { 79 this(new String [] {matcher}, reverseMatch, accessPolicy); 80 } 81 82 91 public FieldAccessStrategy(String [] matchers, boolean reverseMatch, 92 int accessPolicy) { 93 super(matchers, reverseMatch); 94 this.accessPolicy = accessPolicy; 95 } 96 97 98 105 public List findHotSpots(InstructionList il) { 106 Instrumentation instrumentation = getInstrumentation(); 107 List hotSpots = new ArrayList (); 108 int index = 0; 109 110 while ((index = il.indexOf(OpcodeGroups.FIELD_ACCESS_INSTRUCTIONS, 112 index)) != -1) { 113 FieldAccess fa = (FieldAccess)il.get(index); 114 int opcode = fa.getOpcode(); 115 String targetName = fa.getFieldName(); 117 118 if (match(targetName)) { if ((accessPolicy & READ_ACCESS) == READ_ACCESS) { 121 if ((opcode == Opcodes.GETFIELD) || 122 (opcode == Opcodes.GETSTATIC)) { 123 124 HotSpot h = new HotSpot(index, index + 1); 125 instrumentation.setTargetName(targetName); 127 hotSpots.add(h); 128 } 129 } 130 131 if ((accessPolicy & WRITE_ACCESS) == WRITE_ACCESS) { 132 if ((opcode == Opcodes.PUTFIELD) || 133 (opcode == Opcodes.PUTSTATIC)) { 134 135 HotSpot h = new HotSpot(index, index + 1); 136 instrumentation.setTargetName(targetName); 138 hotSpots.add(h); 139 } 140 } 141 } 142 143 index++; 144 } 145 146 return hotSpots; 147 } 148 } 149 | Popular Tags |