Eager vs Lazy resolution of classes

Chris Gray chris.gray@kiffer.be
Tue Jul 20 21:31:00 GMT 2004


On Tuesday 20 July 2004 22:50, Bryce McKinlay wrote:
> 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!!

Yup, Wonka does the same.
> 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.
> [...]
> Since it will likely be quite a bit of extra work to implement [laziness], 
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?

I don't know about popular apps, but one of the reasons why Wonka went from 
being really eager to really lazy was our experience with the code we had to 
run; some of thrown over the wall (as obfuscated jar files, oh joy :-/) by 
third parties, some developed by our own dear colleagues within Acunia. It 
became clear that Java developers think it normal that a class which contains 
references to all sorts of non-existent classes should run just fine provided 
those code paths are never traversed. So my guess is that this one will come 
to bite you sooner rather than later.
BTW not loading classes which are never actively used can also save you 
memory. :)
Best wishes
Chris
-- 
Chris Gray /k/ Embedded Java Solutions
Embedded & Mobile Java, OSGi http://www.kiffer.be/k/
chris.gray@kiffer.be +32 3 216 0369


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /