This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [RFA/JDWP] ReferenceTypeCommandSet.java
Keith Seitz wrote:
On Tue, 2005-07-05 at 16:15 -0400, Bryce McKinlay wrote:
Class preparation is distinct from initialization. Preparation is
effectively linking the class: laying out its fields, initializing class
data structures in the VM, etc. Initialization involves actually running
Java code to initialize the classes static fields, and any "static" code
blocks the class may have. The point at which initialization occurs is
strictly defined by the JLS, and its pretty easy to write a program that
will behave differently if initializations are not performed in the
"right" order.
<warning type="newbie">
So can a class be prepared by a user application and not be initialized?
</warning>
Yes, or at least it is possible for a user application to get a
reference to a Class which is not initialized (eg the 3-argument
Class.forName() or using ".class" syntax in Java source code).
The point at which preparation actually occurs is determined by the
implementation, with the restriction (obviously) that it must be
prepared before it can be initialized.
The failure case I can imagine is:
- VM prepares a class (but the application hasn't yet initialized it)
- JDWP sends ClassPrepare event to debugger
- Debugger queries the value of a static field in the class
- JDWP uses java.lang.reflect to respond to query
---> Class initialized too early
Thinking about it more, I think it should be possible to avoid this
issue by keeping track of whether a class is initialized, and not
attempting to get static field values for uninitialized classes (there
might be a few other cases where initialization could be triggered by
reflection ops, too). The VM could implement something like
VMDebug.isInitialized(jclass) for this.
Bryce