Hi,
I implemented the instrumentation of definition of classes in classpath.
With
the previous implementation, the vm needed to call transformers, now the
call is done in java.lang.ClassLoader.defineClass. This doesn't break
the vm interface.
The vm implementor needs to fill in VMClassLoader.instrumenter the
java.lang.InstrumentationImpl object (or any other implementation, but
it should
be noted that the VMClassLoader.redefineClassWithTransformers needs the
instrumentation object to have a callTransformers method)
The drawback of this implementation is that defineClass will allways
test if there
is an InstrumentationImpl object that is defined. If a vm doesn't want
this test,
it can still modify the VMClassLoader.redefineClassWithTransformers to
be the
VMClassLoader.defineClass method.
Nicolas
2005-12-09 Nicolas Geoffray <[EMAIL PROTECTED]>
* java/lang/ClassLoader
(defineClass(String,byte[],int,int,ProtectionDomain)):
Calls VMClassLoader.defineClassWithTransformers instead
of VMClassLoader.defineClass.
* vm/reference/java/lang/VMClassLoader
(defineClassWithTransformers): New method.
(instrumenter): New Field.
Index: vm/reference/java/lang/VMClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMClassLoader.java,v
retrieving revision 1.16.2.11
diff -u -r1.16.2.11 VMClassLoader.java
--- vm/reference/java/lang/VMClassLoader.java 2 Nov 2005 00:44:15 -0000 1.16.2.11
+++ vm/reference/java/lang/VMClassLoader.java 9 Dec 2005 10:59:27 -0000
@@ -44,6 +44,8 @@
import java.io.File;
import java.io.IOException;
+import java.lang.InstrumentationImpl;
+import java.lang.instrument.Instrumentation;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.ProtectionDomain;
@@ -346,4 +348,41 @@
* for this class.
*/
static native Class findLoadedClass(ClassLoader cl, String name);
+
+ /**
+ * The Instrumentation object created by the vm when agents are defined.
+ */
+ static final Instrumentation instrumenter = null;
+
+ /**
+ * Call the transformers of the possible Instrumentation object
+ *
+ * @param loader the initiating loader
+ * @param name the name of the class
+ * @param data the data representing the classfile, in classfile format
+ * @param offset the offset into the data where the classfile starts
+ * @param len the length of the classfile data in the array
+ * @param pd the protection domain
+ * @return the new data representing the classfile
+ */
+ static final Class defineClassWithTransformers(ClassLoader loader,
+ String name, byte[] data, int offset, int len, ProtectionDomain pd)
+ {
+
+ if (instrumenter != null)
+ {
+ byte[] modifiedData = new byte[len];
+ System.arraycopy(data, offset, modifiedData, 0, len);
+ modifiedData =
+ ((InstrumentationImpl)instrumenter).callTransformers(loader, name,
+ null, pd, modifiedData);
+
+ return defineClass(loader, name, modifiedData, 0, modifiedData.length,
+ pd);
+ }
+ else
+ {
+ return defineClass(loader, name, data, offset, len, pd);
+ }
+ }
}
Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.31.2.14
diff -u -r1.31.2.14 ClassLoader.java
--- java/lang/ClassLoader.java 2 Nov 2005 00:43:33 -0000 1.31.2.14
+++ java/lang/ClassLoader.java 9 Dec 2005 10:59:32 -0000
@@ -467,7 +467,9 @@
checkInitialized();
if (domain == null)
domain = StaticData.defaultProtectionDomain;
- return VMClassLoader.defineClass(this, name, data, offset, len, domain);
+
+ return VMClassLoader.defineClassWithTransformers(this, name, data, offset,
+ len, domain);
}
/**
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches