3 Replies Latest reply on Aug 25, 2005 12:46 AM by Shigeru Chiba

    instrumenting a loaded class

    Nick Collier Newbie

      Hi,

      I'm using a javaassist in a mechanism for creating dyanamic listeners. The idea is that the user can specify a class and field to watch for field access and then an instance and method to call on that instance when the field is accessed. As for implementation, I replace the field access with the access ($proceed($$)) and a method that notifies the listener.

      This works well when I specify the listener and what to watch before the class I want to watch is loaded. The onLoad method of my translator adds the code into the class I want to watch and everything works OK.

      However, if I want to choose what to watch after the class I want to watch is loaded, that is, after onLoad has been called for that class, this doesn't seem to work. What I'm doing in that case, is just getting the appropriate CtClass from the ClassPool, defrosting() it and then replacing the field access. This change doesn't seem to be picked up by the JVM though as the class behaves normally when the field is accessed.

      Any suggestions? I'm hoping this is possible without unloading the class from the JVM but I'm beginning to wonder.

      thanks,

      Nick