R
ringofw
I am activating a Java 5 program from C++ with the invocation API and
have in memory the bytecode that make up the "agent class" i.e. the
class that contains my premain method. After creating the JVM I could
make this into a live class with ClassLoader.defineClass, but but then
it is too late to specify the VM args (and even then the
java.lang.instrument package documentation implies that the agent class
must be in a JAR file).
Is there a way to provoke the running of the premain method (to pass me
the Instrumentation instance) from the invocation API, or will I have
to write my agent class to a JAR file on the fly?
In the past I have used the undocumented sun.misc.ClassFileTransformer
so was able to ClassLoader,defineClass my ClassFileTransformer from
native code, then call a static method on it to register an instance of
itself with the class loader (i.e. doing the equivalent of what I now
want to do within premain). With the Java 5 interface I seem to have a
chicken and egg situation with this approach, at least if I persist
with having my "agent class" also be my class transformer. I can split
it into two and just have the ClassFileTransformer in in native
memory...
But if I resorted to using a JAR file to specify the agent class, and
that agent class referenced my ClassFileTransformer, is there a window
between creating the JVM and premain being activated where I can
defineClass the ClassFileTransformer that premain references? I really
don't want to have to write the ClassFileTransformer to disk too just
so it is picked up on the classpath, but can see that it is possible
that premain could be called before I explicity activate "main"(?)
Mark
have in memory the bytecode that make up the "agent class" i.e. the
class that contains my premain method. After creating the JVM I could
make this into a live class with ClassLoader.defineClass, but but then
it is too late to specify the VM args (and even then the
java.lang.instrument package documentation implies that the agent class
must be in a JAR file).
Is there a way to provoke the running of the premain method (to pass me
the Instrumentation instance) from the invocation API, or will I have
to write my agent class to a JAR file on the fly?
In the past I have used the undocumented sun.misc.ClassFileTransformer
so was able to ClassLoader,defineClass my ClassFileTransformer from
native code, then call a static method on it to register an instance of
itself with the class loader (i.e. doing the equivalent of what I now
want to do within premain). With the Java 5 interface I seem to have a
chicken and egg situation with this approach, at least if I persist
with having my "agent class" also be my class transformer. I can split
it into two and just have the ClassFileTransformer in in native
memory...
But if I resorted to using a JAR file to specify the agent class, and
that agent class referenced my ClassFileTransformer, is there a window
between creating the JVM and premain being activated where I can
defineClass the ClassFileTransformer that premain references? I really
don't want to have to write the ClassFileTransformer to disk too just
so it is picked up on the classpath, but can see that it is possible
that premain could be called before I explicity activate "main"(?)
Mark