Background

Groovy has a performance problem, compared with Java, due to its dynamic nature, while there are several requests for performance improvement.

Proposed Solution

Implementing just-in-time compiler is a proper way to help boosting performance of Groovy. It would be great to have a Groovy module (in this case a JVMTI agent) to help transform/redefine Groovy classes during runtime.

Primitive Operations

As of Groovy 1.6-beta series, its performance has been improved but there are still problems occurred from primitive operations. All operand and results are heavily boxed and unboxed when primitive variables are used. The current implementation of GJIT provides the algorithm to unwrap almost binary operations back to be primitive. Thus, it can speed Groovy performance up when dealing with arithmetic calculation.

Implementation

This is the completely re-written version of GJIT. Basically, GJIT can be thought as a Hotspot-like compiler for Groovy. However it is working outside JVM, and not a part of the virtual machine. GJIT uses JVMTI, the virtual machine tool interface, to:

  1. Transform a class when it is being loaded, based on the assumption that the default metaclass provides the default behaviour.
  2. Redefine the class with the original one, when the metaclass of this class is modified.

Due to the use of JVMTI, GJIT supports Java 5 or later.

Usage

Add

  -javaagent:gjit.jar 

to your Java command line to use GJIT.

Missing Features and Known Bugs