This is the mail archive of the
java-discuss@sources.redhat.com
mailing list for the Java project.
Why interpret dynamically loaded classes?
- To: java-discuss at sourceware dot cygnus dot com
- Subject: Why interpret dynamically loaded classes?
- From: Jack Andrews <jack dot andrews at str dot com dot au>
- Date: Wed, 23 Aug 2000 16:29:48 +1000
Hi,
I note that both GCJ and TowerJ use a bytecode interpreter to handle dynamic
class loading. But why not just compile the dynamically loaded class to a
native shared object at *runtime*, then link at runtime, too?
ie. implement this native ClassLoader (in pseudo-c):
Class ClassLoader::defineClass(String name, byte [] b, int off, int len )
{
filename = "lib" + mangle(name) + ".so";
compile_to_shared_object(filename, b);
void * ptr = dlopen("mypackage_myclass");
return new Class(ptr);
}
You'd just need to deploy the bytecode to native compiler with the
executable rather than the bytecode interpreter.
This way, you get the benefit of before-time compilation for dynamically
loaded classes too. Of course, you'd add an
if (already_compiled(name)) {...}
to the defineClass method for efficiency.
Jack.