How is an elf file created

How do Java AOT compilers work?


There are a number of tools (Excelsior JET etc) that claim to turn Java apps into native executables (). I however understand that these tools are really just creating native wrappers invoked / executed from a shell or command line.

If this understanding is wrong, I don't see how it could be. If a running JVM (process) is basically a high performance interpreter that loads bytecode directly from Java class files, I can't imagine how a Java app (a collection of bytecode files that serve as input to a JVM ) could ever look really converted to an executable.

This is because the JVM process already is a native executable that takes sets of bytecode files as input. Merging these bytecode files and the JVM process into a single unified native executable does not appear to be possible without completely rewriting the JVM and removing the railing from the JVM spec.

So I ask: like these tools indeed Do they "turn" Java class files into a native executable?

Reply:


All programs have a runtime environment. We tend to forget about this, but it is there. Standard library for C that binds system calls to the operating system. Objective-C has a runtime environment that wraps all message delivery.

With Java, the runtime is the JVM. Most known Java implementations are similar to the HotSpot JVM, which is a bytecode interpreter and JIT compiler.

It doesn't have to be the only implementation. There's absolutely nothing to say that you can't create a standard lib-esque runtime for Java and compile the code into native machine code and run that within the runtime that handles calls for new objects in mallocs and file accesses in system calls on the machine. And that is exactly what the AOT compiler does (AOT instead of JIT). Call this runtime what you ... you could call it a JVM implementation (and it is the JVM specification) or a runtime environment or standard lib for Java. It's there and it essentially does the same thing.

This could either be done by reimplementing to target the native computer (as GCJ did). Or you can convert the byte code generated by to machine code (or byte code) for another machine - that's exactly what Android does. Based on Wikipedia, this is what Excelsior JET does ("The compiler converts the portable Java byte code into optimized executable files for the desired hardware and operating system (OS)"), and the same goes for RoboVM.

There are additional complications with Java, which means that this is an exclusive approach very is difficult. The dynamic loading of classes () or proxy objects requires a dynamic that cannot easily be provided by AOT compilers. Therefore, the corresponding JVMs must contain either a JIT compiler (Excelsior JET) or an interpreter (GCJ) in order to be able to process classes into which no precompilation is possible.

Remember, JVM is a specification, with many implementations. The C standard library is also a specification with many different implementations.

Some work has been done on the AOT compilation with Java8. At best, AOT can generally only be summarized within the boundaries of the text box. At the JVM Language Summit 2015 (August 2015), however, there was a presentation: Java Goes AOT (Youtube video). This video is 40 minutes long and goes into many of the deeper technicals and performance benchmarks.




minimally executable example

You can also watch an open source implementation like (now deprecated). E.g. Java file:

Then compile and run with:

Now you can decompile it and see how it works.

says it's an elf file.

It depends on the dynamic libraries:

Therefore, in libgcj.so the Java functionality must be implemented.

You can then decompile it with:

and see exactly how it is implemented.

Looks similar to C ++, lots of name confusion and indirect polymorphic function calls.

I wonder what is the effect of garbage collection. It's worth taking a look: / programming / 7100776 / garbage-collection-implementation-in-compiled-languages ​​and other compiled languages ​​with GC like Go.

Tested on Ubuntu 14.04, GCC 4.8.4.

Also check out https://en.wikipedia.org/wiki/Android_Runtime, the backbone of Android 5 and above that has AOT capabilities for optimizing Android apps.

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.