diff options
author | Nicolas Geoffray <nicolas.geoffray@menlina.com> | 2005-12-14 09:30:42 +0000 |
---|---|---|
committer | Nicolas Geoffray <nicolas.geoffray@menlina.com> | 2005-12-14 09:30:42 +0000 |
commit | 05f169147352fa3eeb9726f3d57597a83eb7d64d (patch) | |
tree | 54ee4ad55982aafa528a16d5c6730ae942d26a20 | |
parent | a19dad5d8d3ee89bc02aa6291840a8ddb00815bb (diff) | |
download | classpath-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.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | java/lang/ClassLoader.java | 4 | ||||
-rw-r--r-- | vm/reference/java/lang/VMClassLoader.java | 43 |
3 files changed, 56 insertions, 1 deletions
@@ -1,3 +1,13 @@ +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. + 2005-12-13 Tom Tromey <tromey@redhat.com> * java/lang/instrument/ClassDefinition.java: Reformatted. diff --git a/java/lang/ClassLoader.java b/java/lang/ClassLoader.java index fe2c7e1b9..d0f6ac42a 100644 --- a/java/lang/ClassLoader.java +++ b/java/lang/ClassLoader.java @@ -467,7 +467,9 @@ public abstract class ClassLoader 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); } /** 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); + } + } } |