Eager vs Lazy resolution of classes
Bryce McKinlay
mckinlay@redhat.com
Tue Jul 20 20:50:00 GMT 2004
The following test case creates a class on the fly in the classpath and
then tries to call into that class statically, as opposed to via
Class.forName() or some other classloader based mechanism.
On Sun's 1.5 beta JVM, I get:
$ rm Bar.class
$ java Resolve
start
99
hello!!
The Java Specification makes it clear that resolution of class
dependencies is "eager". That is, all references from a given class can
be resolved at link time, provided that any errors from resolution are
deferred until active use. However, it also states that implementations
MAY choose to resolve dependencies more lazily if they wish. This seems
to be what Sun's implementation does. This is a concern because the
BC-ABI in its current form is designed for eager resolution. While
spec-compliant, there may be code out there which depends on Sun-like
behaviour.
Interestingly, gij fails this test too, and in fact is not compliant
with the spec at all because it is throwing NoClassDefFoundError before
the first active use of the missing class:
$ rm Foo.class
$ gij Resolve
Exception in thread "main" java.lang.NoClassDefFoundError: while
resolving class: Resolve
at java.lang.VMClassLoader.resolveClass(java.lang.Class)
(/local/gcc-clean/lib/libgcj.so.6.0.0)
at java.lang.Class.initializeClass()
(/local/gcc-clean/lib/libgcj.so.6.0.0)
at java.lang.Class.forName(java.lang.String, boolean,
java.lang.ClassLoader) (/local/gcc-clean/lib/libgcj.so.6.0.0)
....etc
I think its quite possible to make the BC-ABI compatible with Suns
behaviour, but its a little complicated. We'll have to remember which
(if any) otable/atable entries that remain unresolved after linking,
associate them with their class, and then go back and fill in those
entries during linking/initialization of that class (at first active use).
Since it will likely be quite a bit of extra work to implement this, it
would be good to get an understanding of how important this feature is.
ie: is it something that we should be concentrating on for 3.5, or can
it be deferred for later? Does anyone know of popular applications that
rely on being able to do this? My understanding is that Eclipse 3 now
runs on gij, so presumably it does not fall into this category?
Regards
Bryce
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bar.java
Type: text/x-java
Size: 112 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20040720/67931eae/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Resolve.java
Type: text/x-java
Size: 3243 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20040720/67931eae/attachment-0001.bin>
More information about the Java
mailing list