Today Gluon have announced an exciting new development with the Gluon VM project: the Ahead of Time compiler.
After the acquisition and winding down of RoboVM, there was a fear that it would be the end of Java on mobile. In RoboVM’s absence, Gluon VM grew.
Gluon VM is a next-generation virtual machine designed for mobile and embedded platforms. For the first time, you can use Java 9 functionality in mobile platform applications, and deploy them on mobile iOS and Android devices using the app stores. By leveraging OpenJDK, there is full alignment with the latest versions of Java and it is completely compatible with JVMs for desktops and servers.
One half of the core of Gluon VM is the use of OpenJDK Mobile. A year ago Oracle announced the OpenJDK Mobile project. This focuses on porting the JDK to mobile platforms. It creates and maintains patches required for the VM and core class libraries on iOS and Android.
OpenJDK Mobile solves a key problem: in a typical Java environment the HotSpot Just in Time Compiler compiles Java bytecode to native code at runtime. Apple do not allow this for applications on iOS devices. The OpenJDK Mobile project uses the Zero Interpreter instead, which interprets bytecode and executes it. The benefit of this is that there is no assembly code, so there is little effort in using it in different platforms. However, interpreting bytecode using the Zero Interpreter is significantly slower than running native code, and in todays market, app users expect speed.
To overcome this, the other half of the Gluon VM core is the Ahead of Time (AOT) Compiler. This compiles Java bytecode into native code: a Java method is translated into a native function. The Gluon VM keeps track of translated native functions used in a static library. This is bundled with the VM and executed on the client.
The AOT compiler steps in before the Zero Interpreter. It checks to see if there is already a compiled native function for the requested Java method. If there isn’t, then the Zero Interpreter is used for the function. By keeping track of the functions that are and aren’t available natively the AOT can be gradually improved.
Speed for developers