1 package alt.jiapi.util; 2 3 import java.util.ArrayList ; 4 5 import alt.jiapi.Rule; 6 import alt.jiapi.JiapiException; 7 import alt.jiapi.reflect.Instruction; 8 import alt.jiapi.reflect.InstructionList; 9 import alt.jiapi.reflect.instruction.Opcodes; 10 11 17 public class HotSpotLocator { 18 private InstructionList il; 19 private byte[] opCodes; 20 private Rule rule; 21 22 31 public HotSpotLocator(InstructionList il, byte opCode) { 32 this(il, new byte[] { opCode }, "*"); 33 } 34 35 44 public HotSpotLocator(InstructionList il, byte[] opCodes) { 45 this(il, opCodes, "*"); 46 } 47 48 61 public HotSpotLocator(InstructionList il, byte[] opCodes, String resolution) { 62 this.il = il; 66 67 68 this.opCodes = opCodes; 69 70 try { 71 rule = new Rule(resolution); 72 } 73 catch(JiapiException je) { 74 } 75 } 76 77 78 86 public HotSpot[] getHotSpots() { 87 ArrayList al = new ArrayList (); 88 89 for (int i = 0; i < il.size(); i++) { 90 Instruction ins = il.get(i); 91 short opCode = ins.getOpcode(); 92 93 for (int j = 0; j < opCodes.length; j++) { 94 if (opCode == opCodes[j]) { 95 HotSpot hs = createHotSpot(il, i); 96 al.add(hs); 98 } 99 } 100 } 101 102 return (HotSpot[])al.toArray(new HotSpot[0]); 103 } 104 105 106 114 private HotSpot createHotSpot(InstructionList il, int idx) { 115 Instruction end = il.get(idx); 116 Instruction start = end; 117 118 int stackConsumption = end.stackConsumption(); 119 while(stackConsumption > 0) { 120 start = il.get(idx - 1); stackConsumption -= start.stackUsage(); 122 idx--; 123 } 124 125 return new HotSpot(il, start, end); 126 } 127 } 128 | Popular Tags |