Skip to main content

Option to compile to native code

5 replies [Last post]
fuerte
Offline
Joined: 2004-11-22

I noticed when I installed SQL Server 2005 (which uses a lot of .NET code) that it compiled some of its components to native code, for speed of course. Wouldn't it be great if there was an option to compile some .class or .jar to native code (with -server hotspot compiler), just for speed? There could be a .classx or .jarx file that contained the compiled version, with the timestamp of the original file, so that Java would do the compilation automatically later on, if the original file changes.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pdoubleya
Offline
Joined: 2004-02-09

There are already tools to create native executables from Java tools--GCJ can do this, and Excelsior Jet, to name two. I get the impression that the performance improvements have not been so stunning as to encourage people to switch to compiling, and most people seem to like the portability of Java bytecode, maybe because Sun has pushed that since the beginning as a defining feature of the language. Patrick

sjasja
Offline
Joined: 2004-08-15

> I get the impression that the performance improvements
> have not been so stunning as to encourage people to
> switch to compiling

Especially as the "improvement" tends to be [i]negative[/i] in general purpose programs (i.e. not specially constructed benchmarks)... Something as trivial as LinkedList.size() is hard for static compilers to inline.

(Except for short running programs that need to be optimized to the fullest; a situation which you may want to avoid by design.)

ronaldyang
Offline
Joined: 2003-06-19

I think Bea JRockit will keep a persistent cache for you.

sla
Offline
Joined: 2003-06-11

We had an experimental option to do this, but it has been removed in the later releases. Although it was a very promising technology we found the implementation it hard to maintain and the benefit wasn't big enough.

As someone else pointed out, JVMs do compile to native code in runtime and because of that can take advantage of the runtime profile of the program to optimize the code.

Regards,
/Staffan Larsen, JRockit Architect

sjasja
Offline
Joined: 2004-08-15

Hotspot already does compile to native code. It just doesn't write the compiled code to disk. By compiling dynamically it can make optimizations that are not possible or practical for static compilers, such as inlining "virtual" methods (non-final methods). Static compilation tends to slow down programs, not speed them up.

There has been work towards caching some of the compilation on disk though; that has some benefit for short-running programs. To get real benefits from that you need to be running lots of small short-running programs that need to be very fast.