instrumentation - Java agent : transform() not invoked for all classes -


i have simple transformer:

import java.io.bytearrayinputstream; import java.lang.instrument.classfiletransformer; import java.lang.instrument.illegalclassformatexception; import java.security.protectiondomain;  import javassist.classpool; import javassist.ctclass; import javassist.ctmethod;  //this class registered instrumentation agent public class pizzatransformer implements classfiletransformer {      public byte[] transform(classloader loader,                              string classname,                             class classbeingredefined,                             protectiondomain protectiondomain,                             byte[] classfilebuffer) throws      illegalclassformatexception {         byte[] bytecode = classfilebuffer;          system.out.println("this class  "+classname);          return bytecode;         } } 

the agent code follows:

import java.lang.instrument.instrumentation;  public class pizzaagent {     public static void premain(string agentargs, instrumentation inst) {         system.out.println("executing premain.........");         inst.addtransformer(new pizzatransformer(),true);     } } 

the manifest :

boot-class-path: javassist.jar

premain-class: pizzaagent

can-redefine-classes: true

can-retransform-classes: true

what puzzling 4000+ classes printed transform(), when 19000+ classes reported loaded turning on -verbose:class command line launching.

why more 10000 classes not invoking transform()?

thank you

you seeing classes not yet loaded when agent attached. if want handle loaded classes, too, have explicitly retransform these classes. can by:

instrumentation.retransformclasses(instrumentation.getloadedclasses()); 

however, classes not retransformable (instrumentation::ismodifiable) , need split array avoid draining memory.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -