Hi Bil Check how we do that in AspectWerkz by replacing the core java.lang.ClassLoader when possible, and providing many option to feet users needs and environment, since hotswapping the java.lang.ClassLoader is not always possible. http://aspectwerkz.codehaus.org/online.html http://aspectwerkz.codehaus.org/downloads/papers/AspectWerkz-online-architec ture.pdf.zip
If you don't need to support custom classloader, but the system classloader is enough for you, there are many easier ways to do class load time instrumentation (java 1.4 has an option to substitute the system class loader, and a simple "main" wrapper class using Thread.setContextClassLoader can be also be enough). Also note that the JSR 163 will hoppefully bring a standard solution to this in java 1.5, just as the AspectWerkz BEA JRockit module does right now. Alex - http://blogs.codehaus.org/people/avasseur/ ----- Original Message ----- From: "Bil Lewis" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, December 27, 2003 5:09 PM Subject: Using Classloaders to dynamically instrument anything > > What I want to do is instrument users' code as it is loaded -- > even if it's loaded by its own classloaders. > > I don't care where the code comes from (file, url, rmi, byte stream, > etc.), I just want my chance to instrument it. > > Now as I see it, what I *think* I should do is to replace a > low-level definition of defineClass(), which will then see every > class as a byte array as its loaded. But... > > This implies that I'll need to hack the core Java libraries to > get to the proper classloader. Or maybe worse? I have to change > the JVM's primordial classloader? Just changing the System > classloader isn't enough, because people can avoid it. > > And BCEL has no interface for reading a byte array and turning > it into a javaClass (does it?). Using the Repository methods > won't work with arbitrary classloaders (will it?). > > > > > Others have probably thought about this before. Can you give me > direction on how to do this? > > Thanks, > > > -Bil Lewis > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]