# GraalVM

ES4X uses GraalVM, however the same code will run either in interpreted mode on Java 8, 9, 10 and OpenJ9.

For JDK >= 11 (with JVMCI support) or GraalVM ES4X runs in compiled mode.

TIP

In order words, please use Java >= 11 or GraalVM.

There are benefits on using GraalJS namely the updated language support >=ES6 and support out of the box for generators, promises, etc....

# Differences to Nashorn

Unlike Nashorn, GraalJS java interop follows the exact class/method name from Java. For example, the usage of property names to refer to getters and setters, must use the getter and setter. For example:

class Hello {
  private String name;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}

When using this Java Object from Graal, this will not work:

var hello = new Hello();
// get the name
var name = hello.name; // FAIL
// set the name
hello.name = 'Paulo';  // FAIL

This is not valid in Graal and should be:

var hello = new Hello();
// get the name
var name = hello.getName();
// set the name
hello.setName('Paulo');

# Threading

GraalJS is very strict with only a single thread on the JS context at a time. When working with only Asynchronous Vert.x APIs this shall not be an issue. However other libraries can cause problems. To avoid this limitation, it is advised to use the Worker API or the EventBus.

WARNING

GraalJS will not allow multi thread access to the same script context. If there is a need to work with multiple threads, then consider looking at the Worker API.

# Native Images

Currently you cannot generate native images with ES4X, the limitation is because the static analysis of the AOT compiler will not take in consideration the java code invoked from the script (so classes won't be available), plus the fact that the compiler has no support for jvm interop at runtime.

There is work in progress in this area so it might be possible in the future.