Eager vs Lazy resolution of classes

Jeroen Frijters jeroen@sumatra.nl
Wed Jul 21 15:09:00 GMT 2004


Bryce McKinlay wrote:
> The issue here is whether it is ok to do the resolution 
> itself eagerly, deferring errors until active use. That
> is, whether new classes can appear on the classpath at
> runtime, after the class that uses them has 
> already been linked, and expect to be resolved successfully.

I think this depends to a large degree on how eager you are. IKVM is
very eager (all methods in a class have to be compiled in order to run
one method) and until I added a workaround (essentially compiling in
code that uses reflection to retry failed link actions at runtime), this
caused problems with Eclipse 2.x.

I recently rewrote I major portion of IKVM to support lazy linking much
better. This is particularly tricky for IKVM because I'm compiling to an
OO intermediate language. Suppose you have a class Base, Derived and
Foo. While Base is compiled Foo is not yet available, but when Derived
is compiled it is. The code I generate for this is something like:

class Base
{
   public void method(Object /*NOTE really Foo*/ foo) { ... }
}

class Derived extends Base
{
   // this overrides Base.method
   private final void method(Object foo) { method((Foo)foo); }

   public void method(Foo foo) { ... }
}

Regards,
Jeroen



More information about the Java mailing list