confusion when CLASSPATH includes compiled class

Per Bothner per@bothner.com
Tue Mar 22 21:58:00 GMT 2005


Per Bothner wrote:
> Hm.  I'm getting the same GC-crash when I use gij.  So it probably
> isn't related to confusion between compiled and dynamic classes.

I think I understand what is going on, at least for interpreted classes.

Class.forName("Foo", false, loader) leaves the loaded class as JV_STATE_LOADED.
The storage for the static fields is allocated by
_Jv_Linker::ensure_fields_laid_out, which is called just before class init,
before state becomes JV_STATE_PREPARED.

So while the state is JV_STATE_LOADED, we call cls.getField(...).getType().
This calls _Jv_Linker::resolve_field which clears the _Jv_FIELD_UNRESOLVED_FLAG.
But note that field->u.addr is still null (and field->bsize==0)!

This may be ok, but then the GC is called.  _Jv_MarkObj just checks that
field->isResolved(), but it doesn't check that field->u.addr is non-null
or that c->state >= JV_STATE_PREPARED.

Question 1: Is this a bug in the GC or in class linking/loading or in
Field::getType().?  I.e. is it ok for field->isResolved() to be true
even if storage for the field hasn't been allocated?

Question 2: What is the fix?  Assuming the answers to 1 are "GC" and "yes",
then we could fix _Jv_MarkObj either by
(a) only mark the values pointed to if field->u.addr != NULL; or
(b) check that c->state >= JV_STATE_PREPARED - or rather >= JV_STATE_COMPILED.

Does this analysis seem correct?
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/



More information about the Java mailing list