order of class load and object allocation

C

coltrane

Using JVMPI I performed a trace of Class Loading and Object Allocation
for an app. I found that one particular object was allocated before the
class was loaded. At least that was the order of events reported using
JVMPI. Is this possible?

thanks

john
 
C

Chris Smith

coltrane said:
Using JVMPI I performed a trace of Class Loading and Object Allocation
for an app. I found that one particular object was allocated before the
class was loaded. At least that was the order of events reported using
JVMPI. Is this possible?

No, it's not possible.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Uppal

coltrane said:
thanks. I'll chalk it up to a timing issue in JVMPI.

Or maybe you have two classes with the same name (via different classloaders).

-- chris
 
A

Andrea Desole

coltrane said:
thanks. I'll chalk it up to a timing issue in JVMPI.
I don't konw JVMPI, but is it possible that what you have seen is just
the beginning of the allocation, which implies also that the class is
loaded, since it's referenced for the first time?
 
C

coltrane

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.
btw, I am new to the JVMPI api.
 
A

Ann

Chris Smith said:
Yes. Do you have a reason to believe otherwise?
Not by testing, but just by thinking about it,
it seems that a value could be stuffed into a reference
variable without having to load a class first.
 
J

John C. Bollinger

Ann said:
it seems that a value could be stuffed into a reference
variable without having to load a class first.

Yes, provided that the value is null. But this is anyway not about
storing a reference in a variable, it is about allocating an object.
The VM cannot know how much memory is required for the object's fields
until it has loaded the object's class (which involves also loading all
its superclasses), thus it cannot allocate the object before it has
loaded the class.


John Bollinger
(e-mail address removed)
 
C

Chris Uppal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top