Choice of named vs anon classes as dynamic method holders

Charles Oliver Nutter headius at headius.com
Fri Jan 28 12:45:25 PST 2011


On Thu, Jan 27, 2011 at 3:41 PM, Rémi Forax <forax at univ-mlv.fr> wrote:
> One global classloader means no reloading.
> One classloader by class is Ok. Anonymous classloader is faster and
> consumes less memory but breaks this invariant:
>   Class.forName(clazz.getName()) == clazz
> which can be used by existing code (by example reflection invocation doesn't
> work).
>
> In PHP.reboot which generates several classes for one method (I do code
> specialization),
> I use an anonymous classloader if available or one classloader by class
> otherwise.

FWIW, JRuby also uses a similar model. We are mixed-mode, so not all
methods in the system will become JVM bytecode, but when they do we
emit them into a classloader-per-class. Remi's right, the primary cost
is memory; the bytecode stands alone (anon CL can patch existing), the
classloader itself has a bunch of stuff in it, and there may be a cost
in native code generated too. But that's really the only set of costs;
it works fine, they GC fine, and we've been happy with it.

- Charlie


More information about the mlvm-dev mailing list