1 package alt.jiapi.agent; 2 3 import java.util.Properties ; 4 5 import alt.jiapi.InstrumentationContext; 6 import alt.jiapi.InstrumentationDescriptor; 7 import alt.jiapi.reflect.JiapiClass; 8 import alt.jiapi.util.HotSpotAdvice; 9 import alt.jiapi.util.HotSpotAdvisor; 10 11 33 public class HotSpotTransformer extends Transformer { 34 private InstrumentationContext context; 35 private Properties properties; 36 37 public HotSpotTransformer() { 38 } 39 public void init(Properties p) { 40 this.properties = p; 41 String aName = p.getProperty("advice","alt.jiapi.agent.DefaultAdvice"); 42 String iRule = p.getProperty("inclusion-rule"); 43 String eRule = p.getProperty("exclusion-rule"); 44 String resolution = p.getProperty("resolution", "*"); 45 46 if (iRule == null) { 47 iRule = p.getProperty("ir"); 48 } 49 if (eRule == null) { 50 eRule = p.getProperty("er"); 51 } 52 53 if (iRule != null) { 54 try { 55 Class c = Class.forName(aName); 56 Object o = c.newInstance(); 57 HotSpotAdvice hsa = (HotSpotAdvice)o; 58 59 InstrumentationContext ctx = new InstrumentationContext(); 60 InstrumentationDescriptor id = new InstrumentationDescriptor(); 61 id.addInclusionRule(iRule); 62 if (eRule != null) { 63 id.addExclusionRule(eRule); 64 } 65 66 ctx.addInstrumentationDescriptor(id); 67 68 HotSpotAdvisor hsi = 69 new HotSpotAdvisor(id, hsa, HotSpotAdvisor.INVOCATIONS, 70 resolution); 71 72 this.context = ctx; 73 } 74 catch(Exception e) { 75 e.printStackTrace(); 76 } 77 } 78 else { 79 System.out.println("Warning: No inclusion rule given. This Transformer will do nothing."); 80 } 81 } 82 83 86 public boolean transform(JiapiClass clazz) { 87 if (context != null) { 88 context.instrument(clazz); 89 90 if (properties.getProperty("dump") != null) { 91 try { 92 java.io.FileOutputStream fos = 93 new java.io.FileOutputStream (clazz.getName() + ".clazz"); 94 clazz.dump(fos); 95 } 96 catch(Exception e) { 97 System.out.println("Failed to dump " + clazz.getName() +e); 98 } 99 } 100 101 return true; 102 } 103 104 return false; 105 } 106 107 } 111 | Popular Tags |