JVMTI and instrumentation
Alan Bateman
Alan.Bateman at oracle.com
Wed Dec 2 13:31:22 UTC 2015
On 02/12/2015 11:39, Michael Rasmussen wrote:
> :
>
> A further question for JVMTI in this regard:
> ClassFileLoadHook callback seems to not be called before VMInit anymore?
> I know the documentation is vague on this point, only specifying that
> it may be sent in primordial phase; but for previous JDK versions, this
> event is sent for all classes being loaded, even java.lang.Object; where
> as on jdk9, the first class I get event for, is what I'm trying to load
> in my VMInit callback.
This is what we have in JEP 261:
"JVM TI agents can no longer instrument Java code that runs early in the
startup of the run-time environment. The vm start event is not sent
until the module system is initialized, so JVM TI agents that do
load-time instrumentation will not receive ClassFileLoadHook events for
classes loaded during startup and they will also miss some
previously-received CompiledMethodLoad and DynamicCodeGenerated events.
Agents can use the GetLoadedClasses function to get the list of loaded
classes and the GenerateEvents function to generate missed events. (Java
agents will continue to function as before, since they run only during
the live phase.)"
So you won't see CFLH events until the Start phase.
I think this can be re-visited once there is support for "module aware"
agents. The important thing that agents will not be able to load classes
outside the java.base module until the module system has been initialized.
> :
>
>> The transform method gives you the Class<?> of the class being redefined
>> so you should be able to invoke getModule() on this to get the module.
> Yes, when being redefined; but for the initial load/transformation, this
> argument is null, since the class obviously hasn't been defined yet, but
> the module in which it's being loaded should be (disregarding java.base
> classes being loaded before module system is initialized, since this is
> before premain, thus before you can add a instrumentation transformer).
>
Fair point, it will be NULL when it's a class load so it would require
CFT to define a new transform method.
Just on steps to update these APIs for modules then we should have an
initial patch soon to help debugger agents. This has wider scope because
it requires updates to JVM TI, JDWP and JDI. We need to work on
instrumentation support too so use-cases, examples, and working with us
to get this right would be great.
-Alan
More information about the jigsaw-dev
mailing list