coltrane said:
btw, I am new to the JVMPI api.
Me too ;-)
(And that API is deprecated as of JDK1.5, so I suppose I won't be messing with
it. The replacement, JVMTI, looks quite cool, but I haven't touched it yet.)
I wrote a small app that creates 10 instances of a class. It appears
that the an object is allocated before the load. At lease I am
processing an Object_Alloc before the Class_load event. An object with
a specific classid is allocated just prior to the load. There is no
other use of that class.
I think that what must be happening is that the trace event is generated before
the allocation, and that the class "load" event is generated when the class is
lazily initialised just as it's first instance is created, and hence after the
allocation event has been sent. (I /think/ that's what Andrea Desole was
suggesting too).
That's a bit odd, though, because the load event claims that it is generated
when a class is /loaded/, not when it is /initialised/ (the JVM documentation
carefully distinguished between class loading, class linking, and class
initialisation). As far as I can work it out, the class must actually have
been /loaded/ earlier (in order for verification of the caller to work) but
might not yet have been linked or initialised. It's possible that the event is
just badly named, or maybe I'm misunderstanding verification (again!).
The documentation for the class load "hook", JVMPI_EVENT_CLASS_LOAD_HOOK, makes
it clear that that event is generated when the class data is actually loaded
and before any of the other stuff (so you can modify the bytecodes if you
wish). It would be interesting to know (if you have time to check) whether
that gets called after the object allocation too (showing I'm misunderstanding
verification) or is called earlier in the sequence (showing that the "load"
event is misnamed/mis-specified).
-- chris