I am unable to create ScriptEngine
for nashorn
in Java 8 (IBM J9JVM). In the following code, the engine is null
.
private static void runOther(String[] args){
ScriptEngineManager engineManager = new ScriptEngineManager();
ScriptEngine engine = engineManager.getEngineByName("nashorn");
engine.eval("function sum(a, b) { return a + b; }");
}
This failure is introduced by my library, which performs bytecode generation for MethodHandle in java.lang.invoke
package. The changes in my library are:
- the change are only for the standard
java.lang.invoke
package. None is changed for nashorn. - When nashorn is about to set a call site's target with
Methodhandle target
, my library will transform thetarget
into another method handleb
, if thetarget
is created fromGuardWithTestHandle
and set the call site's target tob
. Both 'targetand
b` has the same method type.
My last version of the library was completed in Oct 2016 and it was OK for Nashorn. But the new version I built has the WrongMethodTypeException
when executing getEngineByName
. This exception was handled inside of getEngineByName
and null is returned.
The nashorn source code I got is not consist with the nashorn.jar in JVM. During the debug, what I found was that the exception was from:
global = createNashornGlobal();
inside of NashornScriptEngine.<init>
. After digesting deep, the exception was thrown when doing MethodHandle invocation at UserAccessorProperty
(line318)
/* */ public Object getObjectValue(ScriptObject self, ScriptObject owner)
/* */ {
/* */ try {
/* 215 */ return invokeObjectGetter(getAccessors(owner != null ? owner : self), getObjectGetterInvoker(), self); //owner and self are the same instance.
/* */ } catch (Error|RuntimeException t) {
/* 217 */ throw t;
/* */ } catch (Throwable t) {
/* 219 */ throw new RuntimeException(t);
/* */ }
/* */ }
/* */ private static Object invokeObjectGetter(Accessors gs, MethodHandle invoker, Object self)
/* */ throws Throwable
/* */ {
/* 316 */ Object func = getter;
/* 317 */ if ((func instanceof ScriptFunction)) {
/* 318 */ return invoker.invokeExact(func, self);
/* */ }
/* */
/* 321 */ return ScriptRuntime.UNDEFINED;
/* */ }
At line 318, the invoker
is MutableCallSiteDynamicInvokerHandle
and its method type is (Object,Object)Object
. Both func
and self
are declared as Object
object here and types of parameters and return value are matched completely.
I can not understand this exception, and have no idea next steps for this issue. Thanks if you can provide some ideas and suggestion for the issue here? Or some options/configurations..