[MUD-Dev] Why not compile java into object code?

Chris Gray cg at ami-cg.GraySage.Edmonton.AB.CA
Fri Feb 27 18:39:29 CET 1998


:What would it take to compile java down into object code (.o files)?
:It's not being done...but I wonder why?  I don't care if I have to compile
:for each platform...if I compile just for win95 80% of my users will enjoy
:a tremendous speedup....

There are likely some other replies to this in the queue, but I'll take
a shot at it.

One of the big difficulties is the dynamic nature of inheritance in Java.
If class A inherits from class B, then the set of class member variables
in class B is not known until the details of class A have also been
examined. Similar problems come up with member functions - if class B
has a member function 'F', then a call to 'F' in the context of A might
call it, or might not, depending on whether A also has an 'F'. C++ figures
all this out at compile time because each compilation includes all of
the header files for all of the classes in the hierarchy. Java doesn't
have header files, but would require parsing the source files to extract
the equivalent information. Thus, compiling the source for class A requires
also having had compiled class B, and everything else in the inheritance
chain. Also, such a system would have to have a way of noticing that
class B has changed, and thus the object file for class A is out of date.

All of this sort of checking and setup is normally done when classes are
loaded - see the detailed description of class loading in the language
specification. After a class is loaded, it is assumed to be fixed in stone
as of that point.

:On a similar level, is this what JIT compilers do?  If so, could not
:someone write a JIT that produces an ordinary exe?

I believe that JIT only produces machine code at run-time. A class or
function is compiled just before it is first used (hence the name Just
In Time). At that point, all the details of it are known, so compilation
is possible.

So, in theory Java could be compiled to stand-alone object files, but that
compilation requires compiling, and fixing in stone, pretty well everything
in the referenced parts of the entire class hierarchy.

--
Chris Gray   cg at ami-cg.GraySage.Edmonton.AB.CA



More information about the mud-dev-archive mailing list