summaryrefslogtreecommitdiff
path: root/vm
diff options
context:
space:
mode:
authorNicolas Geoffray <nicolas.geoffray@menlina.com>2005-12-14 09:30:42 +0000
committerNicolas Geoffray <nicolas.geoffray@menlina.com>2005-12-14 09:30:42 +0000
commit05f169147352fa3eeb9726f3d57597a83eb7d64d (patch)
tree54ee4ad55982aafa528a16d5c6730ae942d26a20 /vm
parenta19dad5d8d3ee89bc02aa6291840a8ddb00815bb (diff)
downloadclasspath-05f169147352fa3eeb9726f3d57597a83eb7d64d.tar.gz
2005-12-14 Nicolas Geoffray <nicolas.geoffray@menlina.com>
* 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.
Diffstat (limited to 'vm')
-rw-r--r--vm/reference/java/lang/VMClassLoader.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/vm/reference/java/lang/VMClassLoader.java b/vm/reference/java/lang/VMClassLoader.java
index a777462aa..d4bd87331 100644
--- a/vm/reference/java/lang/VMClassLoader.java
+++ b/vm/reference/java/lang/VMClassLoader.java
@@ -44,6 +44,8 @@ import gnu.classpath.Configuration;
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,45 @@ final class VMClassLoader
* 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. This
+ * implementation assumes the instrumenter is a
+ * <code>InstrumentationImpl</code> object. VM implementors would
+ * have to redefine this method if they provide their own implementation
+ * of the <code>Instrumentation</code> interface.
+ *
+ * @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);
+ }
+ }
}