Skip to content

Verify if GraalVM is used

due to Nashorn being discontinued we are currently trying to change our (still Java 8) application (very big monolith) from Nashorn to GraalVM. Due to the application being used as library in multiple projects, instead of using the whole GraalVM runtime we decided to just adding the necessary jars to the class path (which seem to work so far).

To use GraalVM, I changed all occurrences of getEngineByName to graal.js as follow:

ScriptEngineManager sem = new ScriptEngineManager(null);
scriptEngine = sem.getEngineByName("graal.js");

Due to the application being very complex, understanding every aspect of the application is relatively difficult and I was wondering if there is a way of verifying what JavaScript engine is used with the prepared JavaScript string as input? My goal is to write a Unit test which verifies for every method which takes JavaScript as input, if GraalVM is really used.

What would be the best approach to achieve this?

Answer

you can compare the class name of the script engine with com.oracle.truffle.js.scriptengine.GraalJSScriptEngine something like this:

ScriptEngine  scriptEngine = new ScriptEngineManager().getEngineByName("graal.js");
            String engineName = scriptEngine.getClass().getName();
            boolean isGraalJS = engineName.equals("com.oracle.truffle.js.scriptengine.GraalJSScriptEngine");
            System.out.println(isGraalJS);